Skip to content

fix(wasm): the types failed to compile without the esnext lib - #130

Merged
jamesconwaydev merged 2 commits into
mainfrom
wasm-docs
Nov 20, 2026
Merged

jamesconwaydev merged 2 commits into
mainfrom
wasm-docs

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Problem

  • The shipped .d.ts files use Symbol.dispose. TypeScript only knows that with lib: esnext.disposable, so a project that doesn't list it failed with TS2550.
  • The WASM README said you don't have to call free(), because the garbage collector frees what you drop. The collector does that between turns of the event loop, though. A loop that parses page after page without yielding grows WebAssembly memory until it traps at 4 GB. A node that's still alive also keeps its whole document. And WebAssembly memory never shrinks, which the README didn't say.
  • package.json didn't export ./package.json, had no main, the nodeType docs left out 4 and 7, and tests/browser.rs named Chrome where CI runs Firefox.
  • The root README claimed more than Parsec does: one dependency (the core has two, memchr and url), a C API that never crashes (deep <template> nesting still overflows the stack), hostile inputs in time proportional to their length (a few patterns are still quadratic), a WebAssembly size from an older build, and CSS WPT totals that left out the skipped cases.

Change

  • build.sh puts /// <reference lib="esnext.disposable" /> at the top of both .d.ts files.
  • The WASM README says when to free: in a loop that doesn't yield, free each node and its document, or declare them with using, with an example. It also says memory only grows. Measured with the current build: sixty 2 MB pages in one loop, reading a node from each, reach 1.4 GB of WebAssembly memory without frees and 40 MB with them. Freeing only the document leaves it at 1.4 GB.
  • package.json gains "./package.json" in exports and "main": "./node/parsec_html.js"; the nodeType doc comment lists every value it returns; tests/browser.rs says how CI runs it.
  • The root README's claims are corrected as listed above. Each CSS WPT count now gives its total with skipped cases and the reason they're skipped, the same figures the CI summary prints. The size is 1.1 MB, 526 KB gzipped, in both READMEs, the WASM one with the exact byte count.

Tests

  • tests/package.test.mjs: both .d.ts files start with the reference; parsec-html/package.json can be required and main resolves to the file require gets.
  • Checked by hand with tsc 7.0.2: a consumer with lib: ["es2022", "dom"] compiles against the new package, and fails with TS2550 once the reference line is removed.
  • wasm-pack test --node, cargo clippy --target wasm32-unknown-unknown --all-targets -- -D warnings, cargo fmt --check, ./build.sh and node --test tests/package.test.mjs (13 of 13).

The .d.ts files use Symbol.dispose, which TypeScript knows only with
lib esnext.disposable, so a project that didn't list it got TS2550.
build.sh now puts a reference to that lib at the top of both.

The README said free() wasn't needed, as the garbage collector frees
what you drop. It does that between turns of the event loop, so a loop
that parses and never yields grows memory until it traps, and a node
still alive keeps its document. The README now says when to free, with
a `using` example, and that WebAssembly memory never shrinks.

Smaller fixes: package.json exports ./package.json and has a main;
nodeType's docs list 4 and 7; tests/browser.rs names the browser CI
uses; the size is the current build's.
- One dependency: the core has two, memchr and url, 34 crates in all.
- The C API never crashing: input nested deep enough still overflows
  the stack, which ends the process.
- Hostile inputs in time proportional to length: a few patterns are
  still quadratic.
- The WebAssembly size was an older build's.
- The CSS WPT counts left the skipped cases out of the totals; each now
  says how many were skipped and why.

@foothillsdigital foothillsdigital left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked 04d1d0b:

  • The WPT totals add up. 14,758 + 135 + 129 = 15,022. In each of media queries (1,370 + 14 = 1,384), computed values (12,111 + 355 = 12,466) and cascade (1,474 + 199 = 1,673), the new total is the old one plus the skips, so the failures (0, 755, 131) are unchanged.
  • Two dependencies: crates/parsec/Cargo.toml has memchr and url. cargo tree -p parsec-html-core -e normal has 35 unique crates including itself, so "34 crates in all" is right.
  • nodeType: the match returns 4 for Cdata, 7 for ProcessingInstruction, and 11 for Fragment and ShadowRoot, as the doc now says.
  • package.json: main is ./node/parsec_html.js, the same file as the node export, and node/ is in files. ./package.json is exported, and the new test checks both.
  • build.sh: the reference directive goes first in both .d.ts files, which is where TypeScript requires it, and the test checks it.
  • The README's new limits (quadratic attribute and end-tag patterns, <template> nesting overflowing the stack) are honest, and the C API claim no longer overstates it. The WASM README's using example frees the node and its document, as its text says it must.

Approving.

@jamesconwaydev
jamesconwaydev added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 1c4e342 Nov 20, 2026
33 checks passed
@jamesconwaydev
jamesconwaydev deleted the wasm-docs branch November 20, 2026 19:02
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.

2 participants