Merge pull request #17996 from Microsoft/fix16681

Fix crash when exporting class without name
This commit is contained in:
Ron Buckton 2017-08-24 11:07:12 -07:00 committed by GitHub
commit 038d256fe5
5 changed files with 24 additions and 2 deletions

View file

@ -1204,7 +1204,7 @@ namespace ts {
}
if (hasModifier(decl, ModifierFlags.Export)) {
const exportName = hasModifier(decl, ModifierFlags.Default) ? createIdentifier("default") : decl.name;
const exportName = hasModifier(decl, ModifierFlags.Default) ? createIdentifier("default") : getDeclarationName(decl);
statements = appendExportStatement(statements, exportName, getLocalName(decl), /*location*/ decl);
}

View file

@ -124,7 +124,7 @@ namespace ts {
else {
// export class x { }
const name = (<ClassDeclaration>node).name;
if (!uniqueExports.get(unescapeLeadingUnderscores(name.escapedText))) {
if (name && !uniqueExports.get(unescapeLeadingUnderscores(name.escapedText))) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
uniqueExports.set(unescapeLeadingUnderscores(name.escapedText), true);
exportedNames = append(exportedNames, name);

View file

@ -0,0 +1,8 @@
tests/cases/compiler/exportClassWithoutName.ts(1,1): error TS1211: A class declaration without the 'default' modifier must have a name.
==== tests/cases/compiler/exportClassWithoutName.ts (1 errors) ====
export class {
~~~~~~
!!! error TS1211: A class declaration without the 'default' modifier must have a name.
}

View file

@ -0,0 +1,10 @@
//// [exportClassWithoutName.ts]
export class {
}
//// [exportClassWithoutName.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class default_1 {
}
exports.default_1 = default_1;

View file

@ -0,0 +1,4 @@
//@module: commonjs
//@target: es2015
export class {
}