Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit 43d6330

Browse files
authored
Merge pull request #150 from Shopify/sections_tag_support
Add support for sections tag
2 parents e3318d8 + 05bf390 commit 43d6330

File tree

8 files changed

+43
-0
lines changed

8 files changed

+43
-0
lines changed

grammar/liquid-html.ohm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Liquid <: Helpers {
5757
| liquidTagLiquid
5858
| liquidTagRender
5959
| liquidTagSection
60+
| liquidTagSections
6061
| liquidTagWhen
6162
| liquidTagBaseCase
6263

@@ -97,6 +98,9 @@ Liquid <: Helpers {
9798
liquidTagSection = liquidTagRule<"section", liquidTagSectionMarkup>
9899
liquidTagSectionMarkup = liquidString space*
99100

101+
liquidTagSections = liquidTagRule<"sections", liquidTagSectionsMarkup>
102+
liquidTagSectionsMarkup = liquidString space*
103+
100104
liquidTagLayout = liquidTagRule<"layout", liquidTagLayoutMarkup>
101105
liquidTagLayoutMarkup = liquidExpression space*
102106

src/parser/stage-1-cst.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ export type ConcreteLiquidTagNamed =
295295
| ConcreteLiquidTagLiquid
296296
| ConcreteLiquidTagRender
297297
| ConcreteLiquidTagSection
298+
| ConcreteLiquidTagSections
298299
| ConcreteLiquidTagWhen;
299300

300301
export interface ConcreteLiquidTagNode<Name, Markup>
@@ -319,6 +320,8 @@ export interface ConcreteLiquidTagDecrement
319320
> {}
320321
export interface ConcreteLiquidTagSection
321322
extends ConcreteLiquidTagNode<NamedTags.section, ConcreteStringLiteral> {}
323+
export interface ConcreteLiquidTagSections
324+
extends ConcreteLiquidTagNode<NamedTags.sections, ConcreteStringLiteral> {}
322325
export interface ConcreteLiquidTagLayout
323326
extends ConcreteLiquidTagNode<NamedTags.layout, ConcreteLiquidExpression> {}
324327

@@ -685,6 +688,7 @@ export function toLiquidHtmlCST(source: string): LiquidHtmlCST {
685688
liquidTagRender: 0,
686689
liquidTagInclude: 0,
687690
liquidTagSection: 0,
691+
liquidTagSections: 0,
688692
liquidTagLayout: 0,
689693
liquidTagRule: {
690694
type: ConcreteNodeTypes.LiquidTag,
@@ -729,6 +733,7 @@ export function toLiquidHtmlCST(source: string): LiquidHtmlCST {
729733

730734
liquidTagEchoMarkup: 0,
731735
liquidTagSectionMarkup: 0,
736+
liquidTagSectionsMarkup: 0,
732737
liquidTagLayoutMarkup: 0,
733738
liquidTagAssignMarkup: {
734739
type: ConcreteNodeTypes.AssignMarkup,

src/parser/stage-2-ast.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export type LiquidTagNamed =
176176
| LiquidTagPaginate
177177
| LiquidTagRender
178178
| LiquidTagSection
179+
| LiquidTagSections
179180
| LiquidTagTablerow
180181
| LiquidTagUnless;
181182

@@ -285,6 +286,8 @@ export interface LiquidTagInclude
285286

286287
export interface LiquidTagSection
287288
extends LiquidTagNode<NamedTags.section, LiquidString> {}
289+
export interface LiquidTagSections
290+
extends LiquidTagNode<NamedTags.sections, LiquidString> {}
288291
export interface LiquidTagLayout
289292
extends LiquidTagNode<NamedTags.layout, LiquidExpression> {}
290293

@@ -1006,6 +1009,13 @@ function toNamedLiquidTag(
10061009
markup: toExpression(node.markup) as LiquidString,
10071010
};
10081011
}
1012+
case NamedTags.sections: {
1013+
return {
1014+
...liquidTagBaseAttributes(node),
1015+
name: node.name,
1016+
markup: toExpression(node.markup) as LiquidString,
1017+
};
1018+
}
10091019

10101020
case NamedTags.form: {
10111021
return {

src/printer/print/liquid.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ function printNamedLiquidBlockStart(
196196
case NamedTags.section: {
197197
return tag(' ');
198198
}
199+
case NamedTags.sections: {
200+
return tag(' ');
201+
}
199202

200203
case NamedTags.form: {
201204
const trailingWhitespace = node.markup.length > 1 ? line : ' ';

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export enum NamedTags {
7373
paginate = 'paginate',
7474
render = 'render',
7575
section = 'section',
76+
sections = 'sections',
7677
tablerow = 'tablerow',
7778
unless = 'unless',
7879
when = 'when',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
It should never break a name
2+
printWidth: 1
3+
{% sections 'sectionName' %}
4+
{% sections 'sectionName' %}
5+
{% sections 'sectionName' %}
6+
{%- sections 'sectionName' -%}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
It should never break a name
2+
printWidth: 1
3+
{% sections "sectionName" %}
4+
{% sections "sectionName" %}
5+
{% sections "sectionName"%}
6+
{%- sections
7+
"sectionName"
8+
-%}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { assertFormattedEqualsFixed } from '../test-helpers';
2+
import * as path from 'path';
3+
4+
describe(`Unit: ${path.basename(__dirname)}`, () => {
5+
assertFormattedEqualsFixed(__dirname);
6+
});

0 commit comments

Comments
 (0)