JS: Emit variables for 'this'

The extractor does not emit bindings for 'this', we just ensure that a variable exists for it
This commit is contained in:
Asger F
2026-02-25 10:16:21 +01:00
parent f0e665d08c
commit e0ab5ce49b

View File

@@ -819,6 +819,7 @@ public class ASTExtractor {
// add all declared global (or module-scoped) names, both non-lexical and lexical
scopeManager.addNames(scopeManager.collectDeclaredNames(nd, isStrict, false, DeclKind.none));
scopeManager.addNames(scopeManager.collectDeclaredNames(nd, isStrict, true, DeclKind.none));
scopeManager.addVariables("this");
visitAll(nd.getBody(), toplevelLabel);
@@ -1070,6 +1071,9 @@ public class ASTExtractor {
scopeManager.enterScope((Node) nd);
scopeManager.addNames(locals);
if (!(nd instanceof ArrowFunctionExpression)) {
scopeManager.addVariables("this");
}
// The name of a function expression binds to its own scope.
if (nd.getId() != null && nd instanceof AFunctionExpression) {