@@ -15,7 +15,6 @@ import type * as SvAST from "../parser/svelte-ast-types";
15
15
import type * as Compiler from "svelte/compiler" ;
16
16
import { ScriptLetContext } from "./script-let" ;
17
17
import { LetDirectiveCollections } from "./let-directive-collection" ;
18
- import type { AttributeToken } from "../parser/html" ;
19
18
import { parseAttributes } from "../parser/html" ;
20
19
import { sortedLastIndex } from "../utils" ;
21
20
import {
@@ -181,8 +180,16 @@ export class Context {
181
180
if ( block . selfClosing ) {
182
181
continue ;
183
182
}
184
- const lang = block . attrs . find ( ( attr ) => attr . key . name === "lang" ) ;
185
- if ( ! lang || ! lang . value || lang . value . value === "html" ) {
183
+ const lang = block . attrs . find ( ( attr ) => attr . name === "lang" ) ;
184
+ if ( ! lang || ! Array . isArray ( lang . value ) ) {
185
+ continue ;
186
+ }
187
+ const langValue = lang . value [ 0 ] ;
188
+ if (
189
+ ! langValue ||
190
+ langValue . type !== "Text" ||
191
+ langValue . data === "html"
192
+ ) {
186
193
continue ;
187
194
}
188
195
}
@@ -212,7 +219,13 @@ export class Context {
212
219
spaces . slice ( start , block . contentRange [ 0 ] ) +
213
220
code . slice ( ...block . contentRange ) ;
214
221
for ( const attr of block . attrs ) {
215
- scriptAttrs [ attr . key . name ] = attr . value ?. value ;
222
+ if ( Array . isArray ( attr . value ) ) {
223
+ const attrValue = attr . value [ 0 ] ;
224
+ scriptAttrs [ attr . name ] =
225
+ attrValue && attrValue . type === "Text"
226
+ ? attrValue . data
227
+ : undefined ;
228
+ }
216
229
}
217
230
} else {
218
231
scriptCode += spaces . slice ( start , block . contentRange [ 1 ] ) ;
@@ -338,7 +351,7 @@ type Block =
338
351
| {
339
352
tag : "script" | "style" | "template" ;
340
353
originalTag : string ;
341
- attrs : AttributeToken [ ] ;
354
+ attrs : Compiler . Attribute [ ] ;
342
355
selfClosing ?: false ;
343
356
contentRange : [ number , number ] ;
344
357
startTagRange : [ number , number ] ;
@@ -349,7 +362,7 @@ type Block =
349
362
type SelfClosingBlock = {
350
363
tag : "script" | "style" | "template" ;
351
364
originalTag : string ;
352
- attrs : AttributeToken [ ] ;
365
+ attrs : Compiler . Attribute [ ] ;
353
366
selfClosing : true ;
354
367
startTagRange : [ number , number ] ;
355
368
} ;
@@ -371,7 +384,7 @@ function* extractBlocks(code: string): IterableIterator<Block> {
371
384
372
385
const lowerTag = tag . toLowerCase ( ) as "script" | "style" | "template" ;
373
386
374
- let attrs : AttributeToken [ ] = [ ] ;
387
+ let attrs : Compiler . Attribute [ ] = [ ] ;
375
388
if ( ! nextChar . trim ( ) ) {
376
389
const attrsData = parseAttributes ( code , startTagOpenRe . lastIndex ) ;
377
390
attrs = attrsData . attributes ;
0 commit comments