From a85e445b6f41f953884297af0b95ace4027483d2 Mon Sep 17 00:00:00 2001 From: Cold Fry Date: Thu, 16 Apr 2026 14:22:20 +0000 Subject: [PATCH] apply pilaoda's fix --- src/transformation/utils/typescript/index.ts | 6 ++++-- test/unit/using.spec.ts | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/transformation/utils/typescript/index.ts b/src/transformation/utils/typescript/index.ts index e5984b08f..f12bf4721 100644 --- a/src/transformation/utils/typescript/index.ts +++ b/src/transformation/utils/typescript/index.ts @@ -14,12 +14,14 @@ export function hasExportEquals(sourceFile: ts.SourceFile): boolean { * Search up until finding a node satisfying the callback */ export function findFirstNodeAbove(node: ts.Node, callback: (n: ts.Node) => n is T): T | undefined { - let current = node; + // Synthetic nodes (created by pre-transformers like usingTransformer) may have an unset .parent. + // Fall back to ts.getOriginalNode so we can still walk the source-parsed parent chain. + let current = ts.getOriginalNode(node); while (current.parent) { if (callback(current.parent)) { return current.parent; } else { - current = current.parent; + current = ts.getOriginalNode(current.parent); } } } diff --git a/test/unit/using.spec.ts b/test/unit/using.spec.ts index bfe5312b0..60364f680 100644 --- a/test/unit/using.spec.ts +++ b/test/unit/using.spec.ts @@ -194,6 +194,26 @@ test("await using no extra diagnostics (#1571)", () => { `.expectToHaveNoDiagnostics(); }); +// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1622 +test("await-using with nested async arrow that also has await-using (runtime divergence)", () => { + util.testFunction` + const logs: any[] = []; + async function getA(): Promise { + return { [Symbol.asyncDispose]: async () => {} }; + } + async function outer(): Promise { + await using a = await getA(); + const inner = async (): Promise => { + await using b = await getA(); + return 42; + }; + return inner(); + } + outer().then(v => logs.push(v)); + return logs; + `.expectToEqual([42]); +}); + // https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1584 test("works with disposable classes (#1584)", () => { util.testFunction`