Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: [4.7] support optional variance annotation#4831

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
5d9f45f
feat(ast-spec): add `in` and `out` to `TSTypeParameter`
sosukesuzukiApr 17, 2022
0a74ba8
feat(typescript-estree): add `in` and `out` to `TSTypeParameter`
sosukesuzukiApr 17, 2022
0eb5560
test(typescript-estree): add tests for optional variance syntax
sosukesuzukiApr 17, 2022
435f610
test(typescript-estree): update snapshots
sosukesuzukiApr 17, 2022
1f0958f
fix(typescript-estree): use `hasModifier`
sosukesuzukiMay 18, 2022
088d45c
test(typescript-estree): update snapshots
sosukesuzukiMay 18, 2022
6cd5c7e
test(typescript-estree): fix for babel
sosukesuzukiMay 18, 2022
96f0b45
fix(ast-spec): make `in` and `out` boolean
sosukesuzukiMay 19, 2022
b630664
Merge branch 'main' into optional-variance
bradzacherMay 19, 2022
03acdb3
fix spelling typo
bradzacherMay 19, 2022
42d2c74
test(ast-spec): update snapshots
sosukesuzukiMay 19, 2022
68c350b
test(typescript-estree): update snapshots
sosukesuzukiMay 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@ Program {
params: Array [
TSTypeParameter {
type: "TSTypeParameter",
in: false,
name: Identifier {
type: "Identifier",
name: "T",
Expand All@@ -81,6 +82,7 @@ Program {
end: { column: 11, line: 1 },
},
},
out: false,

range: [10, 11],
loc: {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,6 +75,7 @@ exports[`AST Fixtures declaration ClassDeclaration type-parameters-extends-type-
params: Array [
TSTypeParameter {
type: 'TSTypeParameter',
- in: false,
- name: Identifier {
- type: 'Identifier',
- name: 'T',
Expand All@@ -85,6 +86,7 @@ exports[`AST Fixtures declaration ClassDeclaration type-parameters-extends-type-
- end: { column: 11, line: 1 },
- },
- },
- out: false,
+ name: 'T',

range: [10, 11],
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@ Program {
params: Array [
TSTypeParameter {
type: "TSTypeParameter",
in: false,
name: Identifier {
type: "Identifier",
name: "T",
Expand All@@ -42,6 +43,7 @@ Program {
end: { column: 11, line: 1 },
},
},
out: false,

range: [10, 11],
loc: {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@ exports[`AST Fixtures declaration ClassDeclaration type-parameters AST Alignment
params: Array [
TSTypeParameter {
type: 'TSTypeParameter',
- in: false,
- name: Identifier {
- type: 'Identifier',
- name: 'T',
Expand All@@ -46,6 +47,7 @@ exports[`AST Fixtures declaration ClassDeclaration type-parameters AST Alignment
- end: { column: 11, line: 1 },
- },
- },
- out: false,
+ name: 'T',

range: [10, 11],
Expand Down
2 changes: 2 additions & 0 deletionspackages/ast-spec/src/special/TSTypeParameter/spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,6 @@ export interface TSTypeParameter extends BaseNode {
name: Identifier;
constraint?: TypeNode;
default?: TypeNode;
in: boolean;
out: boolean;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
type Mapper<in T, out U> = (x: T) => U;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
type Processor<in out T> = (x: T) => T;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
type Consumer<in T> = (x: T) => void;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
type Provider<out T> = () => T;
2 changes: 2 additions & 0 deletionspackages/typescript-estree/src/convert.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2342,6 +2342,8 @@ export class Converter {
? this.convertType(node.constraint)
: undefined,
default: node.default ? this.convertType(node.default) : undefined,
in: hasModifier(SyntaxKind.InKeyword, node),
out: hasModifier(SyntaxKind.OutKeyword, node),
});
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,14 @@ tester.addFixturePatternConfig('typescript/types', {
* Babel doesn't support TS 4.7 new feature yet.
*/
'conditional-infer-with-constraint',
/**
* [BABEL ERRORED, BUT TS-ESTREE DID NOT]
* Babel doesn't support TS 4.7 new features yet.
*/
'optional-variance-in',
'optional-variance-out',
'optional-variance-in-out',
'optional-variance-in-and-out',
],
});

Expand Down
7 changes: 7 additions & 0 deletionspackages/typescript-estree/tests/ast-alignment/utils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -150,6 +150,13 @@ export function preprocessBabylonAST(ast: File): any {
type: AST_NODE_TYPES.Identifier,
};
}
// Babel does not support TS 4.7 optional variance yet.
if (!node.in) {
node.in = false;
}
if (!node.out) {
node.out = false;
}
},
MethodDefinition(node) {
/**
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -475,6 +475,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 11,
Expand DownExpand Up@@ -503,6 +504,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
10,
11,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -2732,6 +2732,14 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/object-literal-type-with-accessors.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/optional-variance-in.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/optional-variance-in-and-out.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/optional-variance-in-out.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/optional-variance-out.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/parenthesized-type.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/reference.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,6 +74,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 14,
Expand DownExpand Up@@ -102,6 +103,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
13,
14,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,6 +106,7 @@ Object {
],
"type": "TSObjectKeyword",
},
"in": false,
"loc": Object {
"end": Object {
"column": 36,
Expand DownExpand Up@@ -134,6 +135,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
11,
36,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -219,6 +219,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 2,
Expand DownExpand Up@@ -247,6 +248,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
1,
2,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -168,6 +168,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 4,
Expand DownExpand Up@@ -196,6 +197,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
16,
17,
Expand DownExpand Up@@ -329,6 +331,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 7,
Expand DownExpand Up@@ -357,6 +360,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
44,
45,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -98,6 +98,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 15,
Expand DownExpand Up@@ -126,6 +127,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
24,
25,
Expand DownExpand Up@@ -234,6 +236,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 19,
Expand DownExpand Up@@ -262,6 +265,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
52,
53,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -214,6 +214,7 @@ Object {
"typeParameters": undefined,
},
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 21,
Expand DownExpand Up@@ -242,6 +243,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
10,
21,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,6 +143,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 11,
Expand DownExpand Up@@ -171,6 +172,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
10,
11,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -133,6 +133,7 @@ Object {
},
"typeParameters": undefined,
},
"in": false,
"loc": Object {
"end": Object {
"column": 16,
Expand DownExpand Up@@ -161,6 +162,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
21,
28,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -98,6 +98,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 10,
Expand DownExpand Up@@ -126,6 +127,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
21,
22,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -211,6 +211,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 7,
Expand DownExpand Up@@ -239,6 +240,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
36,
37,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,6 +235,7 @@ Object {
},
},
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 35,
Expand DownExpand Up@@ -263,6 +264,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
11,
35,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -289,6 +289,7 @@ Object {
},
},
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 36,
Expand DownExpand Up@@ -317,6 +318,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
11,
36,
Expand DownExpand Up@@ -828,6 +830,7 @@ Object {
Object {
"constraint": undefined,
"default": undefined,
"in": false,
"loc": Object {
"end": Object {
"column": 18,
Expand DownExpand Up@@ -856,6 +859,7 @@ Object {
],
"type": "Identifier",
},
"out": false,
"range": Array [
175,
176,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp