Skip to content

Fix crash on duplicate default exports #38272

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

Merged
merged 1 commit into from
Apr 30, 2020
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
2 changes: 1 addition & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ namespace ts {
function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean): Symbol {
Debug.assert(!hasDynamicName(node));

const isDefaultExport = hasModifier(node, ModifierFlags.Default);
const isDefaultExport = hasModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default";

// The exported symbol for an export default function/class node is always named "default"
const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node);
Expand Down
34 changes: 34 additions & 0 deletions tests/baselines/reference/exportDefaultDuplicateCrash.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
tests/cases/compiler/exportDefaultDuplicateCrash.ts(3,1): error TS2323: Cannot redeclare exported variable 'default'.
tests/cases/compiler/exportDefaultDuplicateCrash.ts(3,1): error TS2528: A module cannot have multiple default exports.
tests/cases/compiler/exportDefaultDuplicateCrash.ts(4,10): error TS2323: Cannot redeclare exported variable 'default'.
tests/cases/compiler/exportDefaultDuplicateCrash.ts(4,10): error TS2528: A module cannot have multiple default exports.
tests/cases/compiler/exportDefaultDuplicateCrash.ts(4,25): error TS2307: Cannot find module './hi' or its corresponding type declarations.
tests/cases/compiler/exportDefaultDuplicateCrash.ts(5,16): error TS2528: A module cannot have multiple default exports.
tests/cases/compiler/exportDefaultDuplicateCrash.ts(5,31): error TS2307: Cannot find module './hi' or its corresponding type declarations.


==== tests/cases/compiler/exportDefaultDuplicateCrash.ts (7 errors) ====
// #38214

export default function () { }
~~~~~~
!!! error TS2323: Cannot redeclare exported variable 'default'.
~~~~~~
!!! error TS2528: A module cannot have multiple default exports.
!!! related TS2753 tests/cases/compiler/exportDefaultDuplicateCrash.ts:5:16: Another export default is here.
export { default } from './hi'
~~~~~~~
!!! error TS2323: Cannot redeclare exported variable 'default'.
~~~~~~~
!!! error TS2528: A module cannot have multiple default exports.
!!! related TS6204 tests/cases/compiler/exportDefaultDuplicateCrash.ts:5:16: and here.
~~~~~~
!!! error TS2307: Cannot find module './hi' or its corresponding type declarations.
export { aa as default } from './hi'
~~~~~~~
!!! error TS2528: A module cannot have multiple default exports.
!!! related TS2752 tests/cases/compiler/exportDefaultDuplicateCrash.ts:3:1: The first export default is here.
!!! related TS2752 tests/cases/compiler/exportDefaultDuplicateCrash.ts:4:10: The first export default is here.
~~~~~~
!!! error TS2307: Cannot find module './hi' or its corresponding type declarations.

25 changes: 25 additions & 0 deletions tests/baselines/reference/exportDefaultDuplicateCrash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [exportDefaultDuplicateCrash.ts]
// #38214

export default function () { }
export { default } from './hi'
export { aa as default } from './hi'


//// [exportDefaultDuplicateCrash.js]
"use strict";
// #38214
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
exports.__esModule = true;
function default_1() { }
exports["default"] = default_1;
var hi_1 = require("./hi");
__createBinding(exports, hi_1, "default");
var hi_2 = require("./hi");
__createBinding(exports, hi_2, "aa", "default");
7 changes: 7 additions & 0 deletions tests/cases/compiler/exportDefaultDuplicateCrash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @noTypesAndSymbols: true

// #38214

export default function () { }
export { default } from './hi'
export { aa as default } from './hi'