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

Broken optional chaining transpilation #348

Open
fabiospampinato opened this issue Apr 7, 2023 · 0 comments
Open

Broken optional chaining transpilation #348

fabiospampinato opened this issue Apr 7, 2023 · 0 comments

Comments

@fabiospampinato
Copy link

I'm importing the following:

https://cdn.skypack.dev/voby

Which highlights that the transform that SkyPack is using for transpiling optional chaining is broken. I have the following source code:

const IS_BROWSER = !!globalThis.CDATASection?.toString?.().match ( /^\s*function\s+CDATASection\s*\(\s*\)\s*\{\s*\[native code\]\s*\}\s*$/ );

But it gets transpiled to this:

var a, b;
const IS_BROWSER = !!((_b = (_a = globalThis.CDATASection) == null ? void 0 : _a.toString) == null ? void 0 : _b().match(/^\s*function\s+CDATASection\s*\(\s*\)\s*\{\s*\[native code\]\s*\}\s*$/));

Which seems correct at first look, but it isn't, because when _b() is called the this of the function call is undefined, while in the original code that this would have been globalThis.CDATASection itself, i.e. the thing to stringify.

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

1 participant