8000 Changed default ecmaVersion to "latest" · vuejs/vue-eslint-parser@58dedba · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 58dedba

Browse files
committed
Changed default ecmaVersion to "latest"
1 parent d1d2540 commit 58dedba

File tree

8 files changed

+44
-66
lines changed

8 files changed

+44
-66
lines changed

src/common/espree.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ export function getEspree(): Espree {
1919
return espreeCache || (espreeCache = getNewestEspree())
2020
}
2121

22+
export function getEcmaVersionIfUseEspree(
23+
parserOptions: ParserOptions,
24+
): number | undefined {
25+
if (parserOptions.parser != null && parserOptions.parser !== "espree") {
26+
return undefined
27+
}
28+
29+
if (
30+
parserOptions.ecmaVersion === "latest" ||
31+
parserOptions.ecmaVersion == null
32+
) {
33+
return getDefaultEcmaVersion()
34+
}
35+
return normalizeEcmaVersion(parserOptions.ecmaVersion)
36+
}
37+
2238
/**
2339
* Load `espree` from the user dir.
2440
*/
@@ -44,26 +60,8 @@ function getNewestEspree(): Espree {
4460
return newest
4561
}
4662

47-
export function getEcmaVersionIfUseEspree(
48-
parserOptions: ParserOptions,
49-
getDefault?: (defaultVer: number) => number,
50-
): number | undefined {
51-
if (parserOptions.parser != null && parserOptions.parser !== "espree") {
52-
return undefined
53-
}
54-
55-
if (parserOptions.ecmaVersion === "latest") {
56-
return getDefaultEcmaVersion()
57-
}
58-
if (parserOptions.ecmaVersion == null) {
59-
const defVer = getDefaultEcmaVersion()
60-
return getDefault?.(defVer) ?? defVer
61-
}
62-
return normalizeEcmaVersion(parserOptions.ecmaVersion)
63-
}
64-
6563
function getDefaultEcmaVersion(): number {
66-
return normalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()))
64+
return getLatestEcmaVersion(getEspree())
6765
}
6866

6967
/**

src/script-setup/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
parseScriptFragment,
3232
} from "../script/index"
3333
import { extractGeneric } from "../script/generic"
34-
import { getScriptSetupParserOptions } from "./parser-options"
34+
import { DEFAULT_ECMA_VERSION } from "./parser-options"
3535

3636
type RemapBlock = {
3737
range: [number, number]
@@ -214,9 +214,10 @@ export function parseScriptSetupElements(
214214
linesAndColumns: LinesAndColumns,
215215
originalParserOptions: ParserOptions,
216216
): ESLintExtendedProgram {
217-
const parserOptions: ParserOptions = getScriptSetupParserOptions(
218-
originalParserOptions,
219-
)
217+
const parserOptions: ParserOptions = {
218+
...originalParserOptions,
219+
ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION,
220+
}
220221
const scriptSetupModuleCodeBlocks = getScriptSetupModuleCodeBlocks(
221222
scriptSetupElement,
222223
scriptElement,

src/script-setup/parser-options.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
import { getEcmaVersionIfUseEspree, getEspree } from "../common/espree"
2-
import type { ParserOptions } from "../common/parser-options"
1+
export const DEFAULT_ECMA_VERSION = "latest"
32

4-
export const DEFAULT_ECMA_VERSION = 2017
5-
6-
/**
7-
* Get parser options for <script setup>
8-
*/
9-
export function getScriptSetupParserOptions(
10-
parserOptions: ParserOptions,
11-
): ParserOptions {
12-
const espreeEcmaVersion = getEcmaVersionIfUseEspree(
13-
parserOptions,
14-
getDefaultEcmaVersion,
15-
)
16-
17-
return {
18-
...parserOptions,
19-
ecmaVersion: espreeEcmaVersion,
20-
}
21-
}
22-
23-
function getDefaultEcmaVersion() {
24-
return getEspree().latestEcmaVersion
25-
}
3+
export const ANALYZE_SCOPE_DEFAULT_ECMA_VERSION = 2022

src/script/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ import {
5050
fixLocation,
5151
fixLocations,
5252
} from "../common/fix-locations"
53-
import {
54-
DEFAULT_ECMA_VERSION,
55-
getScriptSetupParserOptions,
56-
} from "../script-setup/parser-options"
57-
import { isScriptSetupElement } from "../common/ast-utils"
53+
import { DEFAULT_ECMA_VERSION } from "../script-setup/parser-options"
5854
import type { LinesAndColumns } from "../common/lines-and-columns"
5955
import type { ParserObject } from "../common/parser-object"
6056
import { isEnhancedParserObject, isParserObject } from "../common/parser-object"
@@ -612,13 +608,10 @@ export function parseScriptElement(
612608
linesAndColumns: LinesAndColumns,
613609
originalParserOptions: ParserOptions,
614610
): ESLintExtendedProgram {
615-
const parserOptions: ParserOptions = isScriptSetupElement(node)
616-
? getScriptSetupParserOptions(originalParserOptions)
617-
: {
618-
...originalParserOptions,
619-
ecmaVersion:
620-
originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION,
621-
}
611+
const parserOptions: ParserOptions = {
612+
...originalParserOptions,
613+
ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION,
614+
}
622615

623616
let generic: GenericProcessInfo | null = null
624617
let code: string

src/script/scope-analyzer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
import { getFallbackKeys } from "../ast/index"
1515
import { getEslintScope } from "../common/eslint-scope"
1616
import { getEcmaVersionIfUseEspree } from "../common/espree"
17+
import { ANALYZE_SCOPE_DEFAULT_ECMA_VERSION } from "../script-setup/parser-options"
1718

1819
type ParserResult = {
1920
ast: ESLintProgram
@@ -100,7 +101,9 @@ export function analyzeScope(
100101
ast: ESLintProgram,
101102
parserOptions: ParserOptions,
102103
): escopeTypes.ScopeManager {
103-
const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022
104+
const ecmaVersion =
105+
getEcmaVersionIfUseEspree(parserOptions) ||
106+
ANALYZE_SCOPE_DEFAULT_ECMA_VERSION
104107
const ecmaFeatures = parserOptions.ecmaFeatures || {}
105108
const sourceType = parserOptions.sourceType || "script"
106109
const result = getEslintScope().analyze(ast, {

src/sfc/custom-block/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import type { LocationCalculatorForHtml } from "../../common/location-calculator
1717
import type { ParserObject } from "../../common/parser-object"
1818
import { isEnhancedParserObject } from "../../common/parser-object"
1919
import type { ParserOptions } from "../../common/parser-options"
20-
import { DEFAULT_ECMA_VERSION } from "../../script-setup/parser-options"
20+
import {
21+
ANALYZE_SCOPE_DEFAULT_ECMA_VERSION,
22+
DEFAULT_ECMA_VERSION,
23+
} from "../../script-setup/parser-options"
2124

2225
export type ESLintCustomBlockParser = ParserObject<any, any>
2326

@@ -291,7 +294,9 @@ export function createCustomBlockSharedContext({
291294
return parsedResult.scopeManager
292295
}
293296

294-
const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022
297+
const ecmaVersion =
298+
getEcmaVersionIfUseEspree(parserOptions) ||
299+
ANALYZE_SCOPE_DEFAULT_ECMA_VERSION
295300
const ecmaFeatures = parserOptions.ecmaFeatures || {}
296301
const sourceType = parserOptions.sourceType || "script"
297302
return getEslintScope().analyze(parsedResult.ast, {

test/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ describe("Basic tests", async () => {
588588
parserOptions: {
589589
...BABEL_PARSER_OPTIONS,
590590
sourceType: "module",
591-
ecmaVersion: 2017,
591+
ecmaVersion: "latest",
592592
},
593593
globals: {},
594594
},
@@ -752,7 +752,7 @@ describe("Basic tests", async () => {
752752
const indexOfDecorator = code.indexOf("@Component")
753753
const ast = parse(code, {
754754
...BABEL_PARSER_OPTIONS,
755-
ecmaVersion: 2017,
755+
ecmaVersion: "latest",
756756
sourceType: "module",
757757

758758
// Implicit parserOptions to detect whether the current ESLint supports `result.scopeManager` and `result.visitorKeys`.
@@ -859,7 +859,7 @@ describe("Basic tests", async () => {
859859
languageOptions: {
860860
parser,
861861
parserOptions: {
862-
ecmaVersion: 2015,
862+
ecmaVersion: "latest",
863863
},
864864
},
865865
}

test/test-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function scopeToJSON(scopeManager) {
105105
* Analyze scope
106106
*/
107107
function analyze(ast, parserOptions) {
108-
const ecmaVersion = parserOptions.ecmaVersion || 2017
108+
const ecmaVersion = parserOptions.ecmaVersion || 2022
109109
const ecmaFeatures = parserOptions.ecmaFeatures || {}
110110
const sourceType = parserOptions.sourceType || "script"
111111
const result = escope.analyze(ast, {

0 commit comments

Comments
 (0)
0