Skip to content

feat(wasm): Parsec couldn't be used from JavaScript - #97

Merged
jamesconwaydev merged 6 commits into
mainfrom
bindings-wasm
Nov 19, 2026
Merged

jamesconwaydev merged 6 commits into
mainfrom
bindings-wasm

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Problem

Parsec had no way in from JavaScript (#24). Lexbor ships a WASM build, and npm users of HTML parsers expect a package with types.

Change

  • bindings/wasm: the npm package parsec-html, built with wasm-bindgen.
    • parse and parseFragment.
    • select and selectFirst.
    • Navigation, attributes, textContent, innerHTML and outerHTML.
    • TypeScript types.
  • Two builds, picked by package.json exports: one for browsers and bundlers (await init()), and one for Node that loads itself.
  • Size: 662 KB, 279 KB gzipped, at opt-level = "s" plus wasm-opt -Os. Building with "z" saved 59 KB but parsed 40% slower.
  • wasm.yml: builds and tests the package on pull requests.
  • release-npm.yml: publishes on a v* tag with npm provenance. It needs the repository variable NPM_PUBLISH, so nothing publishes until the maintainer sets up npm trusted publishing.
  • Unblocked by the core sync in fix: an edit cycle could hang serialization, and selectors could crawl #96: parse no longer reads the clock unless there's a budget (fix(html): every parse read the clock, which panics in WebAssembly netweir/netweir#332).
  • README and ROADMAP mark WebAssembly for npm #24 done.

Closes #24

Tests

  • wasm-pack test --node: 5 passed. wasm-pack test --headless --firefox --test browser runs in CI.
  • ./build.sh, then npm install --no-save ./pkg and node --test tests/package.test.mjs: 5 passed, run on the package as someone would install it.

bindings/wasm builds Parsec with wasm-bindgen into the parsec-html npm
package: parse and parseFragment, select and selectFirst, DOM-named
navigation, attributes, text and markup, a few moves and removals, and
TypeScript types. The package holds a web build and a Node build, and
package.json picks between them.

The tests run the exports in Node and in Firefox, then the built package
as it installs. The release workflow builds it on v* tags and publishes
with npm trusted publishing and provenance, only once the maintainer
sets NPM_PUBLISH.

Parsing still panics on wasm32-unknown-unknown: parse_with reads
Instant::now() even without a budget, and there's no clock there. That
needs a change in Netweir's netweir-html before this can pass.
@jamesconwaydev
jamesconwaydev enabled auto-merge (squash) November 19, 2026 06:37
A local build with CARGO_TARGET_DIR inside bindings/wasm left target/
there, and a commit took it in. It's removed, and .gitignore keeps it
out.
@jamesconwaydev
jamesconwaydev merged commit 50aa27a into main Nov 19, 2026
33 checks passed
@jamesconwaydev
jamesconwaydev deleted the bindings-wasm branch November 19, 2026 08:30
@jamesconwaydev jamesconwaydev mentioned this pull request Nov 19, 2026
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.

WebAssembly for npm

1 participant