mirror of https://github.com/sveltejs/svelte
parent
0c0fd47b39
commit
91399eeb85
@ -0,0 +1,35 @@
|
|||||||
|
/** @import { AwaitExpression } from 'estree' */
|
||||||
|
/** @import { Context } from '../types' */
|
||||||
|
import { extract_identifiers } from '../../../utils/ast.js';
|
||||||
|
import * as w from '../../../warnings.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AwaitExpression} node
|
||||||
|
* @param {Context} context
|
||||||
|
*/
|
||||||
|
export function AwaitExpression(node, context) {
|
||||||
|
const declarator = context.path.at(-1);
|
||||||
|
const declaration = context.path.at(-2);
|
||||||
|
const program = context.path.at(-3);
|
||||||
|
|
||||||
|
if (context.state.ast_type === 'instance') {
|
||||||
|
if (
|
||||||
|
declarator?.type !== 'VariableDeclarator' ||
|
||||||
|
context.state.function_depth !== 1 ||
|
||||||
|
declaration?.type !== 'VariableDeclaration' ||
|
||||||
|
program?.type !== 'Program'
|
||||||
|
) {
|
||||||
|
throw new Error('TODO: invalid usage of AwaitExpression in component');
|
||||||
|
}
|
||||||
|
for (const declarator of declaration.declarations) {
|
||||||
|
for (const id of extract_identifiers(declarator.id)) {
|
||||||
|
const binding = context.state.scope.get(id.name);
|
||||||
|
if (binding !== null) {
|
||||||
|
binding.kind = 'derived';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.next();
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
/** @import { AwaitExpression, Expression } from 'estree' */
|
||||||
|
/** @import { ComponentContext } from '../types' */
|
||||||
|
|
||||||
|
import * as b from '../../../../utils/builders.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AwaitExpression} node
|
||||||
|
* @param {ComponentContext} context
|
||||||
|
*/
|
||||||
|
export function AwaitExpression(node, context) {
|
||||||
|
// Inside component
|
||||||
|
if (context.state.analysis.instance) {
|
||||||
|
return b.call('$.await_derived', b.thunk(/** @type {Expression} */ (context.visit(node.argument))));
|
||||||
|
}
|
||||||
|
|
||||||
|
context.next();
|
||||||
|
}
|
Loading…
Reference in new issue