@platformos/liquid-html-parser 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/dist/conditional-comment.d.ts +5 -0
- package/dist/conditional-comment.js +16 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.js +57 -0
- package/dist/grammar.d.ts +16 -0
- package/dist/grammar.js +42 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +28 -0
- package/dist/stage-1-cst.d.ts +477 -0
- package/dist/stage-1-cst.js +1104 -0
- package/dist/stage-2-ast.d.ts +794 -0
- package/dist/stage-2-ast.js +1513 -0
- package/dist/types.d.ts +124 -0
- package/dist/types.js +146 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +31 -0
- package/grammar/liquid-html.ohm +750 -0
- package/grammar/liquid-html.ohm.js +751 -0
- package/package.json +41 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export interface Position {
|
|
2
|
+
/** 0-indexed offset in the string, included */
|
|
3
|
+
start: number;
|
|
4
|
+
/** 0-indexed offset, excluded */
|
|
5
|
+
end: number;
|
|
6
|
+
}
|
|
7
|
+
export declare enum NodeTypes {
|
|
8
|
+
Document = "Document",
|
|
9
|
+
LiquidRawTag = "LiquidRawTag",
|
|
10
|
+
LiquidTag = "LiquidTag",
|
|
11
|
+
LiquidBranch = "LiquidBranch",
|
|
12
|
+
LiquidVariableOutput = "LiquidVariableOutput",
|
|
13
|
+
HtmlSelfClosingElement = "HtmlSelfClosingElement",
|
|
14
|
+
HtmlVoidElement = "HtmlVoidElement",
|
|
15
|
+
HtmlDoctype = "HtmlDoctype",
|
|
16
|
+
HtmlComment = "HtmlComment",
|
|
17
|
+
HtmlElement = "HtmlElement",
|
|
18
|
+
HtmlDanglingMarkerClose = "HtmlDanglingMarkerClose",
|
|
19
|
+
HtmlRawNode = "HtmlRawNode",
|
|
20
|
+
AttrSingleQuoted = "AttrSingleQuoted",
|
|
21
|
+
AttrDoubleQuoted = "AttrDoubleQuoted",
|
|
22
|
+
AttrUnquoted = "AttrUnquoted",
|
|
23
|
+
AttrEmpty = "AttrEmpty",
|
|
24
|
+
TextNode = "TextNode",
|
|
25
|
+
YAMLFrontmatter = "YAMLFrontmatter",
|
|
26
|
+
LiquidVariable = "LiquidVariable",
|
|
27
|
+
LiquidFilter = "LiquidFilter",
|
|
28
|
+
NamedArgument = "NamedArgument",
|
|
29
|
+
LiquidLiteral = "LiquidLiteral",
|
|
30
|
+
BooleanExpression = "BooleanExpression",
|
|
31
|
+
String = "String",
|
|
32
|
+
Number = "Number",
|
|
33
|
+
Range = "Range",
|
|
34
|
+
VariableLookup = "VariableLookup",
|
|
35
|
+
Comparison = "Comparison",
|
|
36
|
+
LogicalExpression = "LogicalExpression",
|
|
37
|
+
AssignMarkup = "AssignMarkup",
|
|
38
|
+
HashAssignMarkup = "HashAssignMarkup",
|
|
39
|
+
ContentForMarkup = "ContentForMarkup",
|
|
40
|
+
CycleMarkup = "CycleMarkup",
|
|
41
|
+
ForMarkup = "ForMarkup",
|
|
42
|
+
PaginateMarkup = "PaginateMarkup",
|
|
43
|
+
RawMarkup = "RawMarkup",
|
|
44
|
+
RenderMarkup = "RenderMarkup",
|
|
45
|
+
FunctionMarkup = "FunctionMarkup",
|
|
46
|
+
GraphQLMarkup = "GraphQLMarkup",
|
|
47
|
+
GraphQLInlineMarkup = "GraphQLInlineMarkup",
|
|
48
|
+
RenderVariableExpression = "RenderVariableExpression",
|
|
49
|
+
RenderAliasExpression = "RenderAliasExpression",
|
|
50
|
+
LiquidDocDescriptionNode = "LiquidDocDescriptionNode",
|
|
51
|
+
LiquidDocParamNode = "LiquidDocParamNode",
|
|
52
|
+
LiquidDocExampleNode = "LiquidDocExampleNode",
|
|
53
|
+
LiquidDocPromptNode = "LiquidDocPromptNode",
|
|
54
|
+
BackgroundMarkup = "BackgroundMarkup",
|
|
55
|
+
BackgroundInlineMarkup = "BackgroundInlineMarkup",
|
|
56
|
+
CacheMarkup = "CacheMarkup",
|
|
57
|
+
LogMarkup = "LogMarkup",
|
|
58
|
+
SessionMarkup = "SessionMarkup",
|
|
59
|
+
ExportMarkup = "ExportMarkup",
|
|
60
|
+
RedirectToMarkup = "RedirectToMarkup",
|
|
61
|
+
IncludeFormMarkup = "IncludeFormMarkup",
|
|
62
|
+
SpamProtectionMarkup = "SpamProtectionMarkup"
|
|
63
|
+
}
|
|
64
|
+
export declare enum NamedTags {
|
|
65
|
+
assign = "assign",
|
|
66
|
+
hash_assign = "hash_assign",
|
|
67
|
+
capture = "capture",
|
|
68
|
+
case = "case",
|
|
69
|
+
content_for = "content_for",
|
|
70
|
+
cycle = "cycle",
|
|
71
|
+
decrement = "decrement",
|
|
72
|
+
echo = "echo",
|
|
73
|
+
elsif = "elsif",
|
|
74
|
+
for = "for",
|
|
75
|
+
form = "form",
|
|
76
|
+
if = "if",
|
|
77
|
+
include = "include",
|
|
78
|
+
increment = "increment",
|
|
79
|
+
layout = "layout",
|
|
80
|
+
liquid = "liquid",
|
|
81
|
+
paginate = "paginate",
|
|
82
|
+
render = "render",
|
|
83
|
+
function = "function",
|
|
84
|
+
graphql = "graphql",
|
|
85
|
+
section = "section",
|
|
86
|
+
sections = "sections",
|
|
87
|
+
tablerow = "tablerow",
|
|
88
|
+
unless = "unless",
|
|
89
|
+
when = "when",
|
|
90
|
+
background = "background",
|
|
91
|
+
cache = "cache",
|
|
92
|
+
catch = "catch",
|
|
93
|
+
context = "context",
|
|
94
|
+
export = "export",
|
|
95
|
+
include_form = "include_form",
|
|
96
|
+
log = "log",
|
|
97
|
+
parse_json = "parse_json",
|
|
98
|
+
print = "print",
|
|
99
|
+
redirect_to = "redirect_to",
|
|
100
|
+
response_headers = "response_headers",
|
|
101
|
+
response_status = "response_status",
|
|
102
|
+
return = "return",
|
|
103
|
+
rollback = "rollback",
|
|
104
|
+
session = "session",
|
|
105
|
+
sign_in = "sign_in",
|
|
106
|
+
spam_protection = "spam_protection",
|
|
107
|
+
theme_render_rc = "theme_render_rc",
|
|
108
|
+
transaction = "transaction",
|
|
109
|
+
try = "try",
|
|
110
|
+
yield = "yield"
|
|
111
|
+
}
|
|
112
|
+
export declare enum Comparators {
|
|
113
|
+
CONTAINS = "contains",
|
|
114
|
+
EQUAL = "==",
|
|
115
|
+
GREATER_THAN = ">",
|
|
116
|
+
GREATER_THAN_OR_EQUAL = ">=",
|
|
117
|
+
LESS_THAN = "<",
|
|
118
|
+
LESS_THAN_OR_EQUAL = "<=",
|
|
119
|
+
NOT_EQUAL = "!="
|
|
120
|
+
}
|
|
121
|
+
export declare const HtmlNodeTypes: readonly [NodeTypes.HtmlElement, NodeTypes.HtmlDanglingMarkerClose, NodeTypes.HtmlRawNode, NodeTypes.HtmlVoidElement, NodeTypes.HtmlSelfClosingElement];
|
|
122
|
+
export declare const LiquidNodeTypes: readonly [NodeTypes.LiquidTag, NodeTypes.LiquidVariableOutput, NodeTypes.LiquidBranch, NodeTypes.LiquidRawTag];
|
|
123
|
+
export declare const LoopNamedTags: readonly [NamedTags.for, NamedTags.tablerow];
|
|
124
|
+
export declare const nonTraversableProperties: Set<string>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nonTraversableProperties = exports.LoopNamedTags = exports.LiquidNodeTypes = exports.HtmlNodeTypes = exports.Comparators = exports.NamedTags = exports.NodeTypes = void 0;
|
|
4
|
+
var NodeTypes;
|
|
5
|
+
(function (NodeTypes) {
|
|
6
|
+
NodeTypes["Document"] = "Document";
|
|
7
|
+
NodeTypes["LiquidRawTag"] = "LiquidRawTag";
|
|
8
|
+
NodeTypes["LiquidTag"] = "LiquidTag";
|
|
9
|
+
NodeTypes["LiquidBranch"] = "LiquidBranch";
|
|
10
|
+
NodeTypes["LiquidVariableOutput"] = "LiquidVariableOutput";
|
|
11
|
+
NodeTypes["HtmlSelfClosingElement"] = "HtmlSelfClosingElement";
|
|
12
|
+
NodeTypes["HtmlVoidElement"] = "HtmlVoidElement";
|
|
13
|
+
NodeTypes["HtmlDoctype"] = "HtmlDoctype";
|
|
14
|
+
NodeTypes["HtmlComment"] = "HtmlComment";
|
|
15
|
+
NodeTypes["HtmlElement"] = "HtmlElement";
|
|
16
|
+
NodeTypes["HtmlDanglingMarkerClose"] = "HtmlDanglingMarkerClose";
|
|
17
|
+
NodeTypes["HtmlRawNode"] = "HtmlRawNode";
|
|
18
|
+
NodeTypes["AttrSingleQuoted"] = "AttrSingleQuoted";
|
|
19
|
+
NodeTypes["AttrDoubleQuoted"] = "AttrDoubleQuoted";
|
|
20
|
+
NodeTypes["AttrUnquoted"] = "AttrUnquoted";
|
|
21
|
+
NodeTypes["AttrEmpty"] = "AttrEmpty";
|
|
22
|
+
NodeTypes["TextNode"] = "TextNode";
|
|
23
|
+
NodeTypes["YAMLFrontmatter"] = "YAMLFrontmatter";
|
|
24
|
+
NodeTypes["LiquidVariable"] = "LiquidVariable";
|
|
25
|
+
NodeTypes["LiquidFilter"] = "LiquidFilter";
|
|
26
|
+
NodeTypes["NamedArgument"] = "NamedArgument";
|
|
27
|
+
NodeTypes["LiquidLiteral"] = "LiquidLiteral";
|
|
28
|
+
NodeTypes["BooleanExpression"] = "BooleanExpression";
|
|
29
|
+
NodeTypes["String"] = "String";
|
|
30
|
+
NodeTypes["Number"] = "Number";
|
|
31
|
+
NodeTypes["Range"] = "Range";
|
|
32
|
+
NodeTypes["VariableLookup"] = "VariableLookup";
|
|
33
|
+
NodeTypes["Comparison"] = "Comparison";
|
|
34
|
+
NodeTypes["LogicalExpression"] = "LogicalExpression";
|
|
35
|
+
NodeTypes["AssignMarkup"] = "AssignMarkup";
|
|
36
|
+
NodeTypes["HashAssignMarkup"] = "HashAssignMarkup";
|
|
37
|
+
NodeTypes["ContentForMarkup"] = "ContentForMarkup";
|
|
38
|
+
NodeTypes["CycleMarkup"] = "CycleMarkup";
|
|
39
|
+
NodeTypes["ForMarkup"] = "ForMarkup";
|
|
40
|
+
NodeTypes["PaginateMarkup"] = "PaginateMarkup";
|
|
41
|
+
NodeTypes["RawMarkup"] = "RawMarkup";
|
|
42
|
+
NodeTypes["RenderMarkup"] = "RenderMarkup";
|
|
43
|
+
NodeTypes["FunctionMarkup"] = "FunctionMarkup";
|
|
44
|
+
NodeTypes["GraphQLMarkup"] = "GraphQLMarkup";
|
|
45
|
+
NodeTypes["GraphQLInlineMarkup"] = "GraphQLInlineMarkup";
|
|
46
|
+
NodeTypes["RenderVariableExpression"] = "RenderVariableExpression";
|
|
47
|
+
NodeTypes["RenderAliasExpression"] = "RenderAliasExpression";
|
|
48
|
+
NodeTypes["LiquidDocDescriptionNode"] = "LiquidDocDescriptionNode";
|
|
49
|
+
NodeTypes["LiquidDocParamNode"] = "LiquidDocParamNode";
|
|
50
|
+
NodeTypes["LiquidDocExampleNode"] = "LiquidDocExampleNode";
|
|
51
|
+
NodeTypes["LiquidDocPromptNode"] = "LiquidDocPromptNode";
|
|
52
|
+
// platformos markup types
|
|
53
|
+
NodeTypes["BackgroundMarkup"] = "BackgroundMarkup";
|
|
54
|
+
NodeTypes["BackgroundInlineMarkup"] = "BackgroundInlineMarkup";
|
|
55
|
+
NodeTypes["CacheMarkup"] = "CacheMarkup";
|
|
56
|
+
NodeTypes["LogMarkup"] = "LogMarkup";
|
|
57
|
+
NodeTypes["SessionMarkup"] = "SessionMarkup";
|
|
58
|
+
NodeTypes["ExportMarkup"] = "ExportMarkup";
|
|
59
|
+
NodeTypes["RedirectToMarkup"] = "RedirectToMarkup";
|
|
60
|
+
NodeTypes["IncludeFormMarkup"] = "IncludeFormMarkup";
|
|
61
|
+
NodeTypes["SpamProtectionMarkup"] = "SpamProtectionMarkup";
|
|
62
|
+
})(NodeTypes || (exports.NodeTypes = NodeTypes = {}));
|
|
63
|
+
// These are officially supported with special node types
|
|
64
|
+
var NamedTags;
|
|
65
|
+
(function (NamedTags) {
|
|
66
|
+
NamedTags["assign"] = "assign";
|
|
67
|
+
NamedTags["hash_assign"] = "hash_assign";
|
|
68
|
+
NamedTags["capture"] = "capture";
|
|
69
|
+
NamedTags["case"] = "case";
|
|
70
|
+
NamedTags["content_for"] = "content_for";
|
|
71
|
+
NamedTags["cycle"] = "cycle";
|
|
72
|
+
NamedTags["decrement"] = "decrement";
|
|
73
|
+
NamedTags["echo"] = "echo";
|
|
74
|
+
NamedTags["elsif"] = "elsif";
|
|
75
|
+
NamedTags["for"] = "for";
|
|
76
|
+
NamedTags["form"] = "form";
|
|
77
|
+
NamedTags["if"] = "if";
|
|
78
|
+
NamedTags["include"] = "include";
|
|
79
|
+
NamedTags["increment"] = "increment";
|
|
80
|
+
NamedTags["layout"] = "layout";
|
|
81
|
+
NamedTags["liquid"] = "liquid";
|
|
82
|
+
NamedTags["paginate"] = "paginate";
|
|
83
|
+
NamedTags["render"] = "render";
|
|
84
|
+
NamedTags["function"] = "function";
|
|
85
|
+
NamedTags["graphql"] = "graphql";
|
|
86
|
+
NamedTags["section"] = "section";
|
|
87
|
+
NamedTags["sections"] = "sections";
|
|
88
|
+
NamedTags["tablerow"] = "tablerow";
|
|
89
|
+
NamedTags["unless"] = "unless";
|
|
90
|
+
NamedTags["when"] = "when";
|
|
91
|
+
// platformos tags
|
|
92
|
+
NamedTags["background"] = "background";
|
|
93
|
+
NamedTags["cache"] = "cache";
|
|
94
|
+
NamedTags["catch"] = "catch";
|
|
95
|
+
NamedTags["context"] = "context";
|
|
96
|
+
NamedTags["export"] = "export";
|
|
97
|
+
NamedTags["include_form"] = "include_form";
|
|
98
|
+
NamedTags["log"] = "log";
|
|
99
|
+
NamedTags["parse_json"] = "parse_json";
|
|
100
|
+
NamedTags["print"] = "print";
|
|
101
|
+
NamedTags["redirect_to"] = "redirect_to";
|
|
102
|
+
NamedTags["response_headers"] = "response_headers";
|
|
103
|
+
NamedTags["response_status"] = "response_status";
|
|
104
|
+
NamedTags["return"] = "return";
|
|
105
|
+
NamedTags["rollback"] = "rollback";
|
|
106
|
+
NamedTags["session"] = "session";
|
|
107
|
+
NamedTags["sign_in"] = "sign_in";
|
|
108
|
+
NamedTags["spam_protection"] = "spam_protection";
|
|
109
|
+
NamedTags["theme_render_rc"] = "theme_render_rc";
|
|
110
|
+
NamedTags["transaction"] = "transaction";
|
|
111
|
+
NamedTags["try"] = "try";
|
|
112
|
+
NamedTags["yield"] = "yield";
|
|
113
|
+
})(NamedTags || (exports.NamedTags = NamedTags = {}));
|
|
114
|
+
var Comparators;
|
|
115
|
+
(function (Comparators) {
|
|
116
|
+
Comparators["CONTAINS"] = "contains";
|
|
117
|
+
Comparators["EQUAL"] = "==";
|
|
118
|
+
Comparators["GREATER_THAN"] = ">";
|
|
119
|
+
Comparators["GREATER_THAN_OR_EQUAL"] = ">=";
|
|
120
|
+
Comparators["LESS_THAN"] = "<";
|
|
121
|
+
Comparators["LESS_THAN_OR_EQUAL"] = "<=";
|
|
122
|
+
Comparators["NOT_EQUAL"] = "!=";
|
|
123
|
+
})(Comparators || (exports.Comparators = Comparators = {}));
|
|
124
|
+
exports.HtmlNodeTypes = [
|
|
125
|
+
NodeTypes.HtmlElement,
|
|
126
|
+
NodeTypes.HtmlDanglingMarkerClose,
|
|
127
|
+
NodeTypes.HtmlRawNode,
|
|
128
|
+
NodeTypes.HtmlVoidElement,
|
|
129
|
+
NodeTypes.HtmlSelfClosingElement,
|
|
130
|
+
];
|
|
131
|
+
exports.LiquidNodeTypes = [
|
|
132
|
+
NodeTypes.LiquidTag,
|
|
133
|
+
NodeTypes.LiquidVariableOutput,
|
|
134
|
+
NodeTypes.LiquidBranch,
|
|
135
|
+
NodeTypes.LiquidRawTag,
|
|
136
|
+
];
|
|
137
|
+
exports.LoopNamedTags = [NamedTags.for, NamedTags.tablerow];
|
|
138
|
+
// Those properties create loops that would make walking infinite
|
|
139
|
+
exports.nonTraversableProperties = new Set([
|
|
140
|
+
'parentNode',
|
|
141
|
+
'prev',
|
|
142
|
+
'next',
|
|
143
|
+
'firstChild',
|
|
144
|
+
'lastChild',
|
|
145
|
+
]);
|
|
146
|
+
//# sourceMappingURL=types.js.map
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Position } from './types';
|
|
2
|
+
export declare function assertNever(x: never): never;
|
|
3
|
+
export declare function locStart(node: {
|
|
4
|
+
position: Position;
|
|
5
|
+
}): number;
|
|
6
|
+
export declare function locEnd(node: {
|
|
7
|
+
position: Position;
|
|
8
|
+
}): number;
|
|
9
|
+
export declare function deepGet<T = any>(path: (string | number)[], obj: any): T;
|
|
10
|
+
export declare function dropLast<T>(n: number, xs: readonly T[]): T[];
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNever = assertNever;
|
|
4
|
+
exports.locStart = locStart;
|
|
5
|
+
exports.locEnd = locEnd;
|
|
6
|
+
exports.deepGet = deepGet;
|
|
7
|
+
exports.dropLast = dropLast;
|
|
8
|
+
function assertNever(x) {
|
|
9
|
+
throw new Error(`Unexpected object: ${x.type}`);
|
|
10
|
+
}
|
|
11
|
+
function locStart(node) {
|
|
12
|
+
return node.position.start;
|
|
13
|
+
}
|
|
14
|
+
function locEnd(node) {
|
|
15
|
+
return node.position.end;
|
|
16
|
+
}
|
|
17
|
+
function deepGet(path, obj) {
|
|
18
|
+
return path.reduce((curr, k) => {
|
|
19
|
+
if (curr && curr[k] !== undefined)
|
|
20
|
+
return curr[k];
|
|
21
|
+
return undefined;
|
|
22
|
+
}, obj);
|
|
23
|
+
}
|
|
24
|
+
function dropLast(n, xs) {
|
|
25
|
+
const result = [...xs];
|
|
26
|
+
for (let i = 0; i < n; i++) {
|
|
27
|
+
result.pop();
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=utils.js.map
|