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

Support frozen string literals #3

Merged
Merged
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
8 changes: 8 additions & 0 deletions Rakefile
Expand Up @@ -6,6 +6,14 @@ Bundler::GemHelper.install_tasks
Rake::TestTask.new
task :default => [:test]

task :test => :set_frozen_string_literal_option
task :set_frozen_string_literal_option do
if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.3"
warn "NOTE: Testing support for frozen string literals"
ENV['RUBYOPT'] += " --enable-frozen-string-literal --debug=frozen-string-literal"
end
end

task :'pull-css-tests' do
sh 'git subtree pull -P test/css-parsing-tests https://github.com/SimonSapin/css-parsing-tests.git master --squash'
end
4 changes: 2 additions & 2 deletions lib/crass/parser.rb
Expand Up @@ -73,7 +73,7 @@ def self.parse_stylesheet(input, options = {})
#
def self.stringify(nodes, options = {})
nodes = [nodes] unless nodes.is_a?(Array)
string = ''
string = String.new

nodes.each do |node|
next if node.nil?
Expand Down Expand Up @@ -614,7 +614,7 @@ def parse_rule(input = @tokens)
# Returns the unescaped value of a selector name or property declaration.
def parse_value(nodes)
nodes = [nodes] unless nodes.is_a?(Array)
string = ''
string = String.new

nodes.each do |node|
case node[:node]
Expand Down
12 changes: 6 additions & 6 deletions lib/crass/tokenizer.rb
Expand Up @@ -273,7 +273,7 @@ def consume
#
# 4.3.15. http://dev.w3.org/csswg/css-syntax/#consume-the-remnants-of-a-bad-url
def consume_bad_url
text = ''
text = String.new

until @s.eos?
if valid_escape?
Expand Down Expand Up @@ -373,7 +373,7 @@ def consume_ident
#
# 4.3.12. http://dev.w3.org/csswg/css-syntax/#consume-a-name
def consume_name
result = ''
result = String.new

until @s.eos?
if match = @s.scan(RE_NAME)
Expand Down Expand Up @@ -405,7 +405,7 @@ def consume_name
#
# 4.3.13. http://dev.w3.org/csswg/css-syntax/#consume-a-number
def consume_number
repr = ''
repr = String.new
type = :integer

repr << @s.consume if @s.peek =~ RE_NUMBER_SIGN
Expand Down Expand Up @@ -459,7 +459,7 @@ def consume_numeric
# 4.3.5. http://dev.w3.org/csswg/css-syntax/#consume-a-string-token
def consume_string(ending = nil)
ending = @s.current if ending.nil?
value = ''
value = String.new

until @s.eos?
case char = @s.consume
Expand Down Expand Up @@ -499,7 +499,7 @@ def consume_string(ending = nil)
#
# 4.3.7. http://dev.w3.org/csswg/css-syntax/#consume-a-unicode-range-token
def consume_unicode_range
value = @s.scan(RE_HEX) || ''
value = @s.scan(RE_HEX) || String.new

while value.length < 6
break unless @s.peek == '?'
Expand Down Expand Up @@ -531,7 +531,7 @@ def consume_unicode_range
#
# 4.3.6. http://dev.w3.org/csswg/css-syntax/#consume-a-url-token
def consume_url
value = ''
value = String.new

@s.scan(RE_WHITESPACE)

Expand Down