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.

babel-plugin-transform-es2015-unicode-regex breaks regex

See original GitHub issue

Bug Report

  • I would like to work on a fix!

Current behavior

/[^\d\-a-z]/iu.exec("a") correctly evaluates to null; however, after applying the babel-plugin-transform-es2015-unicode-regex the transformed code incorrectly evaluates to [ 'a', index: 0, input: 'a', groups: undefined ].

The transformed output is:

/(?:[\0-,\.\/:-`\{-\u017E\u0180-\u2129\u212B-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/i.exec("a");

You can see the input/output with the plugin applied here: https://babeljs.io/repl#?browsers=defaults%2C not ie 11%2C not ie_mob 11&build=&builtIns=false&spec=false&loose=false&code_lz=PQbQegOgJhC0CGsBeBdYBLArgOgKYA9cBjACgCJ4yBKIA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Cstage-2%2Cenv&prettier=false&targets=&version=7.11.6&externalPlugins=babel-plugin-transform-es2015-unicode-regex%406.24.1

Expected behavior

babel-plugin-transform-es2015-unicode-regex should produce code that evaluates to null to match the input.

Relates: https://github.com/facebook/create-react-app/issues/9654

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jridgewellcommented, Sep 18, 2020

This is fixed upstream now, running npm update regexpu-core --depth=2 should bring you up to date.

0reactions
mathiasbynenscommented, Sep 18, 2020

Thanks for taking care of this, @jridgewell!

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/plugin-transform-unicode-regex
Example. In var string = "foo💩bar"; var match = string.match(/foo(.)bar/u);. Copy. Out var string = "foo💩bar"; var match = string.match( /foo((?
Read more >
@babel/plugin-transform-unicode-regex - npm
Compile ES2015 Unicode regex to ES5. Latest version: 7.18.6, last published: 4 months ago. Start using @babel/plugin-transform-unicode-regex ...
Read more >
@babel/plugin-transform-unicode-regex - Package Manager
@babel/plugin-transform-unicode-regex ... Compile ES2015 Unicode regex to ES5. babel-plugin ... babel. The compiler for writing next generation JavaScript.
Read more >
Open Source Disclosures - SnapAttack
COMPONENT NAME VERSION LICENSE @amplitude/types 1.8.2 MIT @amplitude/ua‑parser‑js 0.7.24 MIT @amplitude/utils 1.8.2 MIT
Read more >
babel-plugin-transform-es2015-unicode-regex - npm - Snyk
Learn more about babel-plugin-transform-es2015-unicode-regex: package health score, popularity, security, maintenance, versions and more.
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