@@ -466,6 +466,7 @@ protected function matchExtends($selector, &$out, $from = 0, $initial = true)
466
466
467
467
for ($ l = count ($ tempReplacement ) - 1 ; $ l >= 0 ; $ l --) {
468
468
$ slice = [];
469
+
469
470
foreach ($ tempReplacement [$ l ] as $ chunk ) {
470
471
if (!in_array ($ chunk , $ slice )) {
471
472
$ slice [] = $ chunk ;
@@ -610,7 +611,6 @@ protected function matchExtendsSingle($rawSingle, &$outOrigin)
610
611
return $ found ;
611
612
}
612
613
613
-
614
614
/**
615
615
* Extract a relationship from the fragment.
616
616
*
@@ -620,6 +620,7 @@ protected function matchExtendsSingle($rawSingle, &$outOrigin)
620
620
* the rest.
621
621
*
622
622
* @param array $fragment The selector fragment maybe ending with a direction relationship combinator.
623
+ *
623
624
* @return array The selector without the relationship fragment if any, the relationship fragment.
624
625
*/
625
626
protected function extractRelationshipFromFragment (array $ fragment )
@@ -804,6 +805,7 @@ protected function compileAtRoot(Block $block)
804
805
}
805
806
806
807
$ selfParent = $ block ->selfParent ;
808
+
807
809
if (! $ block ->selfParent ->selectors && isset ($ block ->parent ) && $ block ->parent && isset ($ block ->parent ->selectors ) && $ block ->parent ->selectors ) {
808
810
$ selfParent = $ block ->parent ;
809
811
}
@@ -825,8 +827,10 @@ protected function compileAtRoot(Block $block)
825
827
826
828
/**
827
829
* Filter at-root scope depending of with/without option
828
- * @param $scope
829
- * @param $without
830
+ *
831
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $scope
832
+ * @param mixed $without
833
+ *
830
834
* @return mixed
831
835
*/
832
836
protected function filterScopeWithout ($ scope , $ without )
@@ -846,14 +850,17 @@ protected function filterScopeWithout($scope, $without)
846
850
if (! $ scope ) {
847
851
break ;
848
852
}
853
+
849
854
if (! $ this ->isWithout ($ without , $ scope )) {
850
855
$ s = clone $ scope ;
851
856
$ s ->children = [];
852
857
$ s ->lines = [];
853
858
$ s ->parent = null ;
859
+
854
860
if ($ s ->type !== Type::T_MEDIA && $ s ->type !== Type::T_DIRECTIVE ) {
855
861
$ s ->selectors = [];
856
862
}
863
+
857
864
$ filteredScopes [] = $ s ;
858
865
}
859
866
@@ -863,15 +870,18 @@ protected function filterScopeWithout($scope, $without)
863
870
$ scope = null ;
864
871
}
865
872
}
873
+
866
874
if (!count ($ filteredScopes )) {
867
875
return $ this ->rootBlock ;
868
876
}
869
877
870
878
$ newScope = array_shift ($ filteredScopes );
871
879
$ newScope ->parent = $ this ->rootBlock ;
880
+
872
881
$ this ->rootBlock ->children [] = $ newScope ;
873
882
874
883
$ p = &$ newScope ;
884
+
875
885
while (count ($ filteredScopes )) {
876
886
$ s = array_shift ($ filteredScopes );
877
887
$ s ->parent = $ p ;
@@ -885,15 +895,18 @@ protected function filterScopeWithout($scope, $without)
885
895
/**
886
896
* found missing selector from a at-root compilation in the previous scope
887
897
* (if at-root is just enclosing a property, the selector is in the parent tree)
888
- * @param $scope
889
- * @param $previousScope
898
+ *
899
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $scope
900
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $previousScope
901
+ *
890
902
* @return mixed
891
903
*/
892
904
protected function completeScope ($ scope , $ previousScope )
893
905
{
894
906
if (! $ scope ->type && (! $ scope ->selectors || ! count ($ scope ->selectors )) && count ($ scope ->lines )) {
895
907
$ scope ->selectors = $ this ->findScopeSelectors ($ previousScope , $ scope ->depth );
896
908
}
909
+
897
910
if ($ scope ->children ) {
898
911
foreach ($ scope ->children as $ k => $ c ) {
899
912
$ scope ->children [$ k ] = $ this ->completeScope ($ c , $ previousScope );
@@ -905,22 +918,26 @@ protected function completeScope($scope, $previousScope)
905
918
906
919
/**
907
920
* Find a selector by the depth node in the scope
908
- * @param $scope
909
- * @param $depth
921
+ *
922
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $scope
923
+ * @param integer $depth
924
+ *
910
925
* @return array
911
926
*/
912
927
protected function findScopeSelectors ($ scope , $ depth )
913
928
{
914
929
if ($ scope ->depth === $ depth && $ scope ->selectors ) {
915
930
return $ scope ->selectors ;
916
931
}
932
+
917
933
if ($ scope ->children ) {
918
934
foreach (array_reverse ($ scope ->children ) as $ c ) {
919
935
if ($ s = $ this ->findScopeSelectors ($ c , $ depth )) {
920
936
return $ s ;
921
937
}
922
938
}
923
939
}
940
+
924
941
return [];
925
942
}
926
943
@@ -1016,11 +1033,13 @@ protected function isWithout($without, $block)
1016
1033
if (isset ($ block ->name ) && $ block ->name === 'supports ' ) {
1017
1034
return ($ without & static ::WITH_SUPPORTS ) ? true : false ;
1018
1035
}
1036
+
1019
1037
if (isset ($ block ->selectors ) && strpos (serialize ($ block ->selectors ), '@supports ' ) !== false ) {
1020
1038
return ($ without & static ::WITH_SUPPORTS ) ? true : false ;
1021
1039
}
1022
1040
}
1023
1041
}
1042
+
1024
1043
if ((($ without & static ::WITH_RULE ) && isset ($ block ->selectors ))) {
1025
1044
return true ;
1026
1045
}
@@ -1147,13 +1166,17 @@ protected function compileBlock(Block $block)
1147
1166
1148
1167
if (count ($ block ->children )) {
1149
1168
$ out ->selectors = $ this ->multiplySelectors ($ env , $ block ->selfParent );
1169
+
1150
1170
// propagate selfParent to the children where they still can be useful
1151
1171
$ selfParentSelectors = null ;
1172
+
1152
1173
if (isset ($ block ->selfParent ->selectors )) {
1153
1174
$ selfParentSelectors = $ block ->selfParent ->selectors ;
1154
1175
$ block ->selfParent ->selectors = $ out ->selectors ;
1155
1176
}
1177
+
1156
1178
$ this ->compileChildrenNoReturn ($ block ->children , $ out , $ block ->selfParent );
1179
+
1157
1180
// and revert for the following childs of the same block
1158
1181
if ($ selfParentSelectors ) {
1159
1182
$ block ->selfParent ->selectors = $ selfParentSelectors ;
@@ -1174,6 +1197,7 @@ protected function compileComment($block)
1174
1197
{
1175
1198
$ out = $ this ->makeOutputBlock (Type::T_COMMENT );
1176
1199
$ out ->lines [] = $ block [1 ];
1200
+
1177
1201
$ this ->scope ->children [] = $ out ;
1178
1202
}
1179
1203
@@ -1406,6 +1430,7 @@ protected function compileChildren($stms, OutputBlock $out)
1406
1430
return $ ret ;
1407
1431
}
1408
1432
}
1433
+
1409
1434
return null ;
1410
1435
}
1411
1436
@@ -1420,14 +1445,12 @@ protected function compileChildren($stms, OutputBlock $out)
1420
1445
*/
1421
1446
protected function compileChildrenNoReturn ($ stms , OutputBlock $ out , $ selfParent = null )
1422
1447
{
1423
-
1424
1448
foreach ($ stms as $ stm ) {
1425
1449
if ($ selfParent && isset ($ stm [1 ]) && is_object ($ stm [1 ]) && get_class ($ stm [1 ]) == 'Leafo\ScssPhp\Block ' ) {
1426
1450
$ stm [1 ]->selfParent = $ selfParent ;
1427
1451
$ ret = $ this ->compileChild ($ stm , $ out );
1428
1452
$ stm [1 ]->selfParent = null ;
1429
- }
1430
- elseif ($ selfParent && $ stm [0 ] === TYPE ::T_INCLUDE ) {
1453
+ } elseif ($ selfParent && $ stm [0 ] === TYPE ::T_INCLUDE ) {
1431
1454
$ stm ['selfParent ' ] = $ selfParent ;
1432
1455
$ ret = $ this ->compileChild ($ stm , $ out );
1433
1456
unset($ stm ['selfParent ' ]);
@@ -1681,6 +1704,7 @@ protected function compileChild($child, OutputBlock $out)
1681
1704
} elseif (! empty ($ out ->sourceLine ) and ! empty ($ out ->sourceName )) {
1682
1705
$ this ->sourceLine = $ out ->sourceLine ;
1683
1706
$ this ->sourceIndex = array_search ($ out ->sourceName , $ this ->sourceNames );
1707
+
1684
1708
if ($ this ->sourceIndex === false ) {
1685
1709
$ this ->sourceIndex = null ;
1686
1710
}
@@ -1761,6 +1785,7 @@ protected function compileChild($child, OutputBlock $out)
1761
1785
}
1762
1786
1763
1787
$ fontValue =&$ value ;
1788
+
1764
1789
if ($ value [0 ] === Type::T_LIST && $ value [1 ]==', ' ) {
1765
1790
// this is the case if more than one font is given: example: "font: 400 1em/1.3 arial,helvetica"
1766
1791
// we need to handle the first list element
@@ -1992,14 +2017,16 @@ protected function compileChild($child, OutputBlock $out)
1992
2017
// Find the parent selectors in the env to be able to know what '&' refers to in the mixin
1993
2018
// and assign this fake parent to childs
1994
2019
$ selfParent = null ;
2020
+
1995
2021
if (isset ($ child ['selfParent ' ]) && isset ($ child ['selfParent ' ]->selectors )) {
1996
2022
$ selfParent = $ child ['selfParent ' ];
1997
- }
1998
- else {
2023
+ } else {
1999
2024
$ parentSelectors = $ this ->multiplySelectors ($ this ->env );
2025
+
2000
2026
if ($ parentSelectors ) {
2001
2027
$ parent = new Block ();
2002
2028
$ parent ->selectors = $ parentSelectors ;
2029
+
2003
2030
foreach ($ mixin ->children as $ k => $ child ) {
2004
2031
if (isset ($ child [1 ]) && is_object ($ child [1 ]) && get_class ($ child [1 ]) == 'Leafo\ScssPhp\Block ' ) {
2005
2032
$ mixin ->children [$ k ][1 ]->parent = $ parent ;
@@ -2344,6 +2371,7 @@ protected function reduce($value, $inExp = false)
2344
2371
case Type::T_SELF :
2345
2372
$ selfSelector = $ this ->multiplySelectors ($ this ->env );
2346
2373
$ selfSelector = $ this ->collapseSelectors ($ selfSelector );
2374
+
2347
2375
return [Type::T_STRING , '' , [$ selfSelector ]];
2348
2376
2349
2377
default :
@@ -2532,6 +2560,7 @@ protected function opAdd($left, $right)
2532
2560
2533
2561
return $ strRight ;
2534
2562
}
2563
+
2535
2564
return null ;
2536
2565
}
2537
2566
@@ -3049,6 +3078,7 @@ protected function multiplySelectors(Environment $env, $selfParent = null)
3049
3078
$ parentSelectors = [[]];
3050
3079
3051
3080
$ selfParentSelectors = null ;
3081
+
3052
3082
if (!is_null ($ selfParent ) and $ selfParent ->selectors ) {
3053
3083
$ selfParentSelectors = $ this ->evalSelectors ($ selfParent ->selectors );
3054
3084
}
@@ -3064,12 +3094,15 @@ protected function multiplySelectors(Environment $env, $selfParent = null)
3064
3094
foreach ($ parentSelectors as $ parent ) {
3065
3095
if ($ selfParentSelectors ) {
3066
3096
$ previous = null ;
3097
+
3067
3098
foreach ($ selfParentSelectors as $ selfParent ) {
3068
3099
// if no '&' in the selector, each call will give same result, only add once
3069
3100
$ s = $ this ->joinSelectors ($ parent , $ selector , $ selfParent );
3101
+
3070
3102
if ($ s !== $ previous ) {
3071
3103
$ selectors [serialize ($ s )] = $ s ;
3072
3104
}
3105
+
3073
3106
$ previous = $ s ;
3074
3107
}
3075
3108
} else {
@@ -3083,6 +3116,7 @@ protected function multiplySelectors(Environment $env, $selfParent = null)
3083
3116
}
3084
3117
3085
3118
$ selectors = array_values ($ selectors );
3119
+
3086
3120
return $ selectors ;
3087
3121
}
3088
3122
@@ -3092,6 +3126,7 @@ protected function multiplySelectors(Environment $env, $selfParent = null)
3092
3126
* @param array $parent
3093
3127
* @param array $child
3094
3128
* @param array $selfParentSelectors
3129
+
3095
3130
* @return array
3096
3131
*/
3097
3132
protected function joinSelectors ($ parent , $ child , $ selfParentSelectors = null )
@@ -3105,9 +3140,11 @@ protected function joinSelectors($parent, $child, $selfParentSelectors = null)
3105
3140
foreach ($ part as $ p ) {
3106
3141
if ($ p === static ::$ selfSelector ) {
3107
3142
$ setSelf = true ;
3143
+
3108
3144
if (is_null ($ selfParentSelectors )) {
3109
3145
$ selfParentSelectors = $ parent ;
3110
3146
}
3147
+
3111
3148
foreach ($ selfParentSelectors as $ i => $ parentPart ) {
3112
3149
if ($ i > 0 ) {
3113
3150
$ out [] = $ newPart ;
@@ -3305,6 +3342,7 @@ protected function setExisting($name, $value, Environment $env, $valueUnreduced
3305
3342
}
3306
3343
3307
3344
$ env ->store [$ name ] = $ value ;
3345
+
3308
3346
if ($ valueUnreduced ) {
3309
3347
$ env ->storeUnreduced [$ name ] = $ valueUnreduced ;
3310
3348
}
@@ -3321,6 +3359,7 @@ protected function setExisting($name, $value, Environment $env, $valueUnreduced
3321
3359
protected function setRaw ($ name , $ value , Environment $ env , $ valueUnreduced = null )
3322
3360
{
3323
3361
$ env ->store [$ name ] = $ value ;
3362
+
3324
3363
if ($ valueUnreduced ) {
3325
3364
$ env ->storeUnreduced [$ name ] = $ valueUnreduced ;
3326
3365
}
@@ -3355,6 +3394,7 @@ public function get($name, $shouldThrow = true, Environment $env = null, $unredu
3355
3394
if ($ unreduced && isset ($ env ->storeUnreduced [$ normalizedName ])) {
3356
3395
return $ env ->storeUnreduced [$ normalizedName ];
3357
3396
}
3397
+
3358
3398
return $ env ->store [$ normalizedName ];
3359
3399
}
3360
3400
@@ -3712,6 +3752,7 @@ public function setEncoding($encoding)
3712
3752
public function setIgnoreErrors ($ ignoreErrors )
3713
3753
{
3714
3754
$ this ->ignoreErrors = $ ignoreErrors ;
3755
+
3715
3756
return $ this ;
3716
3757
}
3717
3758
@@ -3737,9 +3778,11 @@ public function throwError($msg)
3737
3778
$ line = $ this ->sourceLine ;
3738
3779
$ loc = isset ($ this ->sourceNames [$ this ->sourceIndex ]) ? $ this ->sourceNames [$ this ->sourceIndex ] . " on line $ line " : "line: $ line " ;
3739
3780
$ msg = "$ msg: $ loc " ;
3781
+
3740
3782
if ($ this ->callStack ) {
3741
3783
$ msg .= "\nCall Stack: \n" ;
3742
3784
$ ncall = 0 ;
3785
+
3743
3786
foreach (array_reverse ($ this ->callStack ) as $ call ) {
3744
3787
$ msg .= "# " . $ ncall ++ . " " . $ call ['n ' ] . " " ;
3745
3788
$ msg .= (isset ($ this ->sourceNames [$ call [Parser::SOURCE_INDEX ]]) ? $ this ->sourceNames [$ call [Parser::SOURCE_INDEX ]] : '(unknown file) ' );
0 commit comments