11import { ModuleKind , ScriptTarget } from "typescript" ;
2- import { awaitMustBeInAsyncFunction } from "../../../src/transformation/utils/diagnostics" ;
2+ import { LuaTarget } from "../../../src" ;
3+ import { awaitMustBeInAsyncFunction , unsupportedForTarget } from "../../../src/transformation/utils/diagnostics" ;
34import * as util from "../../util" ;
45
56const promiseTestLib = `
@@ -385,8 +386,9 @@ test("async function can forward varargs", () => {
385386
386387// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1105
387388describe ( "try/catch in async function" , ( ) => {
388- test ( "await inside try/catch returns inside async function" , ( ) => {
389- util . testModule `
389+ util . testEachVersion (
390+ "await inside try/catch returns inside async function" ,
391+ ( ) => util . testModule `
390392 export let result = 0;
391393 async function foo(): Promise<number> {
392394 try {
@@ -398,11 +400,17 @@ describe("try/catch in async function", () => {
398400 foo().then(value => {
399401 result = value;
400402 });
401- ` . expectToEqual ( { result : 4 } ) ;
402- } ) ;
403+ ` ,
404+ // Cannot execute LuaJIT with test runner
405+ {
406+ ...util . expectEachVersionExceptJit ( builder => builder . expectToEqual ( { result : 4 } ) ) ,
407+ [ LuaTarget . Lua51 ] : builder => builder . expectToHaveDiagnostics ( [ unsupportedForTarget . code ] ) ,
408+ }
409+ ) ;
403410
404- test ( "await inside try/catch throws inside async function" , ( ) => {
405- util . testModule `
411+ util . testEachVersion (
412+ "await inside try/catch throws inside async function" ,
413+ ( ) => util . testModule `
406414 export let reason = "";
407415 async function foo(): Promise<number> {
408416 try {
@@ -414,11 +422,19 @@ describe("try/catch in async function", () => {
414422 foo().catch(e => {
415423 reason = e;
416424 });
417- ` . expectToEqual ( { reason : "an error occurred in the async function: test error" } ) ;
418- } ) ;
425+ ` ,
426+ {
427+ ...util . expectEachVersionExceptJit ( builder =>
428+ builder . expectToEqual ( { reason : "an error occurred in the async function: test error" } )
429+ ) ,
430+ [ LuaTarget . Lua51 ] : builder => builder . expectToHaveDiagnostics ( [ unsupportedForTarget . code ] ) ,
431+ }
432+ ) ;
419433
420- test ( "await inside try/catch deferred rejection uses catch clause" , ( ) => {
421- util . testModule `
434+ util . testEachVersion (
435+ "await inside try/catch deferred rejection uses catch clause" ,
436+ ( ) =>
437+ util . testModule `
422438 export let reason = "";
423439 let reject: (reason: string) => void;
424440
@@ -433,6 +449,12 @@ describe("try/catch in async function", () => {
433449 reason = e;
434450 });
435451 reject("test error");
436- ` . expectToEqual ( { reason : "an error occurred in the async function: test error" } ) ;
437- } ) ;
452+ ` ,
453+ {
454+ ...util . expectEachVersionExceptJit ( builder =>
455+ builder . expectToEqual ( { reason : "an error occurred in the async function: test error" } )
456+ ) ,
457+ [ LuaTarget . Lua51 ] : builder => builder . expectToHaveDiagnostics ( [ unsupportedForTarget . code ] ) ,
458+ }
459+ ) ;
438460} ) ;
0 commit comments