Skip to content

Commit 0fa3008

Browse files
committed
fix(compiler): add enum member scope and computed key walk to client-only check
The TSEnumDeclaration handler in assertNoLiveClientOnlyImports was missing two things that the universal lexical analysis already handles correctly: 1. Enum member names were never recorded as scope bindings, so a later initializer referencing an earlier member whose name shadows a client-only import would falsely throw OCTANE_CLIENT_ONLY_SERVER_USE. 2. Computed member keys were never walked, so a client-only binding used only as a computed enum key was never detected. Fix by creating an enum scope (with the enum's own name and all non- computed member identifier names) before walking members, and visiting computed member keys alongside initializers. Also add TSEnumMember to isReferenceIdentifier so non-computed keys are not treated as references.
1 parent 268166f commit 0fa3008

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎packages/octane/src/compiler/client-only-server.js‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,20 @@ export function assertNoLiveClientOnlyImports(
562562
// smuggle a client-only binding into the server graph.
563563
if (node.type === 'TSEnumDeclaration') {
564564
if (node.declare !== true) {
565-
for (const member of node.body?.members ?? [])
565+
const members = node.body?.members ?? [];
566+
const enumBindings = new Set();
567+
if (node.id?.name) enumBindings.add(node.id.name);
568+
for (const member of members) {
569+
if (member.computed !== true && member.id?.type === 'Identifier') {
570+
enumBindings.add(member.id.name);
571+
}
572+
}
573+
scopes.push(enumBindings);
574+
for (const member of members) {
575+
if (member.computed === true) visit(member.id, member, 'id');
566576
visit(member.initializer, member, 'initializer');
577+
}
578+
scopes.pop();
567579
}
568580
return;
569581
}
@@ -744,6 +756,8 @@ function isReferenceIdentifier(node, parent, key) {
744756
return parent.computed === true || parent.shorthand === true;
745757
}
746758
if (parent.type === 'MethodDefinition' && key === 'key' && !parent.computed) return false;
759+
if (parent.type === 'TSEnumMember' && (key === 'key' || key === 'id') && !parent.computed)
760+
return false;
747761
if (parent.type === 'LabeledStatement' && key === 'label') return false;
748762
if (
749763
(parent.type === 'BreakStatement' || parent.type === 'ContinueStatement') &&

0 commit comments

Comments
 (0)