Skip to content

building async iterators with transform-runtime produces wrong build, but babel-node works properly #4783

@darsain

Description

@darsain

Isolated issue here: https://gist.github.com/anonymous/dcbc9f57057724ee5ffe0650eedc9472

git clone https://gist.github.com/dcbc9f57057724ee5ffe0650eedc9472.git example
cd example
npm install
npm run execute
npm run build

Input Code (index.js)

async function * values(iterable) {
    for (const item of iterable) {
        yield item;
    }
}

async function collect(asyncIterator) {
    const collection = [];
    for await (const value of asyncIterator) {
        collection.push(value);
    }
    return collection;
}

collect(values([5, 4, 3, 2, 1])).then(console.log, console.error);

Babel Configuration (package.json)

{
  "scripts": {
    "build": "babel index.js --out-file build.js && node build.js",
    "execute": "babel-node index.js"
  },
  "babel": {
    "plugins": [
      ["transform-runtime", {"polyfill": false, "regenerator": true}]
    ],
    "presets": ["stage-3", "latest"]
  },
  "dependencies": {
    "babel-runtime": "^6.18.0"
  },
  "devDependencies": {
    "babel-cli": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.15.0",
    "babel-preset-latest": "^6.16.0",
    "babel-preset-stage-3": "^6.17.0"
  }
}

Expected Behavior

Both scripts in package.json:scripts should log the array [5, 4, 3, 2, 1].

Current Behavior

The build script that relies on babel command produces a build file that throws:

TypeError: Object is not async iterable

On the other hand, the execute script relying on babel-node works properly.

Possible Solution

The fact that babel-node works might be a clue.

Also @hzoo on slack mentioned it might be related to #4768.

Your Environment

Module versions are specified in package.json above.

software version
node 6.7.0
npm 3.10.9
Operating System Win 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions