Skip to content

Commit 7ee1e6d

Browse files
committed
fix: Complete Scene VarDecls codegen and fix mage WASM build issues
This commit completes the declarative reactive transform implementation by fixing the code generation and build system: Codegen fixes: - Generate VarDecls in Scene's RenderScene method body - Add WithGeometry, WithMaterial, BindRotation to runtime functions list - Properly structure method body with variable declarations before return Magefile fixes: - Exclude pkg/runtime from Test() - WASM tests require browser runtime - Exclude pkg/runtime from Build() - needs WASM build tags - Align with CI workflow which tests/builds WASM packages separately - Add explicit package lists matching CI behavior This enables scene_gen.go to properly include local variable declarations like rotZ and use the new reactive binding functions with runtime. prefix.
1 parent ee15ef7 commit 7ee1e6d

2 files changed

Lines changed: 60 additions & 9 deletions

File tree

magefile.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,44 @@ func Vet() error {
3939
return sh.RunWith(env, "go", "vet", "./pkg/runtime/...")
4040
}
4141

42-
// Test runs all tests
42+
// Test runs all tests (excluding WASM-only packages)
4343
func Test() error {
4444
fmt.Println("Running tests...")
45-
return sh.RunV("go", "test", "./...")
45+
// Test non-WASM packages (exclude runtime which requires WASM runtime to execute)
46+
packages := []string{
47+
"./cmd/...",
48+
"./internal/...",
49+
"./pkg/ast",
50+
"./pkg/codegen",
51+
"./pkg/parser",
52+
"./pkg/visitors",
53+
}
54+
for _, pkg := range packages {
55+
if err := sh.RunV("go", "test", pkg); err != nil {
56+
return err
57+
}
58+
}
59+
return nil
4660
}
4761

48-
// Build builds all packages for native target
62+
// Build builds all packages for native target (excluding WASM-only packages)
4963
func Build() error {
5064
fmt.Println("Building native packages...")
51-
return sh.RunV("go", "build", "./...")
65+
// Build non-WASM packages (exclude runtime which is WASM-only)
66+
packages := []string{
67+
"./cmd/...",
68+
"./internal/...",
69+
"./pkg/ast",
70+
"./pkg/codegen",
71+
"./pkg/parser",
72+
"./pkg/visitors",
73+
}
74+
for _, pkg := range packages {
75+
if err := sh.RunV("go", "build", pkg); err != nil {
76+
return err
77+
}
78+
}
79+
return nil
5280
}
5381

5482
// BuildWasm builds the runtime package for WebAssembly

pkg/codegen/codegen.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,27 @@ func (g *Generator) generateSceneConstructor(comp *guixast.Component) *ast.FuncD
745745

746746
// generateRenderSceneMethod generates the RenderScene method for a Scene component
747747
func (g *Generator) generateRenderSceneMethod(comp *guixast.Component) *ast.FuncDecl {
748+
// Generate variable declarations first
749+
var stmts []ast.Stmt
750+
if comp.Body != nil && len(comp.Body.VarDecls) > 0 {
751+
for _, varDecl := range comp.Body.VarDecls {
752+
// Generate: varName := value
753+
var lhs []ast.Expr
754+
for _, name := range varDecl.Names {
755+
lhs = append(lhs, ast.NewIdent(name))
756+
}
757+
var rhs []ast.Expr
758+
for _, value := range varDecl.Values {
759+
rhs = append(rhs, g.generateExpr(value))
760+
}
761+
stmts = append(stmts, &ast.AssignStmt{
762+
Lhs: lhs,
763+
Tok: token.DEFINE, // :=
764+
Rhs: rhs,
765+
})
766+
}
767+
}
768+
748769
// Generate scene graph from body children
749770
var sceneNode ast.Expr
750771
if comp.Body != nil && len(comp.Body.Children) > 0 {
@@ -760,6 +781,11 @@ func (g *Generator) generateRenderSceneMethod(comp *guixast.Component) *ast.Func
760781
}
761782
}
762783

784+
// Add return statement
785+
stmts = append(stmts, &ast.ReturnStmt{
786+
Results: []ast.Expr{sceneNode},
787+
})
788+
763789
return &ast.FuncDecl{
764790
Recv: &ast.FieldList{
765791
List: []*ast.Field{
@@ -787,11 +813,7 @@ func (g *Generator) generateRenderSceneMethod(comp *guixast.Component) *ast.Func
787813
},
788814
},
789815
Body: &ast.BlockStmt{
790-
List: []ast.Stmt{
791-
&ast.ReturnStmt{
792-
Results: []ast.Expr{sceneNode},
793-
},
794-
},
816+
List: stmts,
795817
},
796818
}
797819
}
@@ -1867,6 +1889,7 @@ var runtimeFunctions = map[string]bool{
18671889
"LookAtPos": true, "Background": true,
18681890
"Width": true, "Height": true,
18691891
"GeometryProp": true, "MaterialProp": true, "GPURenderUpdate": true,
1892+
"WithGeometry": true, "WithMaterial": true, "BindRotation": true,
18701893
// GPU constructors
18711894
"NewBoxGeometry": true, "NewSphereGeometry": true, "NewPlaneGeometry": true,
18721895
"StandardMaterial": true,

0 commit comments

Comments
 (0)