Skip to content

Commit bd1641f

Browse files
authoredOct 16, 2024
Fix ASI after get/set keyword (#60225)
1 parent 03c5a37 commit bd1641f

File tree

4 files changed

+134
-1
lines changed

4 files changed

+134
-1
lines changed
 

‎src/compiler/parser.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2779,10 +2779,12 @@ namespace Parser {
27792779
case SyntaxKind.DefaultKeyword:
27802780
return nextTokenCanFollowDefaultKeyword();
27812781
case SyntaxKind.StaticKeyword:
2782+
nextToken();
2783+
return canFollowModifier();
27822784
case SyntaxKind.GetKeyword:
27832785
case SyntaxKind.SetKeyword:
27842786
nextToken();
2785-
return canFollowModifier();
2787+
return canFollowGetOrSetKeyword();
27862788
default:
27872789
return nextTokenIsOnSameLineAndCanFollowModifier();
27882790
}
@@ -2813,6 +2815,11 @@ namespace Parser {
28132815
|| isLiteralPropertyName();
28142816
}
28152817

2818+
function canFollowGetOrSetKeyword(): boolean {
2819+
return token() === SyntaxKind.OpenBracketToken
2820+
|| isLiteralPropertyName();
2821+
}
2822+
28162823
function nextTokenCanFollowDefaultKeyword(): boolean {
28172824
nextToken();
28182825
return token() === SyntaxKind.ClassKeyword
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error TS2318: Cannot find global type 'IterableIterator'.
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.
6+
7+
8+
!!! error TS2318: Cannot find global type 'IterableIterator'.
9+
==== canFollowGetSetKeyword.ts (4 errors) ====
10+
class A {
11+
get
12+
*x() {}
13+
}
14+
class B {
15+
set
16+
*x() {}
17+
}
18+
const c = {
19+
get
20+
~~~
21+
!!! error TS18004: No value exists in scope for the shorthand property 'get'. Either declare one or provide an initializer.
22+
*x() {}
23+
~
24+
!!! error TS1005: ',' expected.
25+
};
26+
const d = {
27+
set
28+
~~~
29+
!!! error TS18004: No value exists in scope for the shorthand property 'set'. Either declare one or provide an initializer.
30+
*x() {}
31+
~
32+
!!! error TS1005: ',' expected.
33+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//// [tests/cases/conformance/classes/propertyMemberDeclarations/canFollowGetSetKeyword.ts] ////
2+
3+
//// [canFollowGetSetKeyword.ts]
4+
class A {
5+
get
6+
*x() {}
7+
}
8+
class B {
9+
set
10+
*x() {}
11+
}
12+
const c = {
13+
get
14+
*x() {}
15+
};
16+
const d = {
17+
set
18+
*x() {}
19+
};
20+
21+
//// [canFollowGetSetKeyword.js]
22+
var __generator = (this && this.__generator) || function (thisArg, body) {
23+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25+
function verb(n) { return function (v) { return step([n, v]); }; }
26+
function step(op) {
27+
if (f) throw new TypeError("Generator is already executing.");
28+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
29+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30+
if (y = 0, t) op = [op[0] & 2, t.value];
31+
switch (op[0]) {
32+
case 0: case 1: t = op; break;
33+
case 4: _.label++; return { value: op[1], done: false };
34+
case 5: _.label++; y = op[1]; op = [0]; continue;
35+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
36+
default:
37+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41+
if (t[2]) _.ops.pop();
42+
_.trys.pop(); continue;
43+
}
44+
op = body.call(thisArg, _);
45+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47+
}
48+
};
49+
var A = /** @class */ (function () {
50+
function A() {
51+
}
52+
A.prototype.x = function () { return __generator(this, function (_a) {
53+
return [2 /*return*/];
54+
}); };
55+
return A;
56+
}());
57+
var B = /** @class */ (function () {
58+
function B() {
59+
}
60+
B.prototype.x = function () { return __generator(this, function (_a) {
61+
return [2 /*return*/];
62+
}); };
63+
return B;
64+
}());
65+
var c = {
66+
get: get,
67+
x: function () { return __generator(this, function (_a) {
68+
return [2 /*return*/];
69+
}); }
70+
};
71+
var d = {
72+
set: set,
73+
x: function () { return __generator(this, function (_a) {
74+
return [2 /*return*/];
75+
}); }
76+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @noTypesAndSymbols: true
2+
class A {
3+
get
4+
*x() {}
5+
}
6+
class B {
7+
set
8+
*x() {}
9+
}
10+
const c = {
11+
get
12+
*x() {}
13+
};
14+
const d = {
15+
set
16+
*x() {}
17+
};

0 commit comments

Comments
 (0)