Skip to content

Bug: Uglified babel polyfill with reduce_vars option causes string.split to misbehave in chrome 51 #1964

@bdwain

Description

@bdwain

Bug report or feature request?
Bug report

ES5 or ES6+ input?
Es5

Uglify version (uglifyjs -V)
2.8.26

JavaScript output or error produced.
The native string split method seems to no longer work correctly in the console (or my app) when i load my app. This only happens in chrome 51.

expected behavior (this is in the console after loading my app. uglify is not processing this code directly):

let str = 'fooBar'
str.split(/(?=[A-Z])/)

> ["foo", "Bar"]

actual behavior:

let str = 'fooBar'
str.split(/(?=[A-Z])/)

> ["fooBar"]

How to reproduce
I ran create-react-app with the canary build of react-scripts (because it needs webpack 2 to reproduce the issue) and the only change i had to make was importing babel-polyfill in the entry point to break it. Removing react and all of the css did not fix it. It does not happen in development mode builds. Only production builds. The issue goes away if the build is not minified. Here is the code to reproduce if you just want to clone it. https://github.com/bdwain/uglify-bug.

the full source is just

import 'babel-polyfill';
let foo = 123;
console.log(foo);

The issue seems to have started due to the suggestion in this comment on an uglify thread

The suggestion was to replace ast = ast.transform(compress) with ast = compress.compress(ast);

I do not believe this is due to create-react-app's usage of the webpack plugin specifically because it happens in my own app which is not based on create-react-app. I was able to reproduce it with no options passed to the plugin.

It seems to also be a bug in chrome 51 (because no matter what we do in javascript, native methods should not break), but because it only is exposed when running uglify, it seems relevant. And while I realize that the issue is only appearing when running the webpack uglify plugin, the reason I did not file the issue with them is that it seems to have started when they made a change that was suggested here (same comment as above)

UPDATE: I removed create-react-app and webpack from the example. Now, the example is just uglifying the babel-polyfill with the reduce_vars option enabled (which seems to be the source of the issue). Including that minfied result in index.html causes the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions