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' */
1
5
import is_reference from 'is-reference' ;
2
6
import {
3
7
disallowed_paragraph_contents ,
@@ -35,8 +39,8 @@ import { merge } from '../visitors.js';
35
39
import { a11y_validators } from './a11y.js' ;
36
40
37
41
/**
38
- * @param {import('#compiler'). Attribute } attribute
39
- * @param {import('#compiler'). ElementLike } parent
42
+ * @param {Attribute } attribute
43
+ * @param {ElementLike } parent
40
44
*/
41
45
function validate_attribute ( attribute , parent ) {
42
46
if (
@@ -63,8 +67,8 @@ function validate_attribute(attribute, parent) {
63
67
}
64
68
65
69
/**
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
68
72
*/
69
73
function validate_component ( node , context ) {
70
74
for ( const attribute of node . attributes ) {
@@ -123,16 +127,16 @@ const react_attributes = new Map([
123
127
] ) ;
124
128
125
129
/**
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
128
132
*/
129
133
function validate_element ( node , context ) {
130
134
let has_animate_directive = false ;
131
135
132
- /** @type {import('#compiler'). TransitionDirective | null } */
136
+ /** @type {TransitionDirective | null } */
133
137
let in_transition = null ;
134
138
135
- /** @type {import('#compiler'). TransitionDirective | null } */
139
+ /** @type {TransitionDirective | null } */
136
140
let out_transition = null ;
137
141
138
142
for ( const attribute of node . attributes ) {
@@ -175,7 +179,7 @@ function validate_element(node, context) {
175
179
}
176
180
177
181
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 } */
179
183
validate_slot_attribute ( context , attribute ) ;
180
184
}
181
185
@@ -212,7 +216,7 @@ function validate_element(node, context) {
212
216
has_animate_directive = true ;
213
217
}
214
218
} else if ( attribute . type === 'TransitionDirective' ) {
215
- const existing = /** @type {import('#compiler'). TransitionDirective | null } */ (
219
+ const existing = /** @type {TransitionDirective | null } */ (
216
220
( attribute . intro && in_transition ) || ( attribute . outro && out_transition )
217
221
) ;
218
222
@@ -255,7 +259,7 @@ function validate_element(node, context) {
255
259
}
256
260
257
261
/**
258
- * @param {import('#compiler'). Attribute } attribute
262
+ * @param {Attribute } attribute
259
263
*/
260
264
function validate_attribute_name ( attribute ) {
261
265
if (
@@ -269,8 +273,8 @@ function validate_attribute_name(attribute) {
269
273
}
270
274
271
275
/**
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
274
278
* @param {boolean } is_component
275
279
*/
276
280
function validate_slot_attribute ( context , attribute , is_component = false ) {
@@ -343,8 +347,8 @@ function validate_slot_attribute(context, attribute, is_component = false) {
343
347
}
344
348
345
349
/**
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
348
352
*/
349
353
function validate_block_not_empty ( node , context ) {
350
354
if ( ! node ) return ;
@@ -356,7 +360,7 @@ function validate_block_not_empty(node, context) {
356
360
}
357
361
358
362
/**
359
- * @type {import('zimmerframe'). Visitors<import('#compiler').SvelteNode, import('./types.js').AnalysisState> }
363
+ * @type {Visitors }
360
364
*/
361
365
const validation = {
362
366
MemberExpression ( node , context ) {
@@ -465,7 +469,7 @@ const validation = {
465
469
}
466
470
467
471
if ( parent . name === 'input' && node . name !== 'this' ) {
468
- const type = /** @type {import('#compiler'). Attribute | undefined } */ (
472
+ const type = /** @type {Attribute | undefined } */ (
469
473
parent . attributes . find ( ( a ) => a . type === 'Attribute' && a . name === 'type' )
470
474
) ;
471
475
if ( type && ! is_text_attribute ( type ) ) {
@@ -506,7 +510,7 @@ const validation = {
506
510
}
507
511
508
512
if ( ContentEditableBindings . includes ( node . name ) ) {
509
- const contenteditable = /** @type {import('#compiler'). Attribute } */ (
513
+ const contenteditable = /** @type {Attribute } */ (
510
514
parent . attributes . find ( ( a ) => a . type === 'Attribute' && a . name === 'contenteditable' )
511
515
) ;
512
516
if ( ! contenteditable ) {
@@ -846,8 +850,7 @@ export const validation_legacy = merge(validation, a11y_validators, {
846
850
LabeledStatement ( node , { path, state } ) {
847
851
if (
848
852
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' )
851
854
) {
852
855
w . reactive_declaration_invalid_placement ( node ) ;
853
856
}
@@ -859,8 +862,8 @@ export const validation_legacy = merge(validation, a11y_validators, {
859
862
860
863
/**
861
864
*
862
- * @param {import('estree'). Node } node
863
- * @param {import('../scope'). Scope } scope
865
+ * @param {Node } node
866
+ * @param {Scope } scope
864
867
* @param {string } name
865
868
*/
866
869
function validate_export ( node , scope , name ) {
@@ -877,16 +880,16 @@ function validate_export(node, scope, name) {
877
880
}
878
881
879
882
/**
880
- * @param {import('estree'). CallExpression } node
883
+ * @param {CallExpression } node
881
884
* @param {Scope } scope
882
- * @param {import('#compiler'). SvelteNode[] } path
885
+ * @param {SvelteNode[] } path
883
886
* @returns
884
887
*/
885
888
function validate_call_expression ( node , scope , path ) {
886
889
const rune = get_rune ( node , scope ) ;
887
890
if ( rune === null ) return ;
888
891
889
- const parent = /** @type {import('#compiler'). SvelteNode } */ ( get_parent ( path , - 1 ) ) ;
892
+ const parent = /** @type {SvelteNode } */ ( get_parent ( path , - 1 ) ) ;
890
893
891
894
if ( rune === '$props' ) {
892
895
if ( parent . type === 'VariableDeclarator' ) return ;
@@ -965,8 +968,8 @@ function validate_call_expression(node, scope, path) {
965
968
}
966
969
967
970
/**
968
- * @param {import('estree'). VariableDeclarator } node
969
- * @param {import('./types.js'). AnalysisState } state
971
+ * @param {VariableDeclarator } node
972
+ * @param {AnalysisState } state
970
973
*/
971
974
function ensure_no_module_import_conflict ( node , state ) {
972
975
const ids = extract_identifiers ( node . id ) ;
@@ -981,7 +984,7 @@ function ensure_no_module_import_conflict(node, state) {
981
984
}
982
985
983
986
/**
984
- * @type {import('zimmerframe'). Visitors<import('#compiler').SvelteNode, import('./types.js').AnalysisState> }
987
+ * @type {Visitors }
985
988
*/
986
989
export const validation_runes_js = {
987
990
ImportDeclaration ( node ) {
@@ -1016,7 +1019,7 @@ export const validation_runes_js = {
1016
1019
1017
1020
if ( rune === null ) return ;
1018
1021
1019
- const args = /** @type {import('estree'). CallExpression } */ ( init ) . arguments ;
1022
+ const args = /** @type {CallExpression } */ ( init ) . arguments ;
1020
1023
1021
1024
if ( ( rune === '$derived' || rune === '$derived.by' ) && args . length !== 1 ) {
1022
1025
e . rune_invalid_arguments_length ( node , rune , 'exactly one argument' ) ;
@@ -1073,24 +1076,24 @@ export const validation_runes_js = {
1073
1076
} ,
1074
1077
Identifier ( node , { path, state } ) {
1075
1078
let i = path . length ;
1076
- let parent = /** @type {import('estree'). Expression } */ ( path [ -- i ] ) ;
1079
+ let parent = /** @type {Expression } */ ( path [ -- i ] ) ;
1077
1080
1078
1081
if (
1079
1082
Runes . includes ( /** @type {Runes[number] } */ ( node . name ) ) &&
1080
1083
is_reference ( node , parent ) &&
1081
1084
state . scope . get ( node . name ) === null &&
1082
1085
state . scope . get ( node . name . slice ( 1 ) ) === null
1083
1086
) {
1084
- /** @type {import('estree'). Expression } */
1087
+ /** @type {Expression } */
1085
1088
let current = node ;
1086
1089
let name = node . name ;
1087
1090
1088
1091
while ( parent . type === 'MemberExpression' ) {
1089
1092
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 } ` ;
1091
1094
1092
1095
current = parent ;
1093
- parent = /** @type {import('estree'). Expression } */ ( path [ -- i ] ) ;
1096
+ parent = /** @type {Expression } */ ( path [ -- i ] ) ;
1094
1097
1095
1098
if ( ! Runes . includes ( /** @type {Runes[number] } */ ( name ) ) ) {
1096
1099
if ( name === '$effect.active' ) {
@@ -1109,8 +1112,8 @@ export const validation_runes_js = {
1109
1112
} ;
1110
1113
1111
1114
/**
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
1114
1117
* @param {Scope } scope
1115
1118
* @param {boolean } is_binding
1116
1119
*/
@@ -1156,7 +1159,7 @@ function validate_no_const_assignment(node, argument, scope, is_binding) {
1156
1159
* Validates that the opening of a control flow block is `{` immediately followed by the expected character.
1157
1160
* In legacy mode whitespace is allowed inbetween. TODO remove once legacy mode is gone and move this into parser instead.
1158
1161
* @param {{start: number; end: number} } node
1159
- * @param {import('./types.js'). AnalysisState } state
1162
+ * @param {AnalysisState } state
1160
1163
* @param {string } expected
1161
1164
*/
1162
1165
function validate_opening_tag ( node , state , expected ) {
@@ -1167,9 +1170,9 @@ function validate_opening_tag(node, state, expected) {
1167
1170
}
1168
1171
1169
1172
/**
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
1173
1176
*/
1174
1177
function validate_assignment ( node , argument , state ) {
1175
1178
validate_no_const_assignment ( node , argument , state . scope , false ) ;
@@ -1192,9 +1195,9 @@ function validate_assignment(node, argument, state) {
1192
1195
}
1193
1196
}
1194
1197
1195
- let object = /** @type {import('estree'). Expression | import('estree'). Super } */ ( argument ) ;
1198
+ let object = /** @type {Expression | Super } */ ( argument ) ;
1196
1199
1197
- /** @type {import('estree'). Expression | import('estree'). PrivateIdentifier | null } */
1200
+ /** @type {Expression | PrivateIdentifier | null } */
1198
1201
let property = null ;
1199
1202
1200
1203
while ( object . type === 'MemberExpression' ) {
@@ -1322,7 +1325,7 @@ export const validation_runes = merge(validation, a11y_validators, {
1322
1325
1323
1326
if ( rune === null ) return ;
1324
1327
1325
- const args = /** @type {import('estree'). CallExpression } */ ( init ) . arguments ;
1328
+ const args = /** @type {CallExpression } */ ( init ) . arguments ;
1326
1329
1327
1330
// TODO some of this is duplicated with above, seems off
1328
1331
if ( ( rune === '$derived' || rune === '$derived.by' ) && args . length !== 1 ) {
0 commit comments