Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @import { Expression, Node, Program } from 'estree' */
/** @import * as ESTree from 'estree' */
/** @import { Binding, AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
/** @import { AnalysisState, Visitors } from './types' */
/** @import { Analysis, ComponentAnalysis, Js, ReactiveStatement, Template } from '../types' */
Expand Down Expand Up @@ -206,7 +206,7 @@ const visitors = {
* @returns {Js}
*/
function js(script, root, allow_reactive_declarations, parent) {
/** @type {Program} */
/** @type {ESTree.Program} */
const ast = script?.content ?? {
type: 'Program',
sourceType: 'module',
Expand Down Expand Up @@ -289,7 +289,7 @@ export function analyze_module(source, options) {
});

walk(
/** @type {Node} */ (ast),
/** @type {ESTree.Node} */ (ast),
{
scope,
scopes,
Expand Down Expand Up @@ -347,7 +347,7 @@ export function analyze_component(root, source, options) {

const store_name = name.slice(1);
const declaration = instance.scope.get(store_name);
const init = /** @type {Node | undefined} */ (declaration?.initial);
const init = /** @type {ESTree.Node | undefined} */ (declaration?.initial);

// If we're not in legacy mode through the compiler option, assume the user
// is referencing a rune and not a global store.
Expand Down Expand Up @@ -407,7 +407,7 @@ export function analyze_component(root, source, options) {
/** @type {number} */ (node.start) > /** @type {number} */ (module.ast.start) &&
/** @type {number} */ (node.end) < /** @type {number} */ (module.ast.end) &&
// const state = $state(0) is valid
get_rune(/** @type {Node} */ (path.at(-1)), module.scope) === null
get_rune(/** @type {ESTree.Node} */ (path.at(-1)), module.scope) === null
) {
e.store_invalid_subscription(node);
}
Expand Down Expand Up @@ -636,7 +636,7 @@ export function analyze_component(root, source, options) {
// @ts-expect-error
_: set_scope,
Identifier(node, context) {
const parent = /** @type {Expression} */ (context.path.at(-1));
const parent = /** @type {ESTree.Expression} */ (context.path.at(-1));

if (is_reference(node, parent)) {
const binding = context.state.scope.get(node.name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @import { Program, Property, Statement, VariableDeclarator } from 'estree' */
/** @import * as ESTree from 'estree' */
/** @import { AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
/** @import { ComponentServerTransformState, ComponentVisitors, ServerTransformState, Visitors } from './types.js' */
/** @import { Analysis, ComponentAnalysis } from '../../types.js' */
Expand Down Expand Up @@ -86,7 +86,7 @@ const template_visitors = {
/**
* @param {ComponentAnalysis} analysis
* @param {ValidatedCompileOptions} options
* @returns {Program}
* @returns {ESTree.Program}
*/
export function server_component(analysis, options) {
/** @type {ComponentServerTransformState} */
Expand All @@ -106,11 +106,11 @@ export function server_component(analysis, options) {
skip_hydration_boundaries: false
};

const module = /** @type {Program} */ (
const module = /** @type {ESTree.Program} */ (
walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, global_visitors)
);

const instance = /** @type {Program} */ (
const instance = /** @type {ESTree.Program} */ (
walk(
/** @type {AST.SvelteNode} */ (analysis.instance.ast),
{ ...state, scopes: analysis.instance.scopes },
Expand All @@ -131,7 +131,7 @@ export function server_component(analysis, options) {
)
);

const template = /** @type {Program} */ (
const template = /** @type {ESTree.Program} */ (
walk(
/** @type {AST.SvelteNode} */ (analysis.template.ast),
{ ...state, scopes: analysis.template.scopes },
Expand All @@ -140,7 +140,7 @@ export function server_component(analysis, options) {
)
);

/** @type {VariableDeclarator[]} */
/** @type {ESTree.VariableDeclarator[]} */
const legacy_reactive_declarations = [];

for (const [node] of analysis.reactive_statements) {
Expand Down Expand Up @@ -192,7 +192,7 @@ export function server_component(analysis, options) {
b.function_declaration(
b.id('$$render_inner'),
[b.id('$$renderer')],
b.block(/** @type {Statement[]} */ (rest))
b.block(/** @type {ESTree.Statement[]} */ (rest))
),
b.do_while(
b.unary('!', b.id('$$settled')),
Expand All @@ -219,7 +219,7 @@ export function server_component(analysis, options) {

// Propagate values of bound props upwards if they're undefined in the parent and have a value.
// Don't do this as part of the props retrieval because people could eagerly mutate the prop in the instance script.
/** @type {Property[]} */
/** @type {ESTree.Property[]} */
const props = [];

for (const [name, binding] of analysis.instance.scope.declarations) {
Expand All @@ -239,8 +239,8 @@ export function server_component(analysis, options) {
}

let component_block = b.block([
.../** @type {Statement[]} */ (instance.body),
.../** @type {Statement[]} */ (template.body)
.../** @type {ESTree.Statement[]} */ (instance.body),
.../** @type {ESTree.Statement[]} */ (template.body)
]);

if (analysis.instance.has_await) {
Expand Down Expand Up @@ -395,7 +395,7 @@ export function server_component(analysis, options) {
/**
* @param {Analysis} analysis
* @param {ValidatedModuleCompileOptions} options
* @returns {Program}
* @returns {ESTree.Program}
*/
export function server_module(analysis, options) {
/** @type {ServerTransformState} */
Expand All @@ -411,7 +411,7 @@ export function server_module(analysis, options) {
state_fields: new Map()
};

const module = /** @type {Program} */ (
const module = /** @type {ESTree.Program} */ (
walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, global_visitors)
);

Expand Down
Loading