Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--wip-- [skip ci] #638

Draft
wants to merge 1 commit into
base: jm/doc_tag
Choose a base branch
from
Draft
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
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
Loading