mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
fix(45850): Preserve const enums should keep import refs for exported const enums exported via named exports (#45858)
This commit is contained in:
@@ -24477,7 +24477,19 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isExportOrExportExpression(location: Node) {
|
||||
return !!findAncestor(location, e => e.parent && isExportAssignment(e.parent) && e.parent.expression === e && isEntityNameExpression(e));
|
||||
return !!findAncestor(location, n => {
|
||||
const parent = n.parent;
|
||||
if (parent === undefined) {
|
||||
return "quit";
|
||||
}
|
||||
if (isExportAssignment(parent)) {
|
||||
return parent.expression === n && isEntityNameExpression(n);
|
||||
}
|
||||
if (isExportSpecifier(parent)) {
|
||||
return parent.name === n || parent.propertyName === n;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function markAliasReferenced(symbol: Symbol, location: Node) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [tests/cases/compiler/constEnumPreserveEmitNamedExport1.ts] ////
|
||||
|
||||
//// [a.ts]
|
||||
const enum A {
|
||||
Foo
|
||||
};
|
||||
export { A };
|
||||
|
||||
//// [b.ts]
|
||||
import { A } from './a';
|
||||
export { A };
|
||||
|
||||
|
||||
//// [a.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
A[A["Foo"] = 0] = "Foo";
|
||||
})(A || (A = {}));
|
||||
;
|
||||
export { A };
|
||||
//// [b.js]
|
||||
import { A } from './a';
|
||||
export { A };
|
||||
@@ -0,0 +1,18 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
const enum A {
|
||||
>A : Symbol(A, Decl(a.ts, 0, 0))
|
||||
|
||||
Foo
|
||||
>Foo : Symbol(A.Foo, Decl(a.ts, 0, 14))
|
||||
|
||||
};
|
||||
export { A };
|
||||
>A : Symbol(A, Decl(a.ts, 3, 8))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import { A } from './a';
|
||||
>A : Symbol(A, Decl(b.ts, 0, 8))
|
||||
|
||||
export { A };
|
||||
>A : Symbol(A, Decl(b.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
const enum A {
|
||||
>A : A
|
||||
|
||||
Foo
|
||||
>Foo : A.Foo
|
||||
|
||||
};
|
||||
export { A };
|
||||
>A : typeof A
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import { A } from './a';
|
||||
>A : typeof A
|
||||
|
||||
export { A };
|
||||
>A : typeof A
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [tests/cases/compiler/constEnumPreserveEmitNamedExport2.ts] ////
|
||||
|
||||
//// [a.ts]
|
||||
const enum A {
|
||||
Foo
|
||||
};
|
||||
export { A };
|
||||
|
||||
//// [b.ts]
|
||||
import { A } from './a';
|
||||
export { A as B };
|
||||
|
||||
|
||||
//// [a.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
A[A["Foo"] = 0] = "Foo";
|
||||
})(A || (A = {}));
|
||||
;
|
||||
export { A };
|
||||
//// [b.js]
|
||||
import { A } from './a';
|
||||
export { A as B };
|
||||
@@ -0,0 +1,19 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
const enum A {
|
||||
>A : Symbol(A, Decl(a.ts, 0, 0))
|
||||
|
||||
Foo
|
||||
>Foo : Symbol(A.Foo, Decl(a.ts, 0, 14))
|
||||
|
||||
};
|
||||
export { A };
|
||||
>A : Symbol(A, Decl(a.ts, 3, 8))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import { A } from './a';
|
||||
>A : Symbol(A, Decl(b.ts, 0, 8))
|
||||
|
||||
export { A as B };
|
||||
>A : Symbol(A, Decl(b.ts, 0, 8))
|
||||
>B : Symbol(B, Decl(b.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
const enum A {
|
||||
>A : A
|
||||
|
||||
Foo
|
||||
>Foo : A.Foo
|
||||
|
||||
};
|
||||
export { A };
|
||||
>A : typeof A
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import { A } from './a';
|
||||
>A : typeof A
|
||||
|
||||
export { A as B };
|
||||
>A : typeof A
|
||||
>B : typeof A
|
||||
|
||||
12
tests/cases/compiler/constEnumPreserveEmitNamedExport1.ts
Normal file
12
tests/cases/compiler/constEnumPreserveEmitNamedExport1.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// @preserveConstEnums: true
|
||||
// @target: esnext
|
||||
|
||||
// @filename: a.ts
|
||||
const enum A {
|
||||
Foo
|
||||
};
|
||||
export { A };
|
||||
|
||||
// @filename: b.ts
|
||||
import { A } from './a';
|
||||
export { A };
|
||||
12
tests/cases/compiler/constEnumPreserveEmitNamedExport2.ts
Normal file
12
tests/cases/compiler/constEnumPreserveEmitNamedExport2.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// @preserveConstEnums: true
|
||||
// @target: esnext
|
||||
|
||||
// @filename: a.ts
|
||||
const enum A {
|
||||
Foo
|
||||
};
|
||||
export { A };
|
||||
|
||||
// @filename: b.ts
|
||||
import { A } from './a';
|
||||
export { A as B };
|
||||
Reference in New Issue
Block a user