Skip to content

Fix ASI after get/set keyword #60225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2779,10 +2779,12 @@ namespace Parser {
case SyntaxKind.DefaultKeyword:
return nextTokenCanFollowDefaultKeyword();
case SyntaxKind.StaticKeyword:
nextToken();
return canFollowModifier();
case SyntaxKind.GetKeyword:
case SyntaxKind.SetKeyword:
nextToken();
return canFollowModifier();
return canFollowGetOrSetKeyword();
default:
return nextTokenIsOnSameLineAndCanFollowModifier();
}
Expand Down Expand Up @@ -2813,6 +2815,11 @@ namespace Parser {
|| isLiteralPropertyName();
}

function canFollowGetOrSetKeyword(): boolean {
return token() === SyntaxKind.OpenBracketToken
|| isLiteralPropertyName();
}

function nextTokenCanFollowDefaultKeyword(): boolean {
nextToken();
return token() === SyntaxKind.ClassKeyword
Expand Down
33 changes: 33 additions & 0 deletions tests/baselines/reference/canFollowGetSetKeyword.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
error TS2318: Cannot find global type 'IterableIterator'.
canFollowGetSetKeyword.ts(10,5): error TS18004: No value exists in scope for the shorthand property 'get'. Either declare one or provide an initializer.
canFollowGetSetKeyword.ts(11,5): error TS1005: ',' expected.
canFollowGetSetKeyword.ts(14,5): error TS18004: No value exists in scope for the shorthand property 'set'. Either declare one or provide an initializer.
canFollowGetSetKeyword.ts(15,5): error TS1005: ',' expected.


!!! error TS2318: Cannot find global type 'IterableIterator'.
==== canFollowGetSetKeyword.ts (4 errors) ====
class A {
get
*x() {}
}
class B {
set
*x() {}
}
const c = {
get
~~~
!!! error TS18004: No value exists in scope for the shorthand property 'get'. Either declare one or provide an initializer.
*x() {}
~
!!! error TS1005: ',' expected.
};
const d = {
set
~~~
!!! error TS18004: No value exists in scope for the shorthand property 'set'. Either declare one or provide an initializer.
*x() {}
~
!!! error TS1005: ',' expected.
};
76 changes: 76 additions & 0 deletions tests/baselines/reference/canFollowGetSetKeyword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//// [tests/cases/conformance/classes/propertyMemberDeclarations/canFollowGetSetKeyword.ts] ////

//// [canFollowGetSetKeyword.ts]
class A {
get
*x() {}
}
class B {
set
*x() {}
}
const c = {
get
*x() {}
};
const d = {
set
*x() {}
};

//// [canFollowGetSetKeyword.js]
var __generator = (this && this.__generator) || function (thisArg, body) {
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);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var A = /** @class */ (function () {
function A() {
}
A.prototype.x = function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); };
return A;
}());
var B = /** @class */ (function () {
function B() {
}
B.prototype.x = function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); };
return B;
}());
var c = {
get: get,
x: function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }
};
var d = {
set: set,
x: function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @noTypesAndSymbols: true
class A {
get
*x() {}
}
class B {
set
*x() {}
}
const c = {
get
*x() {}
};
const d = {
set
*x() {}
};