sassc 2.2.1 → 2.4.0

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.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +18 -0
  4. data/Rakefile +1 -3
  5. data/ext/extconf.rb +13 -5
  6. data/ext/libsass/VERSION +1 -1
  7. data/ext/libsass/include/sass/base.h +2 -1
  8. data/ext/libsass/include/sass/context.h +4 -0
  9. data/ext/libsass/src/MurmurHash2.hpp +91 -0
  10. data/ext/libsass/src/ast.cpp +158 -168
  11. data/ext/libsass/src/ast.hpp +389 -230
  12. data/ext/libsass/src/ast_def_macros.hpp +18 -10
  13. data/ext/libsass/src/ast_fwd_decl.cpp +4 -3
  14. data/ext/libsass/src/ast_fwd_decl.hpp +98 -165
  15. data/ext/libsass/src/ast_helpers.hpp +292 -0
  16. data/ext/libsass/src/ast_sel_cmp.cpp +219 -732
  17. data/ext/libsass/src/ast_sel_super.cpp +539 -0
  18. data/ext/libsass/src/ast_sel_unify.cpp +207 -212
  19. data/ext/libsass/src/ast_sel_weave.cpp +616 -0
  20. data/ext/libsass/src/ast_selectors.cpp +594 -1026
  21. data/ext/libsass/src/ast_selectors.hpp +339 -385
  22. data/ext/libsass/src/ast_supports.cpp +36 -52
  23. data/ext/libsass/src/ast_supports.hpp +29 -29
  24. data/ext/libsass/src/ast_values.cpp +271 -84
  25. data/ext/libsass/src/ast_values.hpp +116 -107
  26. data/ext/libsass/src/backtrace.cpp +9 -9
  27. data/ext/libsass/src/backtrace.hpp +5 -5
  28. data/ext/libsass/src/base64vlq.cpp +2 -2
  29. data/ext/libsass/src/base64vlq.hpp +1 -1
  30. data/ext/libsass/src/bind.cpp +18 -18
  31. data/ext/libsass/src/bind.hpp +1 -1
  32. data/ext/libsass/src/c2ast.cpp +3 -3
  33. data/ext/libsass/src/c2ast.hpp +1 -1
  34. data/ext/libsass/src/cencode.c +4 -6
  35. data/ext/libsass/src/check_nesting.cpp +40 -41
  36. data/ext/libsass/src/check_nesting.hpp +6 -2
  37. data/ext/libsass/src/color_maps.cpp +14 -13
  38. data/ext/libsass/src/color_maps.hpp +1 -9
  39. data/ext/libsass/src/constants.cpp +5 -0
  40. data/ext/libsass/src/constants.hpp +6 -0
  41. data/ext/libsass/src/context.cpp +92 -119
  42. data/ext/libsass/src/context.hpp +41 -53
  43. data/ext/libsass/src/cssize.cpp +66 -149
  44. data/ext/libsass/src/cssize.hpp +17 -23
  45. data/ext/libsass/src/dart_helpers.hpp +199 -0
  46. data/ext/libsass/src/debugger.hpp +451 -295
  47. data/ext/libsass/src/emitter.cpp +15 -16
  48. data/ext/libsass/src/emitter.hpp +10 -12
  49. data/ext/libsass/src/environment.cpp +27 -27
  50. data/ext/libsass/src/environment.hpp +29 -24
  51. data/ext/libsass/src/error_handling.cpp +62 -41
  52. data/ext/libsass/src/error_handling.hpp +61 -51
  53. data/ext/libsass/src/eval.cpp +167 -281
  54. data/ext/libsass/src/eval.hpp +27 -29
  55. data/ext/libsass/src/eval_selectors.cpp +75 -0
  56. data/ext/libsass/src/expand.cpp +275 -222
  57. data/ext/libsass/src/expand.hpp +36 -16
  58. data/ext/libsass/src/extender.cpp +1188 -0
  59. data/ext/libsass/src/extender.hpp +399 -0
  60. data/ext/libsass/src/extension.cpp +43 -0
  61. data/ext/libsass/src/extension.hpp +89 -0
  62. data/ext/libsass/src/file.cpp +81 -72
  63. data/ext/libsass/src/file.hpp +28 -37
  64. data/ext/libsass/src/fn_colors.cpp +20 -18
  65. data/ext/libsass/src/fn_lists.cpp +30 -29
  66. data/ext/libsass/src/fn_maps.cpp +3 -3
  67. data/ext/libsass/src/fn_miscs.cpp +34 -46
  68. data/ext/libsass/src/fn_numbers.cpp +20 -13
  69. data/ext/libsass/src/fn_selectors.cpp +98 -128
  70. data/ext/libsass/src/fn_strings.cpp +47 -33
  71. data/ext/libsass/src/fn_utils.cpp +31 -29
  72. data/ext/libsass/src/fn_utils.hpp +17 -11
  73. data/ext/libsass/src/inspect.cpp +186 -148
  74. data/ext/libsass/src/inspect.hpp +31 -29
  75. data/ext/libsass/src/lexer.cpp +20 -82
  76. data/ext/libsass/src/lexer.hpp +5 -16
  77. data/ext/libsass/src/listize.cpp +23 -37
  78. data/ext/libsass/src/listize.hpp +8 -9
  79. data/ext/libsass/src/mapping.hpp +1 -0
  80. data/ext/libsass/src/memory/allocator.cpp +48 -0
  81. data/ext/libsass/src/memory/allocator.hpp +138 -0
  82. data/ext/libsass/src/memory/config.hpp +20 -0
  83. data/ext/libsass/src/memory/memory_pool.hpp +186 -0
  84. data/ext/libsass/src/memory/{SharedPtr.cpp → shared_ptr.cpp} +2 -2
  85. data/ext/libsass/src/memory/{SharedPtr.hpp → shared_ptr.hpp} +55 -9
  86. data/ext/libsass/src/memory.hpp +12 -0
  87. data/ext/libsass/src/operation.hpp +71 -61
  88. data/ext/libsass/src/operators.cpp +19 -18
  89. data/ext/libsass/src/operators.hpp +11 -11
  90. data/ext/libsass/src/ordered_map.hpp +112 -0
  91. data/ext/libsass/src/output.cpp +45 -64
  92. data/ext/libsass/src/output.hpp +6 -6
  93. data/ext/libsass/src/parser.cpp +512 -700
  94. data/ext/libsass/src/parser.hpp +89 -97
  95. data/ext/libsass/src/parser_selectors.cpp +189 -0
  96. data/ext/libsass/src/permutate.hpp +164 -0
  97. data/ext/libsass/src/plugins.cpp +7 -7
  98. data/ext/libsass/src/plugins.hpp +8 -8
  99. data/ext/libsass/src/position.cpp +7 -26
  100. data/ext/libsass/src/position.hpp +44 -21
  101. data/ext/libsass/src/prelexer.cpp +6 -6
  102. data/ext/libsass/src/remove_placeholders.cpp +55 -56
  103. data/ext/libsass/src/remove_placeholders.hpp +21 -18
  104. data/ext/libsass/src/sass.cpp +16 -15
  105. data/ext/libsass/src/sass.hpp +10 -5
  106. data/ext/libsass/src/sass2scss.cpp +4 -4
  107. data/ext/libsass/src/sass_context.cpp +91 -122
  108. data/ext/libsass/src/sass_context.hpp +2 -2
  109. data/ext/libsass/src/sass_functions.cpp +1 -1
  110. data/ext/libsass/src/sass_values.cpp +8 -11
  111. data/ext/libsass/src/settings.hpp +19 -0
  112. data/ext/libsass/src/source.cpp +69 -0
  113. data/ext/libsass/src/source.hpp +95 -0
  114. data/ext/libsass/src/source_data.hpp +32 -0
  115. data/ext/libsass/src/source_map.cpp +22 -18
  116. data/ext/libsass/src/source_map.hpp +12 -9
  117. data/ext/libsass/src/stylesheet.cpp +22 -0
  118. data/ext/libsass/src/stylesheet.hpp +57 -0
  119. data/ext/libsass/src/to_value.cpp +2 -2
  120. data/ext/libsass/src/to_value.hpp +1 -1
  121. data/ext/libsass/src/units.cpp +24 -22
  122. data/ext/libsass/src/units.hpp +8 -8
  123. data/ext/libsass/src/utf8_string.cpp +9 -10
  124. data/ext/libsass/src/utf8_string.hpp +7 -6
  125. data/ext/libsass/src/util.cpp +48 -50
  126. data/ext/libsass/src/util.hpp +20 -21
  127. data/ext/libsass/src/util_string.cpp +111 -61
  128. data/ext/libsass/src/util_string.hpp +62 -8
  129. data/ext/libsass/src/values.cpp +12 -12
  130. data/lib/sassc/engine.rb +5 -3
  131. data/lib/sassc/functions_handler.rb +8 -8
  132. data/lib/sassc/native.rb +4 -6
  133. data/lib/sassc/script.rb +4 -4
  134. data/lib/sassc/version.rb +1 -1
  135. data/test/functions_test.rb +18 -1
  136. data/test/native_test.rb +4 -4
  137. metadata +29 -15
  138. data/ext/libsass/src/extend.cpp +0 -2132
  139. data/ext/libsass/src/extend.hpp +0 -86
  140. data/ext/libsass/src/node.cpp +0 -322
  141. data/ext/libsass/src/node.hpp +0 -118
  142. data/ext/libsass/src/paths.hpp +0 -71
  143. data/ext/libsass/src/sass_util.cpp +0 -152
  144. data/ext/libsass/src/sass_util.hpp +0 -256
  145. data/ext/libsass/src/subset_map.cpp +0 -58
  146. data/ext/libsass/src/subset_map.hpp +0 -76
  147. data/lib/sassc/native/lib_c.rb +0 -21
@@ -0,0 +1,399 @@
1
+ #ifndef SASS_EXTENDER_H
2
+ #define SASS_EXTENDER_H
3
+
4
+ #include <set>
5
+ #include <map>
6
+ #include <string>
7
+
8
+ #include "ast_helpers.hpp"
9
+ #include "ast_fwd_decl.hpp"
10
+ #include "operation.hpp"
11
+ #include "extension.hpp"
12
+ #include "backtrace.hpp"
13
+ #include "ordered_map.hpp"
14
+
15
+ namespace Sass {
16
+
17
+ // ##########################################################################
18
+ // Different hash map types used by extender
19
+ // ##########################################################################
20
+
21
+ // This is special (ptrs!)
22
+ typedef std::unordered_set<
23
+ ComplexSelectorObj,
24
+ ObjPtrHash,
25
+ ObjPtrEquality
26
+ > ExtCplxSelSet;
27
+
28
+ typedef std::unordered_set<
29
+ SimpleSelectorObj,
30
+ ObjHash,
31
+ ObjEquality
32
+ > ExtSmplSelSet;
33
+
34
+ typedef std::unordered_set<
35
+ SelectorListObj,
36
+ ObjPtrHash,
37
+ ObjPtrEquality
38
+ > ExtListSelSet;
39
+
40
+ typedef std::unordered_map<
41
+ SimpleSelectorObj,
42
+ ExtListSelSet,
43
+ ObjHash,
44
+ ObjEquality
45
+ > ExtSelMap;
46
+
47
+ typedef ordered_map<
48
+ ComplexSelectorObj,
49
+ Extension,
50
+ ObjHash,
51
+ ObjEquality
52
+ > ExtSelExtMapEntry;
53
+
54
+ typedef std::unordered_map<
55
+ SimpleSelectorObj,
56
+ ExtSelExtMapEntry,
57
+ ObjHash,
58
+ ObjEquality
59
+ > ExtSelExtMap;
60
+
61
+ typedef std::unordered_map <
62
+ SimpleSelectorObj,
63
+ sass::vector<
64
+ Extension
65
+ >,
66
+ ObjHash,
67
+ ObjEquality
68
+ > ExtByExtMap;
69
+
70
+ class Extender : public Operation_CRTP<void, Extender> {
71
+
72
+ public:
73
+
74
+ enum ExtendMode { TARGETS, REPLACE, NORMAL, };
75
+
76
+ private:
77
+
78
+ // ##########################################################################
79
+ // The mode that controls this extender's behavior.
80
+ // ##########################################################################
81
+ ExtendMode mode;
82
+
83
+ // ##########################################################################
84
+ // Shared backtraces with context and expander. Needed the throw
85
+ // errors when e.g. extending across media query boundaries.
86
+ // ##########################################################################
87
+ Backtraces& traces;
88
+
89
+ // ##########################################################################
90
+ // A map from all simple selectors in the stylesheet to the rules that
91
+ // contain them.This is used to find which rules an `@extend` applies to.
92
+ // ##########################################################################
93
+ ExtSelMap selectors;
94
+
95
+ // ##########################################################################
96
+ // A map from all extended simple selectors
97
+ // to the sources of those extensions.
98
+ // ##########################################################################
99
+ ExtSelExtMap extensions;
100
+
101
+ // ##########################################################################
102
+ // A map from all simple selectors in extenders to
103
+ // the extensions that those extenders define.
104
+ // ##########################################################################
105
+ ExtByExtMap extensionsByExtender;
106
+
107
+ // ##########################################################################
108
+ // A map from CSS rules to the media query contexts they're defined in.
109
+ // This tracks the contexts in which each style rule is defined.
110
+ // If a rule is defined at the top level, it doesn't have an entry.
111
+ // ##########################################################################
112
+ ordered_map<
113
+ SelectorListObj,
114
+ CssMediaRuleObj,
115
+ ObjPtrHash,
116
+ ObjPtrEquality
117
+ > mediaContexts;
118
+
119
+ // ##########################################################################
120
+ // A map from [SimpleSelector]s to the specificity of their source selectors.
121
+ // This tracks the maximum specificity of the [ComplexSelector] that originally
122
+ // contained each [SimpleSelector]. This allows us to ensure we don't trim any
123
+ // selectors that need to exist to satisfy the [second law that of extend][].
124
+ // [second law of extend]: https://github.com/sass/sass/issues/324#issuecomment-4607184
125
+ // ##########################################################################
126
+ std::unordered_map<
127
+ SimpleSelectorObj,
128
+ size_t,
129
+ ObjPtrHash,
130
+ ObjPtrEquality
131
+ > sourceSpecificity;
132
+
133
+ // ##########################################################################
134
+ // A set of [ComplexSelector]s that were originally part of their
135
+ // component [SelectorList]s, as opposed to being added by `@extend`.
136
+ // This allows us to ensure that we don't trim any selectors
137
+ // that need to exist to satisfy the [first law of extend][].
138
+ // ##########################################################################
139
+ ExtCplxSelSet originals;
140
+
141
+ public:
142
+
143
+ // Constructor without default [mode].
144
+ // [traces] are needed to throw errors.
145
+ Extender(Backtraces& traces);
146
+
147
+ // ##########################################################################
148
+ // Constructor with specific [mode].
149
+ // [traces] are needed to throw errors.
150
+ // ##########################################################################
151
+ Extender(ExtendMode mode, Backtraces& traces);
152
+
153
+ // ##########################################################################
154
+ // Empty desctructor
155
+ // ##########################################################################
156
+ ~Extender() {};
157
+
158
+ // ##########################################################################
159
+ // Extends [selector] with [source] extender and [targets] extendees.
160
+ // This works as though `source {@extend target}` were written in the
161
+ // stylesheet, with the exception that [target] can contain compound
162
+ // selectors which must be extended as a unit.
163
+ // ##########################################################################
164
+ static SelectorListObj extend(
165
+ SelectorListObj& selector,
166
+ const SelectorListObj& source,
167
+ const SelectorListObj& target,
168
+ Backtraces& traces);
169
+
170
+ // ##########################################################################
171
+ // Returns a copy of [selector] with [targets] replaced by [source].
172
+ // ##########################################################################
173
+ static SelectorListObj replace(
174
+ SelectorListObj& selector,
175
+ const SelectorListObj& source,
176
+ const SelectorListObj& target,
177
+ Backtraces& traces);
178
+
179
+ // ##########################################################################
180
+ // Adds [selector] to this extender, with [selectorSpan] as the span covering
181
+ // the selector and [ruleSpan] as the span covering the entire style rule.
182
+ // Extends [selector] using any registered extensions, then returns an empty
183
+ // [ModifiableCssStyleRule] with the resulting selector. If any more relevant
184
+ // extensions are added, the returned rule is automatically updated.
185
+ // The [mediaContext] is the media query context in which the selector was
186
+ // defined, or `null` if it was defined at the top level of the document.
187
+ // ##########################################################################
188
+ void addSelector(
189
+ const SelectorListObj& selector,
190
+ const CssMediaRuleObj& mediaContext);
191
+
192
+ // ##########################################################################
193
+ // Registers the [SimpleSelector]s in [list]
194
+ // to point to [rule] in [selectors].
195
+ // ##########################################################################
196
+ void registerSelector(
197
+ const SelectorListObj& list,
198
+ const SelectorListObj& rule);
199
+
200
+ // ##########################################################################
201
+ // Adds an extension to this extender. The [extender] is the selector for the
202
+ // style rule in which the extension is defined, and [target] is the selector
203
+ // passed to `@extend`. The [extend] provides the extend span and indicates
204
+ // whether the extension is optional. The [mediaContext] defines the media query
205
+ // context in which the extension is defined. It can only extend selectors
206
+ // within the same context. A `null` context indicates no media queries.
207
+ // ##########################################################################
208
+ void addExtension(
209
+ const SelectorListObj& extender,
210
+ const SimpleSelectorObj& target,
211
+ const CssMediaRuleObj& mediaQueryContext,
212
+ bool is_optional = false);
213
+
214
+ // ##########################################################################
215
+ // The set of all simple selectors in style rules handled
216
+ // by this extender. This includes simple selectors that
217
+ // were added because of downstream extensions.
218
+ // ##########################################################################
219
+ ExtSmplSelSet getSimpleSelectors() const;
220
+
221
+ // ##########################################################################
222
+ // Check for extends that have not been satisfied.
223
+ // Returns true if any non-optional extension did not
224
+ // extend any selector. Updates the passed reference
225
+ // to point to that Extension for further analysis.
226
+ // ##########################################################################
227
+ bool checkForUnsatisfiedExtends(
228
+ Extension& unsatisfied) const;
229
+
230
+ private:
231
+
232
+ // ##########################################################################
233
+ // A helper function for [extend] and [replace].
234
+ // ##########################################################################
235
+ static SelectorListObj extendOrReplace(
236
+ SelectorListObj& selector,
237
+ const SelectorListObj& source,
238
+ const SelectorListObj& target,
239
+ const ExtendMode mode,
240
+ Backtraces& traces);
241
+
242
+ // ##########################################################################
243
+ // Returns an extension that combines [left] and [right]. Throws
244
+ // a [SassException] if [left] and [right] have incompatible
245
+ // media contexts. Throws an [ArgumentError] if [left]
246
+ // and [right] don't have the same extender and target.
247
+ // ##########################################################################
248
+ static Extension mergeExtension(
249
+ const Extension& lhs,
250
+ const Extension& rhs);
251
+
252
+ // ##########################################################################
253
+ // Extend [extensions] using [newExtensions].
254
+ // ##########################################################################
255
+ // Note: dart-sass throws an error in here
256
+ // ##########################################################################
257
+ void extendExistingStyleRules(
258
+ const ExtListSelSet& rules,
259
+ const ExtSelExtMap& newExtensions);
260
+
261
+ // ##########################################################################
262
+ // Extend [extensions] using [newExtensions]. Note that this does duplicate
263
+ // some work done by [_extendExistingStyleRules], but it's necessary to
264
+ // expand each extension's extender separately without reference to the full
265
+ // selector list, so that relevant results don't get trimmed too early.
266
+ // Returns `null` (Note: empty map) if there are no extensions to add.
267
+ // ##########################################################################
268
+ ExtSelExtMap extendExistingExtensions(
269
+ // Taking in a reference here makes MSVC debug stuck!?
270
+ const sass::vector<Extension>& extensions,
271
+ const ExtSelExtMap& newExtensions);
272
+
273
+ // ##########################################################################
274
+ // Extends [list] using [extensions].
275
+ // ##########################################################################
276
+ SelectorListObj extendList(
277
+ const SelectorListObj& list,
278
+ const ExtSelExtMap& extensions,
279
+ const CssMediaRuleObj& mediaContext);
280
+
281
+ // ##########################################################################
282
+ // Extends [complex] using [extensions], and
283
+ // returns the contents of a [SelectorList].
284
+ // ##########################################################################
285
+ sass::vector<ComplexSelectorObj> extendComplex(
286
+ // Taking in a reference here makes MSVC debug stuck!?
287
+ const ComplexSelectorObj& list,
288
+ const ExtSelExtMap& extensions,
289
+ const CssMediaRuleObj& mediaQueryContext);
290
+
291
+ // ##########################################################################
292
+ // Returns a one-off [Extension] whose
293
+ // extender is composed solely of [simple].
294
+ // ##########################################################################
295
+ Extension extensionForSimple(
296
+ const SimpleSelectorObj& simple) const;
297
+
298
+ // ##########################################################################
299
+ // Returns a one-off [Extension] whose extender is composed
300
+ // solely of a compound selector containing [simples].
301
+ // ##########################################################################
302
+ Extension extensionForCompound(
303
+ // Taking in a reference here makes MSVC debug stuck!?
304
+ const sass::vector<SimpleSelectorObj>& simples) const;
305
+
306
+ // ##########################################################################
307
+ // Extends [compound] using [extensions], and returns the
308
+ // contents of a [SelectorList]. The [inOriginal] parameter
309
+ // indicates whether this is in an original complex selector,
310
+ // meaning that [compound] should not be trimmed out.
311
+ // ##########################################################################
312
+ sass::vector<ComplexSelectorObj> extendCompound(
313
+ const CompoundSelectorObj& compound,
314
+ const ExtSelExtMap& extensions,
315
+ const CssMediaRuleObj& mediaQueryContext,
316
+ bool inOriginal = false);
317
+
318
+ // ##########################################################################
319
+ // Extends [simple] without extending the
320
+ // contents of any selector pseudos it contains.
321
+ // ##########################################################################
322
+ sass::vector<Extension> extendWithoutPseudo(
323
+ const SimpleSelectorObj& simple,
324
+ const ExtSelExtMap& extensions,
325
+ ExtSmplSelSet* targetsUsed) const;
326
+
327
+ // ##########################################################################
328
+ // Extends [simple] and also extending the
329
+ // contents of any selector pseudos it contains.
330
+ // ##########################################################################
331
+ sass::vector<sass::vector<Extension>> extendSimple(
332
+ const SimpleSelectorObj& simple,
333
+ const ExtSelExtMap& extensions,
334
+ const CssMediaRuleObj& mediaQueryContext,
335
+ ExtSmplSelSet* targetsUsed);
336
+
337
+ // ##########################################################################
338
+ // Inner loop helper for [extendPseudo] function
339
+ // ##########################################################################
340
+ static sass::vector<ComplexSelectorObj> extendPseudoComplex(
341
+ const ComplexSelectorObj& complex,
342
+ const PseudoSelectorObj& pseudo,
343
+ const CssMediaRuleObj& mediaQueryContext);
344
+
345
+ // ##########################################################################
346
+ // Extends [pseudo] using [extensions], and returns
347
+ // a list of resulting pseudo selectors.
348
+ // ##########################################################################
349
+ sass::vector<PseudoSelectorObj> extendPseudo(
350
+ const PseudoSelectorObj& pseudo,
351
+ const ExtSelExtMap& extensions,
352
+ const CssMediaRuleObj& mediaQueryContext);
353
+
354
+ // ##########################################################################
355
+ // Rotates the element in list from [start] (inclusive) to [end] (exclusive)
356
+ // one index higher, looping the final element back to [start].
357
+ // ##########################################################################
358
+ static void rotateSlice(
359
+ sass::vector<ComplexSelectorObj>& list,
360
+ size_t start, size_t end);
361
+
362
+ // ##########################################################################
363
+ // Removes elements from [selectors] if they're subselectors of other
364
+ // elements. The [isOriginal] callback indicates which selectors are
365
+ // original to the document, and thus should never be trimmed.
366
+ // ##########################################################################
367
+ sass::vector<ComplexSelectorObj> trim(
368
+ const sass::vector<ComplexSelectorObj>& selectors,
369
+ const ExtCplxSelSet& set) const;
370
+
371
+ // ##########################################################################
372
+ // Returns the maximum specificity of the given [simple] source selector.
373
+ // ##########################################################################
374
+ size_t maxSourceSpecificity(const SimpleSelectorObj& simple) const;
375
+
376
+ // ##########################################################################
377
+ // Returns the maximum specificity for sources that went into producing [compound].
378
+ // ##########################################################################
379
+ size_t maxSourceSpecificity(const CompoundSelectorObj& compound) const;
380
+
381
+ // ##########################################################################
382
+ // Helper function used as callbacks on lists
383
+ // ##########################################################################
384
+ static bool dontTrimComplex(
385
+ const ComplexSelector* complex2,
386
+ const ComplexSelector* complex1,
387
+ const size_t maxSpecificity);
388
+
389
+ // ##########################################################################
390
+ // Helper function used as callbacks on lists
391
+ // ##########################################################################
392
+ static bool hasExactlyOne(const ComplexSelectorObj& vec);
393
+ static bool hasMoreThanOne(const ComplexSelectorObj& vec);
394
+
395
+ };
396
+
397
+ }
398
+
399
+ #endif
@@ -0,0 +1,43 @@
1
+ // sass.hpp must go before all system headers to get the
2
+ // __EXTENSIONS__ fix on Solaris.
3
+ #include "sass.hpp"
4
+
5
+ #include "ast_helpers.hpp"
6
+ #include "extension.hpp"
7
+ #include "ast.hpp"
8
+
9
+ namespace Sass {
10
+
11
+ // ##########################################################################
12
+ // Static function to create a copy with a new extender
13
+ // ##########################################################################
14
+ Extension Extension::withExtender(const ComplexSelectorObj& newExtender) const
15
+ {
16
+ Extension extension(newExtender);
17
+ extension.specificity = specificity;
18
+ extension.isOptional = isOptional;
19
+ extension.target = target;
20
+ return extension;
21
+ }
22
+
23
+ // ##########################################################################
24
+ // Asserts that the [mediaContext] for a selector is
25
+ // compatible with the query context for this extender.
26
+ // ##########################################################################
27
+ void Extension::assertCompatibleMediaContext(CssMediaRuleObj mediaQueryContext, Backtraces& traces) const
28
+ {
29
+
30
+ if (this->mediaContext.isNull()) return;
31
+
32
+ if (mediaQueryContext && ObjPtrEqualityFn(mediaContext->block(), mediaQueryContext->block())) return;
33
+
34
+ if (ObjEqualityFn<CssMediaRuleObj>(mediaQueryContext, mediaContext)) return;
35
+
36
+ throw Exception::ExtendAcrossMedia(traces, *this);
37
+
38
+ }
39
+
40
+ // ##########################################################################
41
+ // ##########################################################################
42
+
43
+ }
@@ -0,0 +1,89 @@
1
+ #ifndef SASS_EXTENSION_H
2
+ #define SASS_EXTENSION_H
3
+
4
+ // sass.hpp must go before all system headers to get the
5
+ // __EXTENSIONS__ fix on Solaris.
6
+ #include "sass.hpp"
7
+
8
+ #include <unordered_map>
9
+ #include <unordered_set>
10
+ #include "ast_fwd_decl.hpp"
11
+ #include "backtrace.hpp"
12
+
13
+ namespace Sass {
14
+
15
+ class Extension {
16
+
17
+ public:
18
+
19
+ // The selector in which the `@extend` appeared.
20
+ ComplexSelectorObj extender;
21
+
22
+ // The selector that's being extended.
23
+ // `null` for one-off extensions.
24
+ SimpleSelectorObj target;
25
+
26
+ // The minimum specificity required for any
27
+ // selector generated from this extender.
28
+ size_t specificity;
29
+
30
+ // Whether this extension is optional.
31
+ bool isOptional;
32
+
33
+ // Whether this is a one-off extender representing a selector that was
34
+ // originally in the document, rather than one defined with `@extend`.
35
+ bool isOriginal;
36
+
37
+ bool isSatisfied;
38
+
39
+ // The media query context to which this extend is restricted,
40
+ // or `null` if it can apply within any context.
41
+ CssMediaRuleObj mediaContext;
42
+
43
+ // Creates a one-off extension that's not intended to be modified over time.
44
+ // If [specificity] isn't passed, it defaults to `extender.maxSpecificity`.
45
+ Extension(ComplexSelectorObj extender) :
46
+ extender(extender),
47
+ target({}),
48
+ specificity(0),
49
+ isOptional(true),
50
+ isOriginal(false),
51
+ isSatisfied(false),
52
+ mediaContext({}) {
53
+
54
+ }
55
+
56
+ // Copy constructor
57
+ Extension(const Extension& extension) :
58
+ extender(extension.extender),
59
+ target(extension.target),
60
+ specificity(extension.specificity),
61
+ isOptional(extension.isOptional),
62
+ isOriginal(extension.isOriginal),
63
+ isSatisfied(extension.isSatisfied),
64
+ mediaContext(extension.mediaContext) {
65
+
66
+ }
67
+
68
+ // Default constructor
69
+ Extension() :
70
+ extender({}),
71
+ target({}),
72
+ specificity(0),
73
+ isOptional(false),
74
+ isOriginal(false),
75
+ isSatisfied(false),
76
+ mediaContext({}) {
77
+ }
78
+
79
+ // Asserts that the [mediaContext] for a selector is
80
+ // compatible with the query context for this extender.
81
+ void assertCompatibleMediaContext(CssMediaRuleObj mediaContext, Backtraces& traces) const;
82
+
83
+ Extension withExtender(const ComplexSelectorObj& newExtender) const;
84
+
85
+ };
86
+
87
+ }
88
+
89
+ #endif