Skip to content

Commit 5204b2c

Browse files
committed
Upgrade to ohm-js v18 (beta.7) with @ohm-js/compiler and to-ast-compat
Replace ohm-js v17 with ohm-js 18.0.0-beta.7 and its companion packages (@ohm-js/compiler, @ohm-js/to-ast-compat). This enables WebAssembly-based parsing for better performance. - Use createToAst() / closure-based toAst instead of node.toAST(mapping) - Use `using match` for automatic resource cleanup - Use typed CstNode, OptNode, MatchResult imports - Update grammar index offsets for new AST shape - Adapt to new error API (FailedMatchResult, getRightmostFailurePosition) - Update test expectations for new error message token ordering
1 parent bda435a commit 5204b2c

9 files changed

Lines changed: 147 additions & 140 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/liquid-html-parser': minor
3+
---
4+
5+
Integrate @ohm-js/wasm for browser-compatible parsing

packages/liquid-html-parser/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
"type-check": "tsc --noEmit"
3333
},
3434
"dependencies": {
35+
"@ohm-js/compiler": "18.0.0-beta.7",
36+
"@ohm-js/to-ast-compat": "18.0.0-beta.7",
3537
"line-column": "^1.0.2",
36-
"ohm-js": "^17.0.0"
38+
"ohm-js": "18.0.0-beta.7"
3739
},
3840
"devDependencies": {
3941
"@types/line-column": "^1.0.0"

packages/liquid-html-parser/src/errors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import lineColumn from 'line-column';
2-
import { MatchResult } from 'ohm-js';
2+
import { FailedMatchResult } from 'ohm-js';
33
import { NodeTypes, Position } from './types';
44

55
interface LineColPosition {
@@ -10,12 +10,12 @@ interface LineColPosition {
1010
export class LiquidHTMLCSTParsingError extends SyntaxError {
1111
loc?: { start: LineColPosition; end: LineColPosition };
1212

13-
constructor(ohm: MatchResult) {
13+
constructor(ohm: FailedMatchResult) {
1414
super(ohm.shortMessage);
1515
this.name = 'LiquidHTMLParsingError';
1616

17-
const input = (ohm as any).input;
18-
const errorPos = (ohm as any)._rightmostFailurePosition;
17+
const input = ohm.input;
18+
const errorPos = ohm.getRightmostFailurePosition();
1919
const lineCol = lineColumn(input).fromIndex(Math.min(errorPos, input.length - 1));
2020

2121
// Plugging ourselves into @babel/code-frame since this is how

packages/liquid-html-parser/src/grammar.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('Unit: liquidHtmlGrammar', () => {
101101
expectMatchSucceeded('<6h>').to.be.false;
102102

103103
function expectMatchSucceeded(text: string) {
104-
const match = grammar.LiquidHTML.match(text, 'Node');
104+
using match = grammar.LiquidHTML.match(text, 'Node');
105105
return expect(match.succeeded(), text);
106106
}
107107
});
@@ -129,7 +129,7 @@ describe('Unit: liquidHtmlGrammar', () => {
129129
`).to.be.true;
130130

131131
function expectMatchSucceeded(text: string) {
132-
const match = grammar.LiquidStatement.match(text.trimStart(), 'Node');
132+
using match = grammar.LiquidStatement.match(text.trimStart(), 'Node');
133133
return expect(match.succeeded(), text);
134134
}
135135
});
@@ -156,7 +156,7 @@ describe('Unit: liquidHtmlGrammar', () => {
156156
});
157157

158158
function expectMatchSucceeded(text: string) {
159-
const match = placeholderGrammars.LiquidHTML.match(text.trimStart(), 'Node');
159+
using match = placeholderGrammars.LiquidHTML.match(text.trimStart(), 'Node');
160160
return expect(match.succeeded(), text);
161161
}
162162
});

packages/liquid-html-parser/src/grammar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { grammars, Grammar } from 'ohm-js';
1+
import { grammars, Grammar } from '@ohm-js/compiler/compat';
22

33
export const liquidHtmlGrammars = grammars(require('../grammar/liquid-html.ohm.js'));
44

0 commit comments

Comments
 (0)