Skip to content

Issue with array filled in a loop and returned at the end #594

@gyandeeps

Description

@gyandeeps

Choose one: is this a bug report or feature request?

This used to work with 0.0.12 but as i upgraded to latest 0.1.4 it broke. I am sorry but not sure which plugin might be causing this as i have no idea about the internals of babili.

Input Code

const getMinQueryNames = (name) => {
    const coll = [];

    for (let i = 0; i < queries.length; i++) {
        const queryName = queries[i].name;

        coll.push(queryName);
        if (queryName === name) {
            break;
        }
    }

    return coll;
};

Babel Configuration (.babelrc, package.json, cli command)

var webpack = require("webpack");
var path = require("path");

module.exports = {
    entry: "./src/index.js",
    output: { 
        filename: "./dist/bundle.js"
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                include: [
                    path.join(__dirname, "src"),
                ],
                use: [
                    {
                        loader: "babel-loader",
                        options: {
                            presets: [["es2015", {"modules": false}], ["babili"]]
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        new webpack.optimize.ModuleConcatenationPlugin()
    ],
    stats: {
        // Nice colored output
        colors: true
    }
};

Expected Behavior

Output from 0.0.12 version and also the demo site gives this output as well.
Watch the return at end.

var getMinQueryNames=function(a){for(var d,b=[],c=0;c<queries.length&&(d=queries[c].name,b.push(d),d!==a);c++);return b};

Current Behavior

Watch the return at end. At runtime its and error because coll is undefined.

var getMinQueryNames=function(a){for(var b,c=[],d=0;d<queries.length&&(b=queries[d].name,c.push(b),b!==a);d++);return coll};

Your Environment

software version(s)
Babel 6.25
node 8.0
npm 5.0.3
Operating System Windows 7

UPDATE

I narrowed it down to mangle and mergeVars plugin. If you use them individually they work fine but if you use them together then they produce this error..

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bugwith es2015The bug is caused when used with es2015-block-scoping plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions