sassc 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +13 -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 +1 -0
  9. data/ext/libsass/src/ast.cpp +49 -59
  10. data/ext/libsass/src/ast.hpp +263 -102
  11. data/ext/libsass/src/ast_def_macros.hpp +8 -0
  12. data/ext/libsass/src/ast_fwd_decl.cpp +2 -1
  13. data/ext/libsass/src/ast_fwd_decl.hpp +40 -116
  14. data/ext/libsass/src/ast_helpers.hpp +292 -0
  15. data/ext/libsass/src/ast_sel_cmp.cpp +209 -722
  16. data/ext/libsass/src/ast_sel_super.cpp +539 -0
  17. data/ext/libsass/src/ast_sel_unify.cpp +207 -212
  18. data/ext/libsass/src/ast_sel_weave.cpp +616 -0
  19. data/ext/libsass/src/ast_selectors.cpp +559 -1001
  20. data/ext/libsass/src/ast_selectors.hpp +311 -367
  21. data/ext/libsass/src/ast_supports.cpp +1 -17
  22. data/ext/libsass/src/ast_values.cpp +216 -29
  23. data/ext/libsass/src/ast_values.hpp +42 -33
  24. data/ext/libsass/src/bind.cpp +1 -1
  25. data/ext/libsass/src/cencode.c +4 -6
  26. data/ext/libsass/src/check_nesting.cpp +5 -6
  27. data/ext/libsass/src/check_nesting.hpp +4 -0
  28. data/ext/libsass/src/color_maps.cpp +11 -10
  29. data/ext/libsass/src/color_maps.hpp +0 -8
  30. data/ext/libsass/src/constants.cpp +5 -0
  31. data/ext/libsass/src/constants.hpp +6 -0
  32. data/ext/libsass/src/context.cpp +30 -60
  33. data/ext/libsass/src/context.hpp +8 -20
  34. data/ext/libsass/src/cssize.cpp +36 -120
  35. data/ext/libsass/src/cssize.hpp +4 -10
  36. data/ext/libsass/src/dart_helpers.hpp +199 -0
  37. data/ext/libsass/src/debugger.hpp +364 -207
  38. data/ext/libsass/src/emitter.cpp +3 -4
  39. data/ext/libsass/src/emitter.hpp +0 -2
  40. data/ext/libsass/src/environment.hpp +5 -0
  41. data/ext/libsass/src/error_handling.cpp +21 -0
  42. data/ext/libsass/src/error_handling.hpp +25 -3
  43. data/ext/libsass/src/eval.cpp +33 -153
  44. data/ext/libsass/src/eval.hpp +11 -13
  45. data/ext/libsass/src/eval_selectors.cpp +75 -0
  46. data/ext/libsass/src/expand.cpp +214 -167
  47. data/ext/libsass/src/expand.hpp +26 -6
  48. data/ext/libsass/src/extender.cpp +1186 -0
  49. data/ext/libsass/src/extender.hpp +399 -0
  50. data/ext/libsass/src/extension.cpp +43 -0
  51. data/ext/libsass/src/extension.hpp +89 -0
  52. data/ext/libsass/src/file.cpp +15 -14
  53. data/ext/libsass/src/file.hpp +5 -12
  54. data/ext/libsass/src/fn_colors.cpp +12 -10
  55. data/ext/libsass/src/fn_lists.cpp +12 -11
  56. data/ext/libsass/src/fn_miscs.cpp +22 -34
  57. data/ext/libsass/src/fn_numbers.cpp +13 -6
  58. data/ext/libsass/src/fn_selectors.cpp +94 -124
  59. data/ext/libsass/src/fn_strings.cpp +16 -14
  60. data/ext/libsass/src/fn_utils.cpp +5 -6
  61. data/ext/libsass/src/fn_utils.hpp +9 -3
  62. data/ext/libsass/src/inspect.cpp +154 -117
  63. data/ext/libsass/src/inspect.hpp +10 -8
  64. data/ext/libsass/src/lexer.cpp +17 -81
  65. data/ext/libsass/src/lexer.hpp +5 -16
  66. data/ext/libsass/src/listize.cpp +22 -36
  67. data/ext/libsass/src/listize.hpp +8 -9
  68. data/ext/libsass/src/memory/SharedPtr.hpp +39 -5
  69. data/ext/libsass/src/operation.hpp +27 -17
  70. data/ext/libsass/src/operators.cpp +1 -0
  71. data/ext/libsass/src/ordered_map.hpp +112 -0
  72. data/ext/libsass/src/output.cpp +30 -49
  73. data/ext/libsass/src/output.hpp +1 -1
  74. data/ext/libsass/src/parser.cpp +211 -381
  75. data/ext/libsass/src/parser.hpp +17 -15
  76. data/ext/libsass/src/parser_selectors.cpp +189 -0
  77. data/ext/libsass/src/permutate.hpp +140 -0
  78. data/ext/libsass/src/position.hpp +1 -1
  79. data/ext/libsass/src/prelexer.cpp +6 -6
  80. data/ext/libsass/src/remove_placeholders.cpp +55 -56
  81. data/ext/libsass/src/remove_placeholders.hpp +21 -18
  82. data/ext/libsass/src/sass.hpp +1 -0
  83. data/ext/libsass/src/sass2scss.cpp +4 -4
  84. data/ext/libsass/src/sass_context.cpp +42 -91
  85. data/ext/libsass/src/sass_context.hpp +2 -2
  86. data/ext/libsass/src/sass_functions.cpp +1 -1
  87. data/ext/libsass/src/sass_values.cpp +0 -1
  88. data/ext/libsass/src/stylesheet.cpp +22 -0
  89. data/ext/libsass/src/stylesheet.hpp +57 -0
  90. data/ext/libsass/src/to_value.cpp +2 -2
  91. data/ext/libsass/src/to_value.hpp +1 -1
  92. data/ext/libsass/src/units.cpp +5 -3
  93. data/ext/libsass/src/util.cpp +10 -12
  94. data/ext/libsass/src/util.hpp +2 -3
  95. data/ext/libsass/src/util_string.cpp +111 -61
  96. data/ext/libsass/src/util_string.hpp +61 -8
  97. data/lib/sassc/engine.rb +5 -3
  98. data/lib/sassc/functions_handler.rb +8 -8
  99. data/lib/sassc/native.rb +1 -1
  100. data/lib/sassc/script.rb +4 -4
  101. data/lib/sassc/version.rb +1 -1
  102. data/test/functions_test.rb +18 -1
  103. data/test/native_test.rb +1 -1
  104. metadata +17 -12
  105. data/ext/libsass/src/extend.cpp +0 -2132
  106. data/ext/libsass/src/extend.hpp +0 -86
  107. data/ext/libsass/src/node.cpp +0 -322
  108. data/ext/libsass/src/node.hpp +0 -118
  109. data/ext/libsass/src/paths.hpp +0 -71
  110. data/ext/libsass/src/sass_util.cpp +0 -152
  111. data/ext/libsass/src/sass_util.hpp +0 -256
  112. data/ext/libsass/src/subset_map.cpp +0 -58
  113. data/ext/libsass/src/subset_map.hpp +0 -76
@@ -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
+ std::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 std::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
+ std::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 std::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
+ std::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
+ std::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
+ std::vector<std::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 std::vector<ComplexSelectorObj> extendPseudoComplex(
341
+ const ComplexSelectorObj& complex,
342
+ const Pseudo_Selector_Obj& pseudo,
343
+ const CssMediaRuleObj& mediaQueryContext);
344
+
345
+ // ##########################################################################
346
+ // Extends [pseudo] using [extensions], and returns
347
+ // a list of resulting pseudo selectors.
348
+ // ##########################################################################
349
+ std::vector<Pseudo_Selector_Obj> extendPseudo(
350
+ const Pseudo_Selector_Obj& 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
+ std::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
+ std::vector<ComplexSelectorObj> trim(
368
+ const std::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