@@ -243,55 +243,45 @@ test.each([
243243} ) ;
244244
245245test ( "Import hoisting (named)" , ( ) => {
246- const importCode = `
247- const bar = foo;
248- import {foo} from "myMod";` ;
249- const luaHeader = `
250- package.loaded["myMod"] = {foo = "foobar"}
251- ${ util . transpileString ( importCode ) } ` ;
252- const tsHeader = "declare const bar: any;" ;
253- const code = "return bar;" ;
254- expect ( util . transpileAndExecute ( code , undefined , luaHeader , tsHeader ) ) . toBe ( "foobar" ) ;
246+ util . testBundle `
247+ export const result = foo;
248+ import { foo } from "./module";
249+ `
250+ . addExtraFile ( "module.ts" , "export const foo = true;" )
251+ . expectToEqual ( { result : true } ) ;
255252} ) ;
256253
257254test ( "Import hoisting (namespace)" , ( ) => {
258- const importCode = `
259- const bar = myMod.foo;
260- import * as myMod from "myMod";` ;
261- const luaHeader = `
262- package.loaded["myMod"] = {foo = "foobar"}
263- ${ util . transpileString ( importCode ) } ` ;
264- const tsHeader = "declare const bar: any;" ;
265- const code = "return bar;" ;
266- expect ( util . transpileAndExecute ( code , undefined , luaHeader , tsHeader ) ) . toBe ( "foobar" ) ;
255+ util . testBundle `
256+ export const result = module.foo;
257+ import * as module from "./module";
258+ `
259+ . addExtraFile ( "module.ts" , "export const foo = true;" )
260+ . expectToEqual ( { result : true } ) ;
267261} ) ;
268262
269263test ( "Import hoisting (side-effect)" , ( ) => {
270- const importCode = `
271- const bar = foo;
272- import "myMod";` ;
273- const luaHeader = `
274- package.loaded["myMod"] = {_ = (function() foo = "foobar" end)()}
275- ${ util . transpileString ( importCode ) } ` ;
276- const tsHeader = "declare const bar: any;" ;
277- const code = "return bar;" ;
278- expect ( util . transpileAndExecute ( code , undefined , luaHeader , tsHeader ) ) . toBe ( "foobar" ) ;
264+ util . testBundle `
265+ export const result = (globalThis as any).result;
266+ import "./module";
267+ `
268+ . addExtraFile ( "module.ts" , "(globalThis as any).result = true; export {};" )
269+ . expectToEqual ( { result : true } ) ;
279270} ) ;
280271
281272test ( "Import hoisted before function" , ( ) => {
282- const importCode = `
283- let bar : any;
284- import {foo} from "myMod";
273+ util . testBundle `
274+ export let result : any;
275+
285276 baz();
286277 function baz() {
287- bar = foo;
288- }` ;
289- const luaHeader = `
290- package.loaded["myMod"] = {foo = "foobar"}
291- ${ util . transpileString ( importCode ) } ` ;
292- const tsHeader = "declare const bar: any;" ;
293- const code = "return bar;" ;
294- expect ( util . transpileAndExecute ( code , undefined , luaHeader , tsHeader ) ) . toBe ( "foobar" ) ;
278+ result = foo;
279+ }
280+
281+ import { foo } from "./module";
282+ `
283+ . addExtraFile ( "module.ts" , "export const foo = true;" )
284+ . expectToEqual ( { result : true } ) ;
295285} ) ;
296286
297287test ( "Hoisting Shorthand Property" , ( ) => {
0 commit comments