@@ -36,7 +36,7 @@ import {
36
36
} from "./style-context" ;
37
37
import { getGlobalsForSvelte , getGlobalsForSvelteScript } from "./globals" ;
38
38
import type { NormalizedParserOptions } from "./parser-options" ;
39
- import { isTypeScript , normalizeParserOptions } from "./parser-options" ;
39
+ import { getLanguage , normalizeParserOptions } from "./parser-options" ;
40
40
import { getFragmentFromRoot } from "./compat" ;
41
41
import {
42
42
isEnableRunes ,
@@ -140,18 +140,24 @@ function parseAsSvelte(
140
140
) ;
141
141
142
142
const scripts = ctx . sourceCode . scripts ;
143
- const resultScript = ctx . isTypeScript ( )
144
- ? parseTypeScriptInSvelte (
145
- scripts . getCurrentVirtualCodeInfo ( ) ,
146
- scripts . attrs ,
147
- parserOptions ,
148
- { slots : ctx . slots , svelteParseContext } ,
149
- )
150
- : parseScriptInSvelte (
151
- scripts . getCurrentVirtualCode ( ) ,
152
- scripts . attrs ,
153
- parserOptions ,
154
- ) ;
143
+ const language = ctx . getLanguage ( ) ;
144
+
145
+ const resultScript =
146
+ language === "ts" || language === "jsdoc"
147
+ ? parseTypeScriptInSvelte (
148
+ scripts . getCurrentVirtualCodeInfo ( ) ,
149
+ {
150
+ ...scripts . attrs ,
151
+ lang : language === "jsdoc" ? "ts" : scripts . attrs . lang ,
152
+ } ,
153
+ parserOptions ,
154
+ { slots : ctx . slots , svelteParseContext } ,
155
+ )
156
+ : parseScriptInSvelte (
157
+ scripts . getCurrentVirtualCode ( ) ,
158
+ scripts . attrs ,
159
+ parserOptions ,
160
+ ) ;
155
161
ctx . scriptLet . restore ( resultScript ) ;
156
162
ctx . tokens . push ( ...resultScript . ast . tokens ) ;
157
163
ctx . comments . push ( ...resultScript . ast . comments ) ;
@@ -249,10 +255,17 @@ function parseAsScript(
249
255
parserOptions : NormalizedParserOptions ,
250
256
svelteParseContext : SvelteParseContext ,
251
257
) : ParseResult {
252
- const lang = parserOptions . filePath ?. split ( "." ) . pop ( ) ;
253
- const resultScript = isTypeScript ( parserOptions , lang )
254
- ? parseTypeScript ( code , { lang } , parserOptions , svelteParseContext )
255
- : parseScript ( code , { lang } , parserOptions ) ;
258
+ const rawLang = parserOptions . filePath ?. split ( "." ) . pop ( ) ;
259
+ const lang = getLanguage ( parserOptions , rawLang , code ) ;
260
+ const resultScript =
261
+ lang === "ts" || lang === "jsdoc"
262
+ ? parseTypeScript (
263
+ code ,
264
+ { lang : lang === "jsdoc" ? "ts" : rawLang } ,
265
+ parserOptions ,
266
+ svelteParseContext ,
267
+ )
268
+ : parseScript ( code , { lang : rawLang } , parserOptions ) ;
256
269
257
270
// Add $$xxx variable
258
271
addGlobalVariables (
0 commit comments