diff --git a/src/common/parser-options.ts b/src/common/parser-options.ts
index d28504e..25656ab 100644
--- a/src/common/parser-options.ts
+++ b/src/common/parser-options.ts
@@ -30,6 +30,7 @@ export interface ParserOptions {
lib?: string[]
project?: string | string[]
+ projectService?: boolean | ProjectServiceOptions
projectFolderIgnoreList?: string[]
tsconfigRootDir?: string
extraFileExtensions?: string[]
@@ -55,6 +56,13 @@ export interface ParserOptions {
>
}
+interface ProjectServiceOptions {
+ allowDefaultProject?: string[]
+ defaultProject?: string
+ loadTypeScriptPlugins?: boolean
+ maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING?: number
+}
+
export function isSFCFile(parserOptions: ParserOptions) {
if (parserOptions.filePath === "") {
return true
diff --git a/src/html/parser.ts b/src/html/parser.ts
index fada147..367eecc 100644
--- a/src/html/parser.ts
+++ b/src/html/parser.ts
@@ -302,6 +302,8 @@ export class Parser {
yield getParserLangFromSFC(doc)
},
),
+ project: undefined,
+ projectService: undefined,
}
const scriptParserOptions = {
...this.baseParserOptions,
diff --git a/src/index.ts b/src/index.ts
index 33eb1c3..3b45a18 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -165,6 +165,8 @@ function parseAsSFC(code: string, options: ParserOptions) {
yield ""
yield getParserLangFromSFC(rootAST)
}),
+ project: undefined,
+ projectService: undefined,
})
}
result.ast.templateBody = templateBody
diff --git a/src/script-setup/index.ts b/src/script-setup/index.ts
index d5c3701..d336b0f 100644
--- a/src/script-setup/index.ts
+++ b/src/script-setup/index.ts
@@ -516,14 +516,12 @@ function getScriptSetupCodeBlocks(
const offsetLocationCalculator =
linesAndColumns.createOffsetLocationCalculator(scriptSetupStartOffset)
- const result = parseScript(
+ const { ast, visitorKeys } = parseScript(
scriptCode,
- parserOptions,
+ { ...parserOptions, project: undefined, projectService: undefined },
offsetLocationCalculator,
)
- const { ast } = result
-
// Holds the `import` and re-`export` statements.
// All import and re-`export` statements are hoisted to the top.
const importCodeBlocks = new CodeBlocks()
@@ -597,7 +595,7 @@ function getScriptSetupCodeBlocks(
}
fixNodeLocations(
body,
- result.visitorKeys,
+ visitorKeys,
offsetLocationCalculator,
)
fixLocation(exportToken, offsetLocationCalculator)
@@ -695,7 +693,7 @@ function getScriptSetupCodeBlocks(
// restore
fixNodeLocations(
body,
- result.visitorKeys,
+ visitorKeys,
offsetLocationCalculator,
)
for (const token of restoreTokens) {
@@ -826,7 +824,7 @@ function getScriptSetupCodeBlocks(
let start = n.range[0]
let end = n.range[1]
traverseNodes(n, {
- visitorKeys: result.visitorKeys,
+ visitorKeys,
enterNode(c) {
start = Math.min(start, c.range[0])
end = Math.max(end, c.range[1])
diff --git a/src/script-setup/parser-options.ts b/src/script-setup/parser-options.ts
index 0a3b686..183b20a 100644
--- a/src/script-setup/parser-options.ts
+++ b/src/script-setup/parser-options.ts
@@ -16,7 +16,7 @@ export function getScriptSetupParserOptions(
return {
...parserOptions,
- ecmaVersion: espreeEcmaVersion,
+ ecmaVersion: espreeEcmaVersion || parserOptions.ecmaVersion,
}
}
diff --git a/src/script/index.ts b/src/script/index.ts
index b8531d3..73c2810 100644
--- a/src/script/index.ts
+++ b/src/script/index.ts
@@ -1302,7 +1302,7 @@ export function parseGenericExpression(
const result = parseScriptFragmentWithOption(
scriptLet,
locationCalculator.getSubCalculatorShift(-14),
- { ...parserOptions, project: undefined },
+ { ...parserOptions, project: undefined, projectService: undefined },
{
preFixLocationProcess(preResult) {
const params = getParams(preResult)
diff --git a/test/parser-options-project.js b/test/parser-options-project.js
new file mode 100644
index 0000000..398835d
--- /dev/null
+++ b/test/parser-options-project.js
@@ -0,0 +1,134 @@
+"use strict"
+
+const assert = require("assert")
+const { parseForESLint } = require("../src")
+const espree = require("espree")
+
+describe("use `project: undefined` when parsing template script-let", () => {
+ it("should be the project option is defined only once in Simple SFC.", () => {
+ let projectCount = 0
+ parseForESLint(
+ `
+
+
+ {{ 'str' }}
+
+
+
+
+ A
+
+
+
+
+
+ `,
+ {
+ project: true,
+ sourceType: "module",
+ ecmaVersion: 2018,
+ parser: {
+ parseForESLint(code, options) {
+ if (options.project) {
+ projectCount++
+ }
+
+ return {
+ ast: espree.parse(code, options),
+ }
+ },
+ },
+ },
+ )
+ assert.strictEqual(projectCount, 1)
+ })
+ it("should be the project option is defined only once in
+
+
+
+ {{ 'str' }}
+
+
+
+
+ A
+
+
+
+
+
+ `,
+ {
+ project: true,
+ sourceType: "module",
+ ecmaVersion: 2018,
+ parser: {
+ parseForESLint(code, options) {
+ if (options.project) {
+ projectCount++
+ }
+
+ return {
+ ast: espree.parse(code, options),
+ }
+ },
+ },
+ },
+ )
+ assert.strictEqual(projectCount, 1)
+ })
+
+ it("should be the project option is defined only once in
+
+
+
+
+ {{ 'str' }}
+
+
+
+
+ A
+
+
+
+
+ `,
+ {
+ project: true,
+ sourceType: "module",
+ ecmaVersion: 2018,
+ parser: {
+ parseForESLint(code, options) {
+ if (options.project) {
+ projectCount++
+ }
+
+ return {
+ ast: espree.parse(code, options),
+ }
+ },
+ },
+ },
+ )
+ assert.strictEqual(projectCount, 1)
+ })
+})