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
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too