File tree Expand file tree Collapse file tree 2 files changed +133
-0
lines changed Expand file tree Collapse file tree 2 files changed +133
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,22 @@ module.exports = function(input) {
104
104
pos = next + 2 ;
105
105
code = value . charCodeAt ( pos ) ;
106
106
107
+ // Operation within calc
108
+ } else if (
109
+ ( code === slash || code === star ) &&
110
+ parent &&
111
+ parent . type === "function" &&
112
+ parent . value === "calc"
113
+ ) {
114
+ token = value [ pos ] ;
115
+ tokens . push ( {
116
+ type : "word" ,
117
+ sourceIndex : pos - before . length ,
118
+ value : token
119
+ } ) ;
120
+ pos += 1 ;
121
+ code = value . charCodeAt ( pos ) ;
122
+
107
123
// Dividers
108
124
} else if ( code === slash || code === comma || code === colon ) {
109
125
token = value [ pos ] ;
@@ -224,6 +240,13 @@ module.exports = function(input) {
224
240
code === colon ||
225
241
code === slash ||
226
242
code === openParentheses ||
243
+ ( code === star &&
244
+ parent &&
245
+ parent . type === "function" &&
246
+ parent . value === "calc" ) ||
247
+ ( code === slash &&
248
+ parent . type === "function" &&
249
+ parent . value === "calc" ) ||
227
250
( code === closeParentheses && balanced )
228
251
)
229
252
) ;
Original file line number Diff line number Diff line change @@ -452,6 +452,116 @@ var tests = [
452
452
}
453
453
]
454
454
} ,
455
+ {
456
+ message : "should correctly parse spaces" ,
457
+ fixture : "calc(1 + 2)" ,
458
+ expected : [
459
+ {
460
+ type : "function" ,
461
+ sourceIndex : 0 ,
462
+ value : "calc" ,
463
+ before : "" ,
464
+ after : "" ,
465
+ nodes : [
466
+ {
467
+ type : "word" ,
468
+ sourceIndex : 5 ,
469
+ value : "1"
470
+ } ,
471
+ {
472
+ type : "space" ,
473
+ sourceIndex : 6 ,
474
+ value : " "
475
+ } ,
476
+ {
477
+ type : "word" ,
478
+ sourceIndex : 7 ,
479
+ value : "+"
480
+ } ,
481
+ {
482
+ type : "space" ,
483
+ sourceIndex : 8 ,
484
+ value : " "
485
+ } ,
486
+ {
487
+ type : "word" ,
488
+ sourceIndex : 9 ,
489
+ value : "2"
490
+ }
491
+ ]
492
+ }
493
+ ]
494
+ } ,
495
+ {
496
+ message : "should correctly parse multiplication with spaces" ,
497
+ fixture : "calc(1 * 2)" ,
498
+ expected : [
499
+ {
500
+ type : "function" ,
501
+ sourceIndex : 0 ,
502
+ value : "calc" ,
503
+ before : "" ,
504
+ after : "" ,
505
+ nodes : [
506
+ {
507
+ type : "word" ,
508
+ sourceIndex : 5 ,
509
+ value : "1"
510
+ } ,
511
+ {
512
+ type : "space" ,
513
+ sourceIndex : 6 ,
514
+ value : " "
515
+ } ,
516
+ {
517
+ type : "word" ,
518
+ sourceIndex : 7 ,
519
+ value : "*"
520
+ } ,
521
+ {
522
+ type : "space" ,
523
+ sourceIndex : 8 ,
524
+ value : " "
525
+ } ,
526
+ {
527
+ type : "word" ,
528
+ sourceIndex : 9 ,
529
+ value : "2"
530
+ }
531
+ ]
532
+ }
533
+ ]
534
+ } ,
535
+ {
536
+ message : "should correctly parse multiplication without spaces" ,
537
+ fixture : "calc(1*2)" ,
538
+ expected : [
539
+ {
540
+ type : "function" ,
541
+ sourceIndex : 0 ,
542
+ value : "calc" ,
543
+ before : "" ,
544
+ after : "" ,
545
+ nodes : [
546
+ {
547
+ type : "word" ,
548
+ sourceIndex : 5 ,
549
+ value : "1"
550
+ } ,
551
+ {
552
+ type : "word" ,
553
+ sourceIndex : 6 ,
554
+ value : "*"
555
+ } ,
556
+ {
557
+ type : "word" ,
558
+ sourceIndex : 7 ,
559
+ value : "2"
560
+ }
561
+ ]
562
+ }
563
+ ]
564
+ } ,
455
565
{
456
566
message : "should correctly process nested calc functions" ,
457
567
fixture : "calc(((768px - 100vw) / 2) - 15px)" ,
You can’t perform that action at this time.
0 commit comments