@@ -15,7 +15,6 @@ import type * as SvAST from "../parser/svelte-ast-types";
1515import type * as Compiler from "svelte/compiler" ;
1616import { ScriptLetContext } from "./script-let" ;
1717import { LetDirectiveCollections } from "./let-directive-collection" ;
18- import type { AttributeToken } from "../parser/html" ;
1918import { parseAttributes } from "../parser/html" ;
2019import { sortedLastIndex } from "../utils" ;
2120import {
@@ -181,8 +180,16 @@ export class Context {
181180 if ( block . selfClosing ) {
182181 continue ;
183182 }
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+ ) {
186193 continue ;
187194 }
188195 }
@@ -212,7 +219,13 @@ export class Context {
212219 spaces . slice ( start , block . contentRange [ 0 ] ) +
213220 code . slice ( ...block . contentRange ) ;
214221 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+ }
216229 }
217230 } else {
218231 scriptCode += spaces . slice ( start , block . contentRange [ 1 ] ) ;
@@ -338,7 +351,7 @@ type Block =
338351 | {
339352 tag : "script" | "style" | "template" ;
340353 originalTag : string ;
341- attrs : AttributeToken [ ] ;
354+ attrs : Compiler . Attribute [ ] ;
342355 selfClosing ?: false ;
343356 contentRange : [ number , number ] ;
344357 startTagRange : [ number , number ] ;
@@ -349,7 +362,7 @@ type Block =
349362type SelfClosingBlock = {
350363 tag : "script" | "style" | "template" ;
351364 originalTag : string ;
352- attrs : AttributeToken [ ] ;
365+ attrs : Compiler . Attribute [ ] ;
353366 selfClosing : true ;
354367 startTagRange : [ number , number ] ;
355368} ;
@@ -371,7 +384,7 @@ function* extractBlocks(code: string): IterableIterator<Block> {
371384
372385 const lowerTag = tag . toLowerCase ( ) as "script" | "style" | "template" ;
373386
374- let attrs : AttributeToken [ ] = [ ] ;
387+ let attrs : Compiler . Attribute [ ] = [ ] ;
375388 if ( ! nextChar . trim ( ) ) {
376389 const attrsData = parseAttributes ( code , startTagOpenRe . lastIndex ) ;
377390 attrs = attrsData . attributes ;
0 commit comments