Skip to content

Commit f2e0063

Browse files
authored
Port "Fix ASI after get/set keyword" (#1055)
1 parent 671b5cb commit f2e0063

File tree

5 files changed

+26
-57
lines changed

5 files changed

+26
-57
lines changed

internal/parser/parser.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3906,9 +3906,12 @@ func (p *Parser) nextTokenCanFollowModifier() bool {
39063906
return p.canFollowExportModifier()
39073907
case ast.KindDefaultKeyword:
39083908
return p.nextTokenCanFollowDefaultKeyword()
3909-
case ast.KindStaticKeyword, ast.KindGetKeyword, ast.KindSetKeyword:
3909+
case ast.KindStaticKeyword:
39103910
p.nextToken()
39113911
return p.canFollowModifier()
3912+
case ast.KindGetKeyword, ast.KindSetKeyword:
3913+
p.nextToken()
3914+
return p.canFollowGetOrSetKeyword()
39123915
default:
39133916
return p.nextTokenIsOnSameLineAndCanFollowModifier()
39143917
}
@@ -3963,6 +3966,10 @@ func (p *Parser) canFollowModifier() bool {
39633966
return p.token == ast.KindOpenBracketToken || p.token == ast.KindOpenBraceToken || p.token == ast.KindAsteriskToken || p.token == ast.KindDotDotDotToken || p.isLiteralPropertyName()
39643967
}
39653968

3969+
func (p *Parser) canFollowGetOrSetKeyword() bool {
3970+
return p.token == ast.KindOpenBracketToken || p.isLiteralPropertyName()
3971+
}
3972+
39663973
func (p *Parser) nextTokenIsOnSameLineAndCanFollowModifier() bool {
39673974
p.nextToken()
39683975
if p.hasPrecedingLineBreak() {
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
error TS2318: Cannot find global type 'IterableIterator'.
2-
canFollowGetSetKeyword.ts(3,5): error TS1003: Identifier expected.
3-
canFollowGetSetKeyword.ts(7,5): error TS1003: Identifier expected.
4-
canFollowGetSetKeyword.ts(11,5): error TS1003: Identifier expected.
5-
canFollowGetSetKeyword.ts(15,5): error TS1003: Identifier expected.
2+
canFollowGetSetKeyword.ts(10,5): error TS18004: No value exists in scope for the shorthand property 'get'. Either declare one or provide an initializer.
3+
canFollowGetSetKeyword.ts(11,5): error TS1005: ',' expected.
4+
canFollowGetSetKeyword.ts(14,5): error TS18004: No value exists in scope for the shorthand property 'set'. Either declare one or provide an initializer.
5+
canFollowGetSetKeyword.ts(15,5): error TS1005: ',' expected.
66

77

88
!!! error TS2318: Cannot find global type 'IterableIterator'.
99
==== canFollowGetSetKeyword.ts (4 errors) ====
1010
class A {
1111
get
1212
*x() {}
13-
~
14-
!!! error TS1003: Identifier expected.
1513
}
1614
class B {
1715
set
1816
*x() {}
19-
~
20-
!!! error TS1003: Identifier expected.
2117
}
2218
const c = {
2319
get
20+
~~~
21+
!!! error TS18004: No value exists in scope for the shorthand property 'get'. Either declare one or provide an initializer.
2422
*x() {}
2523
~
26-
!!! error TS1003: Identifier expected.
24+
!!! error TS1005: ',' expected.
2725
};
2826
const d = {
2927
set
28+
~~~
29+
!!! error TS18004: No value exists in scope for the shorthand property 'set'. Either declare one or provide an initializer.
3030
*x() {}
3131
~
32-
!!! error TS1003: Identifier expected.
32+
!!! error TS1005: ',' expected.
3333
};

testdata/baselines/reference/submodule/conformance/canFollowGetSetKeyword.errors.txt.diff

Lines changed: 0 additions & 46 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/canFollowGetSetKeyword.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ const d = {
2020

2121
//// [canFollowGetSetKeyword.js]
2222
class A {
23+
get;
2324
*x() { }
2425
}
2526
class B {
27+
set;
2628
*x() { }
2729
}
2830
const c = {
31+
get,
2932
*x() { }
3033
};
3134
const d = {
35+
set,
3236
*x() { }
3337
};

testdata/baselines/reference/submodule/conformance/canFollowGetSetKeyword.js.diff

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,18 @@
5959
- return [2 /*return*/];
6060
- }); }
6161
+class A {
62+
+ get;
6263
+ *x() { }
6364
+}
6465
+class B {
66+
+ set;
6567
+ *x() { }
6668
+}
6769
+const c = {
70+
+ get,
6871
+ *x() { }
6972
+};
7073
+const d = {
74+
+ set,
7175
+ *x() { }
7276
};

0 commit comments

Comments
 (0)