Skip to content

Commit

Permalink
Don't emit await keyword with ES transforms disabled (#624)
Browse files Browse the repository at this point in the history
Follow-up to #623. With transforms disabled, we should just early return even in
the async case.
  • Loading branch information
alangpierce committed Jun 20, 2021
1 parent edc56e0 commit 6b6c0d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/TokenProcessor.ts
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
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

0 comments on commit 6b6c0d7

Please sign in to comment.