Skip to content

Commit 509f453

Browse files
committed
fix(compiler): exclude var initializers from localInit in strong effect analysis
var declarations are hoisted with undefined before their initializer runs, so crediting a var initializer as already evaluated can let awaitYields falsely treat `await ready` as yielding when ready is still undefined. Only const/let bindings (which have TDZ) guarantee their initializer ran before any reference.
1 parent 9ed465a commit 509f453

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎packages/octane/src/compiler/strong-effects.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,17 @@ export function createStrongEffectPolicy({ ast, analysis, callNames, report }) {
276276
return maySettle(argument);
277277
},
278278
// The stable initializer of a binding declared in the function that reads
279-
// it: that initializer ran earlier on the same path.
279+
// it: that initializer ran earlier on the same path. `var` is excluded
280+
// because its hoisted binding is `undefined` before the declaration runs.
280281
localInit(expression) {
281282
const node = unwrap(expression);
282283
if (node?.type !== 'Identifier') return null;
283284
const scope = nodeScopes.get(node);
284285
const binding = bindingOf(node);
285286
if (scope === undefined || binding == null || binding.scope == null) return null;
286-
return functionScopeOf(binding.scope) === functionScopeOf(scope) ? stableInit(binding) : null;
287+
if (functionScopeOf(binding.scope) !== functionScopeOf(scope)) return null;
288+
if (declarator(binding)?.kind === 'var') return null;
289+
return stableInit(binding);
287290
},
288291
// A provably known operand value, as `{ value }`, or null.
289292
literal(expression) {

0 commit comments

Comments
 (0)