From 01c813863b970630eb6d5ef3753cc5997e497089 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Fri, 12 May 2023 09:39:45 +0900 Subject: [PATCH 1/3] Make to use `project: undefined` when parsing template script-let. --- src/html/parser.ts | 1 + src/script-setup/index.ts | 12 ++- src/script-setup/parser-options.ts | 2 +- test/parser-options-project.js | 129 +++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 test/parser-options-project.js diff --git a/src/html/parser.ts b/src/html/parser.ts index fada147..baccda4 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/script-setup/index.ts b/src/script-setup/index.ts index d5c3701..d620cb9 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 }, 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/test/parser-options-project.js b/test/parser-options-project.js new file mode 100644 index 0000000..cc7dbbb --- /dev/null +++ b/test/parser-options-project.js @@ -0,0 +1,129 @@ +"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( + ` + + `, + { + 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 + + `, + { + 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 + + + `, + { + project: true, + sourceType: "module", + ecmaVersion: 2018, + parser: { + parseForESLint(code, options) { + if (options.project) { + projectCount++ + } + + return { + ast: espree.parse(code, options), + } + }, + }, + }, + ) + assert.strictEqual(projectCount, 1) + }) +}) From 78db8a80d611e515588f82fe27f4528e637fde21 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Fri, 12 May 2023 09:48:06 +0900 Subject: [PATCH 2/3] fix for css v-bind --- src/index.ts | 1 + test/parser-options-project.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/index.ts b/src/index.ts index 33eb1c3..703e44a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -165,6 +165,7 @@ function parseAsSFC(code: string, options: ParserOptions) { yield " + `, { project: true, From 6353982af997e825265af32f4063743ec8513049 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 29 Jan 2025 13:26:08 +0900 Subject: [PATCH 3/3] add `projectService: undefined` --- src/common/parser-options.ts | 8 ++++++++ src/html/parser.ts | 1 + src/index.ts | 1 + src/script-setup/index.ts | 2 +- src/script/index.ts | 2 +- 5 files changed, 12 insertions(+), 2 deletions(-) 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 baccda4..367eecc 100644 --- a/src/html/parser.ts +++ b/src/html/parser.ts @@ -303,6 +303,7 @@ export class Parser { }, ), project: undefined, + projectService: undefined, } const scriptParserOptions = { ...this.baseParserOptions, diff --git a/src/index.ts b/src/index.ts index 703e44a..3b45a18 100644 --- a/src/index.ts +++ b/src/index.ts @@ -166,6 +166,7 @@ function parseAsSFC(code: string, options: ParserOptions) { 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 d620cb9..d336b0f 100644 --- a/src/script-setup/index.ts +++ b/src/script-setup/index.ts @@ -518,7 +518,7 @@ function getScriptSetupCodeBlocks( const { ast, visitorKeys } = parseScript( scriptCode, - { ...parserOptions, project: undefined }, + { ...parserOptions, project: undefined, projectService: undefined }, offsetLocationCalculator, ) 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) 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