Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/transformation/utils/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export function hasExportEquals(sourceFile: ts.SourceFile): boolean {
* Search up until finding a node satisfying the callback
*/
export function findFirstNodeAbove<T extends ts.Node>(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);
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/using.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AsyncDisposable> {
return { [Symbol.asyncDispose]: async () => {} };
}
async function outer(): Promise<number> {
await using a = await getA();
const inner = async (): Promise<number> => {
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`
Expand Down
Loading