Skip to content

Commit f3daef7

Browse files
committed
tweak
1 parent 201bf37 commit f3daef7

File tree

5 files changed

+10
-30
lines changed

5 files changed

+10
-30
lines changed

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,7 @@ export function analyze_module(source, options) {
302302
function_depth: 0,
303303
has_props_rune: false,
304304
options: /** @type {ValidatedCompileOptions} */ (options),
305-
fragment: {
306-
has_await: false,
307-
node: null
308-
},
305+
fragment: null,
309306
parent_element: null,
310307
reactive_statement: null
311308
},
@@ -694,10 +691,7 @@ export function analyze_component(root, source, options) {
694691
analysis,
695692
options,
696693
ast_type: ast === instance.ast ? 'instance' : ast === template.ast ? 'template' : 'module',
697-
fragment: {
698-
has_await: false,
699-
node: ast === template.ast ? template.ast : null
700-
},
694+
fragment: ast === template.ast ? ast : null,
701695
parent_element: null,
702696
has_props_rune: false,
703697
component_slots: new Set(),
@@ -763,10 +757,7 @@ export function analyze_component(root, source, options) {
763757
scopes,
764758
analysis,
765759
options,
766-
fragment: {
767-
has_await: false,
768-
node: ast === template.ast ? template.ast : null
769-
},
760+
fragment: ast === template.ast ? ast : null,
770761
parent_element: null,
771762
has_props_rune: false,
772763
ast_type: ast === instance.ast ? 'instance' : ast === template.ast ? 'template' : 'module',

packages/svelte/src/compiler/phases/2-analyze/types.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface AnalysisState {
88
analysis: ComponentAnalysis;
99
options: ValidatedCompileOptions;
1010
ast_type: 'instance' | 'template' | 'module';
11-
fragment: FragmentAnalysis;
11+
fragment: AST.Fragment | null;
1212
/**
1313
* Tag name of the parent element. `null` if the parent is `svelte:element`, `#snippet`, a component or the root.
1414
* Parent doesn't necessarily mean direct path predecessor because there could be `#each`, `#if` etc in-between.
@@ -29,11 +29,6 @@ export interface AnalysisState {
2929
reactive_statement: null | ReactiveStatement;
3030
}
3131

32-
export interface FragmentAnalysis {
33-
has_await: boolean;
34-
node: AST.Fragment | null;
35-
}
36-
3732
export type Context<State extends AnalysisState = AnalysisState> = import('zimmerframe').Context<
3833
AST.SvelteNode,
3934
State

packages/svelte/src/compiler/phases/2-analyze/visitors/AwaitExpression.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export function AwaitExpression(node, context) {
1212
if (context.state.expression) {
1313
context.state.expression.has_await = true;
1414
if (
15-
context.state.fragment.node &&
15+
context.state.fragment &&
1616
// TODO there's probably a better way to do this
1717
context.path.find((node) => node.type === 'ConstTag')
1818
) {
19-
context.state.fragment.has_await = true;
19+
context.state.fragment.metadata.has_await = true;
2020
}
2121
suspend = true;
2222
}

packages/svelte/src/compiler/phases/2-analyze/visitors/Fragment.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
* @param {Context} context
77
*/
88
export function Fragment(node, context) {
9-
const fragment_metadata = {
10-
has_await: false,
11-
node
12-
};
13-
context.next({ ...context.state, fragment: fragment_metadata });
14-
node.metadata.has_await = fragment_metadata.has_await;
9+
node.metadata.has_await = false;
10+
context.next({ ...context.state, fragment: node });
1511
}

packages/svelte/src/compiler/types/template.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import type {
1919
} from 'estree';
2020
import type { Scope } from '../phases/scope';
2121
import type { _CSS } from './css';
22-
import type { FragmentAnalysis } from '../phases/2-analyze/types';
23-
24-
type FragmentMetadata = Omit<FragmentAnalysis, 'node'>;
2522

2623
/**
2724
* - `html` — the default, for e.g. `<div>` or `<span>`
@@ -48,7 +45,7 @@ export namespace AST {
4845
type: 'Fragment';
4946
nodes: Array<Text | Tag | ElementLike | Block | Comment>;
5047
/** @internal */
51-
metadata: Partial<FragmentMetadata> & {
48+
metadata: {
5249
/**
5350
* Fragments declare their own scopes. A transparent fragment is one whose scope
5451
* is not represented by a scope in the resulting JavaScript (e.g. an element scope),
@@ -59,6 +56,7 @@ export namespace AST {
5956
* Whether or not we need to traverse into the fragment during mount/hydrate
6057
*/
6158
dynamic: boolean;
59+
has_await: boolean;
6260
};
6361
}
6462

0 commit comments

Comments
 (0)