Commit 3f1ee43
committed
refactor(parse-externals): drop babel for vendored acorn-wasm
Replaces @babel/parser + @babel/traverse + @babel/types in
src/ui/externals/parse-externals.ts with the vendored acorn-wasm
(Rust-built WASM acorn from ultrathink).
Bundle: 5.8 MB → 4.2 MB (-27%); sourcemap 3.6 MB → 524 KB.
Migration:
- @babel/parser → acorn-wasm.parse() (only used as a syntax-error
sentinel; the AST itself is consumed via simple()).
- @babel/traverse → acorn-wasm.simple() (re-parses internally, plain
ESTree-shape node visitor with no `path` wrapper).
- @babel/types `is*()` guards → ESTree `node.type === '...'` checks.
- Babel's `Literal`-family discrimination (StringLiteral /
NumericLiteral / BigIntLiteral / RegExpLiteral / NullLiteral)
collapses into ESTree's single `Literal` shape; we discriminate via
`'regex' in node` / `'bigint' in node` / `typeof node.value`.
- ImportExpression visitor and CallExpression-with-callee.type ===
'Import' both kept as defensive paths because acorn-wasm's emitted
shape isn't strictly fixed across versions.
Locations:
- acorn-wasm doesn't surface `loc.{line,column}` on AST nodes — only
byte `start`/`end` offsets. Built a lazy newline-offset table per
source so offset → vscode.Position is O(log n) per lookup.
Workspace:
- Registered vendor/acorn-wasm as a pnpm workspace package
(already named `acorn-wasm` in its package.json) and added it as
a runtime dep via `acorn-wasm: workspace:*`. This way the import
is `from 'acorn-wasm'` (a package name) rather than `from
'../../../vendor/acorn-wasm/acorn-wasm-sync.mts'` (a relative
`.mts` path that tsc/tsgo refuse without
allowImportingTsExtensions).
Operator-map fallback:
- BinaryExpression / UnaryExpression now `?? kDYNAMIC_VALUE` so
unrecognized operators (which the previous babel code couldn't
hit thanks to typed enums) gracefully fall through to dynamic
rather than producing `undefined` in the function-return type.
Removed deps: @babel/parser, @babel/traverse, @babel/types,
@types/babel__traverse.
Verified: pnpm install + check + test --all + build all green.
out/main.js bundle 4.2 MB. Test suite still passes (smoke).1 parent 650715b commit 3f1ee43
4 files changed
Lines changed: 206 additions & 242 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 117 | | |
121 | 118 | | |
| 119 | + | |
122 | 120 | | |
123 | 121 | | |
124 | 122 | | |
125 | 123 | | |
126 | 124 | | |
127 | | - | |
128 | 125 | | |
129 | 126 | | |
130 | 127 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
0 commit comments