-
Notifications
You must be signed in to change notification settings - Fork 700
Description
Reproduction link or steps
reproduction: https://stackblitz.com/edit/github-er5lxxib?file=repro.js
related: oxc-project/oxc#9630
oxc-parser uses a custom reviver in JSON.parse to restore non json literal on js side, such as regex and bigint https://github.com/oxc-project/oxc/blob/fef680a4775559805e99622fb5aa6155cdf47034/napi/parser/index.js#L20-L35, but this is missing in rolldown/parseAst.
import { parseSync } from 'oxc-parser';
import { parseAst } from 'rolldown/parseAst';
let code = `/regex/; 1n;`;
console.log('===== oxc-parser: parseSync =====');
console.dir(parseSync('test.js', code).program, { depth: 10 });
console.log('===== roldown/parseAst: parseAst ');
console.dir(parseAst(code), { depth: 10 });===== oxc-parser: parseSync =====
{
type: 'Program',
start: 0,
end: 12,
body: [
{
type: 'ExpressionStatement',
start: 0,
end: 8,
expression: {
type: 'Literal',
start: 0,
end: 7,
value: /regex/, <-- 👍
raw: '/regex/',
regex: { pattern: 'regex', flags: '' }
}
},
{
type: 'ExpressionStatement',
start: 9,
end: 12,
expression: {
type: 'Literal',
start: 9,
end: 11,
value: 1n, <-- 👍
raw: '1n',
bigint: '1'
}
}
],
sourceType: 'module',
hashbang: null
}
===== roldown/parseAst: parseAst
{
type: 'Program',
start: 0,
end: 12,
body: [
{
type: 'ExpressionStatement',
start: 0,
end: 8,
expression: {
type: 'Literal',
start: 0,
end: 7,
value: null, <-- ❓
raw: '/regex/',
regex: { pattern: 'regex', flags: '' }
}
},
{
type: 'ExpressionStatement',
start: 9,
end: 12,
expression: {
type: 'Literal',
start: 9,
end: 11,
value: null, <-- ❓
raw: '1n',
bigint: '1'
}
}
],
sourceType: 'module',
hashbang: null
}
I think oxc-parser should expose a separate wrap.js so that rolldown can share the same logic oxc-project/oxc#9630. Since raw transfer also requires extra js side code, that's also probably somehow exposed from oxc-parser in the future. Probably rolldown can add oxc-parser as dev dependencies, so that such wrapper js code be bundled into rolldown entirely.
What is expected?
see above
What is actually happening?
see above
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
rolldown: nightly => 1.0.0-beta.4Any additional comments?
No response