@@ -86,10 +86,42 @@ namespace Sass {
86
86
87
87
std::ostream& operator <<(std::ostream& os, Compound_Selector& compoundSelector) {
88
88
To_String to_string;
89
- os << compoundSelector.perform (&to_string);
89
+ for (size_t i = 0 , L = compoundSelector.length (); i < L; ++i) {
90
+ if (i > 0 ) os << " , " ;
91
+ os << compoundSelector[i]->perform (&to_string);
92
+ }
93
+ return os;
94
+ }
95
+
96
+ std::ostream& operator <<(std::ostream& os, Simple_Selector& simpleSelector) {
97
+ To_String to_string;
98
+ os << simpleSelector.perform (&to_string);
90
99
return os;
91
100
}
92
101
102
+ // Print a string representation of a Compound_Selector
103
+ static void printSimpleSelector (Simple_Selector* pSimpleSelector, const char * message=NULL , bool newline=true ) {
104
+ To_String to_string;
105
+
106
+ if (message) {
107
+ std::cerr << message;
108
+ }
109
+
110
+ if (pSimpleSelector) {
111
+ std::cerr << " [" << *pSimpleSelector << " ]" ;
112
+ } else {
113
+ std::cerr << " NULL" ;
114
+ }
115
+
116
+ if (newline) {
117
+ std::cerr << std::endl;
118
+ }
119
+ }
120
+
121
+ // Print a string representation of a Compound_Selector
122
+ typedef std::pair<Compound_Selector*, Complex_Selector*> SelsNewSeqPair;
123
+ typedef std::vector<SelsNewSeqPair> SelsNewSeqPairCollection;
124
+
93
125
94
126
// Print a string representation of a Compound_Selector
95
127
static void printCompoundSelector (Compound_Selector* pCompoundSelector, const char * message=NULL , bool newline=true ) {
@@ -100,7 +132,7 @@ namespace Sass {
100
132
}
101
133
102
134
if (pCompoundSelector) {
103
- std::cerr << *pCompoundSelector;
135
+ std::cerr << " [ " << *pCompoundSelector << " ] " ;
104
136
} else {
105
137
std::cerr << " NULL" ;
106
138
}
@@ -164,6 +196,32 @@ namespace Sass {
164
196
}
165
197
}
166
198
199
+ static void printSelsNewSeqPairCollection (SelsNewSeqPairCollection& collection, const char * message=NULL , bool newline=true ) {
200
+ To_String to_string;
201
+
202
+ if (message) {
203
+ std::cerr << message;
204
+ }
205
+ bool first = true ;
206
+ std::cerr << " [" ;
207
+ for (SelsNewSeqPair& pair : collection) {
208
+ if (first) {
209
+ first = false ;
210
+ } else {
211
+ std::cerr << " , " ;
212
+ }
213
+ std::cerr << " [" ;
214
+ Compound_Selector* pSels = pair.first ;
215
+ Complex_Selector* pNewSelector = pair.second ;
216
+ std::cerr << " [" << *pSels << " ], " ;
217
+ printComplexSelector (pNewSelector, NULL , false );
218
+ }
219
+ std::cerr << " ]" ;
220
+
221
+ if (newline) {
222
+ std::cerr << std::endl;
223
+ }
224
+ }
167
225
168
226
// Print a string representation of a SourcesSet
169
227
static void printSourcesSet (SourcesSet& sources, Context& ctx, const char * message=NULL , bool newline=true ) {
@@ -525,8 +583,8 @@ namespace Sass {
525
583
unsigned long maxSpecificity = isReplace ? pSeq1->specificity () : 0 ;
526
584
SourcesSet sources = pSeq1->sources ();
527
585
528
- DEBUG_PRINTLN (TRIM, " TRIMASDF SEQ1: " << seq1)
529
- DEBUG_EXEC (TRIM, printSourcesSet (sources, ctx, " TRIMASDF SOURCES: " ))
586
+ DEBUG_PRINTLN (TRIM, " TRIM SEQ1: " << seq1)
587
+ DEBUG_EXEC (TRIM, printSourcesSet (sources, ctx, " TRIM SOURCES: " ))
530
588
531
589
for (SourcesSet::iterator sourcesSetIterator = sources.begin (), sourcesSetIteratorEnd = sources.end (); sourcesSetIterator != sourcesSetIteratorEnd; ++sourcesSetIterator) {
532
590
const Complex_Selector* const pCurrentSelector = *sourcesSetIterator;
@@ -1464,7 +1522,7 @@ namespace Sass {
1464
1522
Complex_Selector* pComplexSelector,
1465
1523
Context& ctx,
1466
1524
ExtensionSubsetMap& subset_map,
1467
- std::set<Compound_Selector> seen, bool isReplace);
1525
+ std::set<Compound_Selector> seen, bool isReplace, bool isOriginal );
1468
1526
1469
1527
1470
1528
@@ -1495,6 +1553,7 @@ namespace Sass {
1495
1553
std::set<Compound_Selector> seen, bool isReplace) {
1496
1554
1497
1555
DEBUG_EXEC (EXTEND_COMPOUND, printCompoundSelector (pSelector, " EXTEND COMPOUND: " ))
1556
+ // TODO: Ruby has another loop here to skip certain members?
1498
1557
1499
1558
Node extendedSelectors = Node::createCollection ();
1500
1559
// extendedSelectors.got_line_feed = true;
@@ -1541,6 +1600,7 @@ namespace Sass {
1541
1600
Compound_Selector* pExtCompoundSelector = pSels; // All the simple selectors to be replaced from the current compound selector from all extensions
1542
1601
1543
1602
// TODO: This can return a Compound_Selector with no elements. Should that just be returning NULL?
1603
+ // RUBY: self_without_sel = Sass::Util.array_minus(members, sels)
1544
1604
Compound_Selector* pSelectorWithoutExtendSelectors = pSelector->minus (pExtCompoundSelector, ctx);
1545
1605
1546
1606
DEBUG_EXEC (EXTEND_COMPOUND, printCompoundSelector (pSelector, " MEMBERS: " ))
@@ -1560,6 +1620,7 @@ namespace Sass {
1560
1620
DEBUG_EXEC (EXTEND_COMPOUND, printCompoundSelector (pSelectorWithoutExtendSelectors, " RHS: " ))
1561
1621
DEBUG_EXEC (EXTEND_COMPOUND, printCompoundSelector (pUnifiedSelector, " UNIFIED: " ))
1562
1622
1623
+ // RUBY: next unless unified
1563
1624
if (!pUnifiedSelector || pUnifiedSelector->length () == 0 ) {
1564
1625
continue ;
1565
1626
}
@@ -1603,6 +1664,7 @@ namespace Sass {
1603
1664
newSourcesSet.insert (pExtComplexSelector);
1604
1665
DEBUG_EXEC (EXTEND_COMPOUND, printSourcesSet (newSourcesSet, ctx, " SOURCES WITH NEW SOURCE: " ))
1605
1666
1667
+ // RUBY: new_seq.add_sources!(sources + [seq])
1606
1668
pNewSelector->addSources (newSourcesSet, ctx);
1607
1669
1608
1670
DEBUG_EXEC (EXTEND_COMPOUND, SourcesSet newSet = pNewSelector->sources (); printSourcesSet (newSet, ctx, " SOURCES ON NEW SELECTOR AFTER ADD: " ))
@@ -1622,6 +1684,7 @@ namespace Sass {
1622
1684
Complex_Selector* pNewSelector = pair.second ;
1623
1685
1624
1686
1687
+ // RUBY??: next [] if seen.include?(sels)
1625
1688
if (seen.find (*pSels) != seen.end ()) {
1626
1689
continue ;
1627
1690
}
@@ -1632,7 +1695,7 @@ namespace Sass {
1632
1695
1633
1696
1634
1697
DEBUG_PRINTLN (EXTEND_COMPOUND, " RECURSING DO EXTEND: " << complexSelectorToNode (pNewSelector, ctx))
1635
- Node recurseExtendedSelectors = extendComplexSelector (pNewSelector, ctx, subset_map, recurseSeen, isReplace);
1698
+ Node recurseExtendedSelectors = extendComplexSelector (pNewSelector, ctx, subset_map, recurseSeen, isReplace, false ); // !:isOriginal
1636
1699
1637
1700
DEBUG_PRINTLN (EXTEND_COMPOUND, " RECURSING DO EXTEND RETURN: " << recurseExtendedSelectors)
1638
1701
@@ -1743,19 +1806,24 @@ namespace Sass {
1743
1806
Complex_Selector* pComplexSelector,
1744
1807
Context& ctx,
1745
1808
ExtensionSubsetMap& subset_map,
1746
- std::set<Compound_Selector> seen, bool isReplace) {
1809
+ std::set<Compound_Selector> seen, bool isReplace, bool isOriginal ) {
1747
1810
1748
1811
Node complexSelector = complexSelectorToNode (pComplexSelector, ctx);
1749
1812
DEBUG_PRINTLN (EXTEND_COMPLEX, " EXTEND COMPLEX: " << complexSelector)
1750
1813
1751
1814
Node extendedNotExpanded = Node::createCollection ();
1752
1815
1753
- for (NodeDeque::iterator complexSelIter = complexSelector.collection ()->begin (), complexSelIterEnd = complexSelector.collection ()->end (); complexSelIter != complexSelIterEnd; ++complexSelIter) {
1816
+ for (NodeDeque::iterator complexSelIter = complexSelector.collection ()->begin (),
1817
+ complexSelIterEnd = complexSelector.collection ()->end ();
1818
+ complexSelIter != complexSelIterEnd; ++complexSelIter)
1819
+ {
1820
+
1754
1821
Node& sseqOrOp = *complexSelIter;
1755
1822
1756
1823
DEBUG_PRINTLN (EXTEND_COMPLEX, " LOOP: " << sseqOrOp)
1757
1824
1758
1825
// If it's not a selector (meaning it's a combinator), just include it automatically
1826
+ // RUBY: next [[sseq_or_op]] unless sseq_or_op.is_a?(SimpleSequence)
1759
1827
if (!sseqOrOp.isSelector ()) {
1760
1828
// Wrap our Combinator in two collections to match ruby. This is essentially making a collection Node
1761
1829
// with one collection child. The collection child represents a Complex_Selector that is only a combinator.
@@ -1769,6 +1837,7 @@ namespace Sass {
1769
1837
1770
1838
Compound_Selector* pCompoundSelector = sseqOrOp.selector ()->head ();
1771
1839
1840
+ // RUBY: extended = sseq_or_op.do_extend(extends, parent_directives, replace, seen)
1772
1841
Node extended = extendCompoundSelector (pCompoundSelector, ctx, subset_map, seen, isReplace);
1773
1842
if (sseqOrOp.got_line_feed ) extended.got_line_feed = true ;
1774
1843
DEBUG_PRINTLN (EXTEND_COMPLEX, " EXTENDED: " << extended)
@@ -1778,6 +1847,14 @@ namespace Sass {
1778
1847
// due to the member mapping: choices = extended.map {|seq| seq.members}
1779
1848
Complex_Selector* pJustCurrentCompoundSelector = sseqOrOp.selector ();
1780
1849
1850
+ // RUBY: extended.first.add_sources!([self]) if original && !has_placeholder?
1851
+ if (isOriginal && !pComplexSelector->has_placeholder ()) {
1852
+ SourcesSet srcset;
1853
+ srcset.insert (pComplexSelector);
1854
+ pJustCurrentCompoundSelector->addSources (srcset, ctx);
1855
+ DEBUG_PRINTLN (EXTEND_COMPLEX, " ADD SOURCES: " << *pComplexSelector)
1856
+ }
1857
+
1781
1858
bool isSuperselector = false ;
1782
1859
for (NodeDeque::iterator iterator = extended.collection ()->begin (), endIterator = extended.collection ()->end ();
1783
1860
iterator != endIterator; ++iterator) {
@@ -1874,7 +1951,7 @@ namespace Sass {
1874
1951
1875
1952
std::set<Compound_Selector> seen;
1876
1953
1877
- Node extendedSelectors = extendComplexSelector (pSelector, ctx, subset_map, seen, isReplace);
1954
+ Node extendedSelectors = extendComplexSelector (pSelector, ctx, subset_map, seen, isReplace, true );
1878
1955
if (!pSelector->has_placeholder ()) {
1879
1956
if (!extendedSelectors.contains (complexSelectorToNode (pSelector, ctx), true /* simpleSelectorOrderDependent*/ )) {
1880
1957
*pNewSelectors << pSelector;
0 commit comments