diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index b4c704c34d..4c05fd6148 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -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' */ @@ -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', @@ -289,7 +289,7 @@ export function analyze_module(source, options) { }); walk( - /** @type {Node} */ (ast), + /** @type {ESTree.Node} */ (ast), { scope, scopes, @@ -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. @@ -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); } @@ -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); diff --git a/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js b/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js index b22b95f5aa..1c9764a759 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js @@ -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' */ @@ -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} */ @@ -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 }, @@ -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 }, @@ -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) { @@ -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')), @@ -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) { @@ -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) { @@ -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} */ @@ -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) );