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

Miscompile of minified code #843

Open
segevfiner opened this issue Sep 17, 2024 · 0 comments
Open

Miscompile of minified code #843

segevfiner opened this issue Sep 17, 2024 · 0 comments

Comments

@segevfiner
Copy link

The following code:

async function n(){return await{call:t=>{console.log("call",t)}}}async function a(t){return await(await n())?.call(t),!0}a("1");

Compiled with: pnpm sucrase dist -d dist2 --transforms imports

Results in:

"use strict"; async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }async function n(){return await{call:t=>{console.log("call",t)}}}async function a(t){return awaitawait _asyncOptionalChain([(await n()), 'optionalAccess', async _ => _.call, 'call', async _2 => _2(t)]),!0}a("1");
//# sourceMappingURL=test2.js.map%

Note the invalid awaitawait syntax. I have also seen cases of it producing returnawait as well. This is a syntax error and fails to run.

Encountered here egoist/tsup#1091, where tsup uses sucrase with only the imports transform to compile to ESM using esbuild and then uses sucrase to transform to CJS as a way to emulate tree shaking with esbuild with CJS, which is not supported natively by it.

easrng pushed a commit to easrng/sucrase that referenced this issue Sep 26, 2024
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