@@ -10,7 +10,7 @@ import { HTMLParser, HTMLTokenizer } from "./html"
10
10
import { parseScript , parseScriptElement } from "./script"
11
11
import * as services from "./parser-services"
12
12
import type { ParserOptions } from "./common/parser-options"
13
- import { getScriptParser } from "./common/parser-options"
13
+ import { getScriptParser , getParserLangFromSFC } from "./common/parser-options"
14
14
import { parseScriptSetupElements } from "./script-setup"
15
15
import { LinesAndColumns } from "./common/lines-and-columns"
16
16
import type { VElement } from "./ast"
@@ -64,7 +64,20 @@ export function parseForESLint(
64
64
result = parseScript ( code , {
65
65
...options ,
66
66
ecmaVersion : options . ecmaVersion || DEFAULT_ECMA_VERSION ,
67
- parser : getScriptParser ( options . parser , null , "script" ) ,
67
+ parser : getScriptParser ( options . parser , ( ) => {
68
+ const ext = (
69
+ path
70
+ . extname ( options . filePath || "unknown.js" )
71
+ . toLowerCase ( ) || ""
72
+ )
73
+ // remove dot
74
+ . slice ( 1 )
75
+ if ( / ^ [ j t ] s x $ / u. test ( ext ) ) {
76
+ return [ ext , ext . slice ( 0 , - 1 ) ]
77
+ }
78
+
79
+ return ext
80
+ } ) ,
68
81
} )
69
82
document = null
70
83
locationCalculator = null
@@ -94,7 +107,9 @@ export function parseForESLint(
94
107
? Object . assign ( template , concreteInfo )
95
108
: undefined
96
109
97
- const scriptParser = getScriptParser ( options . parser , rootAST , "script" )
110
+ const scriptParser = getScriptParser ( options . parser , ( ) =>
111
+ getParserLangFromSFC ( rootAST ) ,
112
+ )
98
113
let scriptSetup : VElement | undefined
99
114
if ( skipParsingScript || ! scripts . length ) {
100
115
result = parseScript ( "" , {
@@ -126,7 +141,10 @@ export function parseForESLint(
126
141
const styles = rootAST . children . filter ( isStyleElement )
127
142
parseStyleElements ( styles , locationCalculator , {
128
143
...options ,
129
- parser : getScriptParser ( options . parser , rootAST , "template" ) ,
144
+ parser : getScriptParser ( options . parser , function * ( ) {
145
+ yield "<template>"
146
+ yield getParserLangFromSFC ( rootAST )
147
+ } ) ,
130
148
} )
131
149
}
132
150
0 commit comments