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 |
90 | |