Skip to content

Conversation

@pdubroy
Copy link

@pdubroy pdubroy commented Oct 9, 2025

What are you adding in this PR?

  • Switch liquid-html-parser from using the JS version of Ohm to the (experimental) WebAssembly version. This brings large performance speedups (~10x faster parse times) but contains some breaking changes to the API.

(I have been coordinating with @charlespwd on these changes.)

The required changes are:

  • @ohm-js/wasm is now an ESM-only package — require(esm) is available in all supported versions of Node, so there should be no need to ship a dual package anymore.
  • The toAST helper from @ohm-js/extras has a bunch of issues, and will be deprecated. The replacement is AstBuilder, which offers a similar, but simpler and less error-prone API.
  • The way that iteration and optional nodes are handled is changing: an expression like (a b)? c has arity 3 in Ohm today; in the new world, it will have arity 2: an opt node (with b and c as children) and a nonterminal (c). The change to iter nodes is similar.
  • Explicit resource management for MatchResult objects: In moving to Wasm, we greatly reduce the memory requirements of the internal parse tree that Ohm builds during matching. The memory is now allocated from Wasm linear memory, but that means it needs to be managed explicitly — preferably, via a using statement (which can be straightforwardly transpiled to ES5).

What's missing?

  • 3 of the LiquidHTMLSyntaxError tests are failing, which is expected since error messages are still TODO.
  • There's a type issue that I papered over with @ts-ignore.

What's next? Any followup issues?

  • I'm not yet satisfied with the migration path here. To make it easier to test and deploy the new version, I'd ideally like it to be something we could toggle on and off with (at most) a minor code change. It should be possible to use AstBuilder as an adapter for toAST, so that we can use the new interface with the old code.
  • It's not blocking, but the @ohm-js/cli package can generate TypeScript types for a grammar's semantic actions. It would be nice to get that working with AstBuilder, so that we could properly type the mapping functions.

@pdubroy pdubroy requested a review from a team as a code owner October 9, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant