Skip to content

Commit 790d036

Browse files
committed
--wip-- [skip ci]
Add doc param tag
1 parent 1afd9de commit 790d036

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

packages/liquid-html-parser/grammar/liquid-html.ohm

+8-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,14 @@ LiquidStatement <: Liquid {
384384
}
385385

386386
LiquidDoc <: Helpers {
387-
Node := (TextNode)*
387+
Node := (LiquidDocNode | TextNode)*
388+
LiquidDocNode =
389+
| descriptionNode
390+
| paramNode
391+
392+
descriptionNode = (~("@param") any)+
393+
paramNode = "@param" space
394+
paramName = letter*
388395
}
389396

390397
LiquidHTML <: Liquid {

packages/liquid-html-parser/src/stage-1-cst.spec.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,10 @@ describe('Unit: Stage 1 (CST)', () => {
980980

981981
it('should parse doc tags', () => {
982982
for (const { toCST, expectPath } of testCases) {
983-
const testStr = `{% doc -%} Renders loading-spinner. {%- enddoc %}`;
983+
const testStr = `{% doc -%}
984+
Renders loading-spinner.
985+
@param
986+
{%- enddoc %}`;
984987

985988
cst = toCST(testStr);
986989
expectPath(cst, '0.type').to.equal('LiquidRawTag');
@@ -994,15 +997,12 @@ describe('Unit: Stage 1 (CST)', () => {
994997
expectPath(cst, '0.blockStartLocEnd').to.equal(0 + '{% doc -%}'.length);
995998
expectPath(cst, '0.blockEndLocStart').to.equal(testStr.length - '{%- enddoc %}'.length);
996999
expectPath(cst, '0.blockEndLocEnd').to.equal(testStr.length);
997-
expectPath(cst, '0.children').to.deep.equal([
998-
{
999-
locEnd: 25,
1000-
locStart: 1,
1001-
source: '{% doc -%} Renders loading-spinner. {%- enddoc %}',
1002-
type: 'TextNode',
1003-
value: 'Renders loading-spinner.',
1004-
},
1005-
]);
1000+
expectPath(cst, '0.children').to.have.lengthOf(2);
1001+
expectPath(cst, '0.children.0.type').to.equal('TextNode');
1002+
// this is too permissive rn
1003+
expectPath(cst, '0.children.0.value').to.equal('Renders loading-spinner.');
1004+
expectPath(cst, '0.children.1.type').to.equal('ParamNode');
1005+
expectPath(cst, '0.children.1.value').to.equal('@param');
10061006
}
10071007
});
10081008

packages/liquid-html-parser/src/stage-1-cst.ts

+17
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export enum ConcreteNodeTypes {
8282
RenderMarkup = 'RenderMarkup',
8383
PaginateMarkup = 'PaginateMarkup',
8484
RenderVariableExpression = 'RenderVariableExpression',
85+
ParamNode = 'ParamNode',
8586
}
8687

8788
export const LiquidLiteralValues = {
@@ -1304,6 +1305,22 @@ function toLiquidDocAST(source: string, matchingSource: string, offset: number)
13041305
locEnd,
13051306
source,
13061307
},
1308+
descriptionNode: {
1309+
type: ConcreteNodeTypes.TextNode,
1310+
value: function () {
1311+
return (this as any).sourceString;
1312+
},
1313+
locStart,
1314+
locEnd,
1315+
source,
1316+
},
1317+
paramNode: {
1318+
type: ConcreteNodeTypes.ParamNode,
1319+
value: 0,
1320+
locStart,
1321+
locEnd,
1322+
source,
1323+
},
13071324
};
13081325

13091326
return toAST(res, LiquidDocMappings);

0 commit comments

Comments
 (0)