Skip to content

Commit 2bd751b

Browse files
committed
fix(compiler): annotate OptionalCallExpression with import provenance for setup detection
Optional hook calls (e.g. readContext?.()) using aliased imports were not recognized as setup hooks by the auto-memo/Strong system. The hook-deps annotation pass only stamped _octaneImportedHook on CallExpression nodes, so autoMemoBuiltinHookName and containsAutoMemoContextRead could not resolve the canonical hook name for OptionalCallExpression with renamed bindings. - Extend hook-deps.js walk to annotate OptionalCallExpression nodes with _octaneImportedHook, _octaneUnboundCallee, and _octaneHookRuntimeImportedHook in callAnnotations. - Extend containsAutoMemoContextRead to check both CallExpression and OptionalCallExpression for context/use reads.
1 parent 0bf9d7f commit 2bd751b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4178,7 +4178,10 @@ function containsAutoMemoContextRead(root, ctx) {
41784178
) {
41794179
return;
41804180
}
4181-
if (node.type === 'CallExpression' && node.callee?.type === 'Identifier') {
4181+
if (
4182+
(node.type === 'CallExpression' || node.type === 'OptionalCallExpression') &&
4183+
node.callee?.type === 'Identifier'
4184+
) {
41824185
const name =
41834186
node._octaneImportedHook ??
41844187
node._octaneHookRuntimeImportedHook ??

‎packages/octane/src/compiler/hook-deps.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,21 @@ function buildScopes(ast, onlyImported, hookRuntimeModules, bindingsOnly = false
605605
if (trustedConfig && node.arguments.length === trustedConfig.deps) {
606606
candidates.push({ call: node, scope, name: trustedName, config: trustedConfig });
607607
}
608+
} else if (node.type === 'OptionalCallExpression') {
609+
const octaneImportedName = canonicalOctaneHookName(node, scope);
610+
const callee = unwrapValue(node.callee);
611+
const unboundCallee =
612+
callee?.type === 'Identifier' && resolveBinding(scope, callee.name) === null;
613+
const hookRuntimeImportedName = canonicalHookName(node, scope, true);
614+
if (octaneImportedName !== null || unboundCallee || hookRuntimeImportedName !== null) {
615+
const props = {};
616+
if (octaneImportedName !== null) props._octaneImportedHook = octaneImportedName;
617+
if (unboundCallee) props._octaneUnboundCallee = true;
618+
if (octaneImportedName === null && hookRuntimeImportedName !== null) {
619+
props._octaneHookRuntimeImportedHook = hookRuntimeImportedName;
620+
}
621+
callAnnotations.set(node, props);
622+
}
608623
}
609624

610625
if (node.type?.startsWith('TS') && !TS_VALUE_WRAPPERS.has(node.type)) return;

0 commit comments

Comments
 (0)