sass4 4.0.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 +7 -0
  2. data/.yardopts +13 -0
  3. data/AGENTS.md +534 -0
  4. data/CODE_OF_CONDUCT.md +10 -0
  5. data/CONTRIBUTING.md +148 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +242 -0
  8. data/VERSION +1 -0
  9. data/VERSION_NAME +1 -0
  10. data/bin/sass +13 -0
  11. data/bin/sass-convert +12 -0
  12. data/bin/scss +13 -0
  13. data/extra/sass-spec-ref.sh +40 -0
  14. data/extra/update_watch.rb +13 -0
  15. data/init.rb +18 -0
  16. data/lib/sass/cache_stores/base.rb +88 -0
  17. data/lib/sass/cache_stores/chain.rb +34 -0
  18. data/lib/sass/cache_stores/filesystem.rb +60 -0
  19. data/lib/sass/cache_stores/memory.rb +46 -0
  20. data/lib/sass/cache_stores/null.rb +25 -0
  21. data/lib/sass/cache_stores.rb +15 -0
  22. data/lib/sass/callbacks.rb +67 -0
  23. data/lib/sass/css.rb +407 -0
  24. data/lib/sass/deprecation.rb +55 -0
  25. data/lib/sass/engine.rb +1236 -0
  26. data/lib/sass/environment.rb +236 -0
  27. data/lib/sass/error.rb +198 -0
  28. data/lib/sass/exec/base.rb +188 -0
  29. data/lib/sass/exec/sass_convert.rb +283 -0
  30. data/lib/sass/exec/sass_scss.rb +436 -0
  31. data/lib/sass/exec.rb +9 -0
  32. data/lib/sass/features.rb +48 -0
  33. data/lib/sass/importers/base.rb +182 -0
  34. data/lib/sass/importers/deprecated_path.rb +51 -0
  35. data/lib/sass/importers/filesystem.rb +221 -0
  36. data/lib/sass/importers.rb +23 -0
  37. data/lib/sass/logger/base.rb +47 -0
  38. data/lib/sass/logger/delayed.rb +50 -0
  39. data/lib/sass/logger/log_level.rb +45 -0
  40. data/lib/sass/logger.rb +17 -0
  41. data/lib/sass/media.rb +210 -0
  42. data/lib/sass/plugin/compiler.rb +552 -0
  43. data/lib/sass/plugin/configuration.rb +134 -0
  44. data/lib/sass/plugin/generic.rb +15 -0
  45. data/lib/sass/plugin/merb.rb +48 -0
  46. data/lib/sass/plugin/rack.rb +60 -0
  47. data/lib/sass/plugin/rails.rb +47 -0
  48. data/lib/sass/plugin/staleness_checker.rb +199 -0
  49. data/lib/sass/plugin.rb +134 -0
  50. data/lib/sass/railtie.rb +10 -0
  51. data/lib/sass/repl.rb +57 -0
  52. data/lib/sass/root.rb +7 -0
  53. data/lib/sass/script/css_lexer.rb +33 -0
  54. data/lib/sass/script/css_parser.rb +36 -0
  55. data/lib/sass/script/functions.rb +3103 -0
  56. data/lib/sass/script/lexer.rb +518 -0
  57. data/lib/sass/script/parser.rb +1164 -0
  58. data/lib/sass/script/tree/funcall.rb +314 -0
  59. data/lib/sass/script/tree/interpolation.rb +220 -0
  60. data/lib/sass/script/tree/list_literal.rb +119 -0
  61. data/lib/sass/script/tree/literal.rb +49 -0
  62. data/lib/sass/script/tree/map_literal.rb +64 -0
  63. data/lib/sass/script/tree/node.rb +119 -0
  64. data/lib/sass/script/tree/operation.rb +149 -0
  65. data/lib/sass/script/tree/selector.rb +26 -0
  66. data/lib/sass/script/tree/string_interpolation.rb +125 -0
  67. data/lib/sass/script/tree/unary_operation.rb +69 -0
  68. data/lib/sass/script/tree/variable.rb +57 -0
  69. data/lib/sass/script/tree.rb +16 -0
  70. data/lib/sass/script/value/arg_list.rb +36 -0
  71. data/lib/sass/script/value/base.rb +258 -0
  72. data/lib/sass/script/value/bool.rb +35 -0
  73. data/lib/sass/script/value/callable.rb +25 -0
  74. data/lib/sass/script/value/color.rb +704 -0
  75. data/lib/sass/script/value/function.rb +19 -0
  76. data/lib/sass/script/value/helpers.rb +298 -0
  77. data/lib/sass/script/value/list.rb +135 -0
  78. data/lib/sass/script/value/map.rb +70 -0
  79. data/lib/sass/script/value/null.rb +44 -0
  80. data/lib/sass/script/value/number.rb +564 -0
  81. data/lib/sass/script/value/string.rb +138 -0
  82. data/lib/sass/script/value.rb +13 -0
  83. data/lib/sass/script.rb +66 -0
  84. data/lib/sass/scss/css_parser.rb +61 -0
  85. data/lib/sass/scss/parser.rb +1343 -0
  86. data/lib/sass/scss/rx.rb +134 -0
  87. data/lib/sass/scss/static_parser.rb +351 -0
  88. data/lib/sass/scss.rb +14 -0
  89. data/lib/sass/selector/abstract_sequence.rb +112 -0
  90. data/lib/sass/selector/comma_sequence.rb +195 -0
  91. data/lib/sass/selector/pseudo.rb +291 -0
  92. data/lib/sass/selector/sequence.rb +661 -0
  93. data/lib/sass/selector/simple.rb +124 -0
  94. data/lib/sass/selector/simple_sequence.rb +348 -0
  95. data/lib/sass/selector.rb +327 -0
  96. data/lib/sass/shared.rb +76 -0
  97. data/lib/sass/source/map.rb +209 -0
  98. data/lib/sass/source/position.rb +39 -0
  99. data/lib/sass/source/range.rb +41 -0
  100. data/lib/sass/stack.rb +140 -0
  101. data/lib/sass/supports.rb +225 -0
  102. data/lib/sass/tree/at_root_node.rb +83 -0
  103. data/lib/sass/tree/charset_node.rb +22 -0
  104. data/lib/sass/tree/comment_node.rb +82 -0
  105. data/lib/sass/tree/content_node.rb +9 -0
  106. data/lib/sass/tree/css_import_node.rb +68 -0
  107. data/lib/sass/tree/debug_node.rb +18 -0
  108. data/lib/sass/tree/directive_node.rb +59 -0
  109. data/lib/sass/tree/each_node.rb +24 -0
  110. data/lib/sass/tree/error_node.rb +18 -0
  111. data/lib/sass/tree/extend_node.rb +43 -0
  112. data/lib/sass/tree/for_node.rb +36 -0
  113. data/lib/sass/tree/function_node.rb +44 -0
  114. data/lib/sass/tree/if_node.rb +52 -0
  115. data/lib/sass/tree/import_node.rb +75 -0
  116. data/lib/sass/tree/keyframe_rule_node.rb +15 -0
  117. data/lib/sass/tree/media_node.rb +48 -0
  118. data/lib/sass/tree/mixin_def_node.rb +38 -0
  119. data/lib/sass/tree/mixin_node.rb +52 -0
  120. data/lib/sass/tree/node.rb +240 -0
  121. data/lib/sass/tree/prop_node.rb +162 -0
  122. data/lib/sass/tree/return_node.rb +19 -0
  123. data/lib/sass/tree/root_node.rb +44 -0
  124. data/lib/sass/tree/rule_node.rb +153 -0
  125. data/lib/sass/tree/supports_node.rb +38 -0
  126. data/lib/sass/tree/trace_node.rb +33 -0
  127. data/lib/sass/tree/variable_node.rb +36 -0
  128. data/lib/sass/tree/visitors/base.rb +72 -0
  129. data/lib/sass/tree/visitors/check_nesting.rb +173 -0
  130. data/lib/sass/tree/visitors/convert.rb +350 -0
  131. data/lib/sass/tree/visitors/cssize.rb +362 -0
  132. data/lib/sass/tree/visitors/deep_copy.rb +107 -0
  133. data/lib/sass/tree/visitors/extend.rb +64 -0
  134. data/lib/sass/tree/visitors/perform.rb +572 -0
  135. data/lib/sass/tree/visitors/set_options.rb +139 -0
  136. data/lib/sass/tree/visitors/to_css.rb +440 -0
  137. data/lib/sass/tree/warn_node.rb +18 -0
  138. data/lib/sass/tree/while_node.rb +18 -0
  139. data/lib/sass/util/multibyte_string_scanner.rb +151 -0
  140. data/lib/sass/util/normalized_map.rb +122 -0
  141. data/lib/sass/util/subset_map.rb +109 -0
  142. data/lib/sass/util/test.rb +9 -0
  143. data/lib/sass/util.rb +1137 -0
  144. data/lib/sass/version.rb +120 -0
  145. data/lib/sass.rb +102 -0
  146. data/rails/init.rb +1 -0
  147. metadata +283 -0
@@ -0,0 +1,124 @@
1
+ module Sass
2
+ module Selector
3
+ # The abstract superclass for simple selectors
4
+ # (that is, those that don't compose multiple selectors).
5
+ class Simple
6
+ # The line of the Sass template on which this selector was declared.
7
+ #
8
+ # @return [Integer]
9
+ attr_accessor :line
10
+
11
+ # The name of the file in which this selector was declared,
12
+ # or `nil` if it was not declared in a file (e.g. on stdin).
13
+ #
14
+ # @return [String, nil]
15
+ attr_accessor :filename
16
+
17
+ # Whether only one instance of this simple selector is allowed in a given
18
+ # complex selector.
19
+ #
20
+ # @return [Boolean]
21
+ def unique?
22
+ false
23
+ end
24
+
25
+ # @see #to_s
26
+ #
27
+ # @return [String]
28
+ def inspect
29
+ to_s
30
+ end
31
+
32
+ # Returns the selector string.
33
+ #
34
+ # @param opts [Hash] rendering options.
35
+ # @option opts [Symbol] :style The css rendering style.
36
+ # @return [String]
37
+ def to_s(opts = {})
38
+ Sass::Util.abstract(self)
39
+ end
40
+
41
+ # Returns a hash code for this selector object.
42
+ #
43
+ # By default, this is based on the value of \{#to\_a},
44
+ # so if that contains information irrelevant to the identity of the selector,
45
+ # this should be overridden.
46
+ #
47
+ # @return [Integer]
48
+ def hash
49
+ @_hash ||= equality_key.hash
50
+ end
51
+
52
+ # Checks equality between this and another object.
53
+ #
54
+ # By default, this is based on the value of \{#to\_a},
55
+ # so if that contains information irrelevant to the identity of the selector,
56
+ # this should be overridden.
57
+ #
58
+ # @param other [Object] The object to test equality against
59
+ # @return [Boolean] Whether or not this is equal to `other`
60
+ def eql?(other)
61
+ other.class == self.class && other.hash == hash && other.equality_key == equality_key
62
+ end
63
+ alias_method :==, :eql?
64
+
65
+ # Unifies this selector with a {SimpleSequence}'s {SimpleSequence#members members array},
66
+ # returning another `SimpleSequence` members array
67
+ # that matches both this selector and the input selector.
68
+ #
69
+ # By default, this just appends this selector to the end of the array
70
+ # (or returns the original array if this selector already exists in it).
71
+ #
72
+ # @param sels [Array<Simple>] A {SimpleSequence}'s {SimpleSequence#members members array}
73
+ # @return [Array<Simple>, nil] A {SimpleSequence} {SimpleSequence#members members array}
74
+ # matching both `sels` and this selector,
75
+ # or `nil` if this is impossible (e.g. unifying `#foo` and `#bar`)
76
+ # @raise [Sass::SyntaxError] If this selector cannot be unified.
77
+ # This will only ever occur when a dynamic selector,
78
+ # such as {Parent} or {Interpolation}, is used in unification.
79
+ # Since these selectors should be resolved
80
+ # by the time extension and unification happen,
81
+ # this exception will only ever be raised as a result of programmer error
82
+ def unify(sels)
83
+ return sels.first.unify([self]) if sels.length == 1 && sels.first.is_a?(Universal)
84
+ return sels if sels.any? {|sel2| eql?(sel2)}
85
+ if !is_a?(Pseudo) || (sels.last.is_a?(Pseudo) && sels.last.type == :element)
86
+ _, i = sels.each_with_index.find {|sel, _| sel.is_a?(Pseudo)}
87
+ end
88
+ return sels + [self] unless i
89
+ sels[0...i] + [self] + sels[i..-1]
90
+ end
91
+
92
+ protected
93
+
94
+ # Returns the key used for testing whether selectors are equal.
95
+ #
96
+ # This is a cached version of \{#to\_s}.
97
+ #
98
+ # @return [String]
99
+ def equality_key
100
+ @equality_key ||= to_s
101
+ end
102
+
103
+ # Unifies two namespaces,
104
+ # returning a namespace that works for both of them if possible.
105
+ #
106
+ # @param ns1 [String, nil] The first namespace.
107
+ # `nil` means none specified, e.g. `foo`.
108
+ # The empty string means no namespace specified, e.g. `|foo`.
109
+ # `"*"` means any namespace is allowed, e.g. `*|foo`.
110
+ # @param ns2 [String, nil] The second namespace. See `ns1`.
111
+ # @return [Array(String or nil, Boolean)]
112
+ # The first value is the unified namespace, or `nil` for no namespace.
113
+ # The second value is whether or not a namespace that works for both inputs
114
+ # could be found at all.
115
+ # If the second value is `false`, the first should be ignored.
116
+ def unify_namespaces(ns1, ns2)
117
+ return ns2, true if ns1 == '*'
118
+ return ns1, true if ns2 == '*'
119
+ return nil, false unless ns1 == ns2
120
+ [ns1, true]
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,348 @@
1
+ module Sass
2
+ module Selector
3
+ # A unseparated sequence of selectors
4
+ # that all apply to a single element.
5
+ # For example, `.foo#bar[attr=baz]` is a simple sequence
6
+ # of the selectors `.foo`, `#bar`, and `[attr=baz]`.
7
+ class SimpleSequence < AbstractSequence
8
+ # The array of individual selectors.
9
+ #
10
+ # @return [Array<Simple>]
11
+ attr_accessor :members
12
+
13
+ # The extending selectors that caused this selector sequence to be
14
+ # generated. For example:
15
+ #
16
+ # a.foo { ... }
17
+ # b.bar {@extend a}
18
+ # c.baz {@extend b}
19
+ #
20
+ # The generated selector `b.foo.bar` has `{b.bar}` as its `sources` set,
21
+ # and the generated selector `c.foo.bar.baz` has `{b.bar, c.baz}` as its
22
+ # `sources` set.
23
+ #
24
+ # This is populated during the {Sequence#do_extend} process.
25
+ #
26
+ # @return {Set<Sequence>}
27
+ attr_accessor :sources
28
+
29
+ # This sequence source range.
30
+ #
31
+ # @return [Sass::Source::Range]
32
+ attr_accessor :source_range
33
+
34
+ # @see \{#subject?}
35
+ attr_writer :subject
36
+
37
+ # Returns the element or universal selector in this sequence,
38
+ # if it exists.
39
+ #
40
+ # @return [Element, Universal, nil]
41
+ def base
42
+ @base ||= (members.first if members.first.is_a?(Element) || members.first.is_a?(Universal))
43
+ end
44
+
45
+ def pseudo_elements
46
+ @pseudo_elements ||= members.select {|sel| sel.is_a?(Pseudo) && sel.type == :element}
47
+ end
48
+
49
+ def selector_pseudo_classes
50
+ @selector_pseudo_classes ||= members.
51
+ select {|sel| sel.is_a?(Pseudo) && sel.type == :class && sel.selector}.
52
+ group_by {|sel| sel.normalized_name}
53
+ end
54
+
55
+ # Returns the non-base, non-pseudo-element selectors in this sequence.
56
+ #
57
+ # @return [Set<Simple>]
58
+ def rest
59
+ @rest ||= Set.new(members - [base] - pseudo_elements)
60
+ end
61
+
62
+ # Whether or not this compound selector is the subject of the parent
63
+ # selector; that is, whether it is prepended with `$` and represents the
64
+ # actual element that will be selected.
65
+ #
66
+ # @return [Boolean]
67
+ def subject?
68
+ @subject
69
+ end
70
+
71
+ # @param selectors [Array<Simple>] See \{#members}
72
+ # @param subject [Boolean] See \{#subject?}
73
+ # @param source_range [Sass::Source::Range]
74
+ def initialize(selectors, subject, source_range = nil)
75
+ @members = selectors
76
+ @subject = subject
77
+ @sources = Set.new
78
+ @source_range = source_range
79
+ end
80
+
81
+ # Resolves the {Parent} selectors within this selector
82
+ # by replacing them with the given parent selector,
83
+ # handling commas appropriately.
84
+ #
85
+ # @param super_cseq [CommaSequence] The parent selector
86
+ # @return [CommaSequence] This selector, with parent references resolved
87
+ # @raise [Sass::SyntaxError] If a parent selector is invalid
88
+ def resolve_parent_refs(super_cseq)
89
+ resolved_members = @members.map do |sel|
90
+ next sel unless sel.is_a?(Pseudo) && sel.selector
91
+ sel.with_selector(sel.selector.resolve_parent_refs(super_cseq, false))
92
+ end.flatten
93
+
94
+ # Parent selector only appears as the first selector in the sequence
95
+ unless (parent = resolved_members.first).is_a?(Parent)
96
+ return CommaSequence.new([Sequence.new([SimpleSequence.new(resolved_members, subject?)])])
97
+ end
98
+
99
+ return super_cseq if @members.size == 1 && parent.suffix.nil?
100
+
101
+ CommaSequence.new(super_cseq.members.map do |super_seq|
102
+ members = super_seq.members.dup
103
+ newline = members.pop if members.last == "\n"
104
+ unless members.last.is_a?(SimpleSequence)
105
+ raise Sass::SyntaxError.new("Invalid parent selector for \"#{self}\": \"" +
106
+ super_seq.to_s + '"')
107
+ end
108
+
109
+ parent_sub = members.last.members
110
+ unless parent.suffix.nil?
111
+ parent_sub = parent_sub.dup
112
+ parent_sub[-1] = parent_sub.last.dup
113
+ case parent_sub.last
114
+ when Sass::Selector::Class, Sass::Selector::Id, Sass::Selector::Placeholder
115
+ parent_sub[-1] = parent_sub.last.class.new(parent_sub.last.name + parent.suffix)
116
+ when Sass::Selector::Element
117
+ parent_sub[-1] = parent_sub.last.class.new(
118
+ parent_sub.last.name + parent.suffix,
119
+ parent_sub.last.namespace)
120
+ when Sass::Selector::Pseudo
121
+ if parent_sub.last.arg || parent_sub.last.selector
122
+ raise Sass::SyntaxError.new("Invalid parent selector for \"#{self}\": \"" +
123
+ super_seq.to_s + '"')
124
+ end
125
+ parent_sub[-1] = Sass::Selector::Pseudo.new(
126
+ parent_sub.last.type,
127
+ parent_sub.last.name + parent.suffix,
128
+ nil, nil)
129
+ else
130
+ raise Sass::SyntaxError.new("Invalid parent selector for \"#{self}\": \"" +
131
+ super_seq.to_s + '"')
132
+ end
133
+ end
134
+
135
+ Sequence.new(members[0...-1] +
136
+ [SimpleSequence.new(parent_sub + resolved_members[1..-1], subject?)] +
137
+ [newline].compact)
138
+ end)
139
+ end
140
+
141
+ # Non-destructively extends this selector with the extensions specified in a hash
142
+ # (which should come from {Sass::Tree::Visitors::Cssize}).
143
+ #
144
+ # @param extends [{Selector::Simple =>
145
+ # Sass::Tree::Visitors::Cssize::Extend}]
146
+ # The extensions to perform on this selector
147
+ # @param parent_directives [Array<Sass::Tree::DirectiveNode>]
148
+ # The directives containing this selector.
149
+ # @param seen [Set<Array<Selector::Simple>>]
150
+ # The set of simple sequences that are currently being replaced.
151
+ # @param original [Boolean]
152
+ # Whether this is the original selector being extended, as opposed to
153
+ # the result of a previous extension that's being re-extended.
154
+ # @return [Array<Sequence>] A list of selectors generated
155
+ # by extending this selector with `extends`.
156
+ # @see CommaSequence#do_extend
157
+ def do_extend(extends, parent_directives, replace, seen)
158
+ seen_with_pseudo_selectors = seen.dup
159
+
160
+ modified_original = false
161
+ members = self.members.map do |sel|
162
+ next sel unless sel.is_a?(Pseudo) && sel.selector
163
+ next sel if seen.include?([sel])
164
+ extended = sel.selector.do_extend(extends, parent_directives, replace, seen, false)
165
+ next sel if extended == sel.selector
166
+ extended.members.reject! {|seq| seq.invisible?}
167
+
168
+ # For `:not()`, we usually want to get rid of any complex
169
+ # selectors because that will cause the selector to fail to
170
+ # parse on all browsers at time of writing. We can keep them
171
+ # if either the original selector had a complex selector, or
172
+ # the result of extending has only complex selectors,
173
+ # because either way we aren't breaking anything that isn't
174
+ # already broken.
175
+ if sel.normalized_name == 'not' &&
176
+ (sel.selector.members.none? {|seq| seq.members.length > 1} &&
177
+ extended.members.any? {|seq| seq.members.length == 1})
178
+ extended.members.reject! {|seq| seq.members.length > 1}
179
+ end
180
+
181
+ modified_original = true
182
+ result = sel.with_selector(extended)
183
+ result.each {|new_sel| seen_with_pseudo_selectors << [new_sel]}
184
+ result
185
+ end.flatten
186
+
187
+ groups = extends[members.to_set].group_by {|ex| ex.extender}.to_a
188
+ groups.map! do |seq, group|
189
+ sels = group.map {|e| e.target}.flatten
190
+ # If A {@extend B} and C {...},
191
+ # seq is A, sels is B, and self is C
192
+
193
+ self_without_sel = Sass::Util.array_minus(members, sels)
194
+ group.each {|e| e.success = true}
195
+ unified = seq.members.last.unify(SimpleSequence.new(self_without_sel, subject?))
196
+ next unless unified
197
+ group.each {|e| check_directives_match!(e, parent_directives)}
198
+ new_seq = Sequence.new(seq.members[0...-1] + [unified])
199
+ new_seq.add_sources!(sources + [seq])
200
+ [sels, new_seq]
201
+ end
202
+ groups.compact!
203
+ groups.map! do |sels, seq|
204
+ next [] if seen.include?(sels)
205
+ seq.do_extend(
206
+ extends, parent_directives, false, seen_with_pseudo_selectors + [sels], false)
207
+ end
208
+ groups.flatten!
209
+
210
+ if modified_original || !replace || groups.empty?
211
+ # First Law of Extend: the result of extending a selector should
212
+ # (almost) always contain the base selector.
213
+ #
214
+ # See https://github.com/nex3/sass/issues/324.
215
+ original = Sequence.new([SimpleSequence.new(members, @subject, source_range)])
216
+ original.add_sources! sources
217
+ groups.unshift original
218
+ end
219
+ groups.uniq!
220
+ groups
221
+ end
222
+
223
+ # Unifies this selector with another {SimpleSequence}, returning
224
+ # another `SimpleSequence` that is a subselector of both input
225
+ # selectors.
226
+ #
227
+ # @param other [SimpleSequence]
228
+ # @return [SimpleSequence, nil] A {SimpleSequence} matching both `sels` and this selector,
229
+ # or `nil` if this is impossible (e.g. unifying `#foo` and `#bar`)
230
+ # @raise [Sass::SyntaxError] If this selector cannot be unified.
231
+ # This will only ever occur when a dynamic selector,
232
+ # such as {Parent} or {Interpolation}, is used in unification.
233
+ # Since these selectors should be resolved
234
+ # by the time extension and unification happen,
235
+ # this exception will only ever be raised as a result of programmer error
236
+ def unify(other)
237
+ sseq = members.inject(other.members) do |member, sel|
238
+ return unless member
239
+ sel.unify(member)
240
+ end
241
+ return unless sseq
242
+ SimpleSequence.new(sseq, other.subject? || subject?)
243
+ end
244
+
245
+ # Returns whether or not this selector matches all elements
246
+ # that the given selector matches (as well as possibly more).
247
+ #
248
+ # @example
249
+ # (.foo).superselector?(.foo.bar) #=> true
250
+ # (.foo).superselector?(.bar) #=> false
251
+ # @param their_sseq [SimpleSequence]
252
+ # @param parents [Array<SimpleSequence, String>] The parent selectors of `their_sseq`, if any.
253
+ # @return [Boolean]
254
+ def superselector?(their_sseq, parents = [])
255
+ return false unless base.nil? || base.eql?(their_sseq.base)
256
+ return false unless pseudo_elements.eql?(their_sseq.pseudo_elements)
257
+ our_spcs = selector_pseudo_classes
258
+ their_spcs = their_sseq.selector_pseudo_classes
259
+
260
+ # Some psuedo-selectors can be subselectors of non-pseudo selectors.
261
+ # Pull those out here so we can efficiently check against them below.
262
+ their_subselector_pseudos = %w(matches any nth-child nth-last-child).
263
+ map {|name| their_spcs[name] || []}.flatten
264
+
265
+ # If `self`'s non-pseudo simple selectors aren't a subset of `their_sseq`'s,
266
+ # it's definitely not a superselector. This also considers being matched
267
+ # by `:matches` or `:any`.
268
+ return false unless rest.all? do |our_sel|
269
+ next true if our_sel.is_a?(Pseudo) && our_sel.selector
270
+ next true if their_sseq.rest.include?(our_sel)
271
+ their_subselector_pseudos.any? do |their_pseudo|
272
+ their_pseudo.selector.members.all? do |their_seq|
273
+ next false unless their_seq.members.length == 1
274
+ their_sseq = their_seq.members.first
275
+ next false unless their_sseq.is_a?(SimpleSequence)
276
+ their_sseq.rest.include?(our_sel)
277
+ end
278
+ end
279
+ end
280
+
281
+ our_spcs.all? do |_name, pseudos|
282
+ pseudos.all? {|pseudo| pseudo.superselector?(their_sseq, parents)}
283
+ end
284
+ end
285
+
286
+ # @see Simple#to_s
287
+ def to_s(opts = {})
288
+ res = @members.map {|m| m.to_s(opts)}.join
289
+
290
+ # :not(%foo) may resolve to the empty string, but it should match every
291
+ # selector so we replace it with "*".
292
+ res = '*' if res.empty?
293
+
294
+ res << '!' if subject?
295
+ res
296
+ end
297
+
298
+ # Returns a string representation of the sequence.
299
+ # This is basically the selector string.
300
+ #
301
+ # @return [String]
302
+ def inspect
303
+ res = members.map {|m| m.inspect}.join
304
+ res << '!' if subject?
305
+ res
306
+ end
307
+
308
+ # Return a copy of this simple sequence with `sources` merged into the
309
+ # {SimpleSequence#sources} set.
310
+ #
311
+ # @param sources [Set<Sequence>]
312
+ # @return [SimpleSequence]
313
+ def with_more_sources(sources)
314
+ sseq = dup
315
+ sseq.members = members.dup
316
+ sseq.sources = self.sources | sources
317
+ sseq
318
+ end
319
+
320
+ private
321
+
322
+ def check_directives_match!(extend, parent_directives)
323
+ dirs1 = extend.directives.map {|d| d.resolved_value}
324
+ dirs2 = parent_directives.map {|d| d.resolved_value}
325
+ return if Sass::Util.subsequence?(dirs1, dirs2)
326
+ line = extend.node.line
327
+ filename = extend.node.filename
328
+
329
+ # TODO(nweiz): this should use the Sass stack trace of the extend node,
330
+ # not the selector.
331
+ raise Sass::SyntaxError.new(<<MESSAGE)
332
+ You may not @extend an outer selector from within #{extend.directives.last.name}.
333
+ You may only @extend selectors within the same directive.
334
+ From "@extend #{extend.target.join(', ')}" on line #{line}#{" of #{filename}" if filename}.
335
+ MESSAGE
336
+ end
337
+
338
+ def _hash
339
+ [base, rest.hash].hash
340
+ end
341
+
342
+ def _eql?(other)
343
+ other.base.eql?(base) && other.pseudo_elements == pseudo_elements &&
344
+ other.rest.eql?(rest) && other.subject? == subject?
345
+ end
346
+ end
347
+ end
348
+ end