Skip to content

Commit

Permalink
Refactor toLiquidDocAst: Assign param attributes via mappings rather …
Browse files Browse the repository at this point in the history
…than directly
  • Loading branch information
jamesmengo committed Jan 14, 2025
1 parent 157c7bf commit cd7d1a6
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions packages/liquid-html-parser/src/stage-1-cst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,51 +1319,42 @@ function toLiquidDocAST(source: string, matchingSource: string, offset: number)

const LiquidDocMappings: Mapping = {
Node: 0,
textNode: {
type: ConcreteNodeTypes.TextNode,
value: function () {
return (this as any).sourceString;
},
locStart,
locEnd,
source,
},
paramNode: {
type: ConcreteNodeTypes.LiquidDocParamNode,
name: 'param',
locStart,
locEnd,
source,
paramType: function (nodes: Node[]) {
const typeNode = nodes[2];
return {
type: ConcreteNodeTypes.TextNode,
value: typeNode.sourceString.slice(1, -1).trim(),
source,
locStart: offset + typeNode.source.startIdx,
locEnd: offset + typeNode.source.endIdx,
};
paramType: 2,
paramName: 4,
paramDescription: 7,
},
paramType: {
type: ConcreteNodeTypes.TextNode,
value: function (nodes: Node[]) {
return nodes[1].sourceString.trim();
},
paramName: function (nodes: Node[]) {
const nameNode = nodes[4];
return {
type: ConcreteNodeTypes.TextNode,
value: nameNode.sourceString.trim(),
source,
locStart: offset + nameNode.source.startIdx,
locEnd: offset + nameNode.source.endIdx,
};
source,
locStart,
locEnd,
},
paramName: {
type: ConcreteNodeTypes.TextNode,
value: function (nodes: Node[]) {
return nodes[0].sourceString.trim();
},
paramDescription: function (nodes: Node[]) {
const descriptionNode = nodes[7];
return {
type: ConcreteNodeTypes.TextNode,
value: descriptionNode.sourceString.trim(),
source,
locStart: offset + descriptionNode.source.startIdx,
locEnd: offset + descriptionNode.source.endIdx,
};
source,
locStart,
locEnd,
},
paramDescription: {
type: ConcreteNodeTypes.TextNode,
value: function (nodes: Node[]) {
return nodes[0].sourceString.trim();
},
source,
locStart,
locEnd,
},
fallbackNode: {
type: ConcreteNodeTypes.TextNode,
Expand Down

0 comments on commit cd7d1a6

Please sign in to comment.