mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-04 14:56:16 -05:00
fix(58772): Duplicate exports.* = assignments in CommonJS output in some cases (#59120)
This commit is contained in:
@@ -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 };
|
||||
|
||||
24
tests/baselines/reference/exportsAndImports5.js
Normal file
24
tests/baselines/reference/exportsAndImports5.js
Normal 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 {};
|
||||
}
|
||||
20
tests/baselines/reference/exportsAndImports5.symbols
Normal file
20
tests/baselines/reference/exportsAndImports5.symbols
Normal 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))
|
||||
|
||||
25
tests/baselines/reference/exportsAndImports5.types
Normal file
25
tests/baselines/reference/exportsAndImports5.types
Normal 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
|
||||
> : ^^^^^^
|
||||
|
||||
11
tests/cases/conformance/es6/modules/exportsAndImports5.ts
Normal file
11
tests/cases/conformance/es6/modules/exportsAndImports5.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user