Skip to content

Commit c115337

Browse files
committed
In the 0.3.2 renderer, omit empty section attribute arrays 🍭
Previously, the renderer was always adding a third attributes array to serialized section arrays. In the majority of cases, these are empty arrays that can be safely omitted, saving file size. Now, like with marker attributes, an array is only emitted if there is at least one custom attribute set.
1 parent 7b87e74 commit c115337

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/js/renderers/mobiledoc/0-3-2.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,19 @@ const postOpcodeCompiler = {
6969
},
7070
openMarkupSection(tagName, attributes) {
7171
this.markers = [];
72-
this.sections.push([MOBILEDOC_MARKUP_SECTION_TYPE, tagName, this.markers, attributes]);
72+
if (attributes && attributes.length !== 0) {
73+
this.sections.push([MOBILEDOC_MARKUP_SECTION_TYPE, tagName, this.markers, attributes]);
74+
} else {
75+
this.sections.push([MOBILEDOC_MARKUP_SECTION_TYPE, tagName, this.markers]);
76+
}
7377
},
7478
openListSection(tagName, attributes) {
7579
this.items = [];
76-
this.sections.push([MOBILEDOC_LIST_SECTION_TYPE, tagName, this.items, attributes]);
80+
if (attributes && attributes.length !== 0) {
81+
this.sections.push([MOBILEDOC_LIST_SECTION_TYPE, tagName, this.items, attributes]);
82+
} else {
83+
this.sections.push([MOBILEDOC_LIST_SECTION_TYPE, tagName, this.items]);
84+
}
7785
},
7886
openListItem() {
7987
this.markers = [];

tests/unit/renderers/mobiledoc/0-3-2-test.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test('renders a post with marker', (assert) => {
4040
cards: [],
4141
markups: [['strong']],
4242
sections: [
43-
[1, normalizeTagName('P'), [[0, [0], 1, 'Hi']], []]
43+
[1, normalizeTagName('P'), [[0, [0], 1, 'Hi']]]
4444
]
4545
});
4646
});
@@ -65,8 +65,7 @@ test('renders a post section with markers sharing a markup', (assert) => {
6565
[
6666
[0, [0], 0, 'Hi'],
6767
[0, [], 1, ' Guy']
68-
],
69-
[]
68+
]
7069
]
7170
]
7271
});
@@ -102,8 +101,7 @@ test('renders a post with markers with markers with complex attributes', (assert
102101
[0, [0], 1, 'Hi'],
103102
[0, [1], 1, ' Guy'],
104103
[0, [0], 1, ' other guy']
105-
],
106-
[]
104+
]
107105
]
108106
]
109107
});
@@ -169,8 +167,7 @@ test('renders a post with atom', (assert) => {
169167
[
170168
[0, [], 0, 'Hi'],
171169
[1, [], 0, 0]
172-
],
173-
[]
170+
]
174171
]
175172
]
176173
});
@@ -200,8 +197,7 @@ test('renders a post with atom and markup', (assert) => {
200197
normalizeTagName('P'),
201198
[
202199
[1, [0], 1, 0]
203-
],
204-
[]
200+
]
205201
]
206202
]
207203
});
@@ -235,8 +231,7 @@ test('renders a post with atom inside markup', (assert) => {
235231
[0, [0], 0, 'Hi '],
236232
[1, [], 0, 0],
237233
[0, [], 1, ' Bye']
238-
],
239-
[]
234+
]
240235
]
241236
]
242237
});
@@ -340,8 +335,7 @@ test('renders a post with a list', (assert) => {
340335
[
341336
[[0, [], 0, 'first item']],
342337
[[0, [], 0, 'second item']]
343-
],
344-
[]
338+
]
345339
]
346340
]
347341
});
@@ -361,8 +355,7 @@ test('renders an aside as markup section', (assert) => {
361355
[
362356
1,
363357
'aside',
364-
[[0, [], 0, 'abc']],
365-
[]
358+
[[0, [], 0, 'abc']]
366359
]
367360
]
368361
});

0 commit comments

Comments
 (0)