mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-20 19:45:07 -06:00
Elide export assignment when it does not resolve to a value (#41904)
* Only mark aliases that resolve to values referenced * Update other affected baselines * Remove redundant check
This commit is contained in:
parent
d156bb805e
commit
035c7ca905
@ -22868,11 +22868,14 @@ namespace ts {
|
||||
|
||||
function markAliasReferenced(symbol: Symbol, location: Node) {
|
||||
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol)) {
|
||||
if (compilerOptions.preserveConstEnums && isExportOrExportExpression(location) || !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
|
||||
markAliasSymbolAsReferenced(symbol);
|
||||
}
|
||||
else {
|
||||
markConstEnumAliasAsReferenced(symbol);
|
||||
const target = resolveAlias(symbol);
|
||||
if (target.flags & SymbolFlags.Value) {
|
||||
if (compilerOptions.preserveConstEnums && isExportOrExportExpression(location) || !isConstEnumOrConstEnumOnlyModule(target)) {
|
||||
markAliasSymbolAsReferenced(symbol);
|
||||
}
|
||||
else {
|
||||
markConstEnumAliasAsReferenced(symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
tests/baselines/reference/exportDefaultImportedType.js
Normal file
15
tests/baselines/reference/exportDefaultImportedType.js
Normal file
@ -0,0 +1,15 @@
|
||||
//// [tests/cases/compiler/exportDefaultImportedType.ts] ////
|
||||
|
||||
//// [exported.ts]
|
||||
type Foo = number;
|
||||
export { Foo };
|
||||
|
||||
//// [main.ts]
|
||||
import { Foo } from "./exported";
|
||||
export default Foo;
|
||||
|
||||
|
||||
//// [exported.js]
|
||||
export {};
|
||||
//// [main.js]
|
||||
export {};
|
||||
@ -215,7 +215,6 @@ export { createDog, Dog };
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createDog = void 0;
|
||||
var animal_1 = require("./animal");
|
||||
var dog_1 = require("./dog");
|
||||
Object.defineProperty(exports, "createDog", { enumerable: true, get: function () { return dog_1.createDog; } });
|
||||
|
||||
|
||||
@ -387,7 +387,6 @@ export default interface Animal {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createDog = void 0;
|
||||
var animal_1 = require("./animal");
|
||||
var dog_1 = require("./dog");
|
||||
Object.defineProperty(exports, "createDog", { enumerable: true, get: function () { return dog_1.createDog; } });
|
||||
|
||||
|
||||
10
tests/cases/compiler/exportDefaultImportedType.ts
Normal file
10
tests/cases/compiler/exportDefaultImportedType.ts
Normal file
@ -0,0 +1,10 @@
|
||||
// @module: es2015
|
||||
// @noTypesAndSymbols: true
|
||||
|
||||
// @Filename: /exported.ts
|
||||
type Foo = number;
|
||||
export { Foo };
|
||||
|
||||
// @Filename: /main.ts
|
||||
import { Foo } from "./exported";
|
||||
export default Foo;
|
||||
Loading…
x
Reference in New Issue
Block a user