Skip to content

Commit 78bb187

Browse files
committed
another fix
1 parent ad1c214 commit 78bb187

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/** @import { AwaitExpression } from 'estree' */
2+
/** @import { Context } from '../types' */
3+
import { extract_identifiers } from '../../../utils/ast.js';
4+
import * as w from '../../../warnings.js';
5+
6+
/**
7+
* @param {AwaitExpression} node
8+
* @param {Context} context
9+
*/
10+
export function AwaitExpression(node, context) {
11+
const declarator = context.path.at(-1);
12+
const declaration = context.path.at(-2);
13+
const program = context.path.at(-3);
14+
15+
if (context.state.ast_type === 'instance') {
16+
if (
17+
declarator?.type !== 'VariableDeclarator' ||
18+
context.state.function_depth !== 1 ||
19+
declaration?.type !== 'VariableDeclaration' ||
20+
program?.type !== 'Program'
21+
) {
22+
throw new Error('TODO: invalid usage of AwaitExpression in component');
23+
}
24+
for (const declarator of declaration.declarations) {
25+
for (const id of extract_identifiers(declarator.id)) {
26+
const binding = context.state.scope.get(id.name);
27+
if (binding !== null) {
28+
binding.kind = 'derived';
29+
}
30+
}
31+
}
32+
}
33+
34+
context.next();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @import { AwaitExpression, Expression } from 'estree' */
2+
/** @import { ComponentContext } from '../types' */
3+
4+
import * as b from '../../../../utils/builders.js';
5+
6+
/**
7+
* @param {AwaitExpression} node
8+
* @param {ComponentContext} context
9+
*/
10+
export function AwaitExpression(node, context) {
11+
// Inside component
12+
if (context.state.analysis.instance) {
13+
return b.call('$.await_derived', b.thunk(/** @type {Expression} */ (context.visit(node.argument))));
14+
}
15+
16+
context.next();
17+
}

0 commit comments

Comments
 (0)