Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

Sign up
Appearance settings

Commit68574cf

Browse files
authored
Changed default ecmaVersion to "latest" (#243)
1 parentaca17d7 commit68574cf

File tree

9 files changed

+47
-69
lines changed

9 files changed

+47
-69
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
returnespreeCache||(espreeCache=getNewestEspree())
2020
}
2121

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

47-
exportfunctiongetEcmaVersionIfUseEspree(
48-
parserOptions:ParserOptions,
49-
getDefault?:(defaultVer:number)=>number,
50-
):number|undefined{
51-
if(parserOptions.parser!=null&&parserOptions.parser!=="espree"){
52-
returnundefined
53-
}
54-
55-
if(parserOptions.ecmaVersion==="latest"){
56-
returngetDefaultEcmaVersion()
57-
}
58-
if(parserOptions.ecmaVersion==null){
59-
constdefVer=getDefaultEcmaVersion()
60-
returngetDefault?.(defVer)??defVer
61-
}
62-
returnnormalizeEcmaVersion(parserOptions.ecmaVersion)
63-
}
64-
6563
functiongetDefaultEcmaVersion():number{
66-
returnnormalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()))
64+
returngetLatestEcmaVersion(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
typeRemapBlock={
3737
range:[number,number]
@@ -214,9 +214,10 @@ export function parseScriptSetupElements(
214214
linesAndColumns:LinesAndColumns,
215215
originalParserOptions:ParserOptions,
216216
):ESLintExtendedProgram{
217-
constparserOptions:ParserOptions=getScriptSetupParserOptions(
218-
originalParserOptions,
219-
)
217+
constparserOptions:ParserOptions={
218+
...originalParserOptions,
219+
ecmaVersion:originalParserOptions.ecmaVersion||DEFAULT_ECMA_VERSION,
220+
}
220221
constscriptSetupModuleCodeBlocks=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-
importtype{ParserOptions}from"../common/parser-options"
1+
exportconstDEFAULT_ECMA_VERSION="latest"
32

4-
exportconstDEFAULT_ECMA_VERSION=2017
5-
6-
/**
7-
* Get parser options for <script setup>
8-
*/
9-
exportfunctiongetScriptSetupParserOptions(
10-
parserOptions:ParserOptions,
11-
):ParserOptions{
12-
constespreeEcmaVersion=getEcmaVersionIfUseEspree(
13-
parserOptions,
14-
getDefaultEcmaVersion,
15-
)
16-
17-
return{
18-
...parserOptions,
19-
ecmaVersion:espreeEcmaVersion||parserOptions.ecmaVersion,
20-
}
21-
}
22-
23-
functiongetDefaultEcmaVersion(){
24-
returngetEspree().latestEcmaVersion
25-
}
3+
exportconstANALYZE_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
importtype{LinesAndColumns}from"../common/lines-and-columns"
5955
importtype{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-
constparserOptions:ParserOptions=isScriptSetupElement(node)
616-
?getScriptSetupParserOptions(originalParserOptions)
617-
:{
618-
...originalParserOptions,
619-
ecmaVersion:
620-
originalParserOptions.ecmaVersion||DEFAULT_ECMA_VERSION,
621-
}
611+
constparserOptions:ParserOptions={
612+
...originalParserOptions,
613+
ecmaVersion:originalParserOptions.ecmaVersion||DEFAULT_ECMA_VERSION,
614+
}
622615

623616
letgeneric:GenericProcessInfo|null=null
624617
letcode: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
typeParserResult={
1920
ast:ESLintProgram
@@ -100,7 +101,9 @@ export function analyzeScope(
100101
ast:ESLintProgram,
101102
parserOptions:ParserOptions,
102103
):escopeTypes.ScopeManager{
103-
constecmaVersion=getEcmaVersionIfUseEspree(parserOptions)||2022
104+
constecmaVersion=
105+
getEcmaVersionIfUseEspree(parserOptions)||
106+
ANALYZE_SCOPE_DEFAULT_ECMA_VERSION
104107
constecmaFeatures=parserOptions.ecmaFeatures||{}
105108
constsourceType=parserOptions.sourceType||"script"
106109
constresult=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
importtype{ParserObject}from"../../common/parser-object"
1818
import{isEnhancedParserObject}from"../../common/parser-object"
1919
importtype{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
exporttypeESLintCustomBlockParser=ParserObject<any,any>
2326

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

294-
constecmaVersion=getEcmaVersionIfUseEspree(parserOptions)||2022
297+
constecmaVersion=
298+
getEcmaVersionIfUseEspree(parserOptions)||
299+
ANALYZE_SCOPE_DEFAULT_ECMA_VERSION
295300
constecmaFeatures=parserOptions.ecmaFeatures||{}
296301
constsourceType=parserOptions.sourceType||"script"
297302
returngetEslintScope().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
constindexOfDecorator=code.indexOf("@Component")
753753
constast=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/parser-options-project.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("use `project: undefined` when parsing template script-let", () => {
2828
{
2929
project:true,
3030
sourceType:"module",
31-
ecmaVersion:2018,
31+
ecmaVersion:"latest",
3232
parser:{
3333
parseForESLint(code,options){
3434
if(options.project){
@@ -72,7 +72,7 @@ describe("use `project: undefined` when parsing template script-let", () => {
7272
{
7373
project:true,
7474
sourceType:"module",
75-
ecmaVersion:2018,
75+
ecmaVersion:"latest",
7676
parser:{
7777
parseForESLint(code,options){
7878
if(options.project){
@@ -115,7 +115,7 @@ describe("use `project: undefined` when parsing template script-let", () => {
115115
{
116116
project:true,
117117
sourceType:"module",
118-
ecmaVersion:2018,
118+
ecmaVersion:"latest",
119119
parser:{
120120
parseForESLint(code,options){
121121
if(options.project){

‎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
functionanalyze(ast,parserOptions){
108-
constecmaVersion=parserOptions.ecmaVersion||2017
108+
constecmaVersion=parserOptions.ecmaVersion||2022
109109
constecmaFeatures=parserOptions.ecmaFeatures||{}
110110
constsourceType=parserOptions.sourceType||"script"
111111
constresult=escope.analyze(ast,{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp