Skip to content

Commit a62869c

Browse files
authored
Merge pull request #14657 from erikmcc/master
Allow export default abstract class. Related to issue 3792.
2 parents 22b4e4d + f9356b9 commit a62869c

7 files changed

+50
-6
lines changed

src/compiler/parser.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,7 @@ namespace ts {
12671267
function nextTokenIsClassOrFunctionOrAsync(): boolean {
12681268
nextToken();
12691269
return token() === SyntaxKind.ClassKeyword || token() === SyntaxKind.FunctionKeyword ||
1270+
(token() === SyntaxKind.AbstractKeyword && lookAhead(nextTokenIsClassKeywordOnSameLine)) ||
12701271
(token() === SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsFunctionKeywordOnSameLine));
12711272
}
12721273

@@ -4661,6 +4662,11 @@ namespace ts {
46614662
return tokenIsIdentifierOrKeyword(token()) && !scanner.hasPrecedingLineBreak();
46624663
}
46634664

4665+
function nextTokenIsClassKeywordOnSameLine() {
4666+
nextToken();
4667+
return token() === SyntaxKind.ClassKeyword && !scanner.hasPrecedingLineBreak();
4668+
}
4669+
46644670
function nextTokenIsFunctionKeywordOnSameLine() {
46654671
nextToken();
46664672
return token() === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak();

tests/baselines/reference/classAbstractManyKeywords.errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(1,25): error TS1005: ';' expected.
21
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(3,1): error TS1128: Declaration or statement expected.
32
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(4,17): error TS1005: '=' expected.
43

54

6-
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts (3 errors) ====
5+
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts (2 errors) ====
76
export default abstract class A {}
8-
~~~~~
9-
!!! error TS1005: ';' expected.
107
export abstract class B {}
118
default abstract class C {}
129
~~~~~~~

tests/baselines/reference/classAbstractManyKeywords.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import abstract class D {}
77
//// [classAbstractManyKeywords.js]
88
"use strict";
99
exports.__esModule = true;
10-
exports["default"] = abstract;
1110
var A = (function () {
1211
function A() {
1312
}
1413
return A;
1514
}());
15+
exports["default"] = A;
1616
var B = (function () {
1717
function B() {
1818
}
@@ -24,7 +24,6 @@ var C = (function () {
2424
}
2525
return C;
2626
}());
27-
var abstract = ;
2827
var D = (function () {
2928
function D() {
3029
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/compiler/exportDefaultAbstractClass.ts] ////
2+
3+
//// [a.ts]
4+
export default abstract class A {}
5+
6+
//// [b.ts]
7+
import A from './a'
8+
9+
10+
//// [a.js]
11+
"use strict";
12+
exports.__esModule = true;
13+
var A = (function () {
14+
function A() {
15+
}
16+
return A;
17+
}());
18+
exports["default"] = A;
19+
//// [b.js]
20+
"use strict";
21+
exports.__esModule = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/a.ts ===
2+
export default abstract class A {}
3+
>A : Symbol(A, Decl(a.ts, 0, 0))
4+
5+
=== tests/cases/compiler/b.ts ===
6+
import A from './a'
7+
>A : Symbol(A, Decl(b.ts, 0, 6))
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/a.ts ===
2+
export default abstract class A {}
3+
>A : A
4+
5+
=== tests/cases/compiler/b.ts ===
6+
import A from './a'
7+
>A : typeof A
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @filename: a.ts
2+
export default abstract class A {}
3+
4+
// @filename: b.ts
5+
import A from './a'

0 commit comments

Comments
 (0)