Skip to content

Commit

Permalink
Add 2021 2022, handle "latest" in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Aug 30, 2021
1 parent 6a88ffe commit d93aec0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/parser/README.md
Expand Up @@ -99,8 +99,8 @@ Default `2018`.

Accepts any valid ECMAScript version number or `'latest'`:

- A version: es3, es5, es6, es7, es8, es9, es10, es11, ..., or
- A year: es2015, es2016, es2017, es2018, es2019, es2020, ...
- A version: es3, es5, es6, es7, es8, es9, es10, es11, es12, es13, ..., or
- A year: es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, ...
- `latest`

When it's a version or a year, the value **must** be a number - so do not include the `es` prefix.
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/parser.ts
Expand Up @@ -102,7 +102,7 @@ function parseForESLint(
jsx: validateBoolean(options.ecmaFeatures.jsx),
});
const analyzeOptions: AnalyzeOptions = {
ecmaVersion: options.ecmaVersion,
ecmaVersion: options.ecmaVersion === 'latest' ? 1e8 : options.ecmaVersion,
globalReturn: options.ecmaFeatures.globalReturn,
jsxPragma: options.jsxPragma,
jsxFragmentName: options.jsxFragmentName,
Expand Down
12 changes: 3 additions & 9 deletions packages/scope-manager/src/ScopeManager.ts
Expand Up @@ -26,7 +26,7 @@ interface ScopeManagerOptions {
globalReturn?: boolean;
sourceType?: 'module' | 'script';
impliedStrict?: boolean;
ecmaVersion?: number | 'latest';
ecmaVersion?: number;
}

class ScopeManager {
Expand Down Expand Up @@ -76,17 +76,11 @@ class ScopeManager {
return this.#options.impliedStrict === true;
}
public isStrictModeSupported(): boolean {
return (
this.#options.ecmaVersion === 'latest' ||
(this.#options.ecmaVersion != null && this.#options.ecmaVersion >= 5)
);
return this.#options.ecmaVersion != null && this.#options.ecmaVersion >= 5;
}

public isES6(): boolean {
return (
this.#options.ecmaVersion === 'latest' ||
(this.#options.ecmaVersion != null && this.#options.ecmaVersion >= 6)
);
return this.#options.ecmaVersion != null && this.#options.ecmaVersion >= 6;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/scope-manager/src/analyze.ts
Expand Up @@ -18,7 +18,7 @@ interface AnalyzeOptions {
* Which ECMAScript version is considered.
* Defaults to `2018`.
*/
ecmaVersion?: EcmaVersion;
ecmaVersion?: number;

/**
* Whether the whole script is executed under node.js environment.
Expand Down Expand Up @@ -81,7 +81,7 @@ const DEFAULT_OPTIONS: Required<AnalyzeOptions> = {
emitDecoratorMetadata: false,
};

function mapEcmaVersion(version: EcmaVersion | undefined): Lib {
function mapEcmaVersion(version: EcmaVersion | number | undefined): Lib {
if (version === 'latest') {
return 'esnext';
}
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/parser-options.ts
Expand Up @@ -12,12 +12,16 @@ type EcmaVersion =
| 9
| 10
| 11
| 12
| 13
| 2015
| 2016
| 2017
| 2018
| 2019
| 2020
| 2021
| 2022
| 'latest';

type SourceType = 'script' | 'module';
Expand Down

0 comments on commit d93aec0

Please sign in to comment.