Skip to content

Commit e8dc414

Browse files
committed
fix(compiler): handle nested awaits in settled and resolve helper event types
Bug 1: settled() treated AwaitExpression as non-thenable via nonPromise(), so await (cond ? await load() : null) was classified as zero-delay. Add an AwaitExpression case that recurses on the argument, and make ConditionalExpression and LogicalExpression use staticValue to skip unreachable branches. Bug 2: eventType() and captureOf() used staticValue() which does not follow frameArgument, so helper parameters always resolved to UNKNOWN. UNKNOWN matches any type/capture, letting mismatched event types or capture flags pass as valid releases. Add frameArgument resolution to both functions.
1 parent e466050 commit e8dc414

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

‎packages/octane/src/compiler/strong-effects.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,23 @@ export function createStrongEffectPolicy({ ast, analysis, callNames, report }) {
341341
switch (node?.type) {
342342
case 'SequenceExpression':
343343
return settled(node.expressions?.at(-1), depth);
344-
case 'ConditionalExpression':
344+
case 'ConditionalExpression': {
345+
const test = staticValue(node.test);
346+
if (test !== UNKNOWN) return settled(test ? node.consequent : node.alternate, depth);
345347
return settled(node.consequent, depth) && settled(node.alternate, depth);
346-
case 'LogicalExpression':
347-
return settled(node.left, depth) && settled(node.right, depth);
348+
}
349+
case 'LogicalExpression': {
350+
if (!settled(node.left, depth)) return false;
351+
const left = staticValue(node.left);
352+
if (left !== UNKNOWN) {
353+
const rightReachable =
354+
node.operator === '??' ? left == null : node.operator === '&&' ? Boolean(left) : !left;
355+
return !rightReachable || settled(node.right, depth);
356+
}
357+
return settled(node.right, depth);
358+
}
359+
case 'AwaitExpression':
360+
return settled(node.argument, depth);
348361
case 'Identifier': {
349362
const init = depth < 8 ? stableInitOf(node) : null;
350363
if (init !== null) return settled(init, depth + 1);
@@ -697,14 +710,29 @@ export function createStrongEffectPolicy({ ast, analysis, callNames, report }) {
697710

698711
// --- platform resources --------------------------------------------------
699712

700-
function eventType(expression) {
713+
function eventType(expression, depth = 0) {
714+
const node = unwrap(expression);
715+
if (node?.type === 'Identifier' && depth < 8) {
716+
const binding = bindingOf(node);
717+
if (binding) {
718+
const argument = frameArgument(binding);
719+
if (argument !== null) return eventType(argument, depth + 1);
720+
}
721+
}
701722
const value = staticValue(expression);
702723
return typeof value === 'string' ? value : UNKNOWN;
703724
}
704725

705-
function captureOf(expression) {
726+
function captureOf(expression, depth = 0) {
706727
const node = unwrap(expression);
707728
if (node == null) return false;
729+
if (node.type === 'Identifier' && depth < 8) {
730+
const binding = bindingOf(node);
731+
if (binding) {
732+
const argument = frameArgument(binding);
733+
if (argument !== null) return captureOf(argument, depth + 1);
734+
}
735+
}
708736
if (node.type === 'ObjectExpression') {
709737
let capture = false;
710738
for (const property of node.properties ?? []) {

0 commit comments

Comments
 (0)