Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for frozen string literals. #2352

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sass/deprecation.rb
Expand Up @@ -45,7 +45,7 @@ def warn(filename, line, column_or_message, message = nil)
message = column_or_message
end

location = "line #{line}"
location = "line #{line}".dup
location << ", column #{column}" if column
location << " of #{filename}" if filename

Expand Down
2 changes: 1 addition & 1 deletion lib/sass/media.rb
Expand Up @@ -147,7 +147,7 @@ def merge(other)
#
# @return [String]
def to_css
css = ''
css = ''.dup
css << resolved_modifier
css << ' ' unless resolved_modifier.empty?
css << resolved_type
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/script/lexer.rb
Expand Up @@ -405,7 +405,7 @@ def special_fun
end

def special_fun_body(parens, prefix = nil)
str = prefix || ''
str = prefix || ''.dup
while (scanned = scan(/.*?([()]|\#\{)/m))
str << scanned
if scanned[-1] == ?(
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/script/parser.rb
Expand Up @@ -817,8 +817,8 @@ def check_for_interpolation(node)
# @param node [Sass::Script::Tree::Node]
def interpolation_deprecation(interpolation)
return if @options[:_convert]
location = "on line #{interpolation.line}"
location << " of #{interpolation.filename}" if interpolation.filename
location = "on line #{interpolation.line}"
location += " of #{interpolation.filename}" if interpolation.filename
Sass::Util.sass_warn <<WARNING
DEPRECATION WARNING #{location}:
\#{} interpolation near operators will be simplified in a future version of Sass.
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/script/tree/interpolation.rb
Expand Up @@ -70,7 +70,7 @@ def inspect
def to_sass(opts = {})
return to_quoted_equivalent.to_sass if deprecation == :immediate

res = ""
res = "".dup
res << @before.to_sass(opts) if @before
res << ' ' if @before && @whitespace_before
res << '#{' unless @originally_text
Expand Down Expand Up @@ -163,7 +163,7 @@ def to_string_interpolation(node_or_interp)
# @return [Sass::Script::Value::String]
# The SassScript string that is the value of the interpolation
def _perform(environment)
res = ""
res = "".dup
res << @before.perform(environment).to_s if @before
res << " " if @before && @whitespace_before

Expand Down
4 changes: 2 additions & 2 deletions lib/sass/script/tree/string_interpolation.rb
Expand Up @@ -52,7 +52,7 @@ def to_sass(opts = {})
quote = type == :string ? opts[:quote] || quote_for(self) || '"' : :none
opts = opts.merge(:quote => quote)

res = ""
res = "".dup
res << quote if quote != :none
res << _to_sass(before, opts)
res << '#{' << @mid.to_sass(opts.merge(:quote => nil)) << '}'
Expand Down Expand Up @@ -87,7 +87,7 @@ def deep_copy
# @return [Sass::Script::Value::String]
# The SassScript string that is the value of the interpolation
def _perform(environment)
res = ""
res = "".dup
before = @before.perform(environment)
res << before.value
mid = @mid.perform(environment)
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/scss/parser.rb
Expand Up @@ -1104,7 +1104,7 @@ def str?
pos = @scanner.pos
line = @line
offset = @offset
@strs.push ""
@strs.push "".dup
throw_error {yield} && @strs.last
rescue Sass::SyntaxError
@scanner.pos = pos
Expand Down Expand Up @@ -1276,7 +1276,7 @@ def self.expected(scanner, expected, line)
was = was[0...15] + "..." if was.size > 18

raise Sass::SyntaxError.new(
"Invalid CSS after \"#{after}\": expected #{expected}, was \"#{was}\"",
"Invalid CSS after \"#{after}\": expected #{expected}, was \"#{was}\"".dup,
:line => line)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/sass/scss/rx.rb
Expand Up @@ -14,7 +14,7 @@ module RX
def self.escape_ident(str)
return "" if str.empty?
return "\\#{str}" if str == '-' || str == '_'
out = ""
out = "".dup
value = str.dup
out << value.slice!(0...1) if value =~ /^[-_]/
if value[0...1] =~ NMSTART
Expand Down
6 changes: 3 additions & 3 deletions lib/sass/scss/static_parser.rb
Expand Up @@ -86,15 +86,15 @@ def selector_comma_sequence
sel = selector
return unless sel
selectors = [sel]
ws = ''
ws = ''.dup
while tok(/,/)
ws << str {ss}
next unless (sel = selector)
selectors << sel
if ws.include?("\n")
selectors[-1] = Selector::Sequence.new(["\n"] + selectors.last.members)
end
ws = ''
ws = ''.dup
end
Selector::CommaSequence.new(selectors)
end
Expand Down Expand Up @@ -140,7 +140,7 @@ def combinator

def reference_combinator
return unless tok(%r{/})
res = '/'
res = '/'.dup
ns, name = expr!(:qualified_name)
res << ns << '|' if ns
res << name << tok!(%r{/})
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/selector.rb
Expand Up @@ -310,7 +310,7 @@ def initialize(name, namespace, operator, value, flags)

# @see Selector#to_s
def to_s(opts = {})
res = "["
res = "[".dup
res << @namespace << "|" if @namespace
res << @name
res << @operator << @value if @value
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/source/map.rb
Expand Up @@ -98,7 +98,7 @@ def to_json(options)
css_uri ||= Sass::Util.file_uri_from_path(
Sass::Util.relative_path_from(css_path, sourcemap_path.dirname))

result = "{\n"
result = "{\n".dup
write_json_field(result, "version", 3, true)

source_uri_to_id = {}
Expand Down Expand Up @@ -156,7 +156,7 @@ def to_json(options)
end

# `segment` is a data chunk for a single position mapping.
segment = ""
segment = "".dup

# Field 1: zero-based starting offset.
segment << Sass::Util.encode_vlq(target_pos.offset - previous_target_offset)
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/tree/css_import_node.rb
Expand Up @@ -58,7 +58,7 @@ def value; raise NotImplementedError; end
def resolved_value
@resolved_value ||=
begin
str = "@import #{resolved_uri}"
str = "@import #{resolved_uri}".dup
str << " supports(#{supports_condition.to_css})" if supports_condition
str << " #{resolved_query.to_css}" if resolved_query
str
Expand Down
11 changes: 5 additions & 6 deletions lib/sass/tree/visitors/convert.rb
Expand Up @@ -92,8 +92,7 @@ def visit_error(node)
end

def visit_directive(node)
res = "#{tab_str}#{interp_to_src(node.value)}"
res.gsub!(/^@import \#\{(.*)\}([^}]*)$/, '@import \1\2')
res = "#{tab_str}#{interp_to_src(node.value)}".gsub(/^@import \#\{(.*)\}([^}]*)$/, '@import \1\2')
return res + "#{semi}\n" unless node.has_children
res + yield
end
Expand Down Expand Up @@ -135,7 +134,7 @@ def visit_if(node)
"else"
end
@is_else = false
str = "#{tab_str}@#{name}"
str = "#{tab_str}@#{name}".dup
str << " #{node.expr.to_sass(@options)}" if node.expr
str << yield
@is_else = true
Expand All @@ -160,9 +159,9 @@ def visit_supports(node)

def visit_cssimport(node)
if node.uri.is_a?(Sass::Script::Tree::Node)
str = "#{tab_str}@import #{node.uri.to_sass(@options)}"
str = "#{tab_str}@import #{node.uri.to_sass(@options)}".dup
else
str = "#{tab_str}@import #{node.uri}"
str = "#{tab_str}@import #{node.uri}".dup
end
str << " supports(#{node.supports_condition.to_src(@options)})" if node.supports_condition
str << " #{interp_to_src(node.query)}" unless node.query.empty?
Expand All @@ -174,7 +173,7 @@ def visit_mixindef(node)
if node.args.empty? && node.splat.nil?
""
else
str = '('
str = '('.dup
str << node.args.map do |v, d|
if d
"#{v.to_sass(@options)}: #{d.to_sass(@options)}"
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/tree/visitors/perform.rb
Expand Up @@ -494,7 +494,7 @@ def visit_warn(node)
res = node.expr.perform(@environment)
res = res.value if res.is_a?(Sass::Script::Value::String)
@environment.stack.with_directive(node.filename, node.line, "@warn") do
msg = "WARNING: #{res}\n "
msg = "WARNING: #{res}\n ".dup
msg << @environment.stack.to_s.gsub("\n", "\n ") << "\n"
Sass::Util.sass_warn msg
end
Expand Down Expand Up @@ -561,7 +561,7 @@ def run_interp(text)
end

def handle_import_loop!(node)
msg = "An @import loop has been found:"
msg = "An @import loop has been found:".dup
files = @environment.stack.frames.select {|f| f.is_import?}.map {|f| f.filename}.compact
if node.filename == node.imported_file.options[:filename]
raise Sass::SyntaxError.new("#{msg} #{node.filename} imports itself")
Expand Down
6 changes: 3 additions & 3 deletions lib/sass/tree/visitors/to_css.rb
Expand Up @@ -131,7 +131,7 @@ def visit_root(node)
if node.style == :compressed && trailing_semicolon?
erase! 1
end
return "" if @result.empty?
return "".dup if @result.empty?

output "\n"

Expand Down Expand Up @@ -421,15 +421,15 @@ def format_custom_property_value(node)
def debug_info_rule(debug_info, options)
node = Sass::Tree::DirectiveNode.resolved("@media -sass-debug-info")
debug_info.map {|k, v| [k.to_s, v.to_s]}.to_a.each do |k, v|
rule = Sass::Tree::RuleNode.new([""])
rule = Sass::Tree::RuleNode.new(["".dup])
rule.resolved_rules = Sass::Selector::CommaSequence.new(
[Sass::Selector::Sequence.new(
[Sass::Selector::SimpleSequence.new(
[Sass::Selector::Element.new(k.to_s.gsub(/[^\w-]/, "\\\\\\0"), nil)],
false)
])
])
prop = Sass::Tree::PropNode.new([""], [""], :new)
prop = Sass::Tree::PropNode.new(["".dup], ["".dup], :new)
prop.resolved_name = "font-family"
prop.resolved_value = Sass::SCSS::RX.escape_ident(v.to_s)
rule << prop
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/util.rb
Expand Up @@ -898,7 +898,7 @@ def sourcemap_name(css)
def json_escape_string(s)
return s if s !~ /["\\\b\f\n\r\t]/

result = ""
result = "".dup
s.split("").each do |c|
case c
when '"', "\\"
Expand Down Expand Up @@ -963,7 +963,7 @@ def encode_vlq(value)
value <<= 1
end

result = ''
result = ''.dup
begin
digit = value & VLQ_BASE_MASK
value >>= VLQ_BASE_SHIFT
Expand Down
4 changes: 2 additions & 2 deletions test/sass/css2sass_test.rb
Expand Up @@ -498,7 +498,7 @@ def test_error_gets_rid_of_trailing_newline_for_was
# Encodings

def test_encoding_error
css2sass("foo\nbar\nb\xFEaz".force_encoding("utf-8"))
css2sass("foo\nbar\nb\xFEaz".dup.force_encoding("utf-8"))
assert(false, "Expected exception")
rescue Sass::SyntaxError => e
assert_equal(3, e.sass_line)
Expand All @@ -507,7 +507,7 @@ def test_encoding_error

def test_ascii_incompatible_encoding_error
template = "foo\nbar\nb_z".encode("utf-16le")
template[9] = "\xFE".force_encoding("utf-16le")
template[9] = "\xFE".dup.force_encoding("utf-16le")
css2sass(template)
assert(false, "Expected exception")
rescue Sass::SyntaxError => e
Expand Down
8 changes: 4 additions & 4 deletions test/sass/encoding_test.rb
Expand Up @@ -7,7 +7,7 @@ class EncodingTest < MiniTest::Test
include Sass::Util::Test

def test_encoding_error
render("foo\nbar\nb\xFEaz".force_encoding("utf-8"))
render("foo\nbar\nb\xFEaz".dup.force_encoding("utf-8"))
assert(false, "Expected exception")
rescue Sass::SyntaxError => e
assert_equal(3, e.sass_line)
Expand All @@ -16,7 +16,7 @@ def test_encoding_error

def test_ascii_incompatible_encoding_error
template = "foo\nbar\nb_z".encode("utf-16le")
template[9] = "\xFE".force_encoding("utf-16le")
template[9] = "\xFE".dup.force_encoding("utf-16le")
render(template)
assert(false, "Expected exception")
rescue Sass::SyntaxError => e
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_utf_16be_with_bom
end

def test_utf_8_with_bom
assert_renders_encoded(<<CSS, <<SASS.force_encoding("BINARY"))
assert_renders_encoded(<<CSS, <<SASS.dup.force_encoding("BINARY"))
@charset "UTF-8";
fóó {
a: b; }
Expand All @@ -118,7 +118,7 @@ def test_charset_with_multibyte_encoding
def test_charset_with_special_case_encoding
# For some reason, a file with an ASCII-compatible UTF-16 charset
# declaration is specced to be parsed as UTF-8.
assert_renders_encoded(<<CSS, <<SASS.force_encoding("BINARY"))
assert_renders_encoded(<<CSS, <<SASS.dup.force_encoding("BINARY"))
@charset "UTF-8";
fóó {
a: b; }
Expand Down
10 changes: 5 additions & 5 deletions test/sass/source_map_test.rb
Expand Up @@ -4,7 +4,7 @@

class SourcemapTest < MiniTest::Test
def test_to_json_requires_args
_, sourcemap = render_with_sourcemap('')
_, sourcemap = render_with_sourcemap(''.dup)
assert_raises(ArgumentError) {sourcemap.to_json({})}
assert_raises(ArgumentError) {sourcemap.to_json({:css_path => 'foo'})}
assert_raises(ArgumentError) {sourcemap.to_json({:sourcemap_path => 'foo'})}
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_simple_charset_mapping_sass
end

def test_different_charset_than_encoding_scss
assert_parses_with_sourcemap(<<SCSS.force_encoding("IBM866"), <<CSS, <<JSON)
assert_parses_with_sourcemap(<<SCSS.dup.force_encoding("IBM866"), <<CSS, <<JSON)
@charset "IBM866";
f\x86\x86 {
\x86: b;
Expand All @@ -203,7 +203,7 @@ def test_different_charset_than_encoding_scss
end

def test_different_charset_than_encoding_sass
assert_parses_with_sourcemap(<<SASS.force_encoding("IBM866"), <<CSS, <<JSON, :syntax => :sass)
assert_parses_with_sourcemap(<<SASS.dup.force_encoding("IBM866"), <<CSS, <<JSON, :syntax => :sass)
@charset "IBM866"
f\x86\x86
\x86: b
Expand Down Expand Up @@ -955,8 +955,8 @@ def assert_parses_with_mapping(source, css, options={})
options[:syntax] ||= :scss
input_filename = filename_for_test(options[:syntax])
mapping = build_mapping_from_annotations(source, css, input_filename)
source.gsub!(ANNOTATION_REGEX, "")
css.gsub!(ANNOTATION_REGEX, "")
source = source.gsub(ANNOTATION_REGEX, "")
css = css.gsub(ANNOTATION_REGEX, "")
rendered, sourcemap = render_with_sourcemap(source, options)
assert_equal css.rstrip, rendered.rstrip
assert_sourcemaps_equal source, css, mapping, sourcemap
Expand Down
6 changes: 3 additions & 3 deletions test/sass/util_test.rb
Expand Up @@ -98,11 +98,11 @@ def test_substitute

def test_strip_string_array
assert_equal(["foo ", " bar ", " baz"],
strip_string_array([" foo ", " bar ", " baz "]))
strip_string_array([" foo ".dup, " bar ".dup, " baz ".dup]))
assert_equal([:foo, " bar ", " baz"],
strip_string_array([:foo, " bar ", " baz "]))
strip_string_array([:foo, " bar ".dup, " baz ".dup]))
assert_equal(["foo ", " bar ", :baz],
strip_string_array([" foo ", " bar ", :baz]))
strip_string_array([" foo ".dup, " bar ".dup, :baz]))
end

def test_paths
Expand Down