Skip to content
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

Allow export default abstract class. Related to issue 3792. #14657

Merged
merged 1 commit into from
Mar 31, 2017
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
6 changes: 6 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ namespace ts {
function nextTokenIsClassOrFunctionOrAsync(): boolean {
nextToken();
return token() === SyntaxKind.ClassKeyword || token() === SyntaxKind.FunctionKeyword ||
(token() === SyntaxKind.AbstractKeyword && lookAhead(nextTokenIsClassKeywordOnSameLine)) ||
(token() === SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsFunctionKeywordOnSameLine));
}

Expand Down Expand Up @@ -4658,6 +4659,11 @@ namespace ts {
return tokenIsIdentifierOrKeyword(token()) && !scanner.hasPrecedingLineBreak();
}

function nextTokenIsClassKeywordOnSameLine() {
nextToken();
return token() === SyntaxKind.ClassKeyword && !scanner.hasPrecedingLineBreak();
}

function nextTokenIsFunctionKeywordOnSameLine() {
nextToken();
return token() === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(1,25): error TS1005: ';' expected.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(3,1): error TS1128: Declaration or statement expected.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(4,17): error TS1005: '=' expected.


==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts (3 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts (2 errors) ====
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow nice test name @aozgaa

export default abstract class A {}
~~~~~
!!! error TS1005: ';' expected.
export abstract class B {}
default abstract class C {}
~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions tests/baselines/reference/classAbstractManyKeywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import abstract class D {}
//// [classAbstractManyKeywords.js]
"use strict";
exports.__esModule = true;
exports["default"] = abstract;
var A = (function () {
function A() {
}
return A;
}());
exports["default"] = A;
var B = (function () {
function B() {
}
Expand All @@ -24,7 +24,6 @@ var C = (function () {
}
return C;
}());
var abstract = ;
var D = (function () {
function D() {
}
Expand Down
21 changes: 21 additions & 0 deletions tests/baselines/reference/exportDefaultAbstractClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/exportDefaultAbstractClass.ts] ////

//// [a.ts]
export default abstract class A {}

//// [b.ts]
import A from './a'


//// [a.js]
"use strict";
exports.__esModule = true;
var A = (function () {
function A() {
}
return A;
}());
exports["default"] = A;
//// [b.js]
"use strict";
exports.__esModule = true;
8 changes: 8 additions & 0 deletions tests/baselines/reference/exportDefaultAbstractClass.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/a.ts ===
export default abstract class A {}
>A : Symbol(A, Decl(a.ts, 0, 0))

=== tests/cases/compiler/b.ts ===
import A from './a'
>A : Symbol(A, Decl(b.ts, 0, 6))

8 changes: 8 additions & 0 deletions tests/baselines/reference/exportDefaultAbstractClass.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/a.ts ===
export default abstract class A {}
>A : A

=== tests/cases/compiler/b.ts ===
import A from './a'
>A : typeof A

5 changes: 5 additions & 0 deletions tests/cases/compiler/exportDefaultAbstractClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @filename: a.ts
export default abstract class A {}

// @filename: b.ts
import A from './a'