Skip to content

Commit 0643242

Browse files
committed
fix(compiler): collect arm-local bindings in singleRoot if-dep proof
armOk in collectSingleRootIfDeps filtered arm statements down to JSX/if-directive nodes and passed only component-level locals into singleRootComponentArmName. A const or function declared inside an @if/@else arm that shadows a same-module component was invisible to both checks, so the shadow resolved to the module-level componentInfo entry. This could falsely widen info.singleRoot, causing callers to take the markerless regime for output that may not be a single element. Collect VariableDeclaration and FunctionDeclaration bindings from each arm's full statement list into an extended locals set, so arm-level shadows are properly rejected by the existing locals.has(name) guard.
1 parent 16c62f2 commit 0643242

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5005,12 +5005,25 @@ function collectSingleRootIfDeps(render, locals, ctx) {
50055005
const deps = new Set();
50065006
const armOk = (arm) => {
50075007
if (isIfDirective(arm)) return ifOk(arm);
5008-
const out = statementsOf(arm).filter((s) => isJsxNode(s) || isIfDirective(s));
5008+
const all = statementsOf(arm);
5009+
const out = all.filter((s) => isJsxNode(s) || isIfDirective(s));
50095010
if (out.length !== 1) return false;
50105011
const sole = out[0];
50115012
if (isIfDirective(sole)) return ifOk(sole);
50125013
if (isPlainHostRoot(sole)) return true;
5013-
const name = singleRootComponentArmName(sole, locals, ctx);
5014+
let armLocals = locals;
5015+
for (const s of all) {
5016+
if (s.type === 'VariableDeclaration') {
5017+
for (const d of s.declarations || []) {
5018+
if (armLocals === locals) armLocals = new Set(locals);
5019+
collectBindings(d.id, armLocals);
5020+
}
5021+
} else if (s.type === 'FunctionDeclaration' && s.id) {
5022+
if (armLocals === locals) armLocals = new Set(locals);
5023+
armLocals.add(s.id.name);
5024+
}
5025+
}
5026+
const name = singleRootComponentArmName(sole, armLocals, ctx);
50145027
if (name === null) return false;
50155028
deps.add(name);
50165029
return true;

0 commit comments

Comments
 (0)