Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/liquid-html-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"devDependencies": {
"@types/line-column": "^1.0.0",
"@types/node": "^22.18.8"
"@types/node": "^22.18.8",
"yaml": "^2.8.3"
}
}
4 changes: 2 additions & 2 deletions packages/liquid-html-parser/specs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ src/
liquid-raw.ts # Raw tag body parsing, Liquid-in-range parsing
liquid-tags.ts # Tag dispatch: environment lookup, MarkupParser creation, tolerant fallback
liquid-variable-output.ts # {{ }} variable output parsing
test-helpers.ts # expectPath, expectPosition, expectBlockStartPosition test utilities
test-helpers.ts # expectPath, expectPosition test utilities

# Markup domain -- Liquid expression grammar
markup/
Expand Down Expand Up @@ -158,7 +158,7 @@ The parser calls these utilities while building the AST.
| `document/liquid-raw.ts` | Raw tag body extraction (scan forward for end tag). `parseLiquidInRange` for tags that parse Liquid inside their body. Defines `RawParserDelegate` interface. | Expression parsing. Tag dispatch. |
| `document/liquid-tags.ts` | Tag dispatch: environment lookup, `MarkupParser` creation from envelope, tolerant-mode try/catch fallback to base case. Defines `TagParserDelegate` interface. | Block body parsing. HTML parsing. |
| `document/liquid-variable-output.ts` | `{{ }}` variable output parsing. | Everything else. |
| `document/test-helpers.ts` | Test utilities: `expectPath`, `expectPosition`, `expectBlockStartPosition`, `expectBlockEndPosition`, `sourceAt`. | Production code. |
| `document/test-helpers.ts` | Test utilities: `expectPath`, `expectPosition`. | Production code. |
| `shared.ts` | `envelopeFromLine()`: constructs `LiquidTagEnvelope` from a `{% liquid %}` line. Shared so both `document/parser.ts` and `tags/liquid.ts` can import it. | Everything else. |
| `tag-definitions.ts` | `TagKind` enum, `TagDefinition<M>` discriminated union, `Parser` interface, `BranchName` type, `LiquidLine` and `LiquidLineContext` types. | Parsing logic. Environment management. |
| `environment.ts` | `Environment` class (tag registry, `tagForName`, `registerTag`, `Environment.default()` singleton). Re-exports all types from `tag-definitions.ts`. | Parsing logic. |
Expand Down
16 changes: 10 additions & 6 deletions packages/liquid-html-parser/specs/recursive-descent.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Public API

`toLiquidHtmlAST(source, options)` and `toLiquidAST(source, options)` parse Liquid (and optionally HTML) source into a typed AST. All oracle tests pass. `ast.test.ts` unit tests pass.
`toLiquidHtmlAST(source, options)` and `toLiquidAST(source, options)` parse Liquid (and optionally HTML) source into a typed AST. All oracle tests and parser specs pass.

Performance is not a constraint. Correctness first.

Expand Down Expand Up @@ -481,19 +481,23 @@ For each `.liquid` file in `fixtures/theme/{base-theme,dawn,horizon}/`:

The golden files represent the ground truth AST output for each fixture. Fixtures are generated locally per `fixtures/README.md`.

### Unit tests (`ast.test.ts`)
### Parser specs (`specs/parser` at the repo root)

Fine-grained tests that assert specific properties at specific AST paths using `deepGet`. Tests cover:
Language-neutral specs: each case is a template and the complete tree, or the error, that
`toLiquidHtmlAST` or `toLiquidAST` gives for it. `src/specs.test.ts` runs them, and
`specs/parser/README.md` describes the format. They cover:

- All expression types (strings, numbers, literals, ranges, lookups, comparisons, logical ops)
- All named tags (assign, echo, render, for, if, case, cycle, paginate, etc.)
- HTML elements, attributes, void elements, raw tags
- Error cases (unclosed nodes, mismatched tags, etc.)
- Completion mode (dangling nodes, placeholder character)
- Branch position tracking
- Whitespace trim markers

These tests import from `./ast`.
### Unit tests

The other tests, like `ast.test.ts` and `document/*.test.ts`, cover what a spec can't state: the
tokenizers, the node factories, and parses with options, like completion mode.

---

Expand All @@ -510,6 +514,6 @@ These tests import from `./ast`.
```bash
cd packages/liquid-html-parser
pnpm vitest run src/parser-oracle.test.ts # oracle golden tests
pnpm vitest run src/ast.test.ts # unit tests
pnpm vitest run src/specs.test.ts # parser specs
pnpm vitest run # all tests
```
Loading
Loading