Skip to content

Commit 738af31

Browse files
authored
Skip leading bar during type's declaration (AssemblyScript#2149)
1 parent 777f440 commit 738af31

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3417,7 +3417,7 @@ export class Parser extends DiagnosticEmitter {
34173417
startPos: i32
34183418
): TypeDeclaration | null {
34193419

3420-
// at 'type': Identifier ('<' TypeParameters '>')? '=' Type ';'?
3420+
// at 'type': Identifier ('<' TypeParameters '>')? '=' '|'? Type ';'?
34213421

34223422
if (tn.skipIdentifier()) {
34233423
let name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
@@ -3428,6 +3428,7 @@ export class Parser extends DiagnosticEmitter {
34283428
flags |= CommonFlags.GENERIC;
34293429
}
34303430
if (tn.skip(Token.EQUALS)) {
3431+
tn.skip(Token.BAR);
34313432
let type = this.parseType(tn);
34323433
if (!type) return null;
34333434
let ret = Node.createTypeDeclaration(

tests/parser/type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
type int32_t = i32;
22
@nonportable()
33
export type uint64_t = u64;
4+
5+
// with leading `|`
6+
export type T1 = | int32_t;
7+
export type T2 =
8+
| int32_t;

tests/parser/type.ts.fixture.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
type int32_t = i32;
22
@nonportable()
33
export type uint64_t = u64;
4+
export type T1 = int32_t;
5+
export type T2 = int32_t;

0 commit comments

Comments
 (0)