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
8 changes: 8 additions & 0 deletions packages/async-rewriter2/src/async-writer-babel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ describe('AsyncWriter', () => {
expect(implicitlyAsyncFn).to.have.callCount(10);
});

it('can use for loops as weird assignments', async() => {
const obj = { foo: null };
implicitlyAsyncFn.resolves(obj);
await runTranspiledCode('for (implicitlyAsyncFn().foo of ["foo", "bar"]);');
expect(implicitlyAsyncFn).to.have.callCount(2);
expect(obj.foo).to.equal('bar');
});

it('works with assignments to objects', async() => {
implicitlyAsyncFn.resolves({ foo: 'bar' });
const ret = runTranspiledCode(`
Expand Down
3 changes: 3 additions & 0 deletions packages/async-rewriter2/src/stages/transform-maybe-await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ export default ({ types: t }: { types: typeof BabelTypes }): babel.PluginObj<{ f
// something that we wouldn't want to modify anyway, because it would
// break the assignment altogether.
if (path.parentPath.isAssignmentExpression() && path.key === 'left') return;
// Assignments can happen in weird places, including in situations like
// `for (obj.prop of [1,2,3]);`.
if (path.parentPath.isForXStatement() && path.key === 'left') return;
// ++ and -- count as assignments for our purposes.
if (path.parentPath.isUpdateExpression()) return;

Expand Down