Skip to content

Commit e044d3e

Browse files
committed
Merge branch 'master' into tscJsFiles
2 parents 607564f + 5a77d67 commit e044d3e

8 files changed

Lines changed: 80 additions & 649 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tests/services/baselines/local/*
1111
tests/baselines/prototyping/local/*
1212
tests/baselines/rwc/*
1313
tests/baselines/test262/*
14-
tests/baselines/reference/projectOutput/*
14+
tests/baselines/reference/projectOutput/*
1515
tests/baselines/local/projectOutput/*
1616
tests/services/baselines/prototyping/local/*
1717
tests/services/browser/typescriptServices.js
@@ -20,6 +20,7 @@ scripts/processDiagnosticMessages.d.ts
2020
scripts/processDiagnosticMessages.js
2121
scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js
2222
src/harness/*.js
23+
src/compiler/diagnosticInformationMap.generated.ts
2324
rwc-report.html
2425
*.swp
2526
build.json

src/compiler/diagnosticInformationMap.generated.ts

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

src/compiler/parser.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4813,7 +4813,7 @@ namespace ts {
48134813
node.decorators = decorators;
48144814
setModifiers(node, modifiers);
48154815
parseExpected(SyntaxKind.ClassKeyword);
4816-
node.name = parseOptionalIdentifier();
4816+
node.name = parseNameOfClassDeclarationOrExpression();
48174817
node.typeParameters = parseTypeParameters();
48184818
node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ true);
48194819

@@ -4829,7 +4829,22 @@ namespace ts {
48294829

48304830
return finishNode(node);
48314831
}
4832-
4832+
4833+
function parseNameOfClassDeclarationOrExpression(): Identifier {
4834+
// implements is a future reserved word so
4835+
// 'class implements' might mean either
4836+
// - class expression with omitted name, 'implements' starts heritage clause
4837+
// - class with name 'implements'
4838+
// 'isImplementsClause' helps to disambiguate between these two cases
4839+
return isIdentifier() && !isImplementsClause()
4840+
? parseIdentifier()
4841+
: undefined;
4842+
}
4843+
4844+
function isImplementsClause() {
4845+
return token === SyntaxKind.ImplementsKeyword && lookAhead(nextTokenIsIdentifierOrKeyword)
4846+
}
4847+
48334848
function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray<HeritageClause> {
48344849
// ClassTail[Yield,Await] : (Modified) See 14.5
48354850
// ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt }

src/compiler/scanner.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -739,18 +739,6 @@ namespace ts {
739739
}
740740
}
741741

742-
function isIdentifierStart(ch: number): boolean {
743-
return ch >= CharacterCodes.A && ch <= CharacterCodes.Z || ch >= CharacterCodes.a && ch <= CharacterCodes.z ||
744-
ch === CharacterCodes.$ || ch === CharacterCodes._ ||
745-
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierStart(ch, languageVersion);
746-
}
747-
748-
function isIdentifierPart(ch: number): boolean {
749-
return ch >= CharacterCodes.A && ch <= CharacterCodes.Z || ch >= CharacterCodes.a && ch <= CharacterCodes.z ||
750-
ch >= CharacterCodes._0 && ch <= CharacterCodes._9 || ch === CharacterCodes.$ || ch === CharacterCodes._ ||
751-
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion);
752-
}
753-
754742
function scanNumber(): number {
755743
let start = pos;
756744
while (isDigit(text.charCodeAt(pos))) pos++;
@@ -1064,12 +1052,12 @@ namespace ts {
10641052
let start = pos;
10651053
while (pos < end) {
10661054
let ch = text.charCodeAt(pos);
1067-
if (isIdentifierPart(ch)) {
1055+
if (isIdentifierPart(ch, languageVersion)) {
10681056
pos++;
10691057
}
10701058
else if (ch === CharacterCodes.backslash) {
10711059
ch = peekUnicodeEscape();
1072-
if (!(ch >= 0 && isIdentifierPart(ch))) {
1060+
if (!(ch >= 0 && isIdentifierPart(ch, languageVersion))) {
10731061
break;
10741062
}
10751063
result += text.substring(start, pos);
@@ -1439,17 +1427,17 @@ namespace ts {
14391427
return pos++, token = SyntaxKind.AtToken;
14401428
case CharacterCodes.backslash:
14411429
let cookedChar = peekUnicodeEscape();
1442-
if (cookedChar >= 0 && isIdentifierStart(cookedChar)) {
1430+
if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) {
14431431
pos += 6;
14441432
tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
14451433
return token = getIdentifierToken();
14461434
}
14471435
error(Diagnostics.Invalid_character);
14481436
return pos++, token = SyntaxKind.Unknown;
14491437
default:
1450-
if (isIdentifierStart(ch)) {
1438+
if (isIdentifierStart(ch, languageVersion)) {
14511439
pos++;
1452-
while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos))) pos++;
1440+
while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++;
14531441
tokenValue = text.substring(tokenPos, pos);
14541442
if (ch === CharacterCodes.backslash) {
14551443
tokenValue += scanIdentifierParts();
@@ -1536,7 +1524,7 @@ namespace ts {
15361524
p++;
15371525
}
15381526

1539-
while (p < end && isIdentifierPart(text.charCodeAt(p))) {
1527+
while (p < end && isIdentifierPart(text.charCodeAt(p), languageVersion)) {
15401528
p++;
15411529
}
15421530
pos = p;
@@ -1599,7 +1587,7 @@ namespace ts {
15991587
let firstCharPosition = pos;
16001588
while (pos < end) {
16011589
let ch = text.charCodeAt(pos);
1602-
if (ch === CharacterCodes.minus || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) {
1590+
if (ch === CharacterCodes.minus || ((firstCharPosition === pos) ? isIdentifierStart(ch, languageVersion) : isIdentifierPart(ch, languageVersion))) {
16031591
pos++;
16041592
}
16051593
else {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [implementsInClassExpression.ts]
2+
interface Foo {
3+
doThing(): void;
4+
}
5+
6+
let cls = class implements Foo {
7+
doThing() { }
8+
}
9+
10+
//// [implementsInClassExpression.js]
11+
var cls = (function () {
12+
function class_1() {
13+
}
14+
class_1.prototype.doThing = function () { };
15+
return class_1;
16+
})();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/implementsInClassExpression.ts ===
2+
interface Foo {
3+
>Foo : Symbol(Foo, Decl(implementsInClassExpression.ts, 0, 0))
4+
5+
doThing(): void;
6+
>doThing : Symbol(doThing, Decl(implementsInClassExpression.ts, 0, 15))
7+
}
8+
9+
let cls = class implements Foo {
10+
>cls : Symbol(cls, Decl(implementsInClassExpression.ts, 4, 3))
11+
>Foo : Symbol(Foo, Decl(implementsInClassExpression.ts, 0, 0))
12+
13+
doThing() { }
14+
>doThing : Symbol((Anonymous class).doThing, Decl(implementsInClassExpression.ts, 4, 32))
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/implementsInClassExpression.ts ===
2+
interface Foo {
3+
>Foo : Foo
4+
5+
doThing(): void;
6+
>doThing : () => void
7+
}
8+
9+
let cls = class implements Foo {
10+
>cls : typeof (Anonymous class)
11+
>class implements Foo { doThing() { }} : typeof (Anonymous class)
12+
>Foo : Foo
13+
14+
doThing() { }
15+
>doThing : () => void
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface Foo {
2+
doThing(): void;
3+
}
4+
5+
let cls = class implements Foo {
6+
doThing() { }
7+
}

0 commit comments

Comments
 (0)