Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
Add doc param tag
  • Loading branch information
jamesmengo committed Dec 3, 2024
1 parent b09fec0 commit 246e6df
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
9 changes: 8 additions & 1 deletion packages/liquid-html-parser/grammar/liquid-html.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,14 @@ LiquidStatement <: Liquid {
}

LiquidDoc <: Helpers {
Node := (TextNode)*
Node := (LiquidDocNode | TextNode)*
LiquidDocNode =
| descriptionNode
| paramNode

descriptionNode = (~("@param") any)+
paramNode = "@param" space
paramName = letter*
}

LiquidHTML <: Liquid {
Expand Down
20 changes: 10 additions & 10 deletions packages/liquid-html-parser/src/stage-1-cst.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,10 @@ describe('Unit: Stage 1 (CST)', () => {

it('should parse doc tags', () => {
for (const { toCST, expectPath } of testCases) {
const testStr = `{% doc -%} Renders loading-spinner. {%- enddoc %}`;
const testStr = `{% doc -%}
Renders loading-spinner.
@param
{%- enddoc %}`;

cst = toCST(testStr);
expectPath(cst, '0.type').to.equal('LiquidRawTag');
Expand All @@ -994,15 +997,12 @@ describe('Unit: Stage 1 (CST)', () => {
expectPath(cst, '0.blockStartLocEnd').to.equal(0 + '{% doc -%}'.length);
expectPath(cst, '0.blockEndLocStart').to.equal(testStr.length - '{%- enddoc %}'.length);
expectPath(cst, '0.blockEndLocEnd').to.equal(testStr.length);
expectPath(cst, '0.children').to.deep.equal([
{
locEnd: 35,
locStart: 11,
source: '{% doc -%} Renders loading-spinner. {%- enddoc %}',
type: 'TextNode',
value: 'Renders loading-spinner.',
},
]);
expectPath(cst, '0.children').to.have.lengthOf(2);
expectPath(cst, '0.children.0.type').to.equal('TextNode');
// this is too permissive rn
expectPath(cst, '0.children.0.value').to.equal('Renders loading-spinner.');
expectPath(cst, '0.children.1.type').to.equal('ParamNode');
expectPath(cst, '0.children.1.value').to.equal('@param');
}
});

Expand Down
17 changes: 17 additions & 0 deletions packages/liquid-html-parser/src/stage-1-cst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export enum ConcreteNodeTypes {
RenderMarkup = 'RenderMarkup',
PaginateMarkup = 'PaginateMarkup',
RenderVariableExpression = 'RenderVariableExpression',
ParamNode = 'ParamNode',
}

export const LiquidLiteralValues = {
Expand Down Expand Up @@ -1304,6 +1305,22 @@ function toLiquidDocAST(source: string, matchingSource: string, offset: number)
locEnd,
source,
},
descriptionNode: {
type: ConcreteNodeTypes.TextNode,
value: function () {
return (this as any).sourceString;
},
locStart,
locEnd,
source,
},
paramNode: {
type: ConcreteNodeTypes.ParamNode,
value: 0,
locStart,
locEnd,
source,
},
};

return toAST(res, LiquidDocMappings);
Expand Down

0 comments on commit 246e6df

Please sign in to comment.