@lightningjs/blits 0.8.0 → 0.8.1
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/CHANGELOG.md +9 -0
- package/package.json +2 -3
- package/src/element.js +3 -0
- package/src/lib/colors/colors.js +50 -40
- package/src/lib/colors/colors.test.js +149 -49
- package/src/lib/colors/htmlColors.js +149 -149
- package/src/lib/setup/base.js +10 -10
- package/src/lib/templateparser/parser.js +50 -12
- package/src/lib/templateparser/parser.test.js +378 -71
- package/src/router/router.js +6 -6
- package/vite/msdfGenerator.js +1 -1
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
|
|
18
18
|
import test from 'tape'
|
|
19
19
|
import parser from './parser.js'
|
|
20
|
+
import symbols from '../symbols.js'
|
|
21
|
+
const { componentType } = symbols
|
|
22
|
+
import { initLog } from '../log.js'
|
|
23
|
+
initLog()
|
|
20
24
|
|
|
21
25
|
test('Type', (assert) => {
|
|
22
26
|
const expected = 'function'
|
|
@@ -43,7 +47,7 @@ test('Parse simple single tag', (assert) => {
|
|
|
43
47
|
const expected = {
|
|
44
48
|
children: [
|
|
45
49
|
{
|
|
46
|
-
|
|
50
|
+
[componentType]: 'Component',
|
|
47
51
|
},
|
|
48
52
|
],
|
|
49
53
|
}
|
|
@@ -59,10 +63,10 @@ test('Parse simple tag and simple nested tag', (assert) => {
|
|
|
59
63
|
const expected = {
|
|
60
64
|
children: [
|
|
61
65
|
{
|
|
62
|
-
|
|
66
|
+
[componentType]: 'Component',
|
|
63
67
|
children: [
|
|
64
68
|
{
|
|
65
|
-
|
|
69
|
+
[componentType]: 'Element',
|
|
66
70
|
},
|
|
67
71
|
],
|
|
68
72
|
},
|
|
@@ -80,7 +84,7 @@ test('Parse simple single tag with static attributes', (assert) => {
|
|
|
80
84
|
const expected = {
|
|
81
85
|
children: [
|
|
82
86
|
{
|
|
83
|
-
|
|
87
|
+
[componentType]: 'Component',
|
|
84
88
|
x: '10',
|
|
85
89
|
y: '20',
|
|
86
90
|
},
|
|
@@ -98,12 +102,12 @@ test('Parse tag with attributes and nested tag with attributes', (assert) => {
|
|
|
98
102
|
const expected = {
|
|
99
103
|
children: [
|
|
100
104
|
{
|
|
101
|
-
|
|
105
|
+
[componentType]: 'Component',
|
|
102
106
|
x: '10',
|
|
103
107
|
y: '20',
|
|
104
108
|
children: [
|
|
105
109
|
{
|
|
106
|
-
|
|
110
|
+
[componentType]: 'Element',
|
|
107
111
|
w: '100',
|
|
108
112
|
h: '300',
|
|
109
113
|
},
|
|
@@ -127,18 +131,18 @@ test('Parse tag with attributes and 2 nested tags with attributes', (assert) =>
|
|
|
127
131
|
const expected = {
|
|
128
132
|
children: [
|
|
129
133
|
{
|
|
130
|
-
|
|
134
|
+
[componentType]: 'Component',
|
|
131
135
|
x: '10',
|
|
132
136
|
y: '20',
|
|
133
137
|
children: [
|
|
134
138
|
{
|
|
135
|
-
|
|
139
|
+
[componentType]: 'Element',
|
|
136
140
|
w: '100',
|
|
137
141
|
h: '300',
|
|
138
142
|
x: '0',
|
|
139
143
|
},
|
|
140
144
|
{
|
|
141
|
-
|
|
145
|
+
[componentType]: 'Element',
|
|
142
146
|
w: '100',
|
|
143
147
|
h: '300',
|
|
144
148
|
x: '50',
|
|
@@ -166,28 +170,28 @@ test('Parse tag with attributes and deep nested tag with attributes', (assert) =
|
|
|
166
170
|
const expected = {
|
|
167
171
|
children: [
|
|
168
172
|
{
|
|
169
|
-
|
|
173
|
+
[componentType]: 'Component',
|
|
170
174
|
x: '10',
|
|
171
175
|
y: '20',
|
|
172
176
|
children: [
|
|
173
177
|
{
|
|
174
|
-
|
|
178
|
+
[componentType]: 'Element',
|
|
175
179
|
w: '100',
|
|
176
180
|
h: '300',
|
|
177
181
|
x: '0',
|
|
178
182
|
},
|
|
179
183
|
{
|
|
180
|
-
|
|
184
|
+
[componentType]: 'Element',
|
|
181
185
|
w: '100',
|
|
182
186
|
h: '300',
|
|
183
187
|
x: '50',
|
|
184
188
|
children: [
|
|
185
189
|
{
|
|
186
|
-
|
|
190
|
+
[componentType]: 'Button',
|
|
187
191
|
label: 'Hello',
|
|
188
192
|
},
|
|
189
193
|
{
|
|
190
|
-
|
|
194
|
+
[componentType]: 'Button',
|
|
191
195
|
label: 'World',
|
|
192
196
|
},
|
|
193
197
|
],
|
|
@@ -208,7 +212,7 @@ test('Parse simple single tag with dynamic attributes', (assert) => {
|
|
|
208
212
|
const expected = {
|
|
209
213
|
children: [
|
|
210
214
|
{
|
|
211
|
-
|
|
215
|
+
[componentType]: 'Component',
|
|
212
216
|
x: '$x',
|
|
213
217
|
y: '$y',
|
|
214
218
|
},
|
|
@@ -226,7 +230,7 @@ test('Parse tag with attributes and reactive attributes', (assert) => {
|
|
|
226
230
|
const expected = {
|
|
227
231
|
children: [
|
|
228
232
|
{
|
|
229
|
-
|
|
233
|
+
[componentType]: 'Component',
|
|
230
234
|
x: '10',
|
|
231
235
|
y: '20',
|
|
232
236
|
':w': 'foo',
|
|
@@ -247,7 +251,7 @@ test("Parse simple single tag where one of the attributes has a dash in it's nam
|
|
|
247
251
|
const expected = {
|
|
248
252
|
children: [
|
|
249
253
|
{
|
|
250
|
-
|
|
254
|
+
[componentType]: 'Component',
|
|
251
255
|
'my-Attribute': 'this',
|
|
252
256
|
x: '10',
|
|
253
257
|
y: '20',
|
|
@@ -266,10 +270,10 @@ test('Parse nested self closing tag', (assert) => {
|
|
|
266
270
|
const expected = {
|
|
267
271
|
children: [
|
|
268
272
|
{
|
|
269
|
-
|
|
273
|
+
[componentType]: 'Component',
|
|
270
274
|
children: [
|
|
271
275
|
{
|
|
272
|
-
|
|
276
|
+
[componentType]: 'Input',
|
|
273
277
|
},
|
|
274
278
|
],
|
|
275
279
|
},
|
|
@@ -287,16 +291,16 @@ test('Parse multiple nested self closing tags', (assert) => {
|
|
|
287
291
|
const expected = {
|
|
288
292
|
children: [
|
|
289
293
|
{
|
|
290
|
-
|
|
294
|
+
[componentType]: 'Component',
|
|
291
295
|
children: [
|
|
292
296
|
{
|
|
293
|
-
|
|
297
|
+
[componentType]: 'Input',
|
|
294
298
|
},
|
|
295
299
|
{
|
|
296
|
-
|
|
300
|
+
[componentType]: 'Input',
|
|
297
301
|
},
|
|
298
302
|
{
|
|
299
|
-
|
|
303
|
+
[componentType]: 'Input',
|
|
300
304
|
},
|
|
301
305
|
],
|
|
302
306
|
},
|
|
@@ -314,7 +318,7 @@ test('Parse attributes which values have spaces in it', (assert) => {
|
|
|
314
318
|
const expected = {
|
|
315
319
|
children: [
|
|
316
320
|
{
|
|
317
|
-
|
|
321
|
+
[componentType]: 'Component',
|
|
318
322
|
attribute: 'I have spaces',
|
|
319
323
|
},
|
|
320
324
|
],
|
|
@@ -338,7 +342,7 @@ test('Parse attributes with an expression in it', (assert) => {
|
|
|
338
342
|
const expected = {
|
|
339
343
|
children: [
|
|
340
344
|
{
|
|
341
|
-
|
|
345
|
+
[componentType]: 'Component',
|
|
342
346
|
':attribute1': '$foo * 2',
|
|
343
347
|
':attribute2': "$ok ? 'Yes' : 'No'",
|
|
344
348
|
':attribute3': "$text.split('').reverse().join('')",
|
|
@@ -366,18 +370,18 @@ test('Parse template with commented tag (and skip it)', (assert) => {
|
|
|
366
370
|
const expected = {
|
|
367
371
|
children: [
|
|
368
372
|
{
|
|
369
|
-
|
|
373
|
+
[componentType]: 'Component',
|
|
370
374
|
x: '10',
|
|
371
375
|
y: '20',
|
|
372
376
|
children: [
|
|
373
377
|
{
|
|
374
|
-
|
|
378
|
+
[componentType]: 'Element',
|
|
375
379
|
w: '100',
|
|
376
380
|
h: '300',
|
|
377
381
|
x: '50',
|
|
378
382
|
children: [
|
|
379
383
|
{
|
|
380
|
-
|
|
384
|
+
[componentType]: 'Button',
|
|
381
385
|
label: 'Hello',
|
|
382
386
|
},
|
|
383
387
|
],
|
|
@@ -405,12 +409,12 @@ test('Parse template with comment spanned across multiple tags (and skip it)', (
|
|
|
405
409
|
const expected = {
|
|
406
410
|
children: [
|
|
407
411
|
{
|
|
408
|
-
|
|
412
|
+
[componentType]: 'Component',
|
|
409
413
|
x: '10',
|
|
410
414
|
y: '20',
|
|
411
415
|
children: [
|
|
412
416
|
{
|
|
413
|
-
|
|
417
|
+
[componentType]: 'Element',
|
|
414
418
|
w: '100',
|
|
415
419
|
h: '300',
|
|
416
420
|
x: '50',
|
|
@@ -440,18 +444,18 @@ test('Parse template with enclosing comment (and skip it)', (assert) => {
|
|
|
440
444
|
const expected = {
|
|
441
445
|
children: [
|
|
442
446
|
{
|
|
443
|
-
|
|
447
|
+
[componentType]: 'Component',
|
|
444
448
|
x: '10',
|
|
445
449
|
y: '20',
|
|
446
450
|
children: [
|
|
447
451
|
{
|
|
448
|
-
|
|
452
|
+
[componentType]: 'Element',
|
|
449
453
|
w: '100',
|
|
450
454
|
h: '300',
|
|
451
455
|
x: '0',
|
|
452
456
|
},
|
|
453
457
|
{
|
|
454
|
-
|
|
458
|
+
[componentType]: 'Element',
|
|
455
459
|
w: '100',
|
|
456
460
|
h: '300',
|
|
457
461
|
x: '50',
|
|
@@ -475,10 +479,10 @@ test('Parse template with for loop', (assert) => {
|
|
|
475
479
|
const expected = {
|
|
476
480
|
children: [
|
|
477
481
|
{
|
|
478
|
-
|
|
482
|
+
[componentType]: 'List',
|
|
479
483
|
children: [
|
|
480
484
|
{
|
|
481
|
-
|
|
485
|
+
[componentType]: 'ListItem',
|
|
482
486
|
':for': 'item in $items',
|
|
483
487
|
},
|
|
484
488
|
],
|
|
@@ -501,15 +505,15 @@ test('Parse template with a conditional (if-statement)', (assert) => {
|
|
|
501
505
|
const expected = {
|
|
502
506
|
children: [
|
|
503
507
|
{
|
|
504
|
-
|
|
508
|
+
[componentType]: 'Component',
|
|
505
509
|
':if': '$loggedIn === true',
|
|
506
510
|
children: [
|
|
507
511
|
{
|
|
508
|
-
|
|
512
|
+
[componentType]: 'Text',
|
|
509
513
|
value: 'Welcome',
|
|
510
514
|
},
|
|
511
515
|
{
|
|
512
|
-
|
|
516
|
+
[componentType]: 'Avatar',
|
|
513
517
|
':user': '$user',
|
|
514
518
|
},
|
|
515
519
|
],
|
|
@@ -533,20 +537,20 @@ test('Parse template with a visibility toggle (show-statement)', (assert) => {
|
|
|
533
537
|
const expected = {
|
|
534
538
|
children: [
|
|
535
539
|
{
|
|
536
|
-
|
|
540
|
+
[componentType]: 'Poster',
|
|
537
541
|
w: '200',
|
|
538
542
|
h: '500',
|
|
539
543
|
children: [
|
|
540
544
|
{
|
|
541
|
-
|
|
545
|
+
[componentType]: 'Label',
|
|
542
546
|
':text': '$text',
|
|
543
547
|
},
|
|
544
548
|
{
|
|
545
|
-
|
|
549
|
+
[componentType]: 'Image',
|
|
546
550
|
src: '$image',
|
|
547
551
|
},
|
|
548
552
|
{
|
|
549
|
-
|
|
553
|
+
[componentType]: 'Star',
|
|
550
554
|
':show': '$favorited === true',
|
|
551
555
|
},
|
|
552
556
|
],
|
|
@@ -570,15 +574,15 @@ test('Parse template with a nameless tag', (assert) => {
|
|
|
570
574
|
const expected = {
|
|
571
575
|
children: [
|
|
572
576
|
{
|
|
573
|
-
|
|
577
|
+
[componentType]: null,
|
|
574
578
|
children: [
|
|
575
579
|
{
|
|
576
|
-
|
|
580
|
+
[componentType]: 'Component',
|
|
577
581
|
x: '50',
|
|
578
582
|
y: '20',
|
|
579
583
|
children: [
|
|
580
584
|
{
|
|
581
|
-
|
|
585
|
+
[componentType]: 'Component',
|
|
582
586
|
w: '100',
|
|
583
587
|
h: '20',
|
|
584
588
|
},
|
|
@@ -602,7 +606,7 @@ test('Parse template with a transition argument (single value)', (assert) => {
|
|
|
602
606
|
const expected = {
|
|
603
607
|
children: [
|
|
604
608
|
{
|
|
605
|
-
|
|
609
|
+
[componentType]: 'Element',
|
|
606
610
|
x: '{transition: $offset}',
|
|
607
611
|
y: '200',
|
|
608
612
|
},
|
|
@@ -622,7 +626,7 @@ test('Parse template with a transition argument (object)', (assert) => {
|
|
|
622
626
|
const expected = {
|
|
623
627
|
children: [
|
|
624
628
|
{
|
|
625
|
-
|
|
629
|
+
[componentType]: 'Element',
|
|
626
630
|
':x': '{transition: {v: $offset, d: 2000}}',
|
|
627
631
|
y: '200',
|
|
628
632
|
},
|
|
@@ -642,7 +646,7 @@ test('Parse template with a different modifier', (assert) => {
|
|
|
642
646
|
const expected = {
|
|
643
647
|
children: [
|
|
644
648
|
{
|
|
645
|
-
|
|
649
|
+
[componentType]: 'Element',
|
|
646
650
|
x: '{modifier: ok}',
|
|
647
651
|
y: '200',
|
|
648
652
|
},
|
|
@@ -662,7 +666,7 @@ test('Parse template with a full transition object (without the transition modif
|
|
|
662
666
|
const expected = {
|
|
663
667
|
children: [
|
|
664
668
|
{
|
|
665
|
-
|
|
669
|
+
[componentType]: 'Element',
|
|
666
670
|
':x': '{transition: {v: $offset, d: 2000, p: 100}}',
|
|
667
671
|
y: '200',
|
|
668
672
|
},
|
|
@@ -701,19 +705,19 @@ test('Parse template with attributes with values spread over multiple lines', (a
|
|
|
701
705
|
const expected = {
|
|
702
706
|
children: [
|
|
703
707
|
{
|
|
704
|
-
|
|
708
|
+
[componentType]: 'Component',
|
|
705
709
|
children: [
|
|
706
710
|
{
|
|
707
|
-
|
|
711
|
+
[componentType]: 'Element',
|
|
708
712
|
w: '160',
|
|
709
713
|
h: '160',
|
|
710
714
|
x: '40',
|
|
711
715
|
y: '40',
|
|
712
|
-
color: '
|
|
716
|
+
color: '0xfb923cff',
|
|
713
717
|
':effects': "[$shader( 'radius', {radius: 44} )]",
|
|
714
718
|
},
|
|
715
719
|
{
|
|
716
|
-
|
|
720
|
+
[componentType]: 'Element',
|
|
717
721
|
w: '120',
|
|
718
722
|
h: '120',
|
|
719
723
|
x: '100',
|
|
@@ -740,15 +744,15 @@ test('Parse template with inline text between tags', (assert) => {
|
|
|
740
744
|
const expected = {
|
|
741
745
|
children: [
|
|
742
746
|
{
|
|
743
|
-
|
|
747
|
+
[componentType]: 'Component',
|
|
744
748
|
children: [
|
|
745
749
|
{
|
|
746
|
-
|
|
750
|
+
[componentType]: 'Element',
|
|
747
751
|
w: '160',
|
|
748
752
|
h: '160',
|
|
749
753
|
x: '40',
|
|
750
754
|
y: '40',
|
|
751
|
-
color: '
|
|
755
|
+
color: '0xfb923cff',
|
|
752
756
|
content: 'Lorem ipsum',
|
|
753
757
|
},
|
|
754
758
|
],
|
|
@@ -779,33 +783,33 @@ test('Parse template with multiple inline texts between different tags', (assert
|
|
|
779
783
|
const expected = {
|
|
780
784
|
children: [
|
|
781
785
|
{
|
|
782
|
-
|
|
786
|
+
[componentType]: 'Component',
|
|
783
787
|
children: [
|
|
784
788
|
{
|
|
785
|
-
|
|
789
|
+
[componentType]: 'Element',
|
|
786
790
|
w: '160',
|
|
787
791
|
h: '160',
|
|
788
792
|
x: '40',
|
|
789
793
|
y: '40',
|
|
790
|
-
color: '
|
|
794
|
+
color: '0xfb923cff',
|
|
791
795
|
content: 'Lorem ipsum',
|
|
792
796
|
},
|
|
793
797
|
{
|
|
794
|
-
|
|
798
|
+
[componentType]: 'Element',
|
|
795
799
|
content: 'dolor sit amet',
|
|
796
800
|
},
|
|
797
801
|
{
|
|
798
|
-
|
|
802
|
+
[componentType]: 'Element',
|
|
799
803
|
children: [
|
|
800
804
|
{
|
|
801
|
-
|
|
805
|
+
[componentType]: 'Text',
|
|
802
806
|
content: 'consectetur adipiscing elit',
|
|
803
807
|
},
|
|
804
808
|
{
|
|
805
|
-
|
|
809
|
+
[componentType]: 'Element',
|
|
806
810
|
children: [
|
|
807
811
|
{
|
|
808
|
-
|
|
812
|
+
[componentType]: 'Text',
|
|
809
813
|
content: 'sed do eiusmod tempor',
|
|
810
814
|
},
|
|
811
815
|
],
|
|
@@ -832,15 +836,15 @@ test('Parse template with attribute name starts with @ character', (assert) => {
|
|
|
832
836
|
const expected = {
|
|
833
837
|
children: [
|
|
834
838
|
{
|
|
835
|
-
|
|
839
|
+
[componentType]: 'Component',
|
|
836
840
|
children: [
|
|
837
841
|
{
|
|
838
|
-
|
|
842
|
+
[componentType]: 'Element',
|
|
839
843
|
w: '160',
|
|
840
844
|
h: '160',
|
|
841
845
|
x: '40',
|
|
842
846
|
y: '40',
|
|
843
|
-
color: '
|
|
847
|
+
color: '0xfb923cff',
|
|
844
848
|
'@loaded': '@loaded',
|
|
845
849
|
},
|
|
846
850
|
],
|
|
@@ -881,19 +885,19 @@ test('Parse template with attribute values with delimited either single or doubl
|
|
|
881
885
|
const expected = {
|
|
882
886
|
children: [
|
|
883
887
|
{
|
|
884
|
-
|
|
888
|
+
[componentType]: 'Component',
|
|
885
889
|
children: [
|
|
886
890
|
{
|
|
887
|
-
|
|
891
|
+
[componentType]: 'Element',
|
|
888
892
|
w: '160',
|
|
889
893
|
h: '160',
|
|
890
894
|
x: '40',
|
|
891
895
|
y: '40',
|
|
892
|
-
color: '
|
|
896
|
+
color: '0xfb923cff',
|
|
893
897
|
':effects': '[$shader( "radius", {radius: 44} )]',
|
|
894
898
|
},
|
|
895
899
|
{
|
|
896
|
-
|
|
900
|
+
[componentType]: 'Element',
|
|
897
901
|
w: '120',
|
|
898
902
|
h: '120',
|
|
899
903
|
x: '100',
|
|
@@ -996,6 +1000,24 @@ test('Parse template with multiple unclosed tags and parsing should fail', (asse
|
|
|
996
1000
|
assert.end()
|
|
997
1001
|
})
|
|
998
1002
|
|
|
1003
|
+
test('Parse template with an unclosed tag and parsing should fail', (assert) => {
|
|
1004
|
+
const template = `
|
|
1005
|
+
<Component>
|
|
1006
|
+
`
|
|
1007
|
+
|
|
1008
|
+
try {
|
|
1009
|
+
parser(template)
|
|
1010
|
+
assert.fail('Parser should throw TemplateStructureError:UnclosedTags')
|
|
1011
|
+
} catch (error) {
|
|
1012
|
+
assert.equal(error.name, 'TemplateStructureError', 'Parser should throw TemplateStructureError')
|
|
1013
|
+
assert.ok(
|
|
1014
|
+
error.message.startsWith('UnclosedTags'),
|
|
1015
|
+
'Parser should throw TemplateStructureError:UnclosedTags'
|
|
1016
|
+
)
|
|
1017
|
+
}
|
|
1018
|
+
assert.end()
|
|
1019
|
+
})
|
|
1020
|
+
|
|
999
1021
|
test('Parse template with an invalid closing tag and parsing should fail', (assert) => {
|
|
1000
1022
|
const template = `
|
|
1001
1023
|
<Component>
|
|
@@ -1081,3 +1103,288 @@ test('Parse template with a closing tag that has attributes and parsing should f
|
|
|
1081
1103
|
|
|
1082
1104
|
assert.end()
|
|
1083
1105
|
})
|
|
1106
|
+
|
|
1107
|
+
test('Parse template with an invalid tag and parsing should fail', (assert) => {
|
|
1108
|
+
const template = `
|
|
1109
|
+
<@Element x="200" />
|
|
1110
|
+
`
|
|
1111
|
+
|
|
1112
|
+
try {
|
|
1113
|
+
parser(template)
|
|
1114
|
+
assert.fail('Parser should throw TemplateParseError:InvalidTag')
|
|
1115
|
+
} catch (error) {
|
|
1116
|
+
assert.equal(error.name, 'TemplateParseError', 'Parser should throw TemplateParseError')
|
|
1117
|
+
assert.ok(
|
|
1118
|
+
error.message.startsWith('InvalidTag'),
|
|
1119
|
+
'Parser should throw TemplateParseError:InvalidTag'
|
|
1120
|
+
)
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
assert.end()
|
|
1124
|
+
})
|
|
1125
|
+
|
|
1126
|
+
test('Parse template with an invalid attribute value and parsing should fail', (assert) => {
|
|
1127
|
+
const template = `
|
|
1128
|
+
<Element x=" />
|
|
1129
|
+
`
|
|
1130
|
+
|
|
1131
|
+
try {
|
|
1132
|
+
parser(template)
|
|
1133
|
+
assert.fail('Parser should throw TemplateParseError:MissingOrInvalidAttributeValue')
|
|
1134
|
+
} catch (error) {
|
|
1135
|
+
assert.equal(error.name, 'TemplateParseError', 'Parser should throw TemplateParseError')
|
|
1136
|
+
assert.ok(
|
|
1137
|
+
error.message.startsWith('MissingOrInvalidAttributeValue'),
|
|
1138
|
+
'Parser should throw TemplateParseError:MissingOrInvalidAttributeValue'
|
|
1139
|
+
)
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
assert.end()
|
|
1143
|
+
})
|
|
1144
|
+
|
|
1145
|
+
test('Parse template with an invalid attribute name and parsing should fail', (assert) => {
|
|
1146
|
+
const template = `
|
|
1147
|
+
<Element invalid^attribute="hello" />
|
|
1148
|
+
`
|
|
1149
|
+
|
|
1150
|
+
try {
|
|
1151
|
+
parser(template)
|
|
1152
|
+
assert.fail('Parser should throw TemplateParseError:InvalidAttribute')
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
assert.equal(error.name, 'TemplateParseError', 'Parser should throw TemplateParseError')
|
|
1155
|
+
assert.ok(
|
|
1156
|
+
error.message.startsWith('InvalidAttribute'),
|
|
1157
|
+
'Parser should throw TemplateParseError:InvalidAttribute'
|
|
1158
|
+
)
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
assert.end()
|
|
1162
|
+
})
|
|
1163
|
+
|
|
1164
|
+
test('Parse template with an invalid attribute name by providing parent component and parsing should fail', (assert) => {
|
|
1165
|
+
const template = `
|
|
1166
|
+
<Element invalid^attribute="hello" />
|
|
1167
|
+
`
|
|
1168
|
+
|
|
1169
|
+
try {
|
|
1170
|
+
parser(template, 'Item', {
|
|
1171
|
+
[componentType]: 'Section',
|
|
1172
|
+
parent: {
|
|
1173
|
+
[componentType]: 'List',
|
|
1174
|
+
parent: {
|
|
1175
|
+
[componentType]: 'Menu',
|
|
1176
|
+
parent: {
|
|
1177
|
+
[componentType]: 'Blits.App',
|
|
1178
|
+
},
|
|
1179
|
+
},
|
|
1180
|
+
},
|
|
1181
|
+
})
|
|
1182
|
+
assert.fail('Parser should throw TemplateParseError:InvalidAttribute')
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
assert.equal(error.name, 'TemplateParseError', 'Parser should throw TemplateParseError')
|
|
1185
|
+
assert.ok(
|
|
1186
|
+
error.message.startsWith('InvalidAttribute'),
|
|
1187
|
+
'Parser should throw TemplateParseError:InvalidAttribute'
|
|
1188
|
+
)
|
|
1189
|
+
assert.ok(
|
|
1190
|
+
error.message.includes('Blits.App/Menu/List/Section/Item'),
|
|
1191
|
+
'Error message should contain the component hierarchy'
|
|
1192
|
+
)
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
assert.end()
|
|
1196
|
+
})
|
|
1197
|
+
|
|
1198
|
+
test('Parse template with an invalid attribute name by providing parent component without component name and parsing should fail', (assert) => {
|
|
1199
|
+
const template = `
|
|
1200
|
+
<Element invalid^attribute="hello" />
|
|
1201
|
+
`
|
|
1202
|
+
|
|
1203
|
+
try {
|
|
1204
|
+
parser(template, null, {
|
|
1205
|
+
[componentType]: 'Section',
|
|
1206
|
+
parent: {
|
|
1207
|
+
[componentType]: 'List',
|
|
1208
|
+
parent: {
|
|
1209
|
+
[componentType]: 'Menu',
|
|
1210
|
+
parent: {
|
|
1211
|
+
[componentType]: 'Blits.App',
|
|
1212
|
+
},
|
|
1213
|
+
},
|
|
1214
|
+
},
|
|
1215
|
+
})
|
|
1216
|
+
assert.fail('Parser should throw TemplateParseError:InvalidAttribute')
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
assert.equal(error.name, 'TemplateParseError', 'Parser should throw TemplateParseError')
|
|
1219
|
+
assert.ok(
|
|
1220
|
+
error.message.startsWith('InvalidAttribute'),
|
|
1221
|
+
'Parser should throw TemplateParseError:InvalidAttribute'
|
|
1222
|
+
)
|
|
1223
|
+
assert.ok(
|
|
1224
|
+
error.message.includes('Blits.App/Menu/List/Section/'),
|
|
1225
|
+
'Error message should contain the component hierarchy without the component name'
|
|
1226
|
+
)
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
assert.end()
|
|
1230
|
+
})
|
|
1231
|
+
|
|
1232
|
+
test('Parse template with an invalid attribute name by providing component file path and parsing should fail', (assert) => {
|
|
1233
|
+
const template = `
|
|
1234
|
+
<Element invalid^attribute="hello" />
|
|
1235
|
+
`
|
|
1236
|
+
|
|
1237
|
+
try {
|
|
1238
|
+
parser(template, 'Item', null, 'src/components/Menu/List/Section/Item.js')
|
|
1239
|
+
assert.fail('Parser should throw TemplateParseError:InvalidAttribute')
|
|
1240
|
+
} catch (error) {
|
|
1241
|
+
assert.equal(error.name, 'TemplateParseError', 'Parser should throw TemplateParseError')
|
|
1242
|
+
assert.ok(
|
|
1243
|
+
error.message.startsWith('InvalidAttribute'),
|
|
1244
|
+
'Parser should throw TemplateParseError:InvalidAttribute'
|
|
1245
|
+
)
|
|
1246
|
+
assert.ok(
|
|
1247
|
+
error.message.includes('src/components/Menu/List/Section/Item.js'),
|
|
1248
|
+
'Error message should contain the component file path'
|
|
1249
|
+
)
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
assert.end()
|
|
1253
|
+
})
|
|
1254
|
+
|
|
1255
|
+
test('Parse template with color and effects attributes and parsing should convert color values', (assert) => {
|
|
1256
|
+
const template = `
|
|
1257
|
+
<Element :color="$backgroundColor">
|
|
1258
|
+
<Element color="{top: '#44037a', bottom: '#240244'}" />
|
|
1259
|
+
<Element color="#44037a" />
|
|
1260
|
+
<Element color="{top: '#44037a'}" :effects="[$shader('radius', {radius: $radius})]" />
|
|
1261
|
+
<Element :color="$colors.color2" :effects="[$shader('radius', {radius: $radius / 2})]" />
|
|
1262
|
+
<Element color="transparent" :effects="[$shader('radius', {radius: 10}), $shader('border', {width: 20, color: '#60a5fa'})]" />
|
|
1263
|
+
<Element color="#fba" />
|
|
1264
|
+
<Element color="#23dd21" />
|
|
1265
|
+
<Element color="#993322ff" />
|
|
1266
|
+
<Element color="ddd" />
|
|
1267
|
+
<Element color="ddffaa" />
|
|
1268
|
+
<Element color="ddffaa00" />
|
|
1269
|
+
<Element color="#E6E6E6" />
|
|
1270
|
+
<Element data="49b383f" color="#ddfa" />
|
|
1271
|
+
<Element color="rgba(255, 255, 255, 0.5)" />
|
|
1272
|
+
<Element color="hsl(120, 100%, 50%)" />
|
|
1273
|
+
<Element color="hsla(120, 100%, 50%, 0.5)" />
|
|
1274
|
+
<Element color="rgb(135, 206, 235)" />
|
|
1275
|
+
<Element color="rgba(135, 206, 235, -0.5)" />
|
|
1276
|
+
<Element color="rgba(222, 125, 44, 1.3)" />
|
|
1277
|
+
<Element color="0xccccccff" />
|
|
1278
|
+
<Element notColor="#dbbeee" />
|
|
1279
|
+
</Element>
|
|
1280
|
+
`
|
|
1281
|
+
|
|
1282
|
+
const expected = {
|
|
1283
|
+
children: [
|
|
1284
|
+
{
|
|
1285
|
+
':color': '$backgroundColor',
|
|
1286
|
+
[componentType]: 'Element',
|
|
1287
|
+
children: [
|
|
1288
|
+
{
|
|
1289
|
+
color: "{top: '0x44037aff', bottom: '0x240244ff'}",
|
|
1290
|
+
[componentType]: 'Element',
|
|
1291
|
+
},
|
|
1292
|
+
{
|
|
1293
|
+
color: '0x44037aff',
|
|
1294
|
+
[componentType]: 'Element',
|
|
1295
|
+
},
|
|
1296
|
+
{
|
|
1297
|
+
color: "{top: '0x44037aff'}",
|
|
1298
|
+
':effects': "[$shader('radius', {radius: $radius})]",
|
|
1299
|
+
[componentType]: 'Element',
|
|
1300
|
+
},
|
|
1301
|
+
{
|
|
1302
|
+
':color': '$colors.color2',
|
|
1303
|
+
':effects': "[$shader('radius', {radius: $radius / 2})]",
|
|
1304
|
+
[componentType]: 'Element',
|
|
1305
|
+
},
|
|
1306
|
+
{
|
|
1307
|
+
color: '0x00000000',
|
|
1308
|
+
':effects':
|
|
1309
|
+
"[$shader('radius', {radius: 10}), $shader('border', {width: 20, color: '0x60a5faff'})]",
|
|
1310
|
+
[componentType]: 'Element',
|
|
1311
|
+
},
|
|
1312
|
+
{
|
|
1313
|
+
color: '0xffbbaaff',
|
|
1314
|
+
[componentType]: 'Element',
|
|
1315
|
+
},
|
|
1316
|
+
{
|
|
1317
|
+
color: '0x23dd21ff',
|
|
1318
|
+
[componentType]: 'Element',
|
|
1319
|
+
},
|
|
1320
|
+
{
|
|
1321
|
+
color: '0x993322ff',
|
|
1322
|
+
[componentType]: 'Element',
|
|
1323
|
+
},
|
|
1324
|
+
{
|
|
1325
|
+
color: '0xddddddff',
|
|
1326
|
+
[componentType]: 'Element',
|
|
1327
|
+
},
|
|
1328
|
+
{
|
|
1329
|
+
color: '0xddffaaff',
|
|
1330
|
+
[componentType]: 'Element',
|
|
1331
|
+
},
|
|
1332
|
+
{
|
|
1333
|
+
color: '0xddffaa00',
|
|
1334
|
+
[componentType]: 'Element',
|
|
1335
|
+
},
|
|
1336
|
+
{
|
|
1337
|
+
color: '0xe6e6e6ff',
|
|
1338
|
+
[componentType]: 'Element',
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
data: '49b383f',
|
|
1342
|
+
color: '#ddfa',
|
|
1343
|
+
[componentType]: 'Element',
|
|
1344
|
+
},
|
|
1345
|
+
{
|
|
1346
|
+
color: '0xffffff80',
|
|
1347
|
+
[componentType]: 'Element',
|
|
1348
|
+
},
|
|
1349
|
+
{
|
|
1350
|
+
color: '0xffffffff',
|
|
1351
|
+
[componentType]: 'Element',
|
|
1352
|
+
},
|
|
1353
|
+
{
|
|
1354
|
+
color: '0xffffffff',
|
|
1355
|
+
[componentType]: 'Element',
|
|
1356
|
+
},
|
|
1357
|
+
{
|
|
1358
|
+
color: '0x87ceebff',
|
|
1359
|
+
[componentType]: 'Element',
|
|
1360
|
+
},
|
|
1361
|
+
{
|
|
1362
|
+
color: '0x87ceeb00',
|
|
1363
|
+
[componentType]: 'Element',
|
|
1364
|
+
},
|
|
1365
|
+
{
|
|
1366
|
+
color: '0xde7d2cff',
|
|
1367
|
+
[componentType]: 'Element',
|
|
1368
|
+
},
|
|
1369
|
+
{
|
|
1370
|
+
color: '0xccccccff',
|
|
1371
|
+
[componentType]: 'Element',
|
|
1372
|
+
},
|
|
1373
|
+
{
|
|
1374
|
+
notColor: '#dbbeee',
|
|
1375
|
+
[componentType]: 'Element',
|
|
1376
|
+
},
|
|
1377
|
+
],
|
|
1378
|
+
},
|
|
1379
|
+
],
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
const actual = parser(template)
|
|
1383
|
+
|
|
1384
|
+
assert.deepEqual(
|
|
1385
|
+
actual,
|
|
1386
|
+
expected,
|
|
1387
|
+
'Parser should return object representation of template with color values converted'
|
|
1388
|
+
)
|
|
1389
|
+
assert.end()
|
|
1390
|
+
})
|