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

esbuild does not handle the new feature of regular expressions properly #3211

Open
aiyadingya opened this issue Jul 4, 2023 · 1 comment

Comments

@aiyadingya
Copy link

The rebuild configuration is as follows:

import * as esbuild from 'esbuild'
const result = await esbuild.build({
  entryPoints: ['app.js'],
  bundle: true,
  outfile: './result_esbuild.js',
  format: 'esm',
  target: ['es2015'],
})

The following example code represents the new features introduced in es8:

const matchObj = '---756---'.match(/(?<digits>[0-9]+)/)
console.log('matchObj', matchObj)

const re = /./.test('\n');
console.log(re)

const er = /^\p{White_Space}+$/u.test('\n \t')
console.log(er)

const es = 'Xabc def'.match(/(?<=X)[a-z]+/g)
console.log(es)

Build the following:

var matchObj = "---756---".match(new RegExp("(?<digits>[0-9]+)"));
console.log("matchObj", matchObj);

var re = /./.test("\n");
console.log(re);

var er = new RegExp("^\\p{White_Space}+$", "u").test("\n 	");
console.log(er);

var es = "Xabc def".match(new RegExp("(?<=X)[a-z]+", "g"));
console.log(es);

I found the explanation of the above conversion in another issue, it seems that esbuild thought that the shim library would handle the above case, then I imported core-js globally and found that it only handles the RegExp named capture groups case. Others still fail in older versions of chrome?

I think if there are syntax features that can't be converted, the shim library can't handle them, and they should be handled like biginit, eg:

supported: {
'bigint': false,
},

The build should throw an error.

image
@evanw
Copy link
Owner

evanw commented Jul 10, 2023

This is by design. If your shim isn't working then that's a problem with the shim, not with esbuild. There is no one shim that esbuild supports so "the shim library can't handle them" isn't something that esbuild knows. You should either get your shim fixed or use a different shim.

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

2 participants