minify
minify copied to clipboard
Using minify get an endless loop of code
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