Skip to content

Commit

Permalink
feat: support TS4.1 features (#2748)
Browse files Browse the repository at this point in the history
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 2be354b
Show file tree
Hide file tree
Showing 51 changed files with 4,503 additions and 119 deletions.
8 changes: 5 additions & 3 deletions .prettierignore
Expand Up @@ -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
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -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",
Expand All @@ -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"
}
}
29 changes: 28 additions & 1 deletion packages/eslint-plugin/tests/rules/no-unused-vars.test.ts
@@ -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: {
Expand Down Expand Up @@ -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,
};
`,
`
Expand Down Expand Up @@ -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: [
Expand Down
6 changes: 6 additions & 0 deletions packages/scope-manager/src/lib/dom.iterable.ts
Expand Up @@ -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,
Expand Down
96 changes: 39 additions & 57 deletions packages/scope-manager/src/lib/dom.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -4724,7 +4718,7 @@ export const dom = {
ReadableByteStreamController: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'ReadableByteStreamController',
},
ReadableStream: {
Expand All @@ -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: {
Expand Down Expand Up @@ -5954,7 +5948,7 @@ export const dom = {
TransformStreamDefaultController: {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
isValueVariable: true,
name: 'TransformStreamDefaultController',
},
TransitionEvent: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions packages/scope-manager/src/lib/es2015.iterable.ts
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions packages/scope-manager/src/lib/es2020.sharedmemory.ts
@@ -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>;
2 changes: 2 additions & 0 deletions packages/scope-manager/src/lib/es2020.ts
Expand Up @@ -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';
Expand All @@ -14,6 +15,7 @@ export const es2020 = {
...es2019,
...es2020_bigint,
...es2020_promise,
...es2020_sharedmemory,
...es2020_string,
...es2020_symbol_wellknown,
...es2020_intl,
Expand Down
24 changes: 24 additions & 0 deletions packages/scope-manager/src/lib/es5.ts
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/scope-manager/src/lib/esnext.ts
Expand Up @@ -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.