"
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 d5c3701a..d336b0f0 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 0a3b6865..183b20a4 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 b8531d30..73c28109 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 00000000..398835db
--- /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)
+ })
+})
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy