File tree Expand file tree Collapse file tree 2 files changed +114
-1
lines changed Expand file tree Collapse file tree 2 files changed +114
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,10 @@ module.exports = function(input) {
5353 } else if (
5454 code === comma ||
5555 code === colon ||
56- ( code === slash && value . charCodeAt ( next + 1 ) !== star )
56+ ( code === slash &&
57+ value . charCodeAt ( next + 1 ) !== star &&
58+ ( ! parent ||
59+ ( parent && parent . type === "function" && parent . value !== "calc" ) ) )
5760 ) {
5861 before = token ;
5962 } else {
Original file line number Diff line number Diff line change @@ -492,6 +492,46 @@ var tests = [
492492 }
493493 ]
494494 } ,
495+ {
496+ message : "should correctly parse subtraction 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+ } ,
495535 {
496536 message : "should correctly parse multiplication with spaces" ,
497537 fixture : "calc(1 * 2)" ,
@@ -532,6 +572,46 @@ var tests = [
532572 }
533573 ]
534574 } ,
575+ {
576+ message : "should correctly parse division with spaces" ,
577+ fixture : "calc(1 / 2)" ,
578+ expected : [
579+ {
580+ type : "function" ,
581+ sourceIndex : 0 ,
582+ value : "calc" ,
583+ before : "" ,
584+ after : "" ,
585+ nodes : [
586+ {
587+ type : "word" ,
588+ sourceIndex : 5 ,
589+ value : "1"
590+ } ,
591+ {
592+ type : "space" ,
593+ sourceIndex : 6 ,
594+ value : " "
595+ } ,
596+ {
597+ type : "word" ,
598+ sourceIndex : 7 ,
599+ value : "/"
600+ } ,
601+ {
602+ type : "space" ,
603+ sourceIndex : 8 ,
604+ value : " "
605+ } ,
606+ {
607+ type : "word" ,
608+ sourceIndex : 9 ,
609+ value : "2"
610+ }
611+ ]
612+ }
613+ ]
614+ } ,
535615 {
536616 message : "should correctly parse multiplication without spaces" ,
537617 fixture : "calc(1*2)" ,
@@ -562,6 +642,36 @@ var tests = [
562642 }
563643 ]
564644 } ,
645+ {
646+ message : "should correctly parse division without spaces" ,
647+ fixture : "calc(1/2)" ,
648+ expected : [
649+ {
650+ type : "function" ,
651+ sourceIndex : 0 ,
652+ value : "calc" ,
653+ before : "" ,
654+ after : "" ,
655+ nodes : [
656+ {
657+ type : "word" ,
658+ sourceIndex : 5 ,
659+ value : "1"
660+ } ,
661+ {
662+ type : "word" ,
663+ sourceIndex : 6 ,
664+ value : "/"
665+ } ,
666+ {
667+ type : "word" ,
668+ sourceIndex : 7 ,
669+ value : "2"
670+ }
671+ ]
672+ }
673+ ]
674+ } ,
565675 {
566676 message : "should correctly process nested calc functions" ,
567677 fixture : "calc(((768px - 100vw) / 2) - 15px)" ,
You can’t perform that action at this time.
0 commit comments