Skip to content

Commit 9d9f1a9

Browse files
committed
Fix bug in await using transformer
1 parent da0774c commit 9d9f1a9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/transformation/pre-transformers/using-transformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function usingTransformer(context: TransformationContext): ts.Transformer
1818
ts.setParent(node2, parent[parent.length - 1]);
1919
parent.push(node2);
2020
ts.visitEachChild(node2, setParent, ctx);
21-
parent.push();
21+
parent.pop();
2222
return node2;
2323
}
2424
ts.visitEachChild(updatedBlock, setParent, ctx);
@@ -74,7 +74,7 @@ function transformBlockWithUsing(
7474
);
7575

7676
const callback = ts.factory.createFunctionExpression(
77-
undefined,
77+
[ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
7878
undefined,
7979
undefined,
8080
undefined,

test/unit/using.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,21 @@ test("await using can handle non-async disposables", () => {
175175
.setTsHeader(usingTestLib)
176176
.expectToEqual({ logs: ["Creating a", "function content", "Disposing a"] });
177177
});
178+
179+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1571
180+
test.only("await using no extra diagnostics (#1571)", () => {
181+
util.testModule`
182+
async function getResource(): Promise<AsyncDisposable> {
183+
return {
184+
[Symbol.asyncDispose]: async () => {}
185+
};
186+
}
187+
188+
async function someOtherAsync() {}
189+
190+
async function main() {
191+
await using resource = await getResource();
192+
await someOtherAsync();
193+
}
194+
`.expectToHaveNoDiagnostics();
195+
});

0 commit comments

Comments
 (0)