Repository navigation
feat(wasm): Parsec couldn't be used from JavaScript - #97
Merged
Merged
Conversation
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.
# Conflicts: # .gitignore
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.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 packageparsec-html, built with wasm-bindgen.parseandparseFragment.selectandselectFirst.textContent,innerHTMLandouterHTML.package.jsonexports: one for browsers and bundlers (await init()), and one for Node that loads itself.opt-level = "s"pluswasm-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 av*tag with npm provenance. It needs the repository variableNPM_PUBLISH, so nothing publishes until the maintainer sets up npm trusted publishing.parseno longer reads the clock unless there's a budget (fix(html): every parse read the clock, which panics in WebAssembly netweir/netweir#332).Closes #24
Tests
wasm-pack test --node: 5 passed.wasm-pack test --headless --firefox --test browserruns in CI../build.sh, thennpm install --no-save ./pkgandnode --test tests/package.test.mjs: 5 passed, run on the package as someone would install it.