Skip to content

Commit 3f1ee43

Browse files
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

File tree

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,14 @@
114114
"vscode:uninstall": "node ./src/lifecycle/uninstall.mjs"
115115
},
116116
"dependencies": {
117-
"@babel/parser": "7.29.3",
118-
"@babel/traverse": "7.29.0",
119-
"@babel/types": "7.29.0",
120117
"@socketsecurity/lib": "catalog:",
121118
"@vscode/python-extension": "1.0.6",
119+
"acorn-wasm": "workspace:*",
122120
"ini": "6.0.0",
123121
"json-to-ast": "2.1.0",
124122
"toml-eslint-parser": "1.0.3"
125123
},
126124
"devDependencies": {
127-
"@types/babel__traverse": "7.28.0",
128125
"@types/ini": "4.1.1",
129126
"@types/json-to-ast": "2.1.4",
130127
"@types/node": "catalog:",

pnpm-lock.yaml

Lines changed: 5 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
# Register .claude/hooks/* as workspace packages so taze (run via
66
# `pnpm run update`) sees and bumps their package.json manifests
77
# alongside the root. Keeps hook deps in lockstep with the parent.
8+
# vendor/acorn-wasm is registered too so the bundle imports it as a
9+
# package by name (acorn-wasm) rather than via a brittle relative
10+
# `.mts` path that tsc/tsgo refuse without allowImportingTsExtensions.
811
packages:
912
- .claude/hooks/*
13+
- vendor/acorn-wasm
1014

1115
# Catalog entries shared across hook workspaces. Pinning them here
1216
# keeps the entire hook tree in lockstep with the parent without each

0 commit comments

Comments
 (0)