fix(58772): Duplicate exports.* = assignments in CommonJS output in some cases (#59120)

This commit is contained in:
Oleksandr T.
2024-07-23 02:10:29 +03:00
committed by GitHub
parent ca4ef16c8f
commit 8a0e47e242
5 changed files with 82 additions and 1 deletions

View File

@@ -47,6 +47,7 @@ import {
isClassStaticBlockDeclaration,
isDefaultImport,
isExpressionStatement,
isFunctionDeclaration,
isGeneratedIdentifier,
isGeneratedPrivateIdentifier,
isIdentifier,
@@ -321,7 +322,7 @@ export function collectExternalModuleInfo(context: TransformationContext, source
}
function addExportedFunctionDeclaration(node: FunctionDeclaration, name: ModuleExportName | undefined, isDefault: boolean) {
exportedFunctions.add(node);
exportedFunctions.add(getOriginalNode(node, isFunctionDeclaration));
if (isDefault) {
// export default function() { }
// function x() { } + export { x as default };

View File

@@ -0,0 +1,24 @@
//// [tests/cases/conformance/es6/modules/exportsAndImports5.ts] ////
//// [a.ts]
export interface A { }
//// [b.ts]
import { A } from "./a"
export function f(): A {
return {};
}
export { f as fV2 };
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [b.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.f = f;
exports.fV2 = f;
function f() {
return {};
}

View File

@@ -0,0 +1,20 @@
//// [tests/cases/conformance/es6/modules/exportsAndImports5.ts] ////
=== a.ts ===
export interface A { }
>A : Symbol(A, Decl(a.ts, 0, 0))
=== b.ts ===
import { A } from "./a"
>A : Symbol(A, Decl(b.ts, 0, 8))
export function f(): A {
>f : Symbol(f, Decl(b.ts, 0, 23))
>A : Symbol(A, Decl(b.ts, 0, 8))
return {};
}
export { f as fV2 };
>f : Symbol(f, Decl(b.ts, 0, 23))
>fV2 : Symbol(fV2, Decl(b.ts, 4, 8))

View File

@@ -0,0 +1,25 @@
//// [tests/cases/conformance/es6/modules/exportsAndImports5.ts] ////
=== a.ts ===
export interface A { }
=== b.ts ===
import { A } from "./a"
>A : any
> : ^^^
export function f(): A {
>f : () => A
> : ^^^^^^
return {};
>{} : {}
> : ^^
}
export { f as fV2 };
>f : () => A
> : ^^^^^^
>fV2 : () => A
> : ^^^^^^

View File

@@ -0,0 +1,11 @@
// @module: commonjs
// @filename: a.ts
export interface A { }
// @filename: b.ts
import { A } from "./a"
export function f(): A {
return {};
}
export { f as fV2 };