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

minify-dead-code-elimination cause regexp match infinite loop. #981

Closed
andycall opened this issue Mar 27, 2020 · 8 comments · Fixed by #982
Closed

minify-dead-code-elimination cause regexp match infinite loop. #981

andycall opened this issue Mar 27, 2020 · 8 comments · Fixed by #982

Comments

@andycall
Copy link

Describe the bug

To Reproduce

Minimal code to reproduce the bug

function getElementTransforms(el) {
  if (!is.dom(el)) return;
  const str = el.style.transform || '';
  const reg = /(\w+)\(([^)]*)\)/g;
  const transforms = new Map();
  let m; while (m = reg.exec(str)) transforms.set(m[1], m[2]);
  return transforms;
}

Actual Output

If there is no Error thrown,

function getElementTransforms(el) {
  if (!is.dom(el)) return;
  var str = el.style.transform || '';
  var transforms = new Map();
  var m;

  while (m = /(\w+)\(([^)]*)\)/g.exec(str)) {
    transforms.set(m[1], m[2]);
  }

  return transforms;
}

Expected Output

function getElementTransforms(el) {
  if (!is.dom(el)) return;
  var str = el.style.transform || '';
  var reg = /(\w+)\(([^)]*)\)/g;
  var transforms = new Map();
  var m;

  while (m = reg.exec(str)) {
    transforms.set(m[1], m[2]);
  }

  return transforms;
}

Configuration
Can be reproduce Using Babel's Online Try Out

babel-minify CLI

babel-plugin-minify-dead-code-elimination: 0.5.1

babel version : 7.9.0

babel-minify-config: default without config

@kingback
Copy link

Yes,It breaks while compile querystringify
https://github.com/unshiftio/querystringify/blob/master/index.js#L48

@wssgcg1213
Copy link

@kingback In our situation, we pass the compile, but make chrome 100% CPU usage and block debugging :(

@kingback
Copy link

@kingback In our situation, we pass the compile, but make chrome 100% CPU usage and block debugging :(

bug code

use resolutions to lock the version of @babel/types, it works for me

{
  "resolutions": {
    "@babel/types": "7.8.7"
  }
}

@JLHwung
Copy link
Contributor

JLHwung commented Mar 30, 2020

As a workaround, you may replace regexp literal by constructor calls:

--- const reg = /(\w+)\(([^)]*)\)/g;
+++ const reg = new RegExp("(\w+)\(([^)]*)\)", "g");

@ChrisCindy
Copy link

Should the plugin provide an option called like 'keepVariable' that doesn't eliminate variables that can be eliminated after evaluating expressions ? We have met the situation that the variables can't be replaced by its value. @JLHwung

@ehoogeveen-medweb
Copy link

It seems strange to me that babel-plugin-minify-dead-code-elimination is even doing anything here - after all, the code isn't dead.

Replacing named constants that are only used in one place seems like a reasonable thing to do in general, but I would expect a different plugin to be responsible for it.

@mwgamble
Copy link

I just ran into this with jQuery. It causes an infinite loop which makes the entire page unresponsive.

@neemzy
Copy link

neemzy commented Jun 2, 2021

I just ran into this with jQuery. It causes an infinite loop which makes the entire page unresponsive.

Same here!

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

Successfully merging a pull request may close this issue.

8 participants