Skip to content

Commit 2dff34e

Browse files
authoredOct 19, 2022
markAliasReferenced should include ExportValue as well (#51219)
1 parent 5ef2634 commit 2dff34e

5 files changed

+90
-2
lines changed
 

‎src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26035,13 +26035,13 @@ namespace ts {
2603526035
function markAliasReferenced(symbol: Symbol, location: Node) {
2603626036
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol, SymbolFlags.Value)) {
2603726037
const target = resolveAlias(symbol);
26038-
if (getAllSymbolFlags(target) & SymbolFlags.Value) {
26038+
if (getAllSymbolFlags(target) & (SymbolFlags.Value | SymbolFlags.ExportValue)) {
2603926039
// An alias resolving to a const enum cannot be elided if (1) 'isolatedModules' is enabled
2604026040
// (because the const enum value will not be inlined), or if (2) the alias is an export
2604126041
// of a const enum declaration that will be preserved.
2604226042
if (compilerOptions.isolatedModules ||
2604326043
shouldPreserveConstEnums(compilerOptions) && isExportOrExportExpression(location) ||
26044-
!isConstEnumOrConstEnumOnlyModule(target)
26044+
!isConstEnumOrConstEnumOnlyModule(getExportSymbolOfValueSymbolIfExported(target))
2604526045
) {
2604626046
markAliasSymbolAsReferenced(symbol);
2604726047
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/compiler/importElisionExportNonExportAndDefault.ts] ////
2+
3+
//// [main.ts]
4+
import MyFunction from "./MyComponent";
5+
6+
MyFunction({msg: "Hello World"});
7+
8+
9+
//// [MyComponent.ts]
10+
interface MyFunction { msg: string; }
11+
12+
export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`);
13+
export default MyFunction;
14+
15+
//// [MyComponent.js]
16+
export const MyFunction = ({ msg }) => console.log(`Got message "${msg}"`);
17+
export default MyFunction;
18+
//// [main.js]
19+
import MyFunction from "./MyComponent";
20+
MyFunction({ msg: "Hello World" });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/main.ts ===
2+
import MyFunction from "./MyComponent";
3+
>MyFunction : Symbol(MyFunction, Decl(main.ts, 0, 6))
4+
5+
MyFunction({msg: "Hello World"});
6+
>msg : Symbol(msg, Decl(main.ts, 2, 12))
7+
8+
9+
=== tests/cases/compiler/MyComponent.ts ===
10+
interface MyFunction { msg: string; }
11+
>MyFunction : Symbol(MyFunction, Decl(MyComponent.ts, 0, 0), Decl(MyComponent.ts, 2, 12))
12+
>msg : Symbol(MyFunction.msg, Decl(MyComponent.ts, 0, 22))
13+
14+
export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`);
15+
>MyFunction : Symbol(MyFunction, Decl(MyComponent.ts, 2, 12))
16+
>msg : Symbol(msg, Decl(MyComponent.ts, 2, 28))
17+
>MyFunction : Symbol(MyFunction, Decl(MyComponent.ts, 0, 0), Decl(MyComponent.ts, 2, 12))
18+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
19+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
20+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
21+
>msg : Symbol(msg, Decl(MyComponent.ts, 2, 28))
22+
23+
export default MyFunction;
24+
>MyFunction : Symbol(MyFunction, Decl(MyComponent.ts, 0, 0), Decl(MyComponent.ts, 2, 12))
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/compiler/main.ts ===
2+
import MyFunction from "./MyComponent";
3+
>MyFunction : any
4+
5+
MyFunction({msg: "Hello World"});
6+
>MyFunction({msg: "Hello World"}) : error
7+
>MyFunction : error
8+
>{msg: "Hello World"} : { msg: string; }
9+
>msg : string
10+
>"Hello World" : "Hello World"
11+
12+
13+
=== tests/cases/compiler/MyComponent.ts ===
14+
interface MyFunction { msg: string; }
15+
>msg : string
16+
17+
export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`);
18+
>MyFunction : ({ msg }: MyFunction) => void
19+
>({ msg }: MyFunction) => console.log(`Got message "${msg}"`) : ({ msg }: MyFunction) => void
20+
>msg : string
21+
>console.log(`Got message "${msg}"`) : void
22+
>console.log : (...data: any[]) => void
23+
>console : Console
24+
>log : (...data: any[]) => void
25+
>`Got message "${msg}"` : string
26+
>msg : string
27+
28+
export default MyFunction;
29+
>MyFunction : MyFunction
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @target: esnext
2+
// @module: esnext
3+
// @filename: main.ts
4+
import MyFunction from "./MyComponent";
5+
6+
MyFunction({msg: "Hello World"});
7+
8+
9+
// @filename: MyComponent.ts
10+
interface MyFunction { msg: string; }
11+
12+
export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`);
13+
export default MyFunction;

0 commit comments

Comments
 (0)