Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markAliasReferenced should include ExportValue as well #51219

Merged
merged 1 commit into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Expand Up @@ -26035,13 +26035,13 @@ namespace ts {
function markAliasReferenced(symbol: Symbol, location: Node) {
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol, SymbolFlags.Value)) {
const target = resolveAlias(symbol);
if (getAllSymbolFlags(target) & SymbolFlags.Value) {
if (getAllSymbolFlags(target) & (SymbolFlags.Value | SymbolFlags.ExportValue)) {
// An alias resolving to a const enum cannot be elided if (1) 'isolatedModules' is enabled
// (because the const enum value will not be inlined), or if (2) the alias is an export
// of a const enum declaration that will be preserved.
if (compilerOptions.isolatedModules ||
shouldPreserveConstEnums(compilerOptions) && isExportOrExportExpression(location) ||
!isConstEnumOrConstEnumOnlyModule(target)
!isConstEnumOrConstEnumOnlyModule(getExportSymbolOfValueSymbolIfExported(target))
) {
markAliasSymbolAsReferenced(symbol);
}
Expand Down
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/importElisionExportNonExportAndDefault.ts] ////

//// [main.ts]
import MyFunction from "./MyComponent";

MyFunction({msg: "Hello World"});


//// [MyComponent.ts]
interface MyFunction { msg: string; }

export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`);
export default MyFunction;

//// [MyComponent.js]
export const MyFunction = ({ msg }) => console.log(`Got message "${msg}"`);
export default MyFunction;
//// [main.js]
import MyFunction from "./MyComponent";
MyFunction({ msg: "Hello World" });
@@ -0,0 +1,25 @@
=== tests/cases/compiler/main.ts ===
import MyFunction from "./MyComponent";
>MyFunction : Symbol(MyFunction, Decl(main.ts, 0, 6))

MyFunction({msg: "Hello World"});
>msg : Symbol(msg, Decl(main.ts, 2, 12))


=== tests/cases/compiler/MyComponent.ts ===
interface MyFunction { msg: string; }
>MyFunction : Symbol(MyFunction, Decl(MyComponent.ts, 0, 0), Decl(MyComponent.ts, 2, 12))
>msg : Symbol(MyFunction.msg, Decl(MyComponent.ts, 0, 22))

export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`);
>MyFunction : Symbol(MyFunction, Decl(MyComponent.ts, 2, 12))
>msg : Symbol(msg, Decl(MyComponent.ts, 2, 28))
>MyFunction : Symbol(MyFunction, Decl(MyComponent.ts, 0, 0), Decl(MyComponent.ts, 2, 12))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>msg : Symbol(msg, Decl(MyComponent.ts, 2, 28))

export default MyFunction;
>MyFunction : Symbol(MyFunction, Decl(MyComponent.ts, 0, 0), Decl(MyComponent.ts, 2, 12))

@@ -0,0 +1,30 @@
=== tests/cases/compiler/main.ts ===
import MyFunction from "./MyComponent";
>MyFunction : any

MyFunction({msg: "Hello World"});
>MyFunction({msg: "Hello World"}) : error
>MyFunction : error
>{msg: "Hello World"} : { msg: string; }
>msg : string
>"Hello World" : "Hello World"


=== tests/cases/compiler/MyComponent.ts ===
interface MyFunction { msg: string; }
>msg : string

export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`);
>MyFunction : ({ msg }: MyFunction) => void
>({ msg }: MyFunction) => console.log(`Got message "${msg}"`) : ({ msg }: MyFunction) => void
>msg : string
>console.log(`Got message "${msg}"`) : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>`Got message "${msg}"` : string
>msg : string

export default MyFunction;
>MyFunction : MyFunction

13 changes: 13 additions & 0 deletions tests/cases/compiler/importElisionExportNonExportAndDefault.ts
@@ -0,0 +1,13 @@
// @target: esnext
// @module: esnext
// @filename: main.ts
import MyFunction from "./MyComponent";

MyFunction({msg: "Hello World"});


// @filename: MyComponent.ts
interface MyFunction { msg: string; }

export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`);
export default MyFunction;