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
7 changes: 4 additions & 3 deletions src/transformation/pre-transformers/using-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function usingTransformer(context: TransformationContext): ts.Transformer
ts.setParent(node2, parent[parent.length - 1]);
parent.push(node2);
ts.visitEachChild(node2, setParent, ctx);
parent.push();
parent.pop();
return node2;
}
ts.visitEachChild(updatedBlock, setParent, ctx);
Expand Down Expand Up @@ -74,12 +74,13 @@ function transformBlockWithUsing(
);

const callback = ts.factory.createFunctionExpression(
undefined,
// Put async keyword in front of callback when we are in an async using
isAwaitUsing ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)] : undefined,
undefined,
undefined,
undefined,
variableNames,
undefined,
ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), // Required for TS to not freak out trying to infer the type of synthetic nodes
callbackBody
);

Expand Down
18 changes: 18 additions & 0 deletions test/unit/using.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,21 @@ test("await using can handle non-async disposables", () => {
.setTsHeader(usingTestLib)
.expectToEqual({ logs: ["Creating a", "function content", "Disposing a"] });
});

// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1571
test("await using no extra diagnostics (#1571)", () => {
util.testModule`
async function getResource(): Promise<AsyncDisposable> {
return {
[Symbol.asyncDispose]: async () => {}
};
}

async function someOtherAsync() {}

async function main() {
await using resource = await getResource();
await someOtherAsync();
}
`.expectToHaveNoDiagnostics();
});