File tree 2 files changed +52
-0
lines changed
packages/svelte/src/compiler/phases
3-transform/client/visitors
2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments