Skip to content

Commit 7a5c6b5

Browse files
authored
chore: more JSDoc imports (#12590)
* more * more * more * more * fix
1 parent 20b8797 commit 7a5c6b5

File tree

4 files changed

+166
-193
lines changed

4 files changed

+166
-193
lines changed

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

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/** @import { AssignmentExpression, CallExpression, Expression, Identifier, Node, Pattern, PrivateIdentifier, Super, UpdateExpression, VariableDeclarator } from 'estree' */
2+
/** @import { Attribute, Component, ElementLike, Fragment, RegularElement, SvelteComponent, SvelteElement, SvelteNode, SvelteSelf, TransitionDirective } from '#compiler' */
3+
/** @import { NodeLike } from '../../errors.js' */
4+
/** @import { AnalysisState, Context, Visitors } from './types.js' */
15
import is_reference from 'is-reference';
26
import {
37
disallowed_paragraph_contents,
@@ -35,8 +39,8 @@ import { merge } from '../visitors.js';
3539
import { a11y_validators } from './a11y.js';
3640

3741
/**
38-
* @param {import('#compiler').Attribute} attribute
39-
* @param {import('#compiler').ElementLike} parent
42+
* @param {Attribute} attribute
43+
* @param {ElementLike} parent
4044
*/
4145
function validate_attribute(attribute, parent) {
4246
if (
@@ -63,8 +67,8 @@ function validate_attribute(attribute, parent) {
6367
}
6468

6569
/**
66-
* @param {import('#compiler').Component | import('#compiler').SvelteComponent | import('#compiler').SvelteSelf} node
67-
* @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types.js').AnalysisState>} context
70+
* @param {Component | SvelteComponent | SvelteSelf} node
71+
* @param {Context} context
6872
*/
6973
function validate_component(node, context) {
7074
for (const attribute of node.attributes) {
@@ -123,16 +127,16 @@ const react_attributes = new Map([
123127
]);
124128

125129
/**
126-
* @param {import('#compiler').RegularElement | import('#compiler').SvelteElement} node
127-
* @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types.js').AnalysisState>} context
130+
* @param {RegularElement | SvelteElement} node
131+
* @param {Context} context
128132
*/
129133
function validate_element(node, context) {
130134
let has_animate_directive = false;
131135

132-
/** @type {import('#compiler').TransitionDirective | null} */
136+
/** @type {TransitionDirective | null} */
133137
let in_transition = null;
134138

135-
/** @type {import('#compiler').TransitionDirective | null} */
139+
/** @type {TransitionDirective | null} */
136140
let out_transition = null;
137141

138142
for (const attribute of node.attributes) {
@@ -175,7 +179,7 @@ function validate_element(node, context) {
175179
}
176180

177181
if (attribute.name === 'slot') {
178-
/** @type {import('#compiler').RegularElement | import('#compiler').SvelteElement | import('#compiler').Component | import('#compiler').SvelteComponent | import('#compiler').SvelteSelf | undefined} */
182+
/** @type {RegularElement | SvelteElement | Component | SvelteComponent | SvelteSelf | undefined} */
179183
validate_slot_attribute(context, attribute);
180184
}
181185

@@ -212,7 +216,7 @@ function validate_element(node, context) {
212216
has_animate_directive = true;
213217
}
214218
} else if (attribute.type === 'TransitionDirective') {
215-
const existing = /** @type {import('#compiler').TransitionDirective | null} */ (
219+
const existing = /** @type {TransitionDirective | null} */ (
216220
(attribute.intro && in_transition) || (attribute.outro && out_transition)
217221
);
218222

@@ -255,7 +259,7 @@ function validate_element(node, context) {
255259
}
256260

257261
/**
258-
* @param {import('#compiler').Attribute} attribute
262+
* @param {Attribute} attribute
259263
*/
260264
function validate_attribute_name(attribute) {
261265
if (
@@ -269,8 +273,8 @@ function validate_attribute_name(attribute) {
269273
}
270274

271275
/**
272-
* @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types.js').AnalysisState>} context
273-
* @param {import('#compiler').Attribute} attribute
276+
* @param {Context} context
277+
* @param {Attribute} attribute
274278
* @param {boolean} is_component
275279
*/
276280
function validate_slot_attribute(context, attribute, is_component = false) {
@@ -343,8 +347,8 @@ function validate_slot_attribute(context, attribute, is_component = false) {
343347
}
344348

345349
/**
346-
* @param {import('#compiler').Fragment | null | undefined} node
347-
* @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types.js').AnalysisState>} context
350+
* @param {Fragment | null | undefined} node
351+
* @param {Context} context
348352
*/
349353
function validate_block_not_empty(node, context) {
350354
if (!node) return;
@@ -356,7 +360,7 @@ function validate_block_not_empty(node, context) {
356360
}
357361

358362
/**
359-
* @type {import('zimmerframe').Visitors<import('#compiler').SvelteNode, import('./types.js').AnalysisState>}
363+
* @type {Visitors}
360364
*/
361365
const validation = {
362366
MemberExpression(node, context) {
@@ -465,7 +469,7 @@ const validation = {
465469
}
466470

467471
if (parent.name === 'input' && node.name !== 'this') {
468-
const type = /** @type {import('#compiler').Attribute | undefined} */ (
472+
const type = /** @type {Attribute | undefined} */ (
469473
parent.attributes.find((a) => a.type === 'Attribute' && a.name === 'type')
470474
);
471475
if (type && !is_text_attribute(type)) {
@@ -506,7 +510,7 @@ const validation = {
506510
}
507511

508512
if (ContentEditableBindings.includes(node.name)) {
509-
const contenteditable = /** @type {import('#compiler').Attribute} */ (
513+
const contenteditable = /** @type {Attribute} */ (
510514
parent.attributes.find((a) => a.type === 'Attribute' && a.name === 'contenteditable')
511515
);
512516
if (!contenteditable) {
@@ -846,8 +850,7 @@ export const validation_legacy = merge(validation, a11y_validators, {
846850
LabeledStatement(node, { path, state }) {
847851
if (
848852
node.label.name === '$' &&
849-
(state.ast_type !== 'instance' ||
850-
/** @type {import('#compiler').SvelteNode} */ (path.at(-1)).type !== 'Program')
853+
(state.ast_type !== 'instance' || /** @type {SvelteNode} */ (path.at(-1)).type !== 'Program')
851854
) {
852855
w.reactive_declaration_invalid_placement(node);
853856
}
@@ -859,8 +862,8 @@ export const validation_legacy = merge(validation, a11y_validators, {
859862

860863
/**
861864
*
862-
* @param {import('estree').Node} node
863-
* @param {import('../scope').Scope} scope
865+
* @param {Node} node
866+
* @param {Scope} scope
864867
* @param {string} name
865868
*/
866869
function validate_export(node, scope, name) {
@@ -877,16 +880,16 @@ function validate_export(node, scope, name) {
877880
}
878881

879882
/**
880-
* @param {import('estree').CallExpression} node
883+
* @param {CallExpression} node
881884
* @param {Scope} scope
882-
* @param {import('#compiler').SvelteNode[]} path
885+
* @param {SvelteNode[]} path
883886
* @returns
884887
*/
885888
function validate_call_expression(node, scope, path) {
886889
const rune = get_rune(node, scope);
887890
if (rune === null) return;
888891

889-
const parent = /** @type {import('#compiler').SvelteNode} */ (get_parent(path, -1));
892+
const parent = /** @type {SvelteNode} */ (get_parent(path, -1));
890893

891894
if (rune === '$props') {
892895
if (parent.type === 'VariableDeclarator') return;
@@ -965,8 +968,8 @@ function validate_call_expression(node, scope, path) {
965968
}
966969

967970
/**
968-
* @param {import('estree').VariableDeclarator} node
969-
* @param {import('./types.js').AnalysisState} state
971+
* @param {VariableDeclarator} node
972+
* @param {AnalysisState} state
970973
*/
971974
function ensure_no_module_import_conflict(node, state) {
972975
const ids = extract_identifiers(node.id);
@@ -981,7 +984,7 @@ function ensure_no_module_import_conflict(node, state) {
981984
}
982985

983986
/**
984-
* @type {import('zimmerframe').Visitors<import('#compiler').SvelteNode, import('./types.js').AnalysisState>}
987+
* @type {Visitors}
985988
*/
986989
export const validation_runes_js = {
987990
ImportDeclaration(node) {
@@ -1016,7 +1019,7 @@ export const validation_runes_js = {
10161019

10171020
if (rune === null) return;
10181021

1019-
const args = /** @type {import('estree').CallExpression} */ (init).arguments;
1022+
const args = /** @type {CallExpression} */ (init).arguments;
10201023

10211024
if ((rune === '$derived' || rune === '$derived.by') && args.length !== 1) {
10221025
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
@@ -1073,24 +1076,24 @@ export const validation_runes_js = {
10731076
},
10741077
Identifier(node, { path, state }) {
10751078
let i = path.length;
1076-
let parent = /** @type {import('estree').Expression} */ (path[--i]);
1079+
let parent = /** @type {Expression} */ (path[--i]);
10771080

10781081
if (
10791082
Runes.includes(/** @type {Runes[number]} */ (node.name)) &&
10801083
is_reference(node, parent) &&
10811084
state.scope.get(node.name) === null &&
10821085
state.scope.get(node.name.slice(1)) === null
10831086
) {
1084-
/** @type {import('estree').Expression} */
1087+
/** @type {Expression} */
10851088
let current = node;
10861089
let name = node.name;
10871090

10881091
while (parent.type === 'MemberExpression') {
10891092
if (parent.computed) e.rune_invalid_computed_property(parent);
1090-
name += `.${/** @type {import('estree').Identifier} */ (parent.property).name}`;
1093+
name += `.${/** @type {Identifier} */ (parent.property).name}`;
10911094

10921095
current = parent;
1093-
parent = /** @type {import('estree').Expression} */ (path[--i]);
1096+
parent = /** @type {Expression} */ (path[--i]);
10941097

10951098
if (!Runes.includes(/** @type {Runes[number]} */ (name))) {
10961099
if (name === '$effect.active') {
@@ -1109,8 +1112,8 @@ export const validation_runes_js = {
11091112
};
11101113

11111114
/**
1112-
* @param {import('../../errors.js').NodeLike} node
1113-
* @param {import('estree').Pattern | import('estree').Expression} argument
1115+
* @param {NodeLike} node
1116+
* @param {Pattern | Expression} argument
11141117
* @param {Scope} scope
11151118
* @param {boolean} is_binding
11161119
*/
@@ -1156,7 +1159,7 @@ function validate_no_const_assignment(node, argument, scope, is_binding) {
11561159
* Validates that the opening of a control flow block is `{` immediately followed by the expected character.
11571160
* In legacy mode whitespace is allowed inbetween. TODO remove once legacy mode is gone and move this into parser instead.
11581161
* @param {{start: number; end: number}} node
1159-
* @param {import('./types.js').AnalysisState} state
1162+
* @param {AnalysisState} state
11601163
* @param {string} expected
11611164
*/
11621165
function validate_opening_tag(node, state, expected) {
@@ -1167,9 +1170,9 @@ function validate_opening_tag(node, state, expected) {
11671170
}
11681171

11691172
/**
1170-
* @param {import('estree').AssignmentExpression | import('estree').UpdateExpression} node
1171-
* @param {import('estree').Pattern | import('estree').Expression} argument
1172-
* @param {import('./types.js').AnalysisState} state
1173+
* @param {AssignmentExpression | UpdateExpression} node
1174+
* @param {Pattern | Expression} argument
1175+
* @param {AnalysisState} state
11731176
*/
11741177
function validate_assignment(node, argument, state) {
11751178
validate_no_const_assignment(node, argument, state.scope, false);
@@ -1192,9 +1195,9 @@ function validate_assignment(node, argument, state) {
11921195
}
11931196
}
11941197

1195-
let object = /** @type {import('estree').Expression | import('estree').Super} */ (argument);
1198+
let object = /** @type {Expression | Super} */ (argument);
11961199

1197-
/** @type {import('estree').Expression | import('estree').PrivateIdentifier | null} */
1200+
/** @type {Expression | PrivateIdentifier | null} */
11981201
let property = null;
11991202

12001203
while (object.type === 'MemberExpression') {
@@ -1322,7 +1325,7 @@ export const validation_runes = merge(validation, a11y_validators, {
13221325

13231326
if (rune === null) return;
13241327

1325-
const args = /** @type {import('estree').CallExpression} */ (init).arguments;
1328+
const args = /** @type {CallExpression} */ (init).arguments;
13261329

13271330
// TODO some of this is duplicated with above, seems off
13281331
if ((rune === '$derived' || rune === '$derived.by') && args.length !== 1) {

0 commit comments

Comments
 (0)