Skip to content

feat: minimal build variant for es-module-shims#211

Merged
guybedford merged 1 commit into
mainfrom
lexer-min
Jul 2, 2026
Merged

feat: minimal build variant for es-module-shims#211
guybedford merged 1 commit into
mainfrom
lexer-min

Conversation

@guybedford

Copy link
Copy Markdown
Owner

Summary

Adds a stripped LEXER_MIN build variant tuned for es-module-shims, which only consumes a subset of the lexer's output. Two new package entry points sit alongside the existing full builds:

Entry point File Engine
es-module-lexer/minimal dist/lexer.minimal.js wasm
es-module-lexer/minimal/js dist/lexer.minimal.asm.js asm.js

What it drops

Verified against the es-module-shims core — the minimal build removes only what shims never reads, gated behind -DLEXER_MIN in C and a build-time MINIMAL flag in the readers (folded out by terser):

  • the parsed import attribute list at (the Attribute struct + ra/aks/ake/avs/ave getters) — assertions stay recoverable via source.slice(a, se - 1)
  • export statement_start (ss) / ess()
  • the facade (f()) / hasModuleSyntax (ms()) flags and the underlying bool
  • the module-only facade fast path (dead once f() is gone)

Imports keep n, s, e, ss, se, d, t, a; exports keep n, s, e, ls, le, ln. parse() returns a 2-tuple in the minimal build.

Footprint (brotli)

full minimal Δ
wasm (dist/lexer.js) 7,113B 6,648B −465B
asm (dist/lexer.asm.js) 6,865B 6,486B −379B
lib/lexer.wasm (raw) 11,364B ~10,900B ~−470B

Build / tooling

  • Shared build steps extracted to build/*.mjs (asm prelude, asm combine, wasm embed, minimal d.ts); the full build is unchanged byte-for-byte.
  • A separate types/lexer.minimal.d.ts (re-exports the shared types, overrides ExportSpecifier minus ss and the 2-tuple parse).
  • Test suite runs against both variants (MINIMAL=1), with min-only-field assertions gated behind !min.
  • bench and footprint cover the full 2×2 (full/minimal × wasm/asm) matrix.

Test plan

  • chomp build produces all 6 dist files + both d.ts
  • chomp test — 147 passing across all four suites (full/minimal × wasm/asm)
  • minimal d.ts typechecks under tsc --strict
  • all four package entry points resolve; assertion type recoverable via slice(a, se-1) in the minimal build

🤖 Generated with Claude Code

Adds a LEXER_MIN build variant that drops the metadata es-module-shims
never reads, exposed as two new package entry points alongside the
existing full builds:

- es-module-lexer/minimal     -> dist/lexer.minimal.js     (wasm)
- es-module-lexer/minimal/js  -> dist/lexer.minimal.asm.js (asm.js)

Gated behind -DLEXER_MIN in the C source and a build-time MINIMAL flag in
the readers (folded out by terser). Dropped:

- the parsed import attribute list `at` (Attribute struct + ra/aks/ake/
  avs/ave getters); assertions remain recoverable via source.slice(a, se-1)
- export statement_start `ss` / ess()
- the facade f() / hasModuleSyntax ms() flags (+ the bool)
- the module-only facade fast path

Imports keep n,s,e,ss,se,d,t,a; exports keep n,s,e,ls,le,ln. parse()
returns a 2-tuple in the minimal build.

Footprint (brotli): wasm 7,113 -> 6,648B, asm 6,865 -> 6,486B.

Shared build steps extracted to build/*.mjs; the full build is unchanged
(byte-for-byte). The test suite runs against both variants (MINIMAL=1)
with min-only-field assertions gated; bench and footprint cover the full
2x2 matrix.
@guybedford
guybedford merged commit 6c90425 into main Jul 2, 2026
1 check passed
@guybedford
guybedford deleted the lexer-min branch July 2, 2026 00:52
guybedford added a commit that referenced this pull request Jul 2, 2026
…e readme (#219)

The minimal wasm build added in #211 predates the #217 memory growth fix
and was missing -s ALLOW_MEMORY_GROWTH=1, so parse() on sources over ~4M
chars threw "Maximum memory size exceeded" (the Large source test from
#217 catches this under test:minimal:wasm).

Also documents the es-module-lexer/minimal build in the readme, and
corrects the stale comments claiming dynamic-import n / ip() are dropped
in the minimal build: _ip is exported and read, only at/ss/f/ms go.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant