From 443abe53730aeaefd2b1f1777dac51cc32f418b3 Mon Sep 17 00:00:00 2001 From: Marius Schulz Date: Sat, 19 Nov 2016 22:30:18 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Allow=20one=20leading=20ignored=20=E2=80=9C?= =?UTF-8?q?|=E2=80=9D=20or=20=E2=80=9C&=E2=80=9D=20in=20a=20type=20positio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compiler/parser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b08f75b0f5bbf..55d267cb53a8b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2615,6 +2615,7 @@ namespace ts { } function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode { + parseOptional(operator); let type = parseConstituentType(); if (token() === operator) { const types = createNodeArray([type], type.pos); From e45c5dbceab76db9932f93dab4dd9aa70dcdf3c3 Mon Sep 17 00:00:00 2001 From: Marius Schulz Date: Sat, 19 Nov 2016 22:30:33 +0100 Subject: [PATCH 2/4] Add tests and accept new baselines --- .../intersectionTypeWithLeadingOperator.js | 8 ++++++++ .../intersectionTypeWithLeadingOperator.symbols | 13 +++++++++++++ .../intersectionTypeWithLeadingOperator.types | 13 +++++++++++++ .../reference/unionTypeWithLeadingOperator.js | 8 ++++++++ .../reference/unionTypeWithLeadingOperator.symbols | 13 +++++++++++++ .../reference/unionTypeWithLeadingOperator.types | 13 +++++++++++++ .../compiler/intersectionTypeWithLeadingOperator.ts | 4 ++++ .../cases/compiler/unionTypeWithLeadingOperator.ts | 4 ++++ 8 files changed, 76 insertions(+) create mode 100644 tests/baselines/reference/intersectionTypeWithLeadingOperator.js create mode 100644 tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols create mode 100644 tests/baselines/reference/intersectionTypeWithLeadingOperator.types create mode 100644 tests/baselines/reference/unionTypeWithLeadingOperator.js create mode 100644 tests/baselines/reference/unionTypeWithLeadingOperator.symbols create mode 100644 tests/baselines/reference/unionTypeWithLeadingOperator.types create mode 100644 tests/cases/compiler/intersectionTypeWithLeadingOperator.ts create mode 100644 tests/cases/compiler/unionTypeWithLeadingOperator.ts diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.js b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js new file mode 100644 index 0000000000000..03f17c0878858 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js @@ -0,0 +1,8 @@ +//// [intersectionTypeWithLeadingOperator.ts] +type A = & string; +type B = + & { foo: string } + & { bar: number }; + + +//// [intersectionTypeWithLeadingOperator.js] diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols new file mode 100644 index 0000000000000..43e0db684dc4e --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/intersectionTypeWithLeadingOperator.ts === +type A = & string; +>A : Symbol(A, Decl(intersectionTypeWithLeadingOperator.ts, 0, 0)) + +type B = +>B : Symbol(B, Decl(intersectionTypeWithLeadingOperator.ts, 0, 18)) + + & { foo: string } +>foo : Symbol(foo, Decl(intersectionTypeWithLeadingOperator.ts, 2, 5)) + + & { bar: number }; +>bar : Symbol(bar, Decl(intersectionTypeWithLeadingOperator.ts, 3, 5)) + diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.types b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types new file mode 100644 index 0000000000000..f2fad709dce68 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/intersectionTypeWithLeadingOperator.ts === +type A = & string; +>A : string + +type B = +>B : B + + & { foo: string } +>foo : string + + & { bar: number }; +>bar : number + diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.js b/tests/baselines/reference/unionTypeWithLeadingOperator.js new file mode 100644 index 0000000000000..b6a40440a481f --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.js @@ -0,0 +1,8 @@ +//// [unionTypeWithLeadingOperator.ts] +type A = | string; +type B = + | { type: "INCREMENT" } + | { type: "DECREMENT" }; + + +//// [unionTypeWithLeadingOperator.js] diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.symbols b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols new file mode 100644 index 0000000000000..97fdcdda8e0c5 --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/unionTypeWithLeadingOperator.ts === +type A = | string; +>A : Symbol(A, Decl(unionTypeWithLeadingOperator.ts, 0, 0)) + +type B = +>B : Symbol(B, Decl(unionTypeWithLeadingOperator.ts, 0, 18)) + + | { type: "INCREMENT" } +>type : Symbol(type, Decl(unionTypeWithLeadingOperator.ts, 2, 5)) + + | { type: "DECREMENT" }; +>type : Symbol(type, Decl(unionTypeWithLeadingOperator.ts, 3, 5)) + diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.types b/tests/baselines/reference/unionTypeWithLeadingOperator.types new file mode 100644 index 0000000000000..db92c6e8eb6a7 --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/unionTypeWithLeadingOperator.ts === +type A = | string; +>A : string + +type B = +>B : B + + | { type: "INCREMENT" } +>type : "INCREMENT" + + | { type: "DECREMENT" }; +>type : "DECREMENT" + diff --git a/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts new file mode 100644 index 0000000000000..9f64cad38dc08 --- /dev/null +++ b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts @@ -0,0 +1,4 @@ +type A = & string; +type B = + & { foo: string } + & { bar: number }; diff --git a/tests/cases/compiler/unionTypeWithLeadingOperator.ts b/tests/cases/compiler/unionTypeWithLeadingOperator.ts new file mode 100644 index 0000000000000..08a876493d073 --- /dev/null +++ b/tests/cases/compiler/unionTypeWithLeadingOperator.ts @@ -0,0 +1,4 @@ +type A = | string; +type B = + | { type: "INCREMENT" } + | { type: "DECREMENT" }; From cd70f22b8806f519ded4caa4acf33f63bce97d57 Mon Sep 17 00:00:00 2001 From: Marius Schulz Date: Sun, 20 Nov 2016 10:48:03 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Add=20=E2=80=9C|=E2=80=9D=20and=20=E2=80=9C?= =?UTF-8?q?&=E2=80=9D=20to=20list=20of=20tokens=20that=20start=20a=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compiler/parser.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 55d267cb53a8b..5117129a573e0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2556,6 +2556,8 @@ namespace ts { case SyntaxKind.OpenBraceToken: case SyntaxKind.OpenBracketToken: case SyntaxKind.LessThanToken: + case SyntaxKind.BarToken: + case SyntaxKind.AmpersandToken: case SyntaxKind.NewKeyword: case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: From d040db42f51593ee5695a6a24a3ae595ee8aec1d Mon Sep 17 00:00:00 2001 From: Marius Schulz Date: Sun, 20 Nov 2016 22:26:32 +0100 Subject: [PATCH 4/4] Add test for proper tuple type handling --- .../reference/intersectionTypeWithLeadingOperator.js | 2 ++ .../reference/intersectionTypeWithLeadingOperator.symbols | 7 +++++++ .../reference/intersectionTypeWithLeadingOperator.types | 7 +++++++ tests/baselines/reference/unionTypeWithLeadingOperator.js | 2 ++ .../reference/unionTypeWithLeadingOperator.symbols | 3 +++ .../baselines/reference/unionTypeWithLeadingOperator.types | 3 +++ .../cases/compiler/intersectionTypeWithLeadingOperator.ts | 2 ++ tests/cases/compiler/unionTypeWithLeadingOperator.ts | 2 ++ 8 files changed, 28 insertions(+) diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.js b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js index 03f17c0878858..61b034f1e0304 100644 --- a/tests/baselines/reference/intersectionTypeWithLeadingOperator.js +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js @@ -3,6 +3,8 @@ type A = & string; type B = & { foo: string } & { bar: number }; + +type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }]; //// [intersectionTypeWithLeadingOperator.js] diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols index 43e0db684dc4e..f6648183bb67a 100644 --- a/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols @@ -11,3 +11,10 @@ type B = & { bar: number }; >bar : Symbol(bar, Decl(intersectionTypeWithLeadingOperator.ts, 3, 5)) +type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }]; +>C : Symbol(C, Decl(intersectionTypeWithLeadingOperator.ts, 3, 20)) +>foo : Symbol(foo, Decl(intersectionTypeWithLeadingOperator.ts, 5, 13)) +>bar : Symbol(bar, Decl(intersectionTypeWithLeadingOperator.ts, 5, 26)) +>foo : Symbol(foo, Decl(intersectionTypeWithLeadingOperator.ts, 5, 40)) +>bar : Symbol(bar, Decl(intersectionTypeWithLeadingOperator.ts, 5, 53)) + diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.types b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types index f2fad709dce68..9961f051f7f38 100644 --- a/tests/baselines/reference/intersectionTypeWithLeadingOperator.types +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types @@ -11,3 +11,10 @@ type B = & { bar: number }; >bar : number +type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }]; +>C : [{ foo: 1; } & { bar: 2; }, { foo: 3; } & { bar: 4; }] +>foo : 1 +>bar : 2 +>foo : 3 +>bar : 4 + diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.js b/tests/baselines/reference/unionTypeWithLeadingOperator.js index b6a40440a481f..0fb366d538e7b 100644 --- a/tests/baselines/reference/unionTypeWithLeadingOperator.js +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.js @@ -3,6 +3,8 @@ type A = | string; type B = | { type: "INCREMENT" } | { type: "DECREMENT" }; + +type C = [| 0 | 1, | "foo" | "bar"]; //// [unionTypeWithLeadingOperator.js] diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.symbols b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols index 97fdcdda8e0c5..8c15d299c4864 100644 --- a/tests/baselines/reference/unionTypeWithLeadingOperator.symbols +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols @@ -11,3 +11,6 @@ type B = | { type: "DECREMENT" }; >type : Symbol(type, Decl(unionTypeWithLeadingOperator.ts, 3, 5)) +type C = [| 0 | 1, | "foo" | "bar"]; +>C : Symbol(C, Decl(unionTypeWithLeadingOperator.ts, 3, 26)) + diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.types b/tests/baselines/reference/unionTypeWithLeadingOperator.types index db92c6e8eb6a7..2ca15fb54a298 100644 --- a/tests/baselines/reference/unionTypeWithLeadingOperator.types +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.types @@ -11,3 +11,6 @@ type B = | { type: "DECREMENT" }; >type : "DECREMENT" +type C = [| 0 | 1, | "foo" | "bar"]; +>C : [0 | 1, "foo" | "bar"] + diff --git a/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts index 9f64cad38dc08..4138dee426110 100644 --- a/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts +++ b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts @@ -2,3 +2,5 @@ type A = & string; type B = & { foo: string } & { bar: number }; + +type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }]; diff --git a/tests/cases/compiler/unionTypeWithLeadingOperator.ts b/tests/cases/compiler/unionTypeWithLeadingOperator.ts index 08a876493d073..9f6d272ce7c03 100644 --- a/tests/cases/compiler/unionTypeWithLeadingOperator.ts +++ b/tests/cases/compiler/unionTypeWithLeadingOperator.ts @@ -2,3 +2,5 @@ type A = | string; type B = | { type: "INCREMENT" } | { type: "DECREMENT" }; + +type C = [| 0 | 1, | "foo" | "bar"];