@@ -991,3 +991,67 @@ test("customName rename declared function", () => {
991991 expect ( mainFile . lua ) . toContain ( "Test2(" ) ;
992992 expect ( mainFile . lua ) . not . toContain ( "Test(" ) ;
993993} ) ;
994+
995+ test ( "customName rename import specifier" , ( ) => {
996+ const testModule = util . testModule `
997+ import { Test } from "./myimport";
998+ import { Test as Aliased } from "./myimport";
999+ Test();
1000+ Aliased();
1001+ ` . addExtraFile (
1002+ "myimport.ts" ,
1003+ `
1004+ /** @customName Test2 **/
1005+ export function Test(this: void): void {}
1006+ `
1007+ ) ;
1008+
1009+ testModule . expectToHaveNoDiagnostics ( ) ;
1010+ const result = testModule . getLuaResult ( ) ;
1011+ expect ( result . transpiledFiles ) . not . toHaveLength ( 0 ) ;
1012+
1013+ const mainFile = result . transpiledFiles . find ( f => f . outPath === "main.lua" ) ;
1014+ expect ( mainFile ) . toBeDefined ( ) ;
1015+
1016+ // avoid ts error "not defined", even though toBeDefined is being checked above
1017+ if ( ! mainFile ) return ;
1018+
1019+ expect ( mainFile . lua ) . toBeDefined ( ) ;
1020+ expect ( mainFile . lua ) . toContain ( "Test2(" ) ;
1021+ expect ( mainFile . lua ) . toContain ( "myimport.Test2" ) ;
1022+ expect ( mainFile . lua ) . not . toContain ( "Test(" ) ;
1023+
1024+ testModule . expectNoExecutionError ( ) ;
1025+ } ) ;
1026+
1027+ test ( "customName import specifier from declarations" , ( ) => {
1028+ const testModule = util . testModule `
1029+ import { Test } from "./myimport";
1030+ import { Test as Aliased } from "./myimport";
1031+ Test();
1032+ Aliased();
1033+ `
1034+ . addExtraFile (
1035+ "myimport.d.ts" ,
1036+ `
1037+ /** @customName Test2 **/
1038+ export declare function Test(this: void): void;
1039+ `
1040+ )
1041+ . setOptions ( { noResolvePaths : [ "./myimport" ] } ) ;
1042+
1043+ testModule . expectToHaveNoDiagnostics ( ) ;
1044+ const result = testModule . getLuaResult ( ) ;
1045+ expect ( result . transpiledFiles ) . not . toHaveLength ( 0 ) ;
1046+
1047+ const mainFile = result . transpiledFiles . find ( f => f . outPath === "main.lua" ) ;
1048+ expect ( mainFile ) . toBeDefined ( ) ;
1049+
1050+ // avoid ts error "not defined", even though toBeDefined is being checked above
1051+ if ( ! mainFile ) return ;
1052+
1053+ expect ( mainFile . lua ) . toBeDefined ( ) ;
1054+ expect ( mainFile . lua ) . toContain ( "Test2(" ) ;
1055+ expect ( mainFile . lua ) . toContain ( "myimport.Test2" ) ;
1056+ expect ( mainFile . lua ) . not . toContain ( "Test(" ) ;
1057+ } ) ;
0 commit comments