urlpattern-polyfill icon indicating copy to clipboard operation
urlpattern-polyfill copied to clipboard

Incompatibility due to the nullish coalescing operator

Open sneko opened this issue 3 years ago • 0 comments

Hi,

Thank you for the polyfill, it works in latest environments but when dealing with older node versions, babel versions... it may fail to compile due to 1 nullish coalescing operator.

https://github.com/kenchris/urlpattern-polyfill/blob/main/src/url-pattern.ts#L159

I get this kind of error:

  const defaultPattern = `[^${escapeString(options.delimiter ?? "/#?")}]+?`;
                                                              ^

SyntaxError: Unexpected token '?'

I browsed a lot of topics posted across years I saw like 4-5 fixes to solve this issue. But in my case, since I have a Babel project I just had to update to:

    "core-js": "^3.22.8",

And in my babel.config.js:

module.exports = {
  presets: ['@babel/preset-env'],
};

In case you don't have Babel and no easy way to add it you will have to investigate 😄 ...

It's not really an issue, much more something to help in case it happens to someone else (I spent hours on this to find the minimal settings to tweak to make it working).

Thank you,

sneko avatar Jun 03 '22 15:06 sneko