pull/16542/head
ComputerGuy 1 month ago
parent 201bf3704b
commit f3daef7947

@ -302,10 +302,7 @@ export function analyze_module(source, options) {
function_depth: 0, function_depth: 0,
has_props_rune: false, has_props_rune: false,
options: /** @type {ValidatedCompileOptions} */ (options), options: /** @type {ValidatedCompileOptions} */ (options),
fragment: { fragment: null,
has_await: false,
node: null
},
parent_element: null, parent_element: null,
reactive_statement: null reactive_statement: null
}, },
@ -694,10 +691,7 @@ export function analyze_component(root, source, options) {
analysis, analysis,
options, options,
ast_type: ast === instance.ast ? 'instance' : ast === template.ast ? 'template' : 'module', ast_type: ast === instance.ast ? 'instance' : ast === template.ast ? 'template' : 'module',
fragment: { fragment: ast === template.ast ? ast : null,
has_await: false,
node: ast === template.ast ? template.ast : null
},
parent_element: null, parent_element: null,
has_props_rune: false, has_props_rune: false,
component_slots: new Set(), component_slots: new Set(),
@ -763,10 +757,7 @@ export function analyze_component(root, source, options) {
scopes, scopes,
analysis, analysis,
options, options,
fragment: { fragment: ast === template.ast ? ast : null,
has_await: false,
node: ast === template.ast ? template.ast : null
},
parent_element: null, parent_element: null,
has_props_rune: false, has_props_rune: false,
ast_type: ast === instance.ast ? 'instance' : ast === template.ast ? 'template' : 'module', ast_type: ast === instance.ast ? 'instance' : ast === template.ast ? 'template' : 'module',

@ -8,7 +8,7 @@ export interface AnalysisState {
analysis: ComponentAnalysis; analysis: ComponentAnalysis;
options: ValidatedCompileOptions; options: ValidatedCompileOptions;
ast_type: 'instance' | 'template' | 'module'; ast_type: 'instance' | 'template' | 'module';
fragment: FragmentAnalysis; fragment: AST.Fragment | null;
/** /**
* Tag name of the parent element. `null` if the parent is `svelte:element`, `#snippet`, a component or the root. * Tag name of the parent element. `null` if the parent is `svelte:element`, `#snippet`, a component or the root.
* Parent doesn't necessarily mean direct path predecessor because there could be `#each`, `#if` etc in-between. * Parent doesn't necessarily mean direct path predecessor because there could be `#each`, `#if` etc in-between.
@ -29,11 +29,6 @@ export interface AnalysisState {
reactive_statement: null | ReactiveStatement; reactive_statement: null | ReactiveStatement;
} }
export interface FragmentAnalysis {
has_await: boolean;
node: AST.Fragment | null;
}
export type Context<State extends AnalysisState = AnalysisState> = import('zimmerframe').Context< export type Context<State extends AnalysisState = AnalysisState> = import('zimmerframe').Context<
AST.SvelteNode, AST.SvelteNode,
State State

@ -12,11 +12,11 @@ export function AwaitExpression(node, context) {
if (context.state.expression) { if (context.state.expression) {
context.state.expression.has_await = true; context.state.expression.has_await = true;
if ( if (
context.state.fragment.node && context.state.fragment &&
// TODO there's probably a better way to do this // TODO there's probably a better way to do this
context.path.find((node) => node.type === 'ConstTag') context.path.find((node) => node.type === 'ConstTag')
) { ) {
context.state.fragment.has_await = true; context.state.fragment.metadata.has_await = true;
} }
suspend = true; suspend = true;
} }

@ -6,10 +6,6 @@
* @param {Context} context * @param {Context} context
*/ */
export function Fragment(node, context) { export function Fragment(node, context) {
const fragment_metadata = { node.metadata.has_await = false;
has_await: false, context.next({ ...context.state, fragment: node });
node
};
context.next({ ...context.state, fragment: fragment_metadata });
node.metadata.has_await = fragment_metadata.has_await;
} }

@ -19,9 +19,6 @@ import type {
} from 'estree'; } from 'estree';
import type { Scope } from '../phases/scope'; import type { Scope } from '../phases/scope';
import type { _CSS } from './css'; import type { _CSS } from './css';
import type { FragmentAnalysis } from '../phases/2-analyze/types';
type FragmentMetadata = Omit<FragmentAnalysis, 'node'>;
/** /**
* - `html` the default, for e.g. `<div>` or `<span>` * - `html` the default, for e.g. `<div>` or `<span>`
@ -48,7 +45,7 @@ export namespace AST {
type: 'Fragment'; type: 'Fragment';
nodes: Array<Text | Tag | ElementLike | Block | Comment>; nodes: Array<Text | Tag | ElementLike | Block | Comment>;
/** @internal */ /** @internal */
metadata: Partial<FragmentMetadata> & { metadata: {
/** /**
* Fragments declare their own scopes. A transparent fragment is one whose scope * Fragments declare their own scopes. A transparent fragment is one whose scope
* is not represented by a scope in the resulting JavaScript (e.g. an element scope), * is not represented by a scope in the resulting JavaScript (e.g. an element scope),
@ -59,6 +56,7 @@ export namespace AST {
* Whether or not we need to traverse into the fragment during mount/hydrate * Whether or not we need to traverse into the fragment during mount/hydrate
*/ */
dynamic: boolean; dynamic: boolean;
has_await: boolean;
}; };
} }

Loading…
Cancel
Save