Skip to content

Commit 813ceb3

Browse files
committed
fix(compiler): unwrap callee in producer skip and trustedFactory
Parenthesized or TypeScript-wrapped callees (e.g. `(derived$)(...)` or `derived$!(...)`) were not recognized by the producer skip in `declaredUses` or by either `trustedFactory`, because both inspected `node.callee` directly instead of peeling wrappers with `unwrapExpression`. This caused method calls inside factory arguments to be lowered through `__declared`, resolving the declaring cell instead of the reader's. Apply `unwrapExpression` to the callee in both `trustedFactory` copies and in the second branch of the producer skip, matching the unwrap the later method-call path already performs.
1 parent babfb44 commit 813ceb3

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

‎packages/octane/src/compiler/signal-declarations.js‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -527,16 +527,17 @@ function declaredUses(ast, lexical, owners, trusted) {
527527
for (const child of node) visit(child, producer);
528528
return;
529529
}
530-
if (
531-
(node.type === 'CallExpression' || node.type === 'OptionalCallExpression') &&
532-
(trusted(node) !== null ||
533-
((node.callee?.type === 'MemberExpression' ||
534-
node.callee?.type === 'OptionalMemberExpression') &&
535-
SIGNAL_FACTORIES.has(propertyName(node.callee))))
536-
) {
537-
visit(node.callee, producer);
538-
visit(node.arguments, true);
539-
return;
530+
if (node.type === 'CallExpression' || node.type === 'OptionalCallExpression') {
531+
const callee = unwrapExpression(node.callee);
532+
if (
533+
trusted(node) !== null ||
534+
((callee?.type === 'MemberExpression' || callee?.type === 'OptionalMemberExpression') &&
535+
SIGNAL_FACTORIES.has(propertyName(callee)))
536+
) {
537+
visit(node.callee, producer);
538+
visit(node.arguments, true);
539+
return;
540+
}
540541
}
541542
const callee =
542543
node.type === 'CallExpression' || node.type === 'OptionalCallExpression'
@@ -620,7 +621,7 @@ export function lowerSignalDeclarations(ast, filename, options) {
620621
// lowered helpers, or null for any other call.
621622
function trustedFactory(node) {
622623
if (node.type !== 'CallExpression' && node.type !== 'OptionalCallExpression') return null;
623-
const callee = node.callee;
624+
const callee = unwrapExpression(node.callee);
624625
const scope = lexical.nodeScopes.get(callee) ?? lexical.rootScope;
625626
if (callee?.type === 'Identifier') {
626627
const record = namedImports.get(callee.name);
@@ -792,7 +793,7 @@ export function signalDeclarationSourceEdits(ast, filename, source, options) {
792793
// lowered helpers, or null for any other call.
793794
const trustedFactory = (node) => {
794795
if (node.type !== 'CallExpression' && node.type !== 'OptionalCallExpression') return null;
795-
const callee = node.callee;
796+
const callee = unwrapExpression(node.callee);
796797
const scope = lexical.nodeScopes.get(callee) ?? lexical.rootScope;
797798
if (callee?.type === 'Identifier') {
798799
const record = namedImports.get(callee.name);

0 commit comments

Comments
 (0)