Skip to content

feat: minimal build v3 API cleanup, literal ImportType, README restructure - #240

Merged
guybedford merged 6 commits into
v3from
minimal-v3-api
Sep 7, 2026
Merged

guybedford merged 6 commits into
v3from
minimal-v3-api

Conversation

@guybedford

@guybedford guybedford commented Sep 7, 2026 •

Copy link
Copy Markdown
Owner

This applies the v3 minimal build API changes that mirror the full build record changes at zero footprint cost, and lands the v3 README restructure and the remaining public API cleanups that came out of reviewing it.

Minimal build (es-module-lexer/minimal):

  • at is dropped from import records. It was always null; attributes are read via source.slice(a, se - 1) as before.
  • export { a as b } from 'c' reports ln: 'a' with ls / le spanning the imported name instead of erasing them to undefined / -1, matching the full build's importName fields. The minimal wasm drops its erasure branch. Namespace reexports and export * are unchanged.
  • The README minimal section gains an "Upgrading from v2" list.
// export { hello as default } from "test-dep"
// v2: { n: 'default', ln: undefined, ls: -1, le: -1 }
// v3: { n: 'default', ln: 'hello', ls: 16, le: 21 }

Shared API:

  • ImportType is a union of named numeric literal type aliases (StaticImportType = 1, DynamicImportType = 2, ...) rather than a runtime enum, so nothing is importable at runtime by mistake under single-file transpilers or type stripping. This removes the enum object from the wasm bundles.
  • initSync is internal only: parse initializes on first use and init covers browser main threads. The asm.js builds export init so all four entry points share the same parse / init API, with a test asserting it per lane.
  • Dynamic import records type attributes as null: the options argument is not parsed, only located by attributesStart.

README and tooling:

  • The package exports table carries footprint (matching chomp footprint) and cold / warm parse speed per MB; environment support, CSP and usage move to the top, with the minimal build documented before the full build; the WASI build steps are replaced by the two emsdk checkouts the build installs itself.
  • chomp bench runs all four builds in one process and prints the per-MB table the README uses.
  • The generated types/ declarations are tracked so the README can link to them.

Brotli sizes: lexer.minimal.js 7522 → 7351 B, lexer.min.wasm 4536 → 4523 B, lexer.js 15168 → 15076 B (before the README size figures were refreshed against chomp footprint).

Test coverage: the shared suites assert the imported name for every reexport in both builds (the full build im / ims / ime fields mapped through the export assertion helper), minimal records are asserted to have no at, each lane checks its entry point exports exactly parse and init, and the type test covers ImportType narrowing, the rejected literal 9, and the absent minimal at.

Drops the always-null `at` field from minimal import records, makes
`ImportType` a type-only const enum with no runtime export, and reports the
imported name of `export { a as b } from 'c'` in the minimal build's
`ln` / `ls` / `le` rather than erasing it, matching the full build's
importName fields.
* README: package exports table carries footprint and cold / warm parse
  speed per MB; environment support, CSP and usage move to the top with the
  minimal build documented before the full build; the WASI build steps are
  removed in favour of the two emsdk checkouts the build installs itself.
* `chomp bench` runs all four builds in one process and prints the per-MB
  table the README uses.
* The generated `types/` declarations are tracked so the README can link
  to them.
* `initSync` is internal only: `parse` initializes on first use and `init`
  covers browser main threads, so nothing needs to call it. The asm.js
  builds export `init` so all four entry points share one API.
Each test lane builds only its own dist, so the export parity test now
checks the module under test rather than importing all four. The README no
longer claims the minimal build tags `export * from` with `t === 8`; it
reports the plain static `1`.
`ImportType` is a union of named numeric literal type aliases
(`StaticImportType = 1`, `DynamicImportType = 2`, ...) rather than an
ambient const enum, so nothing is importable at runtime by mistake under
single-file transpilers and type stripping.

Dynamic import records type `attributes` as `null`: the options argument is
not parsed, only located by `attributesStart`.

README footprints match `chomp footprint`.
@guybedford guybedford changed the title feat: minimal build v3 API cleanup feat: minimal build v3 API cleanup, literal ImportType, README restructure Sep 7, 2026
@guybedford
guybedford merged commit cb764f6 into v3 Sep 7, 2026
3 checks passed
@guybedford
guybedford deleted the minimal-v3-api branch September 7, 2026 05:28
@guybedford guybedford mentioned this pull request Sep 7, 2026
Merged
guybedford added a commit that referenced this pull request Sep 7, 2026
## Breaking

* **Full build records are tagged unions** discriminated by `type` (`static` | `reexport-star` | `dynamic` | `import-meta`; `direct` | `reexport` | `reexport-all`) with descriptive fields (`specifier`, `importStart`/`importEnd`, `attributes`, `phase`, `name`, `localName`, `from`, `importIndex`, `exportStart`) replacing the terse v2 names and numeric type tags. (#233)
* **`es-module-lexer/minimal`** is a new entry point holding the v2-shaped API: `parse` returns `[imports, exports]` only; `at` is dropped (read attributes via `source.slice(a, se - 1)`); `export { a as b } from 'c'` reports the imported name in `ln`/`ls`/`le`. (#211, #240)
* **`ImportType`** is a type-only union of named numeric literal aliases (`StaticImportType = 1`, `DynamicImportType = 2`, …); no runtime enum is exported. `initSync` is no longer exported — `parse` initializes on first use. (#240)
* **`es-module-lexer/js`** is the asm.js build; the unmaintained pure-JS port is removed. (#204)
* Invalid escape sequences in static specifiers throw a parse error instead of yielding `undefined`. (#238)
* Node.js 18+ is required. (#232)

## Features

* **TypeScript**: type-only imports, exports, aliases, interfaces and ambient declarations are lexed as accepted by Node.js type stripping; type-only edges carry `typeOnly`, dynamic imports carry a best-effort `probablyTypeOnly`, and erased declaration bodies never leak nested `import()` types. Full builds only. (#220, #241)
* **Export origin analysis**: reexports resolve to their originating import (`importName`, `from`, `importIndex`) regardless of statement order; `export * from` appears in `exports` as `reexport-all` and its import as `reexport-star`. (#229)
* **Template globs**: a dynamic import whose argument is a single template literal reports a glob specifier with each `${…}` collapsed to `*` (`./locales/*.js`), disambiguated by the parser so regex/division inside substitutions is handled. (#205)
* Dynamic import `attributes` is typed `null`; the options argument is located by `attributesStart`. (#240)
* `parse` initializes the Wasm synchronously on first call; `await init` is only required on browser main threads, and all four entry points export the same `parse` / `init` API. (#237, #240)

## Performance

* SIMD scanning for long line comments and templates in the full Wasm build (the minimal build stays Wasm MVP). (#231, #235)
* Identifier and number runs are skipped in bulk: ~15% faster sweeps across Wasm and asm.js. (#227)
* Module strings decode without `eval`: one-import parse 354 → 238 ns, and the Wasm builds now work under `--disallow-code-generation-from-strings`. (#239)
* Short sources (< 64 chars) copy via the typed-array loop rather than `Buffer`. (#242)
* Strict specifier decoding avoids V8's sloppy/strict cache mismatch. (#220)

## Fixes

* Bounds checks on the open-token and dynamic-import stacks; nesting past 1024 brackets or 512 dynamic imports is a parse error rather than memory corruption. (#243)
* Unannotated `declare let`/`var` and shorthand `declare module 'm'` no longer erase the following statement; `export default interface Foo {}` reports `Foo` as its local name. (#241)
* Typed export binding lists collect every declarator; `export { type as }` / `type as as` follow TypeScript's specifier table; U+00A0 is whitespace around import/export names. (#220)
* Minimal build enforces Wasm MVP (no post-MVP features) and is tested in Firefox 67. (#234)

## Docs & tooling

* README restructured: package exports table with Brotli footprint and cold/warm parse speed per MB, environment/CSP/usage up front, minimal-build "Upgrading from v2" section, WASI build steps replaced by the emsdk checkouts the build installs itself. (#240)
* `chomp bench` runs all four builds in one process and prints the README table; generated `types/` are tracked in the repo. (#240)
* TypeScript differential fuzzer against `stripTypeScriptTypes` in CI; no-eval lanes for minimal and CommonJS. (#220, #239)
guybedford added a commit that referenced this pull request Sep 7, 2026
…cture (#240)

* feat: minimal build v3 API cleanup

Drops the always-null `at` field from minimal import records, makes
`ImportType` a type-only const enum with no runtime export, and reports the
imported name of `export { a as b } from 'c'` in the minimal build's
`ln` / `ls` / `le` rather than erasing it, matching the full build's
importName fields.

* docs: minimal build upgrading from v2

* docs: restructure the README, track types, drop initSync

* README: package exports table carries footprint and cold / warm parse
  speed per MB; environment support, CSP and usage move to the top with the
  minimal build documented before the full build; the WASI build steps are
  removed in favour of the two emsdk checkouts the build installs itself.
* `chomp bench` runs all four builds in one process and prints the per-MB
  table the README uses.
* The generated `types/` declarations are tracked so the README can link
  to them.
* `initSync` is internal only: `parse` initializes on first use and `init`
  covers browser main threads, so nothing needs to call it. The asm.js
  builds export `init` so all four entry points share one API.

* test: check the lane's own entry point exports

Each test lane builds only its own dist, so the export parity test now
checks the module under test rather than importing all four. The README no
longer claims the minimal build tags `export * from` with `t === 8`; it
reports the plain static `1`.

* feat: literal ImportType aliases, null dynamic attributes, README sizes

`ImportType` is a union of named numeric literal type aliases
(`StaticImportType = 1`, `DynamicImportType = 2`, ...) rather than an
ambient const enum, so nothing is importable at runtime by mistake under
single-file transpilers and type stripping.

Dynamic import records type `attributes` as `null`: the options argument is
not parsed, only located by `attributesStart`.

README footprints match `chomp footprint`.

* fix: import the shared types the minimal declarations use
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