diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0ce21b2d9fed9..4aefa1600776a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2558,6 +2558,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: @@ -2617,6 +2619,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); diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.js b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js new file mode 100644 index 0000000000000..61b034f1e0304 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js @@ -0,0 +1,10 @@ +//// [intersectionTypeWithLeadingOperator.ts] +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 new file mode 100644 index 0000000000000..f6648183bb67a --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols @@ -0,0 +1,20 @@ +=== 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)) + +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 new file mode 100644 index 0000000000000..9961f051f7f38 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/intersectionTypeWithLeadingOperator.ts === +type A = & string; +>A : string + +type B = +>B : B + + & { foo: string } +>foo : string + + & { 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 new file mode 100644 index 0000000000000..0fb366d538e7b --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.js @@ -0,0 +1,10 @@ +//// [unionTypeWithLeadingOperator.ts] +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 new file mode 100644 index 0000000000000..8c15d299c4864 --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols @@ -0,0 +1,16 @@ +=== 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)) + +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 new file mode 100644 index 0000000000000..2ca15fb54a298 --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/unionTypeWithLeadingOperator.ts === +type A = | string; +>A : string + +type B = +>B : B + + | { type: "INCREMENT" } +>type : "INCREMENT" + + | { 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 new file mode 100644 index 0000000000000..4138dee426110 --- /dev/null +++ b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts @@ -0,0 +1,6 @@ +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 new file mode 100644 index 0000000000000..9f6d272ce7c03 --- /dev/null +++ b/tests/cases/compiler/unionTypeWithLeadingOperator.ts @@ -0,0 +1,6 @@ +type A = | string; +type B = + | { type: "INCREMENT" } + | { type: "DECREMENT" }; + +type C = [| 0 | 1, | "foo" | "bar"];