Skip to content

Commit

Permalink
[LiquidDoc] Rename exampleContent to content in AST nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Feb 8, 2025
1 parent d3de94a commit c454ba4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 32 deletions.
20 changes: 9 additions & 11 deletions packages/liquid-html-parser/src/stage-1-cst.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ describe('Unit: Stage 1 (CST)', () => {
expectPath(cst, '0.type').to.equal('LiquidRawTag');
expectPath(cst, '0.name').to.equal('doc');
expectPath(cst, '0.children.0.type').to.equal('LiquidDocExampleNode');
expectPath(cst, '0.children.0.exampleContent.value').to.equal('');
expectPath(cst, '0.children.0.content.value').to.equal('');
});

it('should parse example tag with content that has leading whitespace', () => {
Expand All @@ -1247,11 +1247,9 @@ describe('Unit: Stage 1 (CST)', () => {
expectPath(cst, '0.name').to.equal('doc');
expectPath(cst, '0.children.0.type').to.equal('LiquidDocExampleNode');
expectPath(cst, '0.children.0.name').to.equal('example');
expectPath(cst, '0.children.0.exampleContent.value').to.equal('hello there');
expectPath(cst, '0.children.0.exampleContent.locStart').to.equal(
testStr.indexOf('hello there'),
);
expectPath(cst, '0.children.0.exampleContent.locEnd').to.equal(
expectPath(cst, '0.children.0.content.value').to.equal('hello there');
expectPath(cst, '0.children.0.content.locStart').to.equal(testStr.indexOf('hello there'));
expectPath(cst, '0.children.0.content.locEnd').to.equal(
testStr.indexOf('hello there') + 'hello there'.length,
);
});
Expand All @@ -1268,7 +1266,7 @@ describe('Unit: Stage 1 (CST)', () => {
expectPath(cst, '0.name').to.equal('doc');
expectPath(cst, '0.children.0.type').to.equal('LiquidDocExampleNode');
expectPath(cst, '0.children.0.name').to.equal('example');
expectPath(cst, '0.children.0.exampleContent.value').to.equal(
expectPath(cst, '0.children.0.content.value').to.equal(
'\n This is an example\n It supports multiple lines\n',
);
});
Expand All @@ -1282,7 +1280,7 @@ describe('Unit: Stage 1 (CST)', () => {
cst = toCST(testStr);
expectPath(cst, '0.children.0.type').to.equal('LiquidDocExampleNode');
expectPath(cst, '0.children.0.name').to.equal('example');
expectPath(cst, '0.children.0.exampleContent.value').to.equal(
expectPath(cst, '0.children.0.content.value').to.equal(
'\n This is an example\n',
);
expectPath(cst, '0.children.1.type').to.equal('LiquidDocParamNode');
Expand All @@ -1300,7 +1298,7 @@ describe('Unit: Stage 1 (CST)', () => {
expectPath(cst, '0.name').to.equal('doc');
expectPath(cst, '0.children.0.type').to.equal('LiquidDocExampleNode');
expectPath(cst, '0.children.0.name').to.equal('example');
expectPath(cst, '0.children.0.exampleContent.value').to.equal(
expectPath(cst, '0.children.0.content.value').to.equal(
'hello there my friend\n This is an example\n It supports multiple lines\n',
);
});
Expand All @@ -1312,9 +1310,9 @@ describe('Unit: Stage 1 (CST)', () => {
{% enddoc %}`;
cst = toCST(testStr);
expectPath(cst, '0.children.0.type').to.equal('LiquidDocExampleNode');
expectPath(cst, '0.children.0.exampleContent.value').to.equal('hello there\n');
expectPath(cst, '0.children.0.content.value').to.equal('hello there\n');
expectPath(cst, '0.children.1.type').to.equal('LiquidDocExampleNode');
expectPath(cst, '0.children.1.exampleContent.value').to.equal('second example\n');
expectPath(cst, '0.children.1.content.value').to.equal('second example\n');
});

it('should parse @description node', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/liquid-html-parser/src/stage-1-cst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export interface ConcreteLiquidDocDescriptionNode
export interface ConcreteLiquidDocExampleNode
extends ConcreteBasicNode<ConcreteNodeTypes.LiquidDocExampleNode> {
name: 'example';
exampleContent: ConcreteTextNode;
content: ConcreteTextNode;
}

export interface ConcreteHtmlNodeBase<T> extends ConcreteBasicNode<T> {
Expand Down Expand Up @@ -1401,7 +1401,7 @@ function toLiquidDocAST(source: string, matchingSource: string, offset: number)
locStart,
locEnd,
source,
exampleContent: 2,
content: 2,
},
exampleContent: textNode,
textValue: textNode,
Expand Down
22 changes: 7 additions & 15 deletions packages/liquid-html-parser/src/stage-2-ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1322,10 +1322,8 @@ describe('Unit: Stage 2 (AST)', () => {
expectPath(ast, 'children.0.name').to.eql('doc');
expectPath(ast, 'children.0.body.nodes.0.name').to.eql('example');
expectPath(ast, 'children.0.body.nodes.0.type').to.eql('LiquidDocExampleNode');
expectPath(ast, 'children.0.body.nodes.0.exampleContent.type').to.eql('TextNode');
expectPath(ast, 'children.0.body.nodes.0.exampleContent.value').to.eql(
'simple inline example\n',
);
expectPath(ast, 'children.0.body.nodes.0.content.type').to.eql('TextNode');
expectPath(ast, 'children.0.body.nodes.0.content.value').to.eql('simple inline example\n');

ast = toLiquidAST(`
{% doc -%}
Expand All @@ -1336,7 +1334,7 @@ describe('Unit: Stage 2 (AST)', () => {
`);
expectPath(ast, 'children.0.body.nodes.0.type').to.eql('LiquidDocExampleNode');
expectPath(ast, 'children.0.body.nodes.0.name').to.eql('example');
expectPath(ast, 'children.0.body.nodes.0.exampleContent.value').to.eql(
expectPath(ast, 'children.0.body.nodes.0.content.value').to.eql(
'including inline code\n This is a valid example\n It can have multiple lines\n',
);

Expand All @@ -1352,14 +1350,10 @@ describe('Unit: Stage 2 (AST)', () => {
expectPath(ast, 'children.0.name').to.eql('doc');
expectPath(ast, 'children.0.body.nodes.0.type').to.eql('LiquidDocExampleNode');
expectPath(ast, 'children.0.body.nodes.0.name').to.eql('example');
expectPath(ast, 'children.0.body.nodes.0.exampleContent.value').to.eql(
'\n First Example\n',
);
expectPath(ast, 'children.0.body.nodes.0.content.value').to.eql('\n First Example\n');
expectPath(ast, 'children.0.body.nodes.1.type').to.eql('LiquidDocExampleNode');
expectPath(ast, 'children.0.body.nodes.1.name').to.eql('example');
expectPath(ast, 'children.0.body.nodes.1.exampleContent.value').to.eql(
'\n Second Example\n',
);
expectPath(ast, 'children.0.body.nodes.1.content.value').to.eql('\n Second Example\n');

ast = toLiquidAST(`
{% doc -%}
Expand All @@ -1373,7 +1367,7 @@ describe('Unit: Stage 2 (AST)', () => {
expectPath(ast, 'children.0.name').to.eql('doc');
expectPath(ast, 'children.0.body.nodes.0.type').to.eql('LiquidDocExampleNode');
expectPath(ast, 'children.0.body.nodes.0.name').to.eql('example');
expectPath(ast, 'children.0.body.nodes.0.exampleContent.value').to.eql(
expectPath(ast, 'children.0.body.nodes.0.content.value').to.eql(
'\n This is a valid example\n It can have multiple lines\n',
);
expectPath(ast, 'children.0.body.nodes.1.type').to.eql('LiquidDocParamNode');
Expand Down Expand Up @@ -1409,9 +1403,7 @@ describe('Unit: Stage 2 (AST)', () => {

expectPath(ast, 'children.0.body.nodes.1.type').to.eql('LiquidDocExampleNode');
expectPath(ast, 'children.0.body.nodes.1.name').to.eql('example');
expectPath(ast, 'children.0.body.nodes.1.exampleContent.value').to.eql(
'This is an example\n',
);
expectPath(ast, 'children.0.body.nodes.1.content.value').to.eql('This is an example\n');

expectPath(ast, 'children.0.body.nodes.2.type').to.eql('LiquidDocParamNode');
expectPath(ast, 'children.0.body.nodes.2.name').to.eql('param');
Expand Down
4 changes: 2 additions & 2 deletions packages/liquid-html-parser/src/stage-2-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ export interface LiquidDocDescriptionNode extends ASTNode<NodeTypes.LiquidDocDes
export interface LiquidDocExampleNode extends ASTNode<NodeTypes.LiquidDocExampleNode> {
name: 'example';
/** The contents of the example (e.g. "{{ product }}"). Can be multiline. */
exampleContent: TextNode;
content: TextNode;
}

export interface ASTNode<T> {
Expand Down Expand Up @@ -1329,7 +1329,7 @@ function buildAst(
name: node.name,
position: position(node),
source: node.source,
exampleContent: toTextNode(node.exampleContent),
content: toTextNode(node.content),
});
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ export function printLiquidDocExample(
const node = path.getValue();
const parts: Doc[] = ['@example'];

const content = node.exampleContent.value;
const content = node.content.value;
if (content) {
if (content.includes('\n')) {
parts.push(hardline);
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-language-server-common/src/liquidDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function getSnippetDefinition(
},
LiquidDocExampleNode(node: LiquidDocExampleNode) {
return {
content: node.exampleContent.value,
content: node.content.value,
nodeType: 'example',
};
},
Expand Down

0 comments on commit c454ba4

Please sign in to comment.