Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "feat(scope-manager): ignore ECMA version" (#5888)
- Loading branch information
1 parent
3b8d449
commit 2ee81df
Showing
11 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/scope-manager/tests/eslint-scope/map-ecma-version.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { EcmaVersion, Lib, TSESTree } from '@typescript-eslint/types'; | ||
|
||
import { analyze } from '../../src/analyze'; | ||
import { Referencer } from '../../src/referencer'; | ||
|
||
jest.mock('../../src/referencer'); | ||
jest.mock('../../src/ScopeManager'); | ||
|
||
describe('ecma version mapping', () => { | ||
it("should map to 'esnext' when unsuported and new", () => { | ||
expectMapping(2042, 'esnext'); | ||
expectMapping(42, 'esnext'); | ||
}); | ||
|
||
it("should map to 'es5' when unsuported and old", () => { | ||
expectMapping(2002, 'es5'); | ||
expectMapping(2, 'es5'); | ||
}); | ||
|
||
it("should map to 'es{year}' when supported and >= 6", () => { | ||
expectMapping(2015, 'es2015'); | ||
expectMapping(6, 'es2015'); | ||
expectMapping(2020, 'es2020'); | ||
expectMapping(11, 'es2020'); | ||
}); | ||
|
||
it("should map to 'es5' when 5 or 3", () => { | ||
expectMapping(5, 'es5'); | ||
expectMapping(3, 'es5'); | ||
}); | ||
|
||
it("should map to 'es2018' when undefined", () => { | ||
expectMapping(undefined, 'es2018'); | ||
}); | ||
|
||
it("should map to 'esnext' when 'latest'", () => { | ||
// `'latest'` is converted to 1e8 at parser. | ||
expectMapping(1e8, 'esnext'); | ||
}); | ||
}); | ||
|
||
const fakeNode = {} as unknown as TSESTree.Node; | ||
|
||
function expectMapping(ecmaVersion: number | undefined, lib: Lib): void { | ||
(Referencer as jest.Mock).mockClear(); | ||
analyze(fakeNode, { ecmaVersion: ecmaVersion as EcmaVersion }); | ||
expect(Referencer).toHaveBeenCalledWith( | ||
expect.objectContaining({ lib: [lib] }), | ||
expect.any(Object), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters