@shopify/liquid-html-parser
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -73,2 +73,3 @@ /** | ||
LiquidDocParamNameNode = "LiquidDocParamNameNode", | ||
LiquidDocDescriptionNode = "LiquidDocDescriptionNode", | ||
LiquidDocExampleNode = "LiquidDocExampleNode" | ||
@@ -104,5 +105,9 @@ } | ||
} | ||
export interface ConcreteLiquidDocDescriptionNode extends ConcreteBasicNode<ConcreteNodeTypes.LiquidDocDescriptionNode> { | ||
name: 'description'; | ||
content: ConcreteTextNode; | ||
} | ||
export interface ConcreteLiquidDocExampleNode extends ConcreteBasicNode<ConcreteNodeTypes.LiquidDocExampleNode> { | ||
name: 'example'; | ||
exampleContent: ConcreteTextNode; | ||
content: ConcreteTextNode; | ||
} | ||
@@ -270,3 +275,3 @@ export interface ConcreteHtmlNodeBase<T> extends ConcreteBasicNode<T> { | ||
variable: ConcreteRenderVariableExpression | null; | ||
args: ConcreteLiquidNamedArgument[]; | ||
renderArguments: ConcreteLiquidNamedArgument[]; | ||
} | ||
@@ -325,3 +330,3 @@ export interface ConcreteRenderVariableExpression extends ConcreteBasicNode<ConcreteNodeTypes.RenderVariableExpression> { | ||
export type LiquidCST = LiquidConcreteNode[]; | ||
export type LiquidDocConcreteNode = ConcreteLiquidDocParamNode | ConcreteLiquidDocExampleNode; | ||
export type LiquidDocConcreteNode = ConcreteLiquidDocParamNode | ConcreteLiquidDocExampleNode | ConcreteLiquidDocDescriptionNode; | ||
export interface CSTBuildOptions { | ||
@@ -328,0 +333,0 @@ /** |
@@ -79,2 +79,3 @@ "use strict"; | ||
ConcreteNodeTypes["LiquidDocParamNameNode"] = "LiquidDocParamNameNode"; | ||
ConcreteNodeTypes["LiquidDocDescriptionNode"] = "LiquidDocDescriptionNode"; | ||
ConcreteNodeTypes["LiquidDocExampleNode"] = "LiquidDocExampleNode"; | ||
@@ -214,4 +215,4 @@ })(ConcreteNodeTypes = exports.ConcreteNodeTypes || (exports.ConcreteNodeTypes = {})); | ||
whitespaceEnd: (tokens) => tokens[0].children[7].sourceString, | ||
delimiterWhitespaceStart: (tokens) => tokens[2].children[1].sourceString, | ||
delimiterWhitespaceEnd: (tokens) => tokens[2].children[7].sourceString, | ||
delimiterWhitespaceStart: (tokens) => { var _a; return ((_a = tokens[2].children[1]) === null || _a === void 0 ? void 0 : _a.sourceString) || ''; }, | ||
delimiterWhitespaceEnd: (tokens) => { var _a; return ((_a = tokens[2].children[7]) === null || _a === void 0 ? void 0 : _a.sourceString) || ''; }, | ||
locStart, | ||
@@ -386,3 +387,3 @@ locEnd, | ||
alias: 2, | ||
args: 4, | ||
renderArguments: 3, | ||
locStart, | ||
@@ -392,2 +393,10 @@ locEnd, | ||
}, | ||
renderArguments: 1, | ||
completionModeRenderArguments: function (_0, namedArguments, _2, _3, _4, _5, variableLookup, _7) { | ||
const self = this; | ||
// variableLookup.sourceString can be '' when there are no incomplete params | ||
return namedArguments | ||
.toAST(self.args.mapping) | ||
.concat(variableLookup.sourceString === '' ? [] : variableLookup.toAST(self.args.mapping)); | ||
}, | ||
snippetExpression: 0, | ||
@@ -454,2 +463,8 @@ renderVariableExpression: { | ||
contentForTagArgument: 0, | ||
completionModeContentForTagArgument: function (namedArguments, _separator, variableLookup) { | ||
const self = this; | ||
return namedArguments | ||
.toAST(self.args.mapping) | ||
.concat(variableLookup.sourceString === '' ? [] : variableLookup.toAST(self.args.mapping)); | ||
}, | ||
positionalArgument: 0, | ||
@@ -823,2 +838,11 @@ namedArgument: { | ||
}, | ||
descriptionNode: { | ||
type: ConcreteNodeTypes.LiquidDocDescriptionNode, | ||
name: 'description', | ||
locStart, | ||
locEnd, | ||
source, | ||
content: 2, | ||
}, | ||
descriptionContent: textNode, | ||
paramType: 2, | ||
@@ -849,3 +873,3 @@ paramTypeContent: textNode, | ||
source, | ||
exampleContent: 2, | ||
content: 2, | ||
}, | ||
@@ -852,0 +876,0 @@ exampleContent: textNode, |
@@ -38,3 +38,3 @@ /** | ||
/** The union type of all possible node types inside a LiquidHTML AST. */ | ||
export type LiquidHtmlNode = DocumentNode | YAMLFrontmatter | LiquidNode | HtmlDoctype | HtmlNode | AttributeNode | LiquidVariable | LiquidExpression | LiquidFilter | LiquidNamedArgument | AssignMarkup | ContentForMarkup | CycleMarkup | ForMarkup | RenderMarkup | PaginateMarkup | RawMarkup | RenderVariableExpression | LiquidLogicalExpression | LiquidComparison | TextNode | LiquidDocParamNode | LiquidDocExampleNode; | ||
export type LiquidHtmlNode = DocumentNode | YAMLFrontmatter | LiquidNode | HtmlDoctype | HtmlNode | AttributeNode | LiquidVariable | LiquidExpression | LiquidFilter | LiquidNamedArgument | AssignMarkup | ContentForMarkup | CycleMarkup | ForMarkup | RenderMarkup | PaginateMarkup | RawMarkup | RenderVariableExpression | LiquidLogicalExpression | LiquidComparison | TextNode | LiquidDocParamNode | LiquidDocExampleNode | LiquidDocDescriptionNode; | ||
/** The root node of all LiquidHTML ASTs. */ | ||
@@ -256,3 +256,9 @@ export interface DocumentNode extends ASTNode<NodeTypes.Document> { | ||
contentForType: LiquidString; | ||
/** {% content_for 'contentForType', arg1: value1, arg2: value2 %} */ | ||
/** | ||
* WARNING: `args` could contain LiquidVariableLookup when we are in a completion context | ||
* because the NamedArgument isn't fully typed out. | ||
* E.g. {% content_for 'contentForType', arg1: value1, arg2█ %} | ||
* | ||
* @example {% content_for 'contentForType', arg1: value1, arg2: value2 %} | ||
*/ | ||
args: LiquidNamedArgument[]; | ||
@@ -268,3 +274,9 @@ } | ||
variable: RenderVariableExpression | null; | ||
/** {% render 'snippet', arg1: value1, arg2: value2 %} */ | ||
/** | ||
* WARNING: `args` could contain LiquidVariableLookup when we are in a completion context | ||
* because the NamedArgument isn't fully typed out. | ||
* E.g. {% render 'snippet', arg1: value1, arg2█ %} | ||
* | ||
* @example {% render 'snippet', arg1: value1, arg2: value2 %} | ||
*/ | ||
args: LiquidNamedArgument[]; | ||
@@ -574,2 +586,8 @@ } | ||
} | ||
/** Represents a `@description` node in a LiquidDoc comment - `@description descriptionContent` */ | ||
export interface LiquidDocDescriptionNode extends ASTNode<NodeTypes.LiquidDocDescriptionNode> { | ||
name: 'description'; | ||
/** The contents of the description (e.g. "This is a description"). Can be multiline. */ | ||
content: TextNode; | ||
} | ||
/** Represents a `@example` node in a LiquidDoc comment - `@example exampleContent` */ | ||
@@ -579,3 +597,3 @@ export interface LiquidDocExampleNode extends ASTNode<NodeTypes.LiquidDocExampleNode> { | ||
/** The contents of the example (e.g. "{{ product }}"). Can be multiline. */ | ||
exampleContent: TextNode; | ||
content: TextNode; | ||
} | ||
@@ -582,0 +600,0 @@ export interface ASTNode<T> { |
@@ -452,2 +452,12 @@ "use strict"; | ||
} | ||
case stage_1_cst_1.ConcreteNodeTypes.LiquidDocDescriptionNode: { | ||
builder.push({ | ||
type: types_1.NodeTypes.LiquidDocDescriptionNode, | ||
name: node.name, | ||
position: position(node), | ||
source: node.source, | ||
content: toTextNode(node.content), | ||
}); | ||
break; | ||
} | ||
case stage_1_cst_1.ConcreteNodeTypes.LiquidDocExampleNode: { | ||
@@ -459,3 +469,3 @@ builder.push({ | ||
source: node.source, | ||
exampleContent: toTextNode(node.exampleContent), | ||
content: toTextNode(node.content), | ||
}); | ||
@@ -840,3 +850,11 @@ break; | ||
contentForType: toExpression(node.contentForType), | ||
args: node.args.map(toNamedArgument), | ||
/** | ||
* When we're in completion mode we won't necessarily have valid named | ||
* arguments so we need to call toLiquidArgument instead of toNamedArgument. | ||
* We cast using `as` so that this doesn't affect the type system used in | ||
* other areas (like theme check) for a scenario that only occurs in | ||
* completion mode. This means that our types are *wrong* in completion mode | ||
* but this is the compromise we're making to get completions to work. | ||
*/ | ||
args: node.args.map(toLiquidArgument), | ||
position: position(node), | ||
@@ -852,3 +870,11 @@ source: node.source, | ||
variable: toRenderVariableExpression(node.variable), | ||
args: node.args.map(toNamedArgument), | ||
/** | ||
* When we're in completion mode we won't necessarily have valid named | ||
* arguments so we need to call toLiquidArgument instead of toNamedArgument. | ||
* We cast using `as` so that this doesn't affect the type system used in | ||
* other areas (like theme check) for a scenario that only occurs in | ||
* completion mode. This means that our types are *wrong* in completion mode | ||
* but this is the compromise we're making to get completions to work. | ||
*/ | ||
args: node.renderArguments.map(toLiquidArgument), | ||
position: position(node), | ||
@@ -855,0 +881,0 @@ source: node.source, |
@@ -44,2 +44,3 @@ export interface Position { | ||
RenderVariableExpression = "RenderVariableExpression", | ||
LiquidDocDescriptionNode = "LiquidDocDescriptionNode", | ||
LiquidDocParamNode = "LiquidDocParamNode", | ||
@@ -46,0 +47,0 @@ LiquidDocExampleNode = "LiquidDocExampleNode" |
@@ -42,2 +42,3 @@ "use strict"; | ||
NodeTypes["RenderVariableExpression"] = "RenderVariableExpression"; | ||
NodeTypes["LiquidDocDescriptionNode"] = "LiquidDocDescriptionNode"; | ||
NodeTypes["LiquidDocParamNode"] = "LiquidDocParamNode"; | ||
@@ -44,0 +45,0 @@ NodeTypes["LiquidDocExampleNode"] = "LiquidDocExampleNode"; |
@@ -136,2 +136,3 @@ module.exports = String.raw`Helpers { | ||
contentForTagArgument = listOf<contentForNamedArgument<delimTag>, argumentSeparatorOptionalComma> | ||
completionModeContentForTagArgument = listOf<contentForNamedArgument<delimTag>, argumentSeparatorOptionalComma> (argumentSeparator? (liquidVariableLookup<delimTag>))? | ||
contentForNamedArgument<delim> = (variableSegment ("." variableSegment)*) space* ":" space* (liquidExpression<delim>) | ||
@@ -144,3 +145,6 @@ | ||
liquidTagRenderMarkup = | ||
snippetExpression renderVariableExpression? renderAliasExpression? (argumentSeparatorOptionalComma tagArguments) (space* ",")? space* | ||
snippetExpression renderVariableExpression? renderAliasExpression? renderArguments | ||
renderArguments = (argumentSeparatorOptionalComma tagArguments) (space* ",")? space* | ||
completionModeRenderArguments = (argumentSeparatorOptionalComma tagArguments) (space* ",")? space* (argumentSeparator? liquidVariableLookup<delimTag> space*)? | ||
snippetExpression = liquidString<delimTag> | variableSegmentAsLookup | ||
@@ -398,4 +402,5 @@ renderVariableExpression = space+ ("for" | "with") space+ liquidExpression<delimTag> | ||
| exampleNode | ||
| descriptionNode | ||
| fallbackNode | ||
// By default, space matches new lines as well. We override it here to make writing rules easier. | ||
@@ -406,2 +411,6 @@ strictSpace = " " | "\t" | ||
descriptionNode = "@description" strictSpace* descriptionContent | ||
descriptionContent = anyExceptStar<endOfDescription> | ||
endOfDescription = strictSpace* openControl | ||
paramNode = "@param" strictSpace* paramType? strictSpace* (optionalParamName | paramName) (strictSpace* "-")? strictSpace* paramDescription | ||
@@ -553,4 +562,12 @@ paramType = "{" strictSpace* paramTypeContent strictSpace* "}" | ||
liquidFilter<delim> := space* "|" space* identifier (space* ":" space* filterArguments<delim> (space* ",")?)? | ||
liquidTagContentForMarkup := | ||
contentForType (argumentSeparatorOptionalComma completionModeContentForTagArgument) (space* ",")? space* | ||
liquidTagRenderMarkup := | ||
snippetExpression renderVariableExpression? renderAliasExpression? completionModeRenderArguments | ||
liquidTagName := (letter | "█") (alnum | "_")* | ||
variableSegment := (letter | "_" | "█") (identifierCharacter | "█")* | ||
liquidDoc := | ||
liquidDocStart | ||
liquidDocBody | ||
liquidDocEnd? | ||
} | ||
@@ -560,4 +577,12 @@ | ||
liquidFilter<delim> := space* "|" space* identifier (space* ":" space* filterArguments<delim> (space* ",")?)? | ||
liquidTagContentForMarkup := | ||
contentForType (argumentSeparatorOptionalComma completionModeContentForTagArgument) (space* ",")? space* | ||
liquidTagRenderMarkup := | ||
snippetExpression renderVariableExpression? renderAliasExpression? completionModeRenderArguments | ||
liquidTagName := (letter | "█") (alnum | "_")* | ||
variableSegment := (letter | "_" | "█") (identifierCharacter | "█")* | ||
liquidDoc := | ||
liquidDocStart | ||
liquidDocBody | ||
liquidDocEnd? | ||
} | ||
@@ -567,2 +592,6 @@ | ||
liquidFilter<delim> := space* "|" space* identifier (space* ":" space* filterArguments<delim> (space* ",")?)? | ||
liquidTagContentForMarkup := | ||
contentForType (argumentSeparatorOptionalComma completionModeContentForTagArgument) (space* ",")? space* | ||
liquidTagRenderMarkup := | ||
snippetExpression renderVariableExpression? renderAliasExpression? completionModeRenderArguments | ||
liquidTagName := (letter | "█") (alnum | "_")* | ||
@@ -572,3 +601,7 @@ variableSegment := (letter | "_" | "█") (identifierCharacter | "█")* | ||
trailingTagNameTextNode := (alnum | "-" | ":" | "█")+ | ||
liquidDoc := | ||
liquidDocStart | ||
liquidDocBody | ||
liquidDocEnd? | ||
} | ||
`; |
{ | ||
"name": "@shopify/liquid-html-parser", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Liquid HTML parser by Shopify", | ||
@@ -5,0 +5,0 @@ "author": "CP Clermont <cp.clermont@shopify.com>", |
Sorry, the diff of this file is not supported yet
176877
3914