Skip to content

Commit 9096680

Browse files
authored
chore: use ESTree namespace imports (#17040)
1 parent b016474 commit 9096680

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { Expression, Node, Program } from 'estree' */
1+
/** @import * as ESTree from 'estree' */
22
/** @import { Binding, AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
33
/** @import { AnalysisState, Visitors } from './types' */
44
/** @import { Analysis, ComponentAnalysis, Js, ReactiveStatement, Template } from '../types' */
@@ -206,7 +206,7 @@ const visitors = {
206206
* @returns {Js}
207207
*/
208208
function js(script, root, allow_reactive_declarations, parent) {
209-
/** @type {Program} */
209+
/** @type {ESTree.Program} */
210210
const ast = script?.content ?? {
211211
type: 'Program',
212212
sourceType: 'module',
@@ -289,7 +289,7 @@ export function analyze_module(source, options) {
289289
});
290290

291291
walk(
292-
/** @type {Node} */ (ast),
292+
/** @type {ESTree.Node} */ (ast),
293293
{
294294
scope,
295295
scopes,
@@ -347,7 +347,7 @@ export function analyze_component(root, source, options) {
347347

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

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

641641
if (is_reference(node, parent)) {
642642
const binding = context.state.scope.get(node.name);

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { Program, Property, Statement, VariableDeclarator } from 'estree' */
1+
/** @import * as ESTree from 'estree' */
22
/** @import { AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
33
/** @import { ComponentServerTransformState, ComponentVisitors, ServerTransformState, Visitors } from './types.js' */
44
/** @import { Analysis, ComponentAnalysis } from '../../types.js' */
@@ -86,7 +86,7 @@ const template_visitors = {
8686
/**
8787
* @param {ComponentAnalysis} analysis
8888
* @param {ValidatedCompileOptions} options
89-
* @returns {Program}
89+
* @returns {ESTree.Program}
9090
*/
9191
export function server_component(analysis, options) {
9292
/** @type {ComponentServerTransformState} */
@@ -106,11 +106,11 @@ export function server_component(analysis, options) {
106106
skip_hydration_boundaries: false
107107
};
108108

109-
const module = /** @type {Program} */ (
109+
const module = /** @type {ESTree.Program} */ (
110110
walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, global_visitors)
111111
);
112112

113-
const instance = /** @type {Program} */ (
113+
const instance = /** @type {ESTree.Program} */ (
114114
walk(
115115
/** @type {AST.SvelteNode} */ (analysis.instance.ast),
116116
{ ...state, scopes: analysis.instance.scopes },
@@ -131,7 +131,7 @@ export function server_component(analysis, options) {
131131
)
132132
);
133133

134-
const template = /** @type {Program} */ (
134+
const template = /** @type {ESTree.Program} */ (
135135
walk(
136136
/** @type {AST.SvelteNode} */ (analysis.template.ast),
137137
{ ...state, scopes: analysis.template.scopes },
@@ -140,7 +140,7 @@ export function server_component(analysis, options) {
140140
)
141141
);
142142

143-
/** @type {VariableDeclarator[]} */
143+
/** @type {ESTree.VariableDeclarator[]} */
144144
const legacy_reactive_declarations = [];
145145

146146
for (const [node] of analysis.reactive_statements) {
@@ -192,7 +192,7 @@ export function server_component(analysis, options) {
192192
b.function_declaration(
193193
b.id('$$render_inner'),
194194
[b.id('$$renderer')],
195-
b.block(/** @type {Statement[]} */ (rest))
195+
b.block(/** @type {ESTree.Statement[]} */ (rest))
196196
),
197197
b.do_while(
198198
b.unary('!', b.id('$$settled')),
@@ -219,7 +219,7 @@ export function server_component(analysis, options) {
219219

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

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

241241
let component_block = b.block([
242-
.../** @type {Statement[]} */ (instance.body),
243-
.../** @type {Statement[]} */ (template.body)
242+
.../** @type {ESTree.Statement[]} */ (instance.body),
243+
.../** @type {ESTree.Statement[]} */ (template.body)
244244
]);
245245

246246
if (analysis.instance.has_await) {
@@ -395,7 +395,7 @@ export function server_component(analysis, options) {
395395
/**
396396
* @param {Analysis} analysis
397397
* @param {ValidatedModuleCompileOptions} options
398-
* @returns {Program}
398+
* @returns {ESTree.Program}
399399
*/
400400
export function server_module(analysis, options) {
401401
/** @type {ServerTransformState} */
@@ -411,7 +411,7 @@ export function server_module(analysis, options) {
411411
state_fields: new Map()
412412
};
413413

414-
const module = /** @type {Program} */ (
414+
const module = /** @type {ESTree.Program} */ (
415415
walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, global_visitors)
416416
);
417417

0 commit comments

Comments
 (0)