@shopify/liquid-html-parser
Advanced tools
Comparing version 2.0.3 to 2.0.4
import { MatchResult } from 'ohm-js'; | ||
import { NodeTypes, Position } from './types'; | ||
interface LineColPosition { | ||
@@ -13,2 +14,7 @@ line: number; | ||
} | ||
export type UnclosedNode = { | ||
type: NodeTypes; | ||
name: string; | ||
blockStartPosition: Position; | ||
}; | ||
export declare class LiquidHTMLASTParsingError extends SyntaxError { | ||
@@ -19,4 +25,5 @@ loc?: { | ||
}; | ||
constructor(message: string, source: string, startIndex: number, endIndex: number); | ||
unclosed: UnclosedNode | null; | ||
constructor(message: string, source: string, startIndex: number, endIndex: number, unclosed?: UnclosedNode); | ||
} | ||
export {}; |
@@ -34,5 +34,6 @@ "use strict"; | ||
class LiquidHTMLASTParsingError extends SyntaxError { | ||
constructor(message, source, startIndex, endIndex) { | ||
constructor(message, source, startIndex, endIndex, unclosed) { | ||
super(message); | ||
this.name = 'LiquidHTMLParsingError'; | ||
this.unclosed = unclosed !== null && unclosed !== void 0 ? unclosed : null; | ||
const lc = (0, line_column_1.default)(source); | ||
@@ -39,0 +40,0 @@ const start = lc.fromIndex(startIndex); |
@@ -35,3 +35,3 @@ /** | ||
*/ | ||
import { ConcreteAttributeNode, LiquidCST, LiquidHtmlCST, ConcreteLiquidLiteral } from './stage-1-cst'; | ||
import { ConcreteAttributeNode, ConcreteHtmlTagClose, ConcreteLiquidTagClose, LiquidCST, LiquidHtmlCST, ConcreteLiquidLiteral } from './stage-1-cst'; | ||
import { Comparators, NamedTags, NodeTypes, Position } from './types'; | ||
@@ -580,2 +580,3 @@ /** The union type of all possible node types inside a LiquidHTML AST. */ | ||
export declare function toLiquidHtmlAST(source: string, options?: ASTBuildOptions): DocumentNode; | ||
export declare function getName(node: ConcreteLiquidTagClose | ConcreteHtmlTagClose | ParentNode | undefined): string | null; | ||
export declare function cstToAst(cst: LiquidHtmlCST | LiquidCST | ConcreteAttributeNode[], options: ASTBuildOptions): LiquidHtmlNode[]; | ||
@@ -582,0 +583,0 @@ export declare function walk(ast: LiquidHtmlNode, fn: (ast: LiquidHtmlNode, parentNode: LiquidHtmlNode | undefined) => void, parentNode?: LiquidHtmlNode): void; |
@@ -37,3 +37,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLiquidHtmlNode = exports.walk = exports.cstToAst = exports.toLiquidHtmlAST = exports.toLiquidAST = exports.isBranchedTag = exports.RawMarkupKinds = void 0; | ||
exports.isLiquidHtmlNode = exports.walk = exports.cstToAst = exports.getName = exports.toLiquidHtmlAST = exports.toLiquidAST = exports.isBranchedTag = exports.RawMarkupKinds = void 0; | ||
const stage_1_cst_1 = require("./stage-1-cst"); | ||
@@ -179,3 +179,3 @@ const types_1 = require("./types"); | ||
else { | ||
throw new errors_1.LiquidHTMLASTParsingError(`Attempting to close ${nodeType} '${getName(node)}' before ${this.parent.type} '${getName(this.parent)}' was closed`, this.source, this.parent.position.start, node.locEnd); | ||
throw new errors_1.LiquidHTMLASTParsingError(`Attempting to close ${nodeType} '${getName(node)}' before ${this.parent.type} '${getName(this.parent)}' was closed`, this.source, this.parent.position.start, node.locEnd, getUnclosed(this.parent)); | ||
} | ||
@@ -284,2 +284,3 @@ } | ||
} | ||
exports.getName = getName; | ||
function cstToAst(cst, options) { | ||
@@ -291,3 +292,3 @@ var _a; | ||
if (!options.allowUnclosedDocumentNode && builder.cursor.length !== 0) { | ||
throw new errors_1.LiquidHTMLASTParsingError(`Attempting to end parsing before ${(_a = builder.parent) === null || _a === void 0 ? void 0 : _a.type} '${getName(builder.parent)}' was closed`, builder.source, builder.source.length - 1, builder.source.length); | ||
throw new errors_1.LiquidHTMLASTParsingError(`Attempting to end parsing before ${(_a = builder.parent) === null || _a === void 0 ? void 0 : _a.type} '${getName(builder.parent)}' was closed`, builder.source, builder.source.length - 1, builder.source.length, getUnclosed(builder.parent, builder.grandparent)); | ||
} | ||
@@ -618,2 +619,3 @@ return builder.ast; | ||
markup: toConditionalExpression(node.markup), | ||
blockEndPosition: { start: -1, end: -1 }, | ||
children: [], | ||
@@ -1016,3 +1018,2 @@ }; | ||
} | ||
const MAX_NUMBER_OF_SIBLING_DANGLING_NODES = 2; | ||
function isAcceptableDanglingMarkerClose(builder, cst, currIndex, mode) { | ||
@@ -1081,2 +1082,15 @@ if (mode === 'completion') { | ||
exports.isLiquidHtmlNode = isLiquidHtmlNode; | ||
function getUnclosed(node, parentNode) { | ||
var _a; | ||
if (!node) | ||
return undefined; | ||
if (getName(node) === null && parentNode) { | ||
node = parentNode; | ||
} | ||
return { | ||
type: node.type, | ||
name: (_a = getName(node)) !== null && _a !== void 0 ? _a : '', | ||
blockStartPosition: 'blockStartPosition' in node ? node.blockStartPosition : node.position, | ||
}; | ||
} | ||
//# sourceMappingURL=stage-2-ast.js.map |
@@ -262,3 +262,3 @@ module.exports = String.raw`Helpers { | ||
variableSegment = (letter | "_") identifierCharacter* | ||
variableSegment = (letter | "_") (~endOfTagName identifierCharacter)* | ||
variableSegmentAsLookup = variableSegment | ||
@@ -434,3 +434,3 @@ identifier = variableSegment "?"? | ||
Attr = | ||
liquidNode | AttrSingleQuoted | AttrDoubleQuoted | AttrUnquoted | attrEmpty | ||
AttrSingleQuoted | AttrDoubleQuoted | AttrUnquoted | liquidNode | attrEmpty | ||
@@ -437,0 +437,0 @@ attrEmpty = attrName |
{ | ||
"name": "@shopify/liquid-html-parser", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"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
154744
3528