Skip to content

Fix var/lexical name hoisting for destructuring patterns#2360

Merged
lahma merged 2 commits into
sebastienros:mainfrom
lahma:fix/var-destructuring-hoisting
Mar 25, 2026
Merged

Fix var/lexical name hoisting for destructuring patterns#2360
lahma merged 2 commits into
sebastienros:mainfrom
lahma:fix/var-destructuring-hoisting

Conversation

@lahma

@lahma lahma commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • HoistingScope.ScriptWalker only collected Identifier names when building _varNames and _lexicalNames, silently skipping destructuring patterns (ArrayPattern, ObjectPattern, etc.)
  • This caused variables like x in for await (var [[x] = [1]] of [[]]) to not be hoisted into the function scope, resulting in ReferenceError in strict mode (sloppy mode worked because undeclared assignments create implicit globals)
  • Use the existing GetBoundNames() method (from AstExtensions) which correctly recurses into all pattern types — the same method already used by Engine.Ast.cs and Engine.cs for declaration instantiation

Test plan

  • "use strict"; async function fn() { for await (var [[x] = [1]] of [[]]) print(x); } now prints 1 (was ReferenceError)
  • All async-func-dstr-var and async-gen-dstr-var test262 tests pass (632 tests)
  • Full test262 suite: 95,999 passed, 0 failures, 0 regressions

Fixes #2354

🤖 Generated with Claude Code

lahma and others added 2 commits March 25, 2026 07:34
HoistingScope.ScriptWalker only collected Identifier names when building
_varNames and _lexicalNames, silently skipping destructuring patterns
(ArrayPattern, ObjectPattern). This caused variables like x in
`for await (var [[x] = [1]] of [[]])` to not be hoisted into the
function scope, resulting in ReferenceError in strict mode.

Use the existing GetBoundNames() method (from AstExtensions) which
correctly recurses into all pattern types. This is the same method
already used by Engine.Ast.cs and Engine.cs for declaration instantiation.

Fixes sebastienros#2354

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lahma
lahma enabled auto-merge (squash) March 25, 2026 05:43
@lahma
lahma merged commit 9e90fd4 into sebastienros:main Mar 25, 2026
7 of 8 checks passed
@lahma
lahma deleted the fix/var-destructuring-hoisting branch July 13, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Jint.Tests.Test262 doesn't properly check async tests

1 participant