From 9220079656abbd8136d60b7233bf7dee9d9a2324 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 17 Nov 2021 16:04:37 +0200 Subject: [PATCH] init --- src/parser.ts | 3 ++- tests/parser/type.ts | 5 +++++ tests/parser/type.ts.fixture.ts | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index 1ffd242c8b..53bbdd0562 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -3417,7 +3417,7 @@ export class Parser extends DiagnosticEmitter { startPos: i32 ): TypeDeclaration | null { - // at 'type': Identifier ('<' TypeParameters '>')? '=' Type ';'? + // at 'type': Identifier ('<' TypeParameters '>')? '=' '|'? Type ';'? if (tn.skipIdentifier()) { let name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); @@ -3428,6 +3428,7 @@ export class Parser extends DiagnosticEmitter { flags |= CommonFlags.GENERIC; } if (tn.skip(Token.EQUALS)) { + tn.skip(Token.BAR); let type = this.parseType(tn); if (!type) return null; let ret = Node.createTypeDeclaration( diff --git a/tests/parser/type.ts b/tests/parser/type.ts index ed301e91d2..dc6e5175db 100644 --- a/tests/parser/type.ts +++ b/tests/parser/type.ts @@ -1,3 +1,8 @@ type int32_t = i32; @nonportable() export type uint64_t = u64; + +// with leading `|` +export type T1 = | int32_t; +export type T2 = + | int32_t; diff --git a/tests/parser/type.ts.fixture.ts b/tests/parser/type.ts.fixture.ts index ed301e91d2..d58bbc9ce4 100644 --- a/tests/parser/type.ts.fixture.ts +++ b/tests/parser/type.ts.fixture.ts @@ -1,3 +1,5 @@ type int32_t = i32; @nonportable() export type uint64_t = u64; +export type T1 = int32_t; +export type T2 = int32_t;