Skip to content

Commit fe9585f

Browse files
committed
Adds arrays to performance test templates.
Only demo / test changes here — it’s not too hard to support this since most (all?) templating engines will accept a native _array_ as input for a set of children.
1 parent 57959e4 commit fe9585f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

demo/performance/common.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default class CommonTest {
5858
title: 'test',
5959
content1: 'AAA',
6060
content2: 'BBB',
61+
items: [{ text: 'one' }, { text: 'two' }, { text: 'three' }],
6162
},
6263
{
6364
attr: '456',
@@ -76,6 +77,7 @@ export default class CommonTest {
7677
title: 'test',
7778
content1: 'ZZZ',
7879
content2: 'BBB',
80+
items: [{ text: 'one' }, { text: 'two' }, { text: 'three' }, { text: 'four' }, { text: 'five' }, { text: 'six' }],
7981
},
8082
];
8183

@@ -235,14 +237,19 @@ export class HtmlLiteralInterface {
235237
// We can get around the optimization by using eval though!
236238
static getResultEval(html, properties) {
237239
// eslint-disable-next-line no-unused-vars
238-
const { attr, one, two, three, four, five, six, seven, eight, nine, ten, id, hidden, title, content1, content2 } = properties;
240+
const { attr, one, two, three, four, five, six, seven, eight, nine, ten, id, hidden, title, content1, content2, items } = properties;
239241
// eslint-disable-next-line no-eval
240242
return eval(`html\`<div data-id="p1" attr="\${attr}">
241243
<div data-id="p2" data-foo one="\${one}" two="\${two}" three="\${three}" four="\${four}" five="\${five}" .six="\${six}" .seven="\${seven}" .eight="\${eight}" .nine="\${nine}" .ten="\${ten}">
242244
<div data-id="p3" data-bar="bar">
243245
<div data-id="\${id}" boolean ?hidden="\${hidden}" .title="\${title}">
244246
\${content1} -- \${content2}
245247
</div>
248+
<ul data-id="list">
249+
\${(items ?? []).map(item => {
250+
return html\`<li>\${item.text}</li>\`;
251+
})}
252+
</ul>
246253
</div>
247254
</div>
248255
<div class="extra">

demo/performance/react.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Test extends CommonTest {
1111

1212
// TODO: This is sorta cheating since we aren’t asking it to _parse_ anything…
1313
static getResult(properties) {
14-
const { attr, one, two, three, four, five, six, seven, eight, nine, ten, id, hidden, title, content1, content2 } = properties;
14+
const { attr, one, two, three, four, five, six, seven, eight, nine, ten, id, hidden, title, content1, content2, items } = properties;
1515
return createElement('div', { 'data-id': 'p1', attr }, [
1616
createElement('div', { 'data-id': 'p2', 'data-foo': '', one, two, three, four, five, six, seven, eight, nine, ten }, [
1717
createElement('div', { 'data-id': 'p3', 'data-bar': 'bar' }, [
@@ -20,6 +20,9 @@ class Test extends CommonTest {
2020
' -- ',
2121
content2,
2222
]),
23+
createElement('ul', { 'data-id': 'list' }, (items ?? []).map(item => {
24+
return createElement('li', null, [item.text]);
25+
})),
2326
]),
2427
createElement('p', null, [
2528
'Just something a little ',

test/test-parser.js

+4
Original file line numberDiff line numberDiff line change
@@ -1544,12 +1544,16 @@ describe('errors coverage', () => {
15441544
assertThrows(callback, expectedMessage, { startsWith: true });
15451545
});
15461546
1547+
//////////////////////////////////////////////////////////////////////////////
1548+
15471549
it('throws when cdata exists', () => {
15481550
const callback = () => htmlol`<![CDATA[<]]>`;
15491551
const expectedMessage = '[#140]';
15501552
assertThrows(callback, expectedMessage, { startsWith: true });
15511553
});
15521554
1555+
//////////////////////////////////////////////////////////////////////////////
1556+
15531557
it('throws when escapes are used', () => {
15541558
const callback = () => htmlol`\n`;
15551559
const expectedMessage = '[#150]';

0 commit comments

Comments
 (0)