@@ -10,7 +10,7 @@ import { HTMLParser, HTMLTokenizer } from "./html"
1010import { parseScript , parseScriptElement } from "./script"
1111import * as services from "./parser-services"
1212import type { ParserOptions } from "./common/parser-options"
13- import { getScriptParser } from "./common/parser-options"
13+ import { getScriptParser , getParserLangFromSFC } from "./common/parser-options"
1414import { parseScriptSetupElements } from "./script-setup"
1515import { LinesAndColumns } from "./common/lines-and-columns"
1616import type { VElement } from "./ast"
@@ -64,7 +64,20 @@ export function parseForESLint(
6464 result = parseScript ( code , {
6565 ...options ,
6666 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+ } ) ,
6881 } )
6982 document = null
7083 locationCalculator = null
@@ -94,7 +107,9 @@ export function parseForESLint(
94107 ? Object . assign ( template , concreteInfo )
95108 : undefined
96109
97- const scriptParser = getScriptParser ( options . parser , rootAST , "script" )
110+ const scriptParser = getScriptParser ( options . parser , ( ) =>
111+ getParserLangFromSFC ( rootAST ) ,
112+ )
98113 let scriptSetup : VElement | undefined
99114 if ( skipParsingScript || ! scripts . length ) {
100115 result = parseScript ( "" , {
@@ -126,7 +141,10 @@ export function parseForESLint(
126141 const styles = rootAST . children . filter ( isStyleElement )
127142 parseStyleElements ( styles , locationCalculator , {
128143 ...options ,
129- parser : getScriptParser ( options . parser , rootAST , "template" ) ,
144+ parser : getScriptParser ( options . parser , function * ( ) {
145+ yield "<template>"
146+ yield getParserLangFromSFC ( rootAST )
147+ } ) ,
130148 } )
131149 }
132150
0 commit comments