Skip to content

Commit 8a0e47e

Browse files
authored
fix(58772): Duplicate exports.* = assignments in CommonJS output in some cases (#59120)
1 parent ca4ef16 commit 8a0e47e

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

src/compiler/transformers/utilities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
isClassStaticBlockDeclaration,
4848
isDefaultImport,
4949
isExpressionStatement,
50+
isFunctionDeclaration,
5051
isGeneratedIdentifier,
5152
isGeneratedPrivateIdentifier,
5253
isIdentifier,
@@ -321,7 +322,7 @@ export function collectExternalModuleInfo(context: TransformationContext, source
321322
}
322323

323324
function addExportedFunctionDeclaration(node: FunctionDeclaration, name: ModuleExportName | undefined, isDefault: boolean) {
324-
exportedFunctions.add(node);
325+
exportedFunctions.add(getOriginalNode(node, isFunctionDeclaration));
325326
if (isDefault) {
326327
// export default function() { }
327328
// function x() { } + export { x as default };
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/conformance/es6/modules/exportsAndImports5.ts] ////
2+
3+
//// [a.ts]
4+
export interface A { }
5+
6+
//// [b.ts]
7+
import { A } from "./a"
8+
export function f(): A {
9+
return {};
10+
}
11+
export { f as fV2 };
12+
13+
14+
//// [a.js]
15+
"use strict";
16+
Object.defineProperty(exports, "__esModule", { value: true });
17+
//// [b.js]
18+
"use strict";
19+
Object.defineProperty(exports, "__esModule", { value: true });
20+
exports.f = f;
21+
exports.fV2 = f;
22+
function f() {
23+
return {};
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/conformance/es6/modules/exportsAndImports5.ts] ////
2+
3+
=== a.ts ===
4+
export interface A { }
5+
>A : Symbol(A, Decl(a.ts, 0, 0))
6+
7+
=== b.ts ===
8+
import { A } from "./a"
9+
>A : Symbol(A, Decl(b.ts, 0, 8))
10+
11+
export function f(): A {
12+
>f : Symbol(f, Decl(b.ts, 0, 23))
13+
>A : Symbol(A, Decl(b.ts, 0, 8))
14+
15+
return {};
16+
}
17+
export { f as fV2 };
18+
>f : Symbol(f, Decl(b.ts, 0, 23))
19+
>fV2 : Symbol(fV2, Decl(b.ts, 4, 8))
20+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/conformance/es6/modules/exportsAndImports5.ts] ////
2+
3+
=== a.ts ===
4+
5+
export interface A { }
6+
7+
=== b.ts ===
8+
import { A } from "./a"
9+
>A : any
10+
> : ^^^
11+
12+
export function f(): A {
13+
>f : () => A
14+
> : ^^^^^^
15+
16+
return {};
17+
>{} : {}
18+
> : ^^
19+
}
20+
export { f as fV2 };
21+
>f : () => A
22+
> : ^^^^^^
23+
>fV2 : () => A
24+
> : ^^^^^^
25+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @module: commonjs
2+
3+
// @filename: a.ts
4+
export interface A { }
5+
6+
// @filename: b.ts
7+
import { A } from "./a"
8+
export function f(): A {
9+
return {};
10+
}
11+
export { f as fV2 };

0 commit comments

Comments
 (0)