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

Using minify get an endless loop of code #1012

Open
Larmyliu opened this issue Jun 9, 2021 · 0 comments
Open

Using minify get an endless loop of code #1012

Larmyliu opened this issue Jun 9, 2021 · 0 comments

Comments

@Larmyliu
Copy link

Larmyliu commented Jun 9, 2021

Describe the bug
I have a piece of code that uses regexp to get keys and values,if i use this plugin(Babel-minify),i get an endless loop of code,but if i use terser, i can get the right code

To Reproduce
Minimal code to reproduce the bug

parseQuery = function (query) {
    // input "a=1&b=2"
    // output: {a: "1", b: "2"}
    query = query.replace(/\?/g, '');
    var reg = /([^=&\s]+)[=\s]*([^&\s]*)/g;
    var obj = {};

    while (reg.exec(query)) {
      obj[RegExp.$1] = RegExp.$2;
    }

    return obj;
};

Actual Output

parseQuery = function (a) {
    a = a.replace(/\?/g, "");
    for (var b = {};
        /([^=&\s]+)[=\s]*([^&\s]*)/g.exec(a);) b[RegExp.$1] = RegExp.$2;
    return b
};

if i input use parseQuery("a=1&b=2"), this is an endless loop that causes the page to get stuck

Expected Output
if i use terser

parseQuery = function (e) {
    e = e.replace(/\?/g, "");
    for (var r = /([^=&\s]+)[=\s]*([^&\s]*)/g, g = {}; r.exec(e);) g[RegExp.$1] = RegExp.$2;
    return g
};

input parseQuery("a=1&b=2"), i can get {a: "1", b: "2"} successfully
Configuration

How are you using babel-minify?

i use babel-minify CLI in global

npm install babel-minify -g
minify index.js -d lib

Additional context
i also use terser in global, but can get right code, It runs normally in the browser

npm install terser -g
terser --compress --mangle -- index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant