question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ehoogeveen-medwebcommented, Aug 17, 2020

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.

0reactions
neemzycommented, Jun 2, 2021

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

Same here!

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel-plugin-minify-dead-code-elimination-while-loop-fixed
Inlines bindings when possible. Tries to evaluate expressions and prunes unreachable as a result.
Read more >
regular expression goes into infinite loop - Stack Overflow
Essentially, what is happening is there are too many ways to match your regular expression with your string, and the parser is continually...
Read more >
Changelog — Python 3.11.1 documentation
These cases now raise ValueError - Removed a dead code path ... gh-98458: Fix infinite loop in unittest when a self-referencing chained exception...
Read more >
rollup.js
Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library...
Read more >
https://perldoc.perl.org/5.22.0/perldelta.txt
This could lead to different outcomes than existing code expects (though the documentation ... PATTERN?> construct, which allows matching a regex only once, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found