File tree Expand file tree Collapse file tree
src/transformation/utils/typescript Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,12 +14,14 @@ export function hasExportEquals(sourceFile: ts.SourceFile): boolean {
1414 * Search up until finding a node satisfying the callback
1515 */
1616export 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}
Original file line number Diff line number Diff 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
198218test ( "works with disposable classes (#1584)" , ( ) => {
199219 util . testFunction `
You can’t perform that action at this time.
0 commit comments