Skip to content

Commit 843544d

Browse files
authored
apply pilaoda's fix (#1711)
1 parent 3d14be8 commit 843544d

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/transformation/utils/typescript/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ export function hasExportEquals(sourceFile: ts.SourceFile): boolean {
1414
* Search up until finding a node satisfying the callback
1515
*/
1616
export function findFirstNodeAbove<T extends ts.Node>(node: ts.Node, callback: (n: ts.Node) => n is T): T | undefined {
17-
let current = node;
17+
// Synthetic nodes (created by pre-transformers like usingTransformer) may have an unset .parent.
18+
// Fall back to ts.getOriginalNode so we can still walk the source-parsed parent chain.
19+
let current = ts.getOriginalNode(node);
1820
while (current.parent) {
1921
if (callback(current.parent)) {
2022
return current.parent;
2123
} else {
22-
current = current.parent;
24+
current = ts.getOriginalNode(current.parent);
2325
}
2426
}
2527
}

test/unit/using.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,26 @@ test("await using no extra diagnostics (#1571)", () => {
194194
`.expectToHaveNoDiagnostics();
195195
});
196196

197+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1622
198+
test("await-using with nested async arrow that also has await-using (runtime divergence)", () => {
199+
util.testFunction`
200+
const logs: any[] = [];
201+
async function getA(): Promise<AsyncDisposable> {
202+
return { [Symbol.asyncDispose]: async () => {} };
203+
}
204+
async function outer(): Promise<number> {
205+
await using a = await getA();
206+
const inner = async (): Promise<number> => {
207+
await using b = await getA();
208+
return 42;
209+
};
210+
return inner();
211+
}
212+
outer().then(v => logs.push(v));
213+
return logs;
214+
`.expectToEqual([42]);
215+
});
216+
197217
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1584
198218
test("works with disposable classes (#1584)", () => {
199219
util.testFunction`

0 commit comments

Comments
 (0)