Skip to content

Commit 4df2e10

Browse files
authored
Merge pull request #4337 from masatake/typescript--optional-prop
TypeScript: extract optional property in class
2 parents d48558f + 9e922fe commit 4df2e10

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Units/parser-typescript.r/ts-class.d/expected.tags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ tasks input.ts /^ private tasks: string[] = [];$/;" p class:TasksService
6969
taskObj input.ts /^ private taskObj: object = {};$/;" p class:TasksService
7070
getAllTasks input.ts /^ getAllTasks(): string[] {$/;" m class:TasksService
7171
getTaskObj input.ts /^ getTaskObj(): object {$/;" m class:TasksService
72+
Test input-0.ts /^export class Test {$/;" c
73+
var input-0.ts /^ public var?: string;$/;" p class:Test
74+
foo input-0.ts /^ public foo() {$/;" m class:Test
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Taken from the #4336 reported by @zeerd
2+
export class Test {
3+
public var?: string;
4+
5+
public foo() {
6+
return 'hello';
7+
}
8+
}

parsers/typescript.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,9 +1652,9 @@ static void parseConstructorParams (const int classScope, const int constrScope,
16521652
}
16531653

16541654
MULTI_CHAR_PARSER_DEF (ClassBodyChars, "\n,{", TOKEN_NL, TOKEN_COMMA, TOKEN_OPEN_CURLY)
1655-
MULTI_CHAR_PARSER_DEF (ClassBodyAfterCurlyChars, "\n}*@(:;=-+/^<>.,|&",
1655+
MULTI_CHAR_PARSER_DEF (ClassBodyAfterCurlyChars, "\n}*@(?:;=-+/^<>.,|&",
16561656
TOKEN_NL, TOKEN_CLOSE_CURLY, TOKEN_STAR, TOKEN_AT, TOKEN_OPEN_PAREN,
1657-
TOKEN_COLON, TOKEN_SEMICOLON, TOKEN_EQUAL_SIGN,
1657+
TOKEN_QUESTION_MARK, TOKEN_COLON, TOKEN_SEMICOLON, TOKEN_EQUAL_SIGN,
16581658
TOKEN_MINUS, TOKEN_PLUS, TOKEN_DIV, TOKEN_POWER,
16591659
TOKEN_GREATER, TOKEN_LOWER, TOKEN_PERIOD, TOKEN_COMMA,
16601660
TOKEN_PIPE, TOKEN_AMPERSAND)
@@ -1808,6 +1808,8 @@ static void parseClassBody (const int scope, tokenInfo *const token)
18081808
}
18091809
parsingValue = true;
18101810
break;
1811+
case TOKEN_QUESTION_MARK:
1812+
break; /* Just consuming the token */
18111813
case TOKEN_COLON:
18121814
uwiUngetC (':');
18131815
parsePropertyType (token);

0 commit comments

Comments
 (0)