chore: use ESTree namespace imports

pull/17040/head
Rich Harris 1 week ago
parent 8368a4beb9
commit 5ceea766b1

@ -1,4 +1,4 @@
/** @import { Expression, Node, Program } from 'estree' */ /** @import * as ESTree from 'estree' */
/** @import { Binding, AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */ /** @import { Binding, AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
/** @import { AnalysisState, Visitors } from './types' */ /** @import { AnalysisState, Visitors } from './types' */
/** @import { Analysis, ComponentAnalysis, Js, ReactiveStatement, Template } from '../types' */ /** @import { Analysis, ComponentAnalysis, Js, ReactiveStatement, Template } from '../types' */
@ -206,7 +206,7 @@ const visitors = {
* @returns {Js} * @returns {Js}
*/ */
function js(script, root, allow_reactive_declarations, parent) { function js(script, root, allow_reactive_declarations, parent) {
/** @type {Program} */ /** @type {ESTree.Program} */
const ast = script?.content ?? { const ast = script?.content ?? {
type: 'Program', type: 'Program',
sourceType: 'module', sourceType: 'module',
@ -289,7 +289,7 @@ export function analyze_module(source, options) {
}); });
walk( walk(
/** @type {Node} */ (ast), /** @type {ESTree.Node} */ (ast),
{ {
scope, scope,
scopes, scopes,
@ -347,7 +347,7 @@ export function analyze_component(root, source, options) {
const store_name = name.slice(1); const store_name = name.slice(1);
const declaration = instance.scope.get(store_name); 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 // If we're not in legacy mode through the compiler option, assume the user
// is referencing a rune and not a global store. // 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.start) > /** @type {number} */ (module.ast.start) &&
/** @type {number} */ (node.end) < /** @type {number} */ (module.ast.end) && /** @type {number} */ (node.end) < /** @type {number} */ (module.ast.end) &&
// const state = $state(0) is valid // 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); e.store_invalid_subscription(node);
} }
@ -636,7 +636,7 @@ export function analyze_component(root, source, options) {
// @ts-expect-error // @ts-expect-error
_: set_scope, _: set_scope,
Identifier(node, context) { 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)) { if (is_reference(node, parent)) {
const binding = context.state.scope.get(node.name); const binding = context.state.scope.get(node.name);

@ -1,4 +1,4 @@
/** @import { Program, Property, Statement, VariableDeclarator } from 'estree' */ /** @import * as ESTree from 'estree' */
/** @import { AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */ /** @import { AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
/** @import { ComponentServerTransformState, ComponentVisitors, ServerTransformState, Visitors } from './types.js' */ /** @import { ComponentServerTransformState, ComponentVisitors, ServerTransformState, Visitors } from './types.js' */
/** @import { Analysis, ComponentAnalysis } from '../../types.js' */ /** @import { Analysis, ComponentAnalysis } from '../../types.js' */
@ -86,7 +86,7 @@ const template_visitors = {
/** /**
* @param {ComponentAnalysis} analysis * @param {ComponentAnalysis} analysis
* @param {ValidatedCompileOptions} options * @param {ValidatedCompileOptions} options
* @returns {Program} * @returns {ESTree.Program}
*/ */
export function server_component(analysis, options) { export function server_component(analysis, options) {
/** @type {ComponentServerTransformState} */ /** @type {ComponentServerTransformState} */
@ -106,11 +106,11 @@ export function server_component(analysis, options) {
skip_hydration_boundaries: false skip_hydration_boundaries: false
}; };
const module = /** @type {Program} */ ( const module = /** @type {ESTree.Program} */ (
walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, global_visitors) walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, global_visitors)
); );
const instance = /** @type {Program} */ ( const instance = /** @type {ESTree.Program} */ (
walk( walk(
/** @type {AST.SvelteNode} */ (analysis.instance.ast), /** @type {AST.SvelteNode} */ (analysis.instance.ast),
{ ...state, scopes: analysis.instance.scopes }, { ...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( walk(
/** @type {AST.SvelteNode} */ (analysis.template.ast), /** @type {AST.SvelteNode} */ (analysis.template.ast),
{ ...state, scopes: analysis.template.scopes }, { ...state, scopes: analysis.template.scopes },
@ -140,7 +140,7 @@ export function server_component(analysis, options) {
) )
); );
/** @type {VariableDeclarator[]} */ /** @type {ESTree.VariableDeclarator[]} */
const legacy_reactive_declarations = []; const legacy_reactive_declarations = [];
for (const [node] of analysis.reactive_statements) { for (const [node] of analysis.reactive_statements) {
@ -192,7 +192,7 @@ export function server_component(analysis, options) {
b.function_declaration( b.function_declaration(
b.id('$$render_inner'), b.id('$$render_inner'),
[b.id('$$renderer')], [b.id('$$renderer')],
b.block(/** @type {Statement[]} */ (rest)) b.block(/** @type {ESTree.Statement[]} */ (rest))
), ),
b.do_while( b.do_while(
b.unary('!', b.id('$$settled')), 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. // 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. // 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 = []; const props = [];
for (const [name, binding] of analysis.instance.scope.declarations) { for (const [name, binding] of analysis.instance.scope.declarations) {
@ -239,8 +239,8 @@ export function server_component(analysis, options) {
} }
let component_block = b.block([ let component_block = b.block([
.../** @type {Statement[]} */ (instance.body), .../** @type {ESTree.Statement[]} */ (instance.body),
.../** @type {Statement[]} */ (template.body) .../** @type {ESTree.Statement[]} */ (template.body)
]); ]);
if (analysis.instance.has_await) { if (analysis.instance.has_await) {
@ -395,7 +395,7 @@ export function server_component(analysis, options) {
/** /**
* @param {Analysis} analysis * @param {Analysis} analysis
* @param {ValidatedModuleCompileOptions} options * @param {ValidatedModuleCompileOptions} options
* @returns {Program} * @returns {ESTree.Program}
*/ */
export function server_module(analysis, options) { export function server_module(analysis, options) {
/** @type {ServerTransformState} */ /** @type {ServerTransformState} */
@ -411,7 +411,7 @@ export function server_module(analysis, options) {
state_fields: new Map() state_fields: new Map()
}; };
const module = /** @type {Program} */ ( const module = /** @type {ESTree.Program} */ (
walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, global_visitors) walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, global_visitors)
); );

Loading…
Cancel
Save