Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Don't emit await keyword with ES transforms disabled #624

Merged
merged 1 commit into from
Jun 20, 2021
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
3 changes: 0 additions & 3 deletions src/TokenProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ export default class TokenProcessor {
token.isAsyncOperation = isAsyncOperation(this);
}
if (this.disableESTransforms) {
if (token.isAsyncOperation) {
this.resultCode += "await ";
}
return;
}
if (token.numNullishCoalesceStarts) {
Expand Down
18 changes: 17 additions & 1 deletion test/sucrase-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ describe("sucrase", () => {
);
});

it("omits optional changing nullish transformations if ES transforms disabled", () => {
it("omits optional chaining nullish transformations if ES transforms disabled", () => {
assertResult(
`
await navigator.share?.({});
Expand All @@ -1316,6 +1316,22 @@ describe("sucrase", () => {
);
});

it("properly skips optional chaining transform when the right-hand side uses await", () => {
assertResult(
`
async function foo() {
a?.b(await f());
}
`,
`
async function foo() {
a?.b(await f());
}
`,
{transforms: [], disableESTransforms: true},
);
});

it("omits optional catch binding transformations if ES transforms disabled", () => {
assertResult(
`
Expand Down