Skip to content

Commit cb504a0

Browse files
committed
fix(compiler): taint autoMemo locals from pattern sources, for-of/in declarations, and nested scopes
collectAutoMemoLocalHazards.feed now: - checks the binding pattern (not just the RHS) for isDeferredRefRead and containsImportedMemberRead, catching destructuring like `const { current } = refObj` and `const { v = ref.current } = props`; - collects free identifiers from pattern expression positions (defaults, computed keys) so transitive tainting propagates through them; The walk now: - feeds for-of/in declarations (`for (const x of hazardous)`), which were explicitly skipped when the LHS was a VariableDeclaration; - feeds nested VariableDeclaration nodes anywhere in the body, not only top-level ones.
1 parent 16cfb6c commit cb504a0

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

‎packages/octane/src/compiler/compile.js‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4243,17 +4243,26 @@ function collectAutoMemoLocalHazards(stmts, importedNames) {
42434243
const names = new Set();
42444244
collectBindings(pattern, names);
42454245
if (names.size === 0) return;
4246-
const direct = containsDeferredRefRead(rhs) || containsImportedMemberRead(rhs, importedNames);
4247-
for (const name of names) {
4248-
if (hazards.has(name)) continue;
4249-
if (direct) {
4246+
const direct =
4247+
containsDeferredRefRead(rhs) ||
4248+
containsImportedMemberRead(rhs, importedNames) ||
4249+
containsDeferredRefRead(pattern) ||
4250+
containsImportedMemberRead(pattern, importedNames);
4251+
if (direct) {
4252+
for (const name of names) {
42504253
hazards.add(name);
42514254
sourceFrees.delete(name);
4252-
continue;
42534255
}
4256+
return;
4257+
}
4258+
const rhsFree = collectFreeIdentifiers(rhs, []);
4259+
const patFree = collectFreeIdentifiers(pattern, names);
4260+
for (const name of names) {
4261+
if (hazards.has(name)) continue;
42544262
let set = sourceFrees.get(name);
42554263
if (set === undefined) sourceFrees.set(name, (set = new Set()));
4256-
for (const id of collectFreeIdentifiers(rhs, [])) set.add(id);
4264+
for (const id of rhsFree) set.add(id);
4265+
for (const id of patFree) set.add(id);
42574266
}
42584267
};
42594268
for (const stmt of stmts) {
@@ -4276,12 +4285,14 @@ function collectAutoMemoLocalHazards(stmts, importedNames) {
42764285
seen.add(n);
42774286
if (n.type === 'AssignmentExpression' && n.left?.type !== 'MemberExpression') {
42784287
feed(n.left, n.right);
4279-
} else if (
4280-
(n.type === 'ForOfStatement' || n.type === 'ForInStatement') &&
4281-
n.left &&
4282-
n.left.type !== 'VariableDeclaration'
4283-
) {
4284-
feed(n.left, n.right);
4288+
} else if ((n.type === 'ForOfStatement' || n.type === 'ForInStatement') && n.left) {
4289+
if (n.left.type === 'VariableDeclaration') {
4290+
for (const d of n.left.declarations || []) feed(d.id, n.right);
4291+
} else {
4292+
feed(n.left, n.right);
4293+
}
4294+
} else if (n.type === 'VariableDeclaration') {
4295+
for (const d of n.declarations || []) feed(d.id, d.init);
42854296
}
42864297
for (const key in n) {
42874298
if (AST_WALK_SKIP_KEYS.has(key)) continue;

0 commit comments

Comments
 (0)