Skip to content

Commit

Permalink
Correctly handle class declarations inside functions. Fixes dop251#530.
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Aug 28, 2023
1 parent 81d7606 commit 3dbe69d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,8 @@ func (c *compiler) compileLexicalDeclarationsFuncBody(list []ast.Statement, call
c.createLexicalIdBindingFuncBody(name, isConst, offset, calleeBinding)
})
}
} else if cls, ok := st.(*ast.ClassDeclaration); ok {
c.createLexicalIdBindingFuncBody(cls.Class.Name.Name, false, int(cls.Class.Name.Idx)-1, calleeBinding)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5814,6 +5814,18 @@ func TestGeneratorMethods(t *testing.T) {
testScriptWithTestLib(SCRIPT, _undefined, t)
}

func TestFunctionBodyClassDecl(t *testing.T) {
const SCRIPT = `
function as(requiredArgument = {}) {
class something { }
};
`
_, err := Compile("", SCRIPT, false)
if err != nil {
t.Fatal(err)
}
}

/*
func TestBabel(t *testing.T) {
src, err := os.ReadFile("babel7.js")
Expand Down

0 comments on commit 3dbe69d

Please sign in to comment.