Merge pull request #17996 from Microsoft/fix16681
Fix crash when exporting class without name
This commit is contained in:
commit
038d256fe5
5 changed files with 24 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
}
|
10
tests/baselines/reference/exportClassWithoutName.js
Normal file
10
tests/baselines/reference/exportClassWithoutName.js
Normal 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;
|
4
tests/cases/compiler/exportClassWithoutName.ts
Normal file
4
tests/cases/compiler/exportClassWithoutName.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
//@module: commonjs
|
||||
//@target: es2015
|
||||
export class {
|
||||
}
|
Loading…
Reference in a new issue