-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(scope-manager): ignore ECMA version #5881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a5f7bd4
5aa6a27
e42f754
70e73fb
04e8bed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import type { EcmaVersion, Lib, TSESTree } from '@typescript-eslint/types'; | ||
import type { Lib, TSESTree } from '@typescript-eslint/types'; | ||
import { visitorKeys } from '@typescript-eslint/visitor-keys'; | ||
|
||
import { lib as TSLibraries } from './lib'; | ||
import type { ReferencerOptions } from './referencer'; | ||
import { Referencer } from './referencer'; | ||
import { ScopeManager } from './ScopeManager'; | ||
|
@@ -16,13 +15,6 @@ interface AnalyzeOptions { | |
*/ | ||
childVisitorKeys?: ReferencerOptions['childVisitorKeys']; | ||
|
||
/** | ||
* Which ECMAScript version is considered. | ||
* Defaults to `2018`. | ||
* `'latest'` is converted to 1e8 at parser. | ||
*/ | ||
ecmaVersion?: EcmaVersion | 1e8; | ||
|
||
/** | ||
* Whether the whole script is executed under node.js environment. | ||
* When enabled, the scope manager adds a function scope immediately following the global scope. | ||
|
@@ -31,7 +23,7 @@ interface AnalyzeOptions { | |
globalReturn?: boolean; | ||
|
||
/** | ||
* Implied strict mode (if ecmaVersion >= 5). | ||
* Implied strict mode. | ||
* Defaults to `false`. | ||
*/ | ||
impliedStrict?: boolean; | ||
|
@@ -54,7 +46,7 @@ interface AnalyzeOptions { | |
/** | ||
* The lib used by the project. | ||
* This automatically defines a type variable for any types provided by the configured TS libs. | ||
* Defaults to the lib for the provided `ecmaVersion`. | ||
* Defaults to ['esnext']. | ||
* | ||
* https://www.typescriptlang.org/tsconfig#lib | ||
*/ | ||
|
@@ -74,7 +66,6 @@ interface AnalyzeOptions { | |
|
||
const DEFAULT_OPTIONS: Required<AnalyzeOptions> = { | ||
childVisitorKeys: visitorKeys, | ||
ecmaVersion: 2018, | ||
globalReturn: false, | ||
impliedStrict: false, | ||
jsxPragma: 'React', | ||
|
@@ -84,34 +75,16 @@ const DEFAULT_OPTIONS: Required<AnalyzeOptions> = { | |
emitDecoratorMetadata: false, | ||
}; | ||
|
||
/** | ||
* Convert ecmaVersion to lib. | ||
* `'latest'` is converted to 1e8 at parser. | ||
*/ | ||
function mapEcmaVersion(version: EcmaVersion | 1e8 | undefined): Lib { | ||
if (version == null || version === 3 || version === 5) { | ||
return 'es5'; | ||
} | ||
|
||
const year = version > 2000 ? version : 2015 + (version - 6); | ||
const lib = `es${year}`; | ||
|
||
return lib in TSLibraries ? (lib as Lib) : year > 2020 ? 'esnext' : 'es5'; | ||
} | ||
|
||
/** | ||
* Takes an AST and returns the analyzed scopes. | ||
*/ | ||
function analyze( | ||
tree: TSESTree.Node, | ||
providedOptions?: AnalyzeOptions, | ||
): ScopeManager { | ||
const ecmaVersion = | ||
providedOptions?.ecmaVersion ?? DEFAULT_OPTIONS.ecmaVersion; | ||
const options: Required<AnalyzeOptions> = { | ||
childVisitorKeys: | ||
providedOptions?.childVisitorKeys ?? DEFAULT_OPTIONS.childVisitorKeys, | ||
ecmaVersion, | ||
globalReturn: providedOptions?.globalReturn ?? DEFAULT_OPTIONS.globalReturn, | ||
impliedStrict: | ||
providedOptions?.impliedStrict ?? DEFAULT_OPTIONS.impliedStrict, | ||
|
@@ -122,7 +95,7 @@ function analyze( | |
jsxFragmentName: | ||
providedOptions?.jsxFragmentName ?? DEFAULT_OPTIONS.jsxFragmentName, | ||
sourceType: providedOptions?.sourceType ?? DEFAULT_OPTIONS.sourceType, | ||
lib: providedOptions?.lib ?? [mapEcmaVersion(ecmaVersion)], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm. I wonder if maybe I was too over-zealous with my recommendation to cull higher? Having this auto-resolved is a really nice property. For the most part it shouldn't cause any issues for people (it just includes a few more global variables for people using rules like Hmm. WDYT? I'm torn on if it's worth the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neither of those are rules we recommend folks use - and folks should generally always be in >=ES2021 or so these days. I say let's kill them for now, and use the RC period to see if anybody notices! 🔪 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I will mark this as a breaking change now though. |
||
lib: providedOptions?.lib ?? ['esnext'], | ||
emitDecoratorMetadata: | ||
providedOptions?.emitDecoratorMetadata ?? | ||
DEFAULT_OPTIONS.emitDecoratorMetadata, | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.