/usr/lib/ruby/vendor_ruby/sass/tree/rule_node.rb is in ruby-sass 3.4.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | require 'pathname'
module Sass::Tree
# A static node representing a CSS rule.
#
# @see Sass::Tree
class RuleNode < Node
# The character used to include the parent selector
PARENT = '&'
# The CSS selector for this rule,
# interspersed with {Sass::Script::Tree::Node}s
# representing `#{}`-interpolation.
# Any adjacent strings will be merged together.
#
# @return [Array<String, Sass::Script::Tree::Node>]
attr_accessor :rule
# The CSS selector for this rule, without any unresolved
# interpolation but with parent references still intact. It's only
# guaranteed to be set once {Tree::Visitors::Perform} has been
# run, but it may be set before then for optimization reasons.
#
# @return [Selector::CommaSequence]
attr_accessor :parsed_rules
# The CSS selector for this rule, without any unresolved
# interpolation or parent references. It's only set once
# {Tree::Visitors::Perform} has been run.
#
# @return [Selector::CommaSequence]
attr_accessor :resolved_rules
# How deep this rule is indented
# relative to a base-level rule.
# This is only greater than 0 in the case that:
#
# * This node is in a CSS tree
# * The style is :nested
# * This is a child rule of another rule
# * The parent rule has properties, and thus will be rendered
#
# @return [Fixnum]
attr_accessor :tabs
# The entire selector source range for this rule.
# @return [Sass::Source::Range]
attr_accessor :selector_source_range
# Whether or not this rule is the last rule in a nested group.
# This is only set in a CSS tree.
#
# @return [Boolean]
attr_accessor :group_end
# The stack trace.
# This is only readable in a CSS tree as it is written during the perform step
# and only when the :trace_selectors option is set.
#
# @return [String]
attr_accessor :stack_trace
# @param rule [Array<String, Sass::Script::Tree::Node>, Sass::Selector::CommaSequence]
# The CSS rule, either unparsed or parsed.
# @param selector_source_range [Sass::Source::Range]
def initialize(rule, selector_source_range = nil)
if rule.is_a?(Sass::Selector::CommaSequence)
@rule = [rule.to_s]
@parsed_rules = rule
else
merged = Sass::Util.merge_adjacent_strings(rule)
@rule = Sass::Util.strip_string_array(merged)
try_to_parse_non_interpolated_rules
end
@selector_source_range = selector_source_range
@tabs = 0
super()
end
# If we've precached the parsed selector, set the line on it, too.
def line=(line)
@parsed_rules.line = line if @parsed_rules
super
end
# If we've precached the parsed selector, set the filename on it, too.
def filename=(filename)
@parsed_rules.filename = filename if @parsed_rules
super
end
# Compares the contents of two rules.
#
# @param other [Object] The object to compare with
# @return [Boolean] Whether or not this node and the other object
# are the same
def ==(other)
self.class == other.class && rule == other.rule && super
end
# Adds another {RuleNode}'s rules to this one's.
#
# @param node [RuleNode] The other node
def add_rules(node)
@rule = Sass::Util.strip_string_array(
Sass::Util.merge_adjacent_strings(@rule + ["\n"] + node.rule))
try_to_parse_non_interpolated_rules
end
# @return [Boolean] Whether or not this rule is continued on the next line
def continued?
last = @rule.last
last.is_a?(String) && last[-1] == ?,
end
# A hash that will be associated with this rule in the CSS document
# if the {file:SASS_REFERENCE.md#debug_info-option `:debug_info` option} is enabled.
# This data is used by e.g. [the FireSass Firebug
# extension](https://addons.mozilla.org/en-US/firefox/addon/103988).
#
# @return [{#to_s => #to_s}]
def debug_info
{:filename => filename && ("file://" + Sass::Util.escape_uri(File.expand_path(filename))),
:line => line}
end
# A rule node is invisible if it has only placeholder selectors.
def invisible?
resolved_rules.members.all? {|seq| seq.has_placeholder?}
end
private
def try_to_parse_non_interpolated_rules
if @rule.all? {|t| t.kind_of?(String)}
# We don't use real filename/line info because we don't have it yet.
# When we get it, we'll set it on the parsed rules if possible.
parser = Sass::SCSS::StaticParser.new(@rule.join.strip, nil, nil, 1)
# rubocop:disable RescueModifier
@parsed_rules = parser.parse_selector rescue nil
# rubocop:enable RescueModifier
end
end
end
end
|