Skip to content

Commit 4d4c72d

Browse files
committed
--wip-- [skip ci]
1 parent 94274ed commit 4d4c72d

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export interface ConcreteLiquidDocParamNode
111111
name: string;
112112
}
113113

114+
export type ConcreteLiquidDocNode = ConcreteLiquidDocParamNode;
115+
114116
export interface ConcreteHtmlNodeBase<T> extends ConcreteBasicNode<T> {
115117
attrList?: ConcreteAttributeNode[];
116118
}
@@ -1302,8 +1304,16 @@ function toLiquidDocAST(source: string, matchingSource: string, offset: number)
13021304

13031305
const LiquidDocMappings: Mapping = {
13041306
Node: 0,
1307+
textNode: {
1308+
type: ConcreteNodeTypes.TextNode,
1309+
locStart,
1310+
locEnd,
1311+
source,
1312+
name: 0,
1313+
},
13051314
paramNode: {
13061315
type: ConcreteNodeTypes.LiquidDocParamNode,
1316+
name: 0,
13071317
locStart,
13081318
locEnd,
13091319
source,

packages/liquid-html-parser/src/stage-2-ast.spec.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -1229,22 +1229,19 @@ describe('Unit: Stage 2 (AST)', () => {
12291229
expectPath(ast, 'children.0.body.type').toEqual('RawMarkup');
12301230
expectPath(ast, 'children.0.body.nodes').toEqual([]);
12311231

1232-
ast = toLiquidAST(`{% doc -%} single line doc {%- enddoc %}`);
1232+
ast = toLiquidAST(`
1233+
{% doc -%}
1234+
@param asdf
1235+
@unsupported
1236+
{%- enddoc %}
1237+
`);
12331238
expectPath(ast, 'children.0.type').to.eql('LiquidRawTag');
12341239
expectPath(ast, 'children.0.name').to.eql('doc');
1235-
expectPath(ast, 'children.0.body.value').to.eql(' single line doc ');
1236-
expectPath(ast, 'children.0.body.nodes.0.type').toEqual('TextNode');
1240+
// expectPath(ast, 'children.0.body.value').to.eql('@param asdf');
1241+
expectPath(ast, 'children.0.body.nodes.0.type').toEqual('LiquidDocParamNode');
1242+
expectPath(ast, 'children.0.body.nodes.0.name').to.eql('@param');
12371243

1238-
ast = toLiquidAST(`{% doc -%}
1239-
multi line doc
1240-
multi line doc
1241-
{%- enddoc %}`);
1242-
expectPath(ast, 'children.0.type').to.eql('LiquidRawTag');
1243-
expectPath(ast, 'children.0.name').to.eql('doc');
1244-
expectPath(ast, 'children.0.body.nodes.0.value').to.eql(
1245-
`multi line doc\n multi line doc`,
1246-
);
1247-
expectPath(ast, 'children.0.body.nodes.0.type').toEqual('TextNode');
1244+
expectPath(ast, 'children.0.body.nodes.1.type').toEqual('TextNode');
12481245
});
12491246

12501247
it('should parse unclosed tables with assignments', () => {

packages/liquid-html-parser/src/stage-2-ast.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ import {
7373
LiquidHtmlConcreteNode,
7474
ConcreteLiquidTagBaseCase,
7575
ConcreteLiquidTagContentForMarkup,
76+
ConcreteLiquidDocParamNode,
77+
ConcreteLiquidDocNode,
7678
} from './stage-1-cst';
7779
import { Comparators, NamedTags, NodeTypes, nonTraversableProperties, Position } from './types';
7880
import { assertNever, deepGet, dropLast } from './utils';
@@ -107,7 +109,8 @@ export type LiquidHtmlNode =
107109
| RenderVariableExpression
108110
| LiquidLogicalExpression
109111
| LiquidComparison
110-
| TextNode;
112+
| TextNode
113+
| LiquidDocParamNode;
111114

112115
/** The root node of all LiquidHTML ASTs. */
113116
export interface DocumentNode extends ASTNode<NodeTypes.Document> {
@@ -754,6 +757,10 @@ export interface TextNode extends ASTNode<NodeTypes.TextNode> {
754757
value: string;
755758
}
756759

760+
export interface LiquidDocParamNode extends ASTNode<NodeTypes.LiquidDocParamNode> {
761+
name: string;
762+
}
763+
757764
export interface ASTNode<T> {
758765
/**
759766
* The type of the node, as a string.
@@ -1103,7 +1110,7 @@ export function cstToAst(
11031110
}
11041111

11051112
function buildAst(
1106-
cst: LiquidHtmlCST | LiquidCST | ConcreteAttributeNode[],
1113+
cst: LiquidHtmlCST | LiquidCST | ConcreteAttributeNode[] | ConcreteLiquidDocNode[],
11071114
options: ASTBuildOptions,
11081115
) {
11091116
const builder = new ASTBuilder(cst[0].source);
@@ -1268,6 +1275,16 @@ function buildAst(
12681275
break;
12691276
}
12701277

1278+
case ConcreteNodeTypes.LiquidDocParamNode: {
1279+
builder.push({
1280+
type: NodeTypes.LiquidDocParamNode,
1281+
name: node.name,
1282+
position: position(node),
1283+
source: node.source,
1284+
});
1285+
break;
1286+
}
1287+
12711288
default: {
12721289
assertNever(node);
12731290
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export enum NodeTypes {
4444
RawMarkup = 'RawMarkup',
4545
RenderMarkup = 'RenderMarkup',
4646
RenderVariableExpression = 'RenderVariableExpression',
47+
LiquidDocParamNode = 'LiquidDocParamNode',
4748
}
4849

4950
// These are officially supported with special node types

0 commit comments

Comments
 (0)