Skip to content

Commit 53320f5

Browse files
authored
Fix crash on duplicate default exports (microsoft#38272)
1 parent 6f7faa7 commit 53320f5

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

src/compiler/binder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ namespace ts {
413413
function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean): Symbol {
414414
Debug.assert(!hasDynamicName(node));
415415

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

418418
// The exported symbol for an export default function/class node is always named "default"
419419
const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
tests/cases/compiler/exportDefaultDuplicateCrash.ts(3,1): error TS2323: Cannot redeclare exported variable 'default'.
2+
tests/cases/compiler/exportDefaultDuplicateCrash.ts(3,1): error TS2528: A module cannot have multiple default exports.
3+
tests/cases/compiler/exportDefaultDuplicateCrash.ts(4,10): error TS2323: Cannot redeclare exported variable 'default'.
4+
tests/cases/compiler/exportDefaultDuplicateCrash.ts(4,10): error TS2528: A module cannot have multiple default exports.
5+
tests/cases/compiler/exportDefaultDuplicateCrash.ts(4,25): error TS2307: Cannot find module './hi' or its corresponding type declarations.
6+
tests/cases/compiler/exportDefaultDuplicateCrash.ts(5,16): error TS2528: A module cannot have multiple default exports.
7+
tests/cases/compiler/exportDefaultDuplicateCrash.ts(5,31): error TS2307: Cannot find module './hi' or its corresponding type declarations.
8+
9+
10+
==== tests/cases/compiler/exportDefaultDuplicateCrash.ts (7 errors) ====
11+
// #38214
12+
13+
export default function () { }
14+
~~~~~~
15+
!!! error TS2323: Cannot redeclare exported variable 'default'.
16+
~~~~~~
17+
!!! error TS2528: A module cannot have multiple default exports.
18+
!!! related TS2753 tests/cases/compiler/exportDefaultDuplicateCrash.ts:5:16: Another export default is here.
19+
export { default } from './hi'
20+
~~~~~~~
21+
!!! error TS2323: Cannot redeclare exported variable 'default'.
22+
~~~~~~~
23+
!!! error TS2528: A module cannot have multiple default exports.
24+
!!! related TS6204 tests/cases/compiler/exportDefaultDuplicateCrash.ts:5:16: and here.
25+
~~~~~~
26+
!!! error TS2307: Cannot find module './hi' or its corresponding type declarations.
27+
export { aa as default } from './hi'
28+
~~~~~~~
29+
!!! error TS2528: A module cannot have multiple default exports.
30+
!!! related TS2752 tests/cases/compiler/exportDefaultDuplicateCrash.ts:3:1: The first export default is here.
31+
!!! related TS2752 tests/cases/compiler/exportDefaultDuplicateCrash.ts:4:10: The first export default is here.
32+
~~~~~~
33+
!!! error TS2307: Cannot find module './hi' or its corresponding type declarations.
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [exportDefaultDuplicateCrash.ts]
2+
// #38214
3+
4+
export default function () { }
5+
export { default } from './hi'
6+
export { aa as default } from './hi'
7+
8+
9+
//// [exportDefaultDuplicateCrash.js]
10+
"use strict";
11+
// #38214
12+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13+
if (k2 === undefined) k2 = k;
14+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
15+
}) : (function(o, m, k, k2) {
16+
if (k2 === undefined) k2 = k;
17+
o[k2] = m[k];
18+
}));
19+
exports.__esModule = true;
20+
function default_1() { }
21+
exports["default"] = default_1;
22+
var hi_1 = require("./hi");
23+
__createBinding(exports, hi_1, "default");
24+
var hi_2 = require("./hi");
25+
__createBinding(exports, hi_2, "aa", "default");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @noTypesAndSymbols: true
2+
3+
// #38214
4+
5+
export default function () { }
6+
export { default } from './hi'
7+
export { aa as default } from './hi'

0 commit comments

Comments
 (0)