@@ -150,14 +150,10 @@ function convertAttribute(
150
150
ctx . addToken ( "HTMLIdentifier" , keyRange ) ;
151
151
return attribute ;
152
152
}
153
- const value = Array . isArray ( node . value ) ? node . value : [ node . value ] ;
153
+ const value = node . value ;
154
154
const shorthand =
155
- value . some ( ( v ) => v . type === "AttributeShorthand" ) ||
156
- // for Svelte v5
157
- ( value . length === 1 &&
158
- value [ 0 ] . type === "ExpressionTag" &&
159
- ctx . code [ node . start ] === "{" &&
160
- ctx . code [ node . end - 1 ] === "}" ) ;
155
+ isAttributeShorthandForSvelteV4 ( value ) ||
156
+ isAttributeShorthandForSvelteV5 ( value ) ;
161
157
if ( shorthand ) {
162
158
const key : ESTree . Identifier = {
163
159
...attribute . key ,
@@ -187,14 +183,29 @@ function convertAttribute(
187
183
// Not required for shorthands. Therefore, register the token here.
188
184
ctx . addToken ( "HTMLIdentifier" , keyRange ) ;
189
185
190
- processAttributeValue (
191
- value as Exclude < ( typeof value ) [ number ] , SvAST . AttributeShorthand > [ ] ,
192
- attribute ,
193
- parent ,
194
- ctx ,
195
- ) ;
186
+ processAttributeValue ( value , attribute , parent , ctx ) ;
196
187
197
188
return attribute ;
189
+
190
+ function isAttributeShorthandForSvelteV4 (
191
+ value : Exclude < ( SvAST . Attribute | Compiler . Attribute ) [ "value" ] , boolean > ,
192
+ ) : value is [ SvAST . AttributeShorthand ] {
193
+ return Array . isArray ( value ) && value [ 0 ] ?. type === "AttributeShorthand" ;
194
+ }
195
+
196
+ function isAttributeShorthandForSvelteV5 (
197
+ value : Exclude <
198
+ ( SvAST . Attribute | Compiler . Attribute ) [ "value" ] ,
199
+ boolean | [ SvAST . AttributeShorthand ]
200
+ > ,
201
+ ) : boolean {
202
+ return (
203
+ ! Array . isArray ( value ) &&
204
+ value . type === "ExpressionTag" &&
205
+ ctx . code [ node . start ] === "{" &&
206
+ ctx . code [ node . end - 1 ] === "}"
207
+ ) ;
208
+ }
198
209
}
199
210
200
211
/** Common process attribute value */
0 commit comments