Skip to content
Permalink
Browse files

feat: support TS4.1 features (#2748)

Fixes #2583

- Adds AST for Key Remapping in Mapped Types and Template Literal Types
- Adds visitor keys for the above
- Adds scope manager support for the above (just tests were required as it all is pretty simple)
- Regenerates the scope-manager lib types
  • Loading branch information
bradzacher committed Nov 8, 2020
1 parent 83385ac commit 2be354bb15f9013a2da1b13a0c0836e9ef057e16
Showing with 4,503 additions and 119 deletions.
  1. +5 −3 .prettierignore
  2. +3 −3 package.json
  3. +28 −1 packages/eslint-plugin/tests/rules/no-unused-vars.test.ts
  4. +6 −0 packages/scope-manager/src/lib/dom.iterable.ts
  5. +39 −57 packages/scope-manager/src/lib/dom.ts
  6. +0 −6 packages/scope-manager/src/lib/es2015.iterable.ts
  7. +14 −0 packages/scope-manager/src/lib/es2020.sharedmemory.ts
  8. +2 −0 packages/scope-manager/src/lib/es2020.ts
  9. +24 −0 packages/scope-manager/src/lib/es5.ts
  10. +2 −0 packages/scope-manager/src/lib/esnext.ts
  11. +32 −0 packages/scope-manager/src/lib/esnext.weakref.ts
  12. +6 −0 packages/scope-manager/src/lib/index.ts
  13. +92 −0 packages/scope-manager/src/lib/webworker.iterable.ts
  14. +14 −14 packages/scope-manager/src/lib/webworker.ts
  15. +3 −0 packages/scope-manager/tests/fixtures/type-declaration/literal-type1.ts
  16. +87 −0 packages/scope-manager/tests/fixtures/type-declaration/literal-type1.ts.shot
  17. +2 −0 packages/scope-manager/tests/fixtures/type-declaration/literal-type2.ts
  18. +158 −0 packages/scope-manager/tests/fixtures/type-declaration/literal-type2.ts.shot
  19. +8 −0 packages/scope-manager/tests/fixtures/type-declaration/literal-type3.ts
  20. +121 −0 packages/scope-manager/tests/fixtures/type-declaration/literal-type3.ts.shot
  21. +2 −0 packages/scope-manager/tests/fixtures/type-declaration/mapped-named.ts
  22. +116 −0 packages/scope-manager/tests/fixtures/type-declaration/mapped-named.ts.shot
  23. +3 −0 packages/shared-fixtures/fixtures/typescript/types/mapped-named-type.src.ts
  24. +1 −0 packages/shared-fixtures/fixtures/typescript/types/template-literal-type-1.src.ts
  25. +1 −0 packages/shared-fixtures/fixtures/typescript/types/template-literal-type-2.src.ts
  26. +3 −0 packages/shared-fixtures/fixtures/typescript/types/template-literal-type-3.src.ts
  27. +2 −0 packages/shared-fixtures/fixtures/typescript/types/template-literal-type-4.src.ts
  28. +1 −0 packages/types/src/ast-node-types.ts
  29. +1 −5 packages/types/src/index.ts
  30. +3 −0 packages/types/src/lib.ts
  31. +16 −7 packages/types/src/ts-estree.ts
  32. +3 −3 packages/typescript-estree/package.json
  33. +16 −0 packages/typescript-estree/src/convert.ts
  34. +2 −2 packages/typescript-estree/src/parser.ts
  35. +1 −0 packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts
  36. +1 −0 packages/typescript-estree/src/ts-estree/ts-nodes.ts
  37. +55 −2 packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
  38. +2 −1 packages/typescript-estree/tests/ast-alignment/parse.ts
  39. +10 −0 packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap
  40. +764 −0 packages/typescript-estree/tests/snapshots/typescript/types/mapped-named-type.src.ts.shot
  41. +1 −0 packages/typescript-estree/tests/snapshots/typescript/types/mapped-readonly-minus.src.ts.shot
  42. +1 −0 packages/typescript-estree/tests/snapshots/typescript/types/mapped-readonly-plus.src.ts.shot
  43. +1 −0 packages/typescript-estree/tests/snapshots/typescript/types/mapped-readonly.src.ts.shot
  44. +1 −0 packages/typescript-estree/tests/snapshots/typescript/types/mapped-untypped.src.ts.shot
  45. +1 −0 packages/typescript-estree/tests/snapshots/typescript/types/mapped.src.ts.shot
  46. +211 −0 packages/typescript-estree/tests/snapshots/typescript/types/template-literal-type-1.src.ts.shot
  47. +289 −0 packages/typescript-estree/tests/snapshots/typescript/types/template-literal-type-2.src.ts.shot
  48. +884 −0 packages/typescript-estree/tests/snapshots/typescript/types/template-literal-type-3.src.ts.shot
  49. +1,434 −0 packages/typescript-estree/tests/snapshots/typescript/types/template-literal-type-4.src.ts.shot
  50. +2 −1 packages/visitor-keys/src/visitor-keys.ts
  51. +29 −14 yarn.lock
@@ -16,6 +16,8 @@ CONTRIBUTORS.md
# Ignore CHANGELOG.md files to avoid issues with automated release job
CHANGELOG.md

# TODO - remove this once prettier supports labelled tuples
packages/scope-manager/tests/fixtures/type-declaration/tuple-labelled.ts
packages/scope-manager/tests/fixtures/type-declaration/tuple-labelled-rest.ts
# TODO - remove this once prettier supports TS4.1
packages/scope-manager/tests/fixtures/type-declaration/literal-type1.ts
packages/scope-manager/tests/fixtures/type-declaration/literal-type2.ts
packages/scope-manager/tests/fixtures/type-declaration/literal-type3.ts
packages/scope-manager/tests/fixtures/type-declaration/mapped-named.ts
@@ -86,7 +86,7 @@
"all-contributors-cli": "^6.17.2",
"cspell": "^4.1.0",
"cz-conventional-changelog": "^3.3.0",
"downlevel-dts": "^0.6.0",
"downlevel-dts": "^0.7.0",
"eslint": "^7.7.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^2.3.0",
@@ -106,9 +106,9 @@
"ts-jest": "^26.3.0",
"ts-node": "^9.0.0",
"tslint": "^6.1.3",
"typescript": ">=3.3.1 <4.1.0"
"typescript": ">=3.3.1 <4.2.0 || 4.1.1-rc"
},
"resolutions": {
"typescript": "4.0.2"
"typescript": "4.1.1-rc"
}
}
@@ -1,5 +1,5 @@
import rule from '../../src/rules/no-unused-vars';
import { RuleTester } from '../RuleTester';
import { noFormat, RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parserOptions: {
@@ -387,6 +387,17 @@ export const map: { [name in Foo]: Bar } = {
a: 1,
b: 2,
c: 3,
};
`,
// 4.1 remapped mapped type
noFormat`
type Foo = 'a' | 'b' | 'c';
type Bar = number;
export const map: { [name in Foo as string]: Bar } = {
a: 1,
b: 2,
c: 3,
};
`,
`
@@ -900,6 +911,22 @@ declare function A(A: string): string;
`,
filename: 'foo.d.ts',
},
// 4.1 template literal types
noFormat`
type Color = 'red' | 'blue';
type Quantity = 'one' | 'two';
export type SeussFish = \`\${Quantity | Color} fish\`;
`,
noFormat`
type VerticalAlignment = "top" | "middle" | "bottom";
type HorizontalAlignment = "left" | "center" | "right";
export declare function setAlignment(value: \`\${VerticalAlignment}-\${HorizontalAlignment}\`): void;
`,
noFormat`
type EnthusiasticGreeting<T extends string> = \`\${Uppercase<T>} - \${Lowercase<T>} - \${Capitalize<T>} - \${Uncapitalize<T>}\`;
export type HELLO = EnthusiasticGreeting<"heLLo">;
`,
],

invalid: [
@@ -125,6 +125,12 @@ export const dom_iterable = {
isValueVariable: false,
name: 'Headers',
},
IDBDatabase: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'IDBDatabase',
},
IDBObjectStore: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -299,6 +299,12 @@ export const dom = {
isValueVariable: false,
name: 'CredentialCreationOptions',
},
CredentialPropertiesOutput: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'CredentialPropertiesOutput',
},
CredentialRequestOptions: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -1745,12 +1751,6 @@ export const dom = {
isValueVariable: false,
name: 'WorkletOptions',
},
txAuthGenericArg: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'txAuthGenericArg',
},
EventListener: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -2369,12 +2369,6 @@ export const dom = {
isValueVariable: true,
name: 'ConvolverNode',
},
Coordinates: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'Coordinates',
},
CountQueuingStrategy: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -2906,9 +2900,27 @@ export const dom = {
Geolocation: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'Geolocation',
},
GeolocationCoordinates: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: true,
name: 'GeolocationCoordinates',
},
GeolocationPosition: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: true,
name: 'GeolocationPosition',
},
GeolocationPositionError: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: true,
name: 'GeolocationPositionError',
},
GlobalEventHandlersEventMap: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -3473,12 +3485,6 @@ export const dom = {
isValueVariable: true,
name: 'History',
},
HkdfCtrParams: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'HkdfCtrParams',
},
IDBArrayKey: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -4415,18 +4421,6 @@ export const dom = {
isValueVariable: true,
name: 'PopStateEvent',
},
Position: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'Position',
},
PositionError: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'PositionError',
},
ProcessingInstruction: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -4724,7 +4718,7 @@ export const dom = {
ReadableByteStreamController: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'ReadableByteStreamController',
},
ReadableStream: {
@@ -4736,25 +4730,25 @@ export const dom = {
ReadableStreamBYOBReader: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'ReadableStreamBYOBReader',
},
ReadableStreamBYOBRequest: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'ReadableStreamBYOBRequest',
},
ReadableStreamDefaultController: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'ReadableStreamDefaultController',
},
ReadableStreamDefaultReader: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'ReadableStreamDefaultReader',
},
ReadableStreamReader: {
@@ -5954,7 +5948,7 @@ export const dom = {
TransformStreamDefaultController: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'TransformStreamDefaultController',
},
TransitionEvent: {
@@ -6374,13 +6368,13 @@ export const dom = {
WritableStreamDefaultController: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'WritableStreamDefaultController',
},
WritableStreamDefaultWriter: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'WritableStreamDefaultWriter',
},
XMLDocument: {
@@ -6851,24 +6845,6 @@ export const dom = {
isValueVariable: false,
name: 'COSEAlgorithmIdentifier',
},
AuthenticatorSelectionList: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'AuthenticatorSelectionList',
},
AAGUID: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'AAGUID',
},
AuthenticationExtensionsSupported: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'AuthenticationExtensionsSupported',
},
UvmEntry: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -7769,6 +7745,12 @@ export const dom = {
isValueVariable: false,
name: 'RequestRedirect',
},
ResidentKeyRequirement: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'ResidentKeyRequirement',
},
ResizeQuality: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -145,12 +145,6 @@ export const es2015_iterable = {
isValueVariable: false,
name: 'PromiseConstructor',
},
Reflect: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: true,
name: 'Reflect',
},
String: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -0,0 +1,14 @@
// THIS CODE WAS AUTOMATICALLY GENERATED
// DO NOT EDIT THIS CODE BY HAND
// YOU CAN REGENERATE IT USING yarn generate:lib

import { ImplicitLibVariableOptions } from '../variable';

export const es2020_sharedmemory = {
Atomics: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'Atomics',
},
} as Record<string, ImplicitLibVariableOptions>;
@@ -6,6 +6,7 @@ import { ImplicitLibVariableOptions } from '../variable';
import { es2019 } from './es2019';
import { es2020_bigint } from './es2020.bigint';
import { es2020_promise } from './es2020.promise';
import { es2020_sharedmemory } from './es2020.sharedmemory';
import { es2020_string } from './es2020.string';
import { es2020_symbol_wellknown } from './es2020.symbol.wellknown';
import { es2020_intl } from './es2020.intl';
@@ -14,6 +15,7 @@ export const es2020 = {
...es2019,
...es2020_bigint,
...es2020_promise,
...es2020_sharedmemory,
...es2020_string,
...es2020_symbol_wellknown,
...es2020_intl,
@@ -419,6 +419,30 @@ export const es5 = {
isValueVariable: false,
name: 'InstanceType',
},
Uppercase: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'Uppercase',
},
Lowercase: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'Lowercase',
},
Capitalize: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'Capitalize',
},
Uncapitalize: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
name: 'Uncapitalize',
},
ThisType: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
@@ -7,10 +7,12 @@ import { es2020 } from './es2020';
import { esnext_intl } from './esnext.intl';
import { esnext_string } from './esnext.string';
import { esnext_promise } from './esnext.promise';
import { esnext_weakref } from './esnext.weakref';

export const esnext = {
...es2020,
...esnext_intl,
...esnext_string,
...esnext_promise,
...esnext_weakref,
} as Record<string, ImplicitLibVariableOptions>;

0 comments on commit 2be354b

Please sign in to comment.