@platformos/liquid-html-parser 0.0.5 → 0.0.7

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/dist/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MatchResult } from 'ohm-js';
1
+ import { FailedMatchResult } from 'ohm-js';
2
2
  import { NodeTypes, Position } from './types';
3
3
  interface LineColPosition {
4
4
  line: number;
@@ -9,7 +9,7 @@ export declare class LiquidHTMLCSTParsingError extends SyntaxError {
9
9
  start: LineColPosition;
10
10
  end: LineColPosition;
11
11
  };
12
- constructor(ohm: MatchResult);
12
+ constructor(ohm: FailedMatchResult);
13
13
  }
14
14
  export type UnclosedNode = {
15
15
  type: NodeTypes;
@@ -79,9 +79,6 @@ export declare enum ConcreteNodeTypes {
79
79
  LiquidDocDescriptionNode = "LiquidDocDescriptionNode",
80
80
  LiquidDocExampleNode = "LiquidDocExampleNode",
81
81
  LiquidDocPromptNode = "LiquidDocPromptNode",
82
- JsonHashLiteral = "JsonHashLiteral",
83
- JsonArrayLiteral = "JsonArrayLiteral",
84
- JsonKeyValuePair = "JsonKeyValuePair",
85
82
  BackgroundMarkup = "BackgroundMarkup",
86
83
  BackgroundInlineMarkup = "BackgroundInlineMarkup",
87
84
  CacheMarkup = "CacheMarkup",
@@ -276,8 +273,6 @@ export interface ConcreteLiquidTagAssign extends ConcreteLiquidTagNode<NamedTags
276
273
  }
277
274
  export interface ConcreteLiquidTagAssignMarkup extends ConcreteBasicNode<ConcreteNodeTypes.AssignMarkup> {
278
275
  name: string;
279
- target: ConcreteLiquidVariableLookup;
280
- operator: string;
281
276
  value: ConcreteLiquidVariable;
282
277
  }
283
278
  export interface ConcreteLiquidTagHashAssign extends ConcreteLiquidTagNode<NamedTags.hash_assign, ConcreteLiquidTagHashAssignMarkup> {
@@ -431,7 +426,7 @@ export interface ConcreteLiquidNamedArgument extends ConcreteBasicNode<ConcreteN
431
426
  name: string;
432
427
  value: ConcreteLiquidExpression;
433
428
  }
434
- export type ConcreteLiquidExpression = ConcreteStringLiteral | ConcreteNumberLiteral | ConcreteLiquidLiteral | ConcreteLiquidRange | ConcreteLiquidVariableLookup | ConcreteJsonHashLiteral | ConcreteJsonArrayLiteral;
429
+ export type ConcreteLiquidExpression = ConcreteStringLiteral | ConcreteNumberLiteral | ConcreteLiquidLiteral | ConcreteLiquidRange | ConcreteLiquidVariableLookup;
435
430
  export type ConcreteComplexLiquidExpression = ConcreteLiquidBooleanExpression | ConcreteLiquidExpression;
436
431
  export interface ConcreteLiquidBooleanExpression extends ConcreteBasicNode<ConcreteNodeTypes.BooleanExpression> {
437
432
  conditions: ConcreteLiquidCondition[];
@@ -455,17 +450,6 @@ export interface ConcreteLiquidVariableLookup extends ConcreteBasicNode<Concrete
455
450
  name: string | null;
456
451
  lookups: ConcreteLiquidExpression[];
457
452
  }
458
- export interface ConcreteJsonHashLiteral extends ConcreteBasicNode<ConcreteNodeTypes.JsonHashLiteral> {
459
- entries: ConcreteJsonKeyValuePair[];
460
- }
461
- export interface ConcreteJsonKeyValuePair extends ConcreteBasicNode<ConcreteNodeTypes.JsonKeyValuePair> {
462
- key: ConcreteLiquidExpression;
463
- value: ConcreteJsonValue;
464
- }
465
- export interface ConcreteJsonArrayLiteral extends ConcreteBasicNode<ConcreteNodeTypes.JsonArrayLiteral> {
466
- elements: ConcreteJsonValue[];
467
- }
468
- export type ConcreteJsonValue = ConcreteJsonHashLiteral | ConcreteJsonArrayLiteral | ConcreteLiquidExpression;
469
453
  export type ConcreteHtmlNode = ConcreteHtmlDoctype | ConcreteHtmlComment | ConcreteHtmlRawTag | ConcreteHtmlVoidElement | ConcreteHtmlSelfClosingElement | ConcreteHtmlTagOpen | ConcreteHtmlTagClose;
470
454
  export interface ConcreteTextNode extends ConcreteBasicNode<ConcreteNodeTypes.TextNode> {
471
455
  value: string;
@@ -87,9 +87,6 @@ var ConcreteNodeTypes;
87
87
  ConcreteNodeTypes["LiquidDocDescriptionNode"] = "LiquidDocDescriptionNode";
88
88
  ConcreteNodeTypes["LiquidDocExampleNode"] = "LiquidDocExampleNode";
89
89
  ConcreteNodeTypes["LiquidDocPromptNode"] = "LiquidDocPromptNode";
90
- ConcreteNodeTypes["JsonHashLiteral"] = "JsonHashLiteral";
91
- ConcreteNodeTypes["JsonArrayLiteral"] = "JsonArrayLiteral";
92
- ConcreteNodeTypes["JsonKeyValuePair"] = "JsonKeyValuePair";
93
90
  // platformos markup types
94
91
  ConcreteNodeTypes["BackgroundMarkup"] = "BackgroundMarkup";
95
92
  ConcreteNodeTypes["BackgroundInlineMarkup"] = "BackgroundInlineMarkup";
@@ -377,66 +374,12 @@ function toCST(source /* the original file */, grammars, grammar, cstMappings, m
377
374
  liquidTagLayoutMarkup: 0,
378
375
  liquidTagAssignMarkup: {
379
376
  type: ConcreteNodeTypes.AssignMarkup,
380
- name: (tokens) => tokens[0].children[0].sourceString,
381
- target: 0,
382
- operator: 2,
383
- value: 4,
384
- locStart,
385
- locEnd,
386
- source,
387
- },
388
- assignTarget: {
389
- type: ConcreteNodeTypes.VariableLookup,
390
377
  name: 0,
391
- lookups: 1,
392
- locStart,
393
- locEnd,
394
- source,
395
- },
396
- assignOperator: (node) => node.sourceString,
397
- liquidAssignVariable: {
398
- type: ConcreteNodeTypes.LiquidVariable,
399
- expression: 0,
400
- filters: 1,
401
- rawSource: (tokens) => source.slice(locStart(tokens), tokens[tokens.length - 2].source.endIdx).trimEnd(),
402
- locStart,
403
- locEnd: locEndSecondToLast,
404
- source,
405
- },
406
- liquidAssignExpression: 0,
407
- liquidJsonHashLiteral: {
408
- type: ConcreteNodeTypes.JsonHashLiteral,
409
- entries: 2,
410
- locStart,
411
- locEnd,
412
- source,
413
- },
414
- liquidJsonKeyValue: {
415
- type: ConcreteNodeTypes.JsonKeyValuePair,
416
- key: 0,
417
378
  value: 4,
418
379
  locStart,
419
380
  locEnd,
420
381
  source,
421
382
  },
422
- liquidJsonKey: 0,
423
- liquidJsonBareKey: {
424
- type: ConcreteNodeTypes.VariableLookup,
425
- name: 0,
426
- lookups: () => [],
427
- locStart,
428
- locEnd,
429
- source,
430
- },
431
- liquidJsonArrayLiteral: {
432
- type: ConcreteNodeTypes.JsonArrayLiteral,
433
- elements: 2,
434
- locStart,
435
- locEnd,
436
- source,
437
- },
438
- liquidJsonValue: 0,
439
- liquidJsonSep: 1,
440
383
  liquidTagHashAssignMarkup: {
441
384
  type: ConcreteNodeTypes.HashAssignMarkup,
442
385
  target: 0,
@@ -35,7 +35,7 @@
35
35
  import { ConcreteAttributeNode, ConcreteHtmlTagClose, ConcreteLiquidTagClose, LiquidCST, LiquidHtmlCST, ConcreteLiquidLiteral } from './stage-1-cst';
36
36
  import { Comparators, NamedTags, NodeTypes, Position } from './types';
37
37
  /** The union type of all possible node types inside a LiquidHTML AST. */
38
- export type LiquidHtmlNode = DocumentNode | YAMLFrontmatter | LiquidNode | HtmlDoctype | HtmlNode | AttributeNode | LiquidVariable | ComplexLiquidExpression | LiquidFilter | LiquidNamedArgument | AssignMarkup | HashAssignMarkup | ContentForMarkup | CycleMarkup | ForMarkup | RenderMarkup | FunctionMarkup | GraphQLMarkup | GraphQLInlineMarkup | PaginateMarkup | RawMarkup | RenderVariableExpression | RenderAliasExpression | LiquidLogicalExpression | LiquidComparison | TextNode | LiquidDocParamNode | LiquidDocExampleNode | LiquidDocPromptNode | LiquidDocDescriptionNode | JsonHashLiteral | JsonArrayLiteral | JsonKeyValuePair | BackgroundMarkup | BackgroundInlineMarkup | CacheMarkup | LogMarkup | SessionMarkup | ExportMarkup | RedirectToMarkup | IncludeFormMarkup | SpamProtectionMarkup;
38
+ export type LiquidHtmlNode = DocumentNode | YAMLFrontmatter | LiquidNode | HtmlDoctype | HtmlNode | AttributeNode | LiquidVariable | ComplexLiquidExpression | LiquidFilter | LiquidNamedArgument | AssignMarkup | HashAssignMarkup | ContentForMarkup | CycleMarkup | ForMarkup | RenderMarkup | FunctionMarkup | GraphQLMarkup | GraphQLInlineMarkup | PaginateMarkup | RawMarkup | RenderVariableExpression | RenderAliasExpression | LiquidLogicalExpression | LiquidComparison | TextNode | LiquidDocParamNode | LiquidDocExampleNode | LiquidDocPromptNode | LiquidDocDescriptionNode | BackgroundMarkup | BackgroundInlineMarkup | CacheMarkup | LogMarkup | SessionMarkup | ExportMarkup | RedirectToMarkup | IncludeFormMarkup | SpamProtectionMarkup;
39
39
  /** The root node of all LiquidHTML ASTs. */
40
40
  export interface DocumentNode extends ASTNode<NodeTypes.Document> {
41
41
  children: LiquidHtmlNode[];
@@ -137,12 +137,8 @@ export interface LiquidTagAssign extends LiquidTagNode<NamedTags.assign, AssignM
137
137
  }
138
138
  /** {% assign name = value %} */
139
139
  export interface AssignMarkup extends ASTNode<NodeTypes.AssignMarkup> {
140
- /** the base variable name (backward compatible) */
140
+ /** the name of the variable that is being assigned */
141
141
  name: string;
142
- /** bracket/dot lookups on the target (empty for simple assignment) */
143
- lookups: LiquidExpression[];
144
- /** '=' for assignment, '<<' for array append */
145
- operator: '=' | '<<';
146
142
  /** the value of the variable that is being assigned */
147
143
  value: LiquidVariable;
148
144
  }
@@ -510,7 +506,7 @@ export interface LiquidVariable extends ASTNode<NodeTypes.LiquidVariable> {
510
506
  rawSource: string;
511
507
  }
512
508
  /** The union type of all Liquid expression nodes */
513
- export type LiquidExpression = LiquidString | LiquidNumber | LiquidLiteral | LiquidRange | LiquidVariableLookup | JsonHashLiteral | JsonArrayLiteral;
509
+ export type LiquidExpression = LiquidString | LiquidNumber | LiquidLiteral | LiquidRange | LiquidVariableLookup;
514
510
  export type ComplexLiquidExpression = LiquidBooleanExpression | LiquidExpression;
515
511
  /** https://shopify.dev/docs/api/liquid/filters */
516
512
  export interface LiquidFilter extends ASTNode<NodeTypes.LiquidFilter> {
@@ -569,19 +565,6 @@ export interface LiquidVariableLookup extends ASTNode<NodeTypes.VariableLookup>
569
565
  /** name.lookup1[lookup2] */
570
566
  lookups: LiquidExpression[];
571
567
  }
572
- /** Represents a JSON hash literal { key: value, ... } */
573
- export interface JsonHashLiteral extends ASTNode<NodeTypes.JsonHashLiteral> {
574
- entries: JsonKeyValuePair[];
575
- }
576
- /** Represents a key-value pair in a JSON hash literal */
577
- export interface JsonKeyValuePair extends ASTNode<NodeTypes.JsonKeyValuePair> {
578
- key: LiquidExpression;
579
- value: LiquidExpression;
580
- }
581
- /** Represents a JSON array literal [el1, el2, ...] */
582
- export interface JsonArrayLiteral extends ASTNode<NodeTypes.JsonArrayLiteral> {
583
- elements: LiquidExpression[];
584
- }
585
568
  /** The union type of all HTML nodes */
586
569
  export type HtmlNode = HtmlComment | HtmlElement | HtmlDanglingMarkerClose | HtmlVoidElement | HtmlSelfClosingElement | HtmlRawNode;
587
570
  /** The basic HTML node with an opening and closing tags. */
@@ -916,8 +916,6 @@ function toAssignMarkup(node) {
916
916
  return {
917
917
  type: types_1.NodeTypes.AssignMarkup,
918
918
  name: node.name,
919
- lookups: node.target.lookups.map(toExpression),
920
- operator: node.operator,
921
919
  value: toLiquidVariable(node.value),
922
920
  position: position(node),
923
921
  source: node.source,
@@ -1352,36 +1350,11 @@ function toExpression(node) {
1352
1350
  source: node.source,
1353
1351
  };
1354
1352
  }
1355
- case stage_1_cst_1.ConcreteNodeTypes.JsonHashLiteral: {
1356
- return {
1357
- type: types_1.NodeTypes.JsonHashLiteral,
1358
- entries: node.entries.map(toJsonKeyValuePair),
1359
- position: position(node),
1360
- source: node.source,
1361
- };
1362
- }
1363
- case stage_1_cst_1.ConcreteNodeTypes.JsonArrayLiteral: {
1364
- return {
1365
- type: types_1.NodeTypes.JsonArrayLiteral,
1366
- elements: node.elements.map(toExpression),
1367
- position: position(node),
1368
- source: node.source,
1369
- };
1370
- }
1371
1353
  default: {
1372
1354
  return (0, utils_1.assertNever)(node);
1373
1355
  }
1374
1356
  }
1375
1357
  }
1376
- function toJsonKeyValuePair(node) {
1377
- return {
1378
- type: types_1.NodeTypes.JsonKeyValuePair,
1379
- key: toExpression(node.key),
1380
- value: toExpression(node.value),
1381
- position: position(node),
1382
- source: node.source,
1383
- };
1384
- }
1385
1358
  function toFilter(node) {
1386
1359
  return {
1387
1360
  type: types_1.NodeTypes.LiquidFilter,
package/dist/types.d.ts CHANGED
@@ -51,9 +51,6 @@ export declare enum NodeTypes {
51
51
  LiquidDocParamNode = "LiquidDocParamNode",
52
52
  LiquidDocExampleNode = "LiquidDocExampleNode",
53
53
  LiquidDocPromptNode = "LiquidDocPromptNode",
54
- JsonHashLiteral = "JsonHashLiteral",
55
- JsonArrayLiteral = "JsonArrayLiteral",
56
- JsonKeyValuePair = "JsonKeyValuePair",
57
54
  BackgroundMarkup = "BackgroundMarkup",
58
55
  BackgroundInlineMarkup = "BackgroundInlineMarkup",
59
56
  CacheMarkup = "CacheMarkup",
package/dist/types.js CHANGED
@@ -49,9 +49,6 @@ var NodeTypes;
49
49
  NodeTypes["LiquidDocParamNode"] = "LiquidDocParamNode";
50
50
  NodeTypes["LiquidDocExampleNode"] = "LiquidDocExampleNode";
51
51
  NodeTypes["LiquidDocPromptNode"] = "LiquidDocPromptNode";
52
- NodeTypes["JsonHashLiteral"] = "JsonHashLiteral";
53
- NodeTypes["JsonArrayLiteral"] = "JsonArrayLiteral";
54
- NodeTypes["JsonKeyValuePair"] = "JsonKeyValuePair";
55
52
  // platformos markup types
56
53
  NodeTypes["BackgroundMarkup"] = "BackgroundMarkup";
57
54
  NodeTypes["BackgroundInlineMarkup"] = "BackgroundInlineMarkup";
@@ -129,33 +129,7 @@ Liquid <: Helpers {
129
129
  liquidTagEchoMarkup = liquidVariable<delimTag>
130
130
 
131
131
  liquidTagAssign = liquidTagRule<"assign", liquidTagAssignMarkup>
132
- liquidTagAssignMarkup = assignTarget<delimTag> space* assignOperator space* liquidAssignVariable<delimTag>
133
-
134
- // Assign-specific sub-rules
135
- assignTarget<delim> = variableSegment lookup<delim>*
136
- assignOperator = "<<" | "="
137
-
138
- // Assign variable: like liquidVariable but expression allows JSON literals
139
- liquidAssignVariable<delim> = liquidAssignExpression<delim> liquidFilter<delim>* space* &delim
140
- liquidAssignExpression<delim> =
141
- | liquidJsonHashLiteral<delim>
142
- | liquidJsonArrayLiteral<delim>
143
- | liquidComplexExpression<delim>
144
-
145
- // JSON literal rules (assign-only, recursive)
146
- liquidJsonHashLiteral<delim> =
147
- "{" space* listOf<liquidJsonKeyValue<delim>, liquidJsonSep> space* "}"
148
- liquidJsonKeyValue<delim> =
149
- liquidJsonKey<delim> space* ":" space* liquidJsonValue<delim>
150
- liquidJsonKey<delim> = liquidString<delim> | liquidJsonBareKey
151
- liquidJsonBareKey = variableSegment
152
- liquidJsonArrayLiteral<delim> =
153
- "[" space* listOf<liquidJsonValue<delim>, liquidJsonSep> space* "]"
154
- liquidJsonValue<delim> =
155
- | liquidJsonHashLiteral<delim>
156
- | liquidJsonArrayLiteral<delim>
157
- | liquidExpression<delim>
158
- liquidJsonSep = space* "," space*
132
+ liquidTagAssignMarkup = variableSegment space* "=" space* liquidVariable<delimTag>
159
133
 
160
134
  liquidTagHashAssign = liquidTagRule<"hash_assign", liquidTagHashAssignMarkup>
161
135
  liquidTagHashAssignMarkup = liquidVariableLookup<delimTag> space* "=" space* liquidVariable<delimTag>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformos/liquid-html-parser",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Liquid HTML parser for platformOS",
5
5
  "author": "platformOS",
6
6
  "homepage": "https://github.com/Platform-OS/platformos-tools/tree/master/packages/liquid-html-parser#readme",
@@ -33,9 +33,9 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "line-column": "^1.0.2",
36
- "ohm-js": "^17.0.0"
36
+ "ohm-js": "^17.5.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/line-column": "^1.0.0"
39
+ "@types/line-column": "^1.0.2"
40
40
  }
41
41
  }