Skip to content

await doesn't work in for..let loops #1021

@pepkin88

Description

@pepkin88

Example:

fn = ->>
  for let v in [Promise.resolve 1]
    await v

Result:

var fn;
fn = async function(){
  var i$, ref$, len$, results$ = [], fn$ = function*(v){
    return (await v);
  };
  for (i$ = 0, len$ = (ref$ = [Promise.resolve(1)]).length; i$ < len$; ++i$) {
    results$.push((yield* (fn$.call(this, ref$[i$]))));
  }
  return results$;
};

Expected result:

var fn;
fn = async function(){
  var i$, ref$, len$, results$ = [], fn$ = async function(v){
    return (await v);
  };
  for (i$ = 0, len$ = (ref$ = [Promise.resolve(1)]).length; i$ < len$; ++i$) {
    results$.push((await (fn$.call(this, ref$[i$]))));
  }
  return results$;
};

It seems the mechanism for yields is also used for awaits, but those require a special treatment.

I also noticed that asynchronous generator functions are not yet supported, so I couldn't test for that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions