diff --git a/src/html/parser.ts b/src/html/parser.ts
index 9a6c1be..82edb7d 100644
--- a/src/html/parser.ts
+++ b/src/html/parser.ts
@@ -302,6 +302,7 @@ export class Parser {
yield getParserLangFromSFC(doc)
},
),
+ project: undefined,
}
const scriptParserOptions = {
...this.baseParserOptions,
diff --git a/src/index.ts b/src/index.ts
index 20a067f..f4e0077 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -164,6 +164,7 @@ function parseAsSFC(code: string, options: ParserOptions) {
yield ""
yield getParserLangFromSFC(rootAST)
}),
+ project: undefined,
})
}
result.ast.templateBody = templateBody
diff --git a/src/script-setup/index.ts b/src/script-setup/index.ts
index e820bdc..22f5104 100644
--- a/src/script-setup/index.ts
+++ b/src/script-setup/index.ts
@@ -513,14 +513,12 @@ function getScriptSetupCodeBlocks(
const offsetLocationCalculator =
linesAndColumns.createOffsetLocationCalculator(scriptSetupStartOffset)
- const result = parseScript(
+ const { ast, visitorKeys } = parseScript(
scriptCode,
- parserOptions,
+ { ...parserOptions, project: 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()
@@ -594,7 +592,7 @@ function getScriptSetupCodeBlocks(
}
fixNodeLocations(
body,
- result.visitorKeys,
+ visitorKeys,
offsetLocationCalculator,
)
fixLocation(exportToken, offsetLocationCalculator)
@@ -692,7 +690,7 @@ function getScriptSetupCodeBlocks(
// restore
fixNodeLocations(
body,
- result.visitorKeys,
+ visitorKeys,
offsetLocationCalculator,
)
for (const token of restoreTokens) {
@@ -823,7 +821,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 4dc263f..cfd01ba 100644
--- a/src/script-setup/parser-options.ts
+++ b/src/script-setup/parser-options.ts
@@ -17,7 +17,7 @@ export function getScriptSetupParserOptions(
return {
...parserOptions,
- ecmaVersion: espreeEcmaVersion,
+ ecmaVersion: espreeEcmaVersion || parserOptions.ecmaVersion,
}
}
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)
+ })
+})