Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect folding of Array.concat (babel-plugin-minify-constant-folding) #577

Closed
aphix opened this issue Jun 13, 2017 · 4 comments
Closed
Labels
bug Confirmed bug

Comments

@aphix
Copy link

aphix commented Jun 13, 2017

I've noticed a strange behavior due to the minify-constant-folding transform used in babili >= 0.1.0.

Test case:

var a = ['first'];
var b = ['second'].concat(a);
// babel-preset-babili >= 0.1.0 produces:
// var b=['second',a];			(INCORRECT)

// babel-preset-babili <= 0.0.12 leaves untouched:
// var b=['second'].concat(a);		(CORRECT)

if (b[0] !== 'second' || b[1] !== 'first') {
	throw new Error('fail!')
} else {
	console.log('pass!');
}

Here's an alternate case, based on the example found in the package's README:

// README Example:
[a, b, c].concat([d, e], f, g, [h]);
// becomes [a, b, c, d, e, f, g, h]; 		(CORRECT)

// Functionally equivalent:
var x = [d, e];
[a, b, c].concat(x, f, g, [h]);
// becomes [a, b, c, x, f, g, h]; 		(INCORRECT)

For reference, here's my .babelrc I used to test/produce the above results:

{
    "presets": [],
    "minified": true,
    "compact": true,
    "sourceMaps": true,
    "retainLines": true,
    "plugins": [
        "minify-constant-folding",
    ],
}

Let me know if you'd like any further information.

Thanks,
Aphix

@boopathi boopathi added the bug Confirmed bug label Jun 13, 2017
@boopathi
Copy link
Member

Thanks for the report.

/cc @j-f1

@j-f1
Copy link
Contributor

j-f1 commented Jun 13, 2017

@boopathi Is there a way to protect against that? It doesn’t look like there is.

@swernerx
Copy link

swernerx commented Jun 14, 2017

This also broke https://github.com/sebastian-software/prepublish - I removed the plugin for now as it feels pretty unsafe when such massive issues are not covered by any test suite. https://github.com/sebastian-software/prepublish/releases/tag/0.16.3

@j-f1
Copy link
Contributor

j-f1 commented Jun 14, 2017

@swernerx Sorry about the breakage. I didn’t realize that it could break that way. It should be fixed pending the next release. For now, you can just pin it to the last working version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

4 participants