egoist / egoist/tsup

minify=true will generate error code?

Open
#1,091 3 comments 5 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

demo:
```
async function getClient() {
return await {
call: (data) => {console.log('call', data)}
};
}

async function test(data: string) {
const client = await getClient();
await client?.call(data);
return true;
}
test("1");
```

tsup.config.json

```
import {defineConfig} from 'tsup';

process.env.NODE_ENV = 'development';

export default defineConfig([
{
entry: ['./index.ts'],
format: ['cjs'],
splitting: true,
sourcemap: true,
minify: true,
outDir: './dist/',
noExternal: [],
define: {
},
plugins: [
],
target: 'es2020',
tsconfig: './tsconfig.json'
}
]);
```
tsconfig.json

```
{
"compilerOptions": {
"types": ["node"],
"target": "ES2022",
"paths": {
},
"typeRoots": [
]
},
"include": [
],
"exclude": ["node_modules"]
}
```

run dist/index.js

the error:
```
"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");
^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1178:20)
at Module._compile (node:internal/modules/cjs/loader:1220:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
at node:internal/main/run_main_module:23:47
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the report using index.ts, tsup.config.json, and tsconfig.json, with minify enabled, then run the generated dist/index.js under Node.js. Inspect the emitted code around the optional-call expression and compare the minified and non-minified outputs; done means the same example runs without the reported SyntaxError when minified.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.