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

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

@ -8,7 +8,7 @@ export interface AnalysisState {
analysis: ComponentAnalysis;
options: ValidatedCompileOptions;
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.
* 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;
}
export interface FragmentAnalysis {
has_await: boolean;
node: AST.Fragment | null;
}
export type Context<State extends AnalysisState = AnalysisState> = import('zimmerframe').Context<
AST.SvelteNode,
State

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

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

@ -19,9 +19,6 @@ import type {
} from 'estree';
import type { Scope } from '../phases/scope';
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>`
@ -48,7 +45,7 @@ export namespace AST {
type: 'Fragment';
nodes: Array<Text | Tag | ElementLike | Block | Comment>;
/** @internal */
metadata: Partial<FragmentMetadata> & {
metadata: {
/**
* 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),
@ -59,6 +56,7 @@ export namespace AST {
* Whether or not we need to traverse into the fragment during mount/hydrate
*/
dynamic: boolean;
has_await: boolean;
};
}

Loading…
Cancel
Save