Skip to content
Browse files

Get rid of //! and allow #{} in comments everywhere.

  • Loading branch information...
1 parent 8932111 commit 870d200fef6c93f7dd75815ba62e05a7a0663a67 @nex3 nex3 committed Oct 4, 2011
View
4 doc-src/SASS_CHANGELOG.md
@@ -48,6 +48,10 @@ to support any vendor prefix, as well as the plain `:any` selector.
are fully disallowed.
They were deprecated in 3.1.8.
+* `#{}` interpolation is now allowed in all comments.
+
+* The `!` flag may not be used with `//` comments (e.g. `//!`).
+
## 3.1.9 (Unreleased)
* Fix a regression in 3.1.8 that broke the `+` combinator in selectors.
View
14 lib/sass/engine.rb
@@ -496,7 +496,7 @@ def append_children(parent, children, root)
continued_rule = nil
end
- if child.is_a?(Tree::CommentNode) && child.silent
+ if child.is_a?(Tree::CommentNode) && child.type == :silent
if continued_comment &&
child.line == continued_comment.line +
continued_comment.lines + 1
@@ -615,17 +615,19 @@ def parse_variable(line)
def parse_comment(line)
if line.text[1] == CSS_COMMENT_CHAR || line.text[1] == SASS_COMMENT_CHAR
silent = line.text[1] == SASS_COMMENT_CHAR
- if loud = line.text[2] == SASS_LOUD_COMMENT_CHAR
- value = self.class.parse_interp(line.text, line.index, line.offset, :filename => @filename)
- value[0].slice!(2) # get rid of the "!"
- else
+ loud = !silent && line.text[2] == SASS_LOUD_COMMENT_CHAR
+ if silent
value = [line.text]
+ else
+ value = self.class.parse_interp(line.text, line.index, line.offset, :filename => @filename)
+ value[0].slice!(2) if loud # get rid of the "!"
end
value = with_extracted_values(value) do |str|
str = str.gsub(/^#{line.comment_tab_str}/m, '')[2..-1] # get rid of // or /*
format_comment_text(str, silent)
end
- Tree::CommentNode.new(value, silent, loud)
+ type = if silent then :silent elsif loud then :loud else :normal end
+ Tree::CommentNode.new(value, type)
else
Tree::RuleNode.new(parse_interp(line))
end
View
2 lib/sass/less.rb
@@ -31,7 +31,7 @@ def build_with_sass(env)
WARNING: Sass doesn't support mixing in selector sequences.
Replacing "#{sel}" with "@extend #{base}"
WARNING
- env << Node::SassNode.new(Sass::Tree::CommentNode.new("// #{sel};", true, false))
+ env << Node::SassNode.new(Sass::Tree::CommentNode.new("// #{sel};", :silent))
env << Node::SassNode.new(Sass::Tree::ExtendNode.new([base]))
end
end
View
16 lib/sass/scss/parser.rb
@@ -90,26 +90,22 @@ def whitespace
def process_comment(text, node)
silent = text =~ /^\/\//
+ loud = !silent && text =~ %r{^/[/*]!}
line = @line - text.count("\n")
- if loud = text =~ %r{^/[/*]!}
- value = Sass::Engine.parse_interp(text, line, @scanner.pos - text.size, :filename => @filename)
- value[0].slice!(2) # get rid of the "!"
- else
- value = [text]
- end
if silent
- value = Sass::Util.with_extracted_values(value) do |str|
- str.sub(/^\s*\/\//, '/*').gsub(/^\s*\/\//, ' *') + ' */'
- end
+ value = [text.sub(/^\s*\/\//, '/*').gsub(/^\s*\/\//, ' *') + ' */']
else
+ value = Sass::Engine.parse_interp(text, line, @scanner.pos - text.size, :filename => @filename)
+ value[0].slice!(2) if loud # get rid of the "!"
value.unshift(@scanner.
string[0...@scanner.pos].
reverse[/.*?\*\/(.*?)($|\Z)/, 1].
reverse.gsub(/[^\s]/, ' '))
end
- comment = Sass::Tree::CommentNode.new(value, silent, loud)
+ type = if silent then :silent elsif loud then :loud else :normal end
+ comment = Sass::Tree::CommentNode.new(value, type)
comment.line = line
node << comment
end
View
34 lib/sass/tree/comment_node.rb
@@ -19,26 +19,18 @@ class CommentNode < Node
# @return [String]
attr_accessor :resolved_value
- # Whether the comment is loud.
+ # The type of the comment. `:silent` means it's never output to CSS,
+ # `:normal` means it's output in every compile mode except `:compressed`,
+ # and `:loud` means it's output even in `:compressed`.
#
- # Loud comments start with ! and force the comment to be generated
- # irrespective of compilation settings or the comment syntax used.
- #
- # @return [Boolean]
- attr_accessor :loud
-
- # Whether or not the comment is silent (that is, doesn't output to CSS).
- #
- # @return [Boolean]
- attr_accessor :silent
+ # @return [Symbol]
+ attr_accessor :type
# @param value [Array<String, Sass::Script::Node>] See \{#value}
- # @param silent [Boolean] See \{#silent}
- # @param loud [Boolean] See \{#loud}
- def initialize(value, silent, loud)
+ # @param type [Symbol] See \{#type}
+ def initialize(value, type)
@value = Sass::Util.with_extracted_values(value) {|str| normalize_indentation str}
- @silent = silent
- @loud = loud
+ @type = type
super()
end
@@ -48,7 +40,7 @@ def initialize(value, silent, loud)
# @return [Boolean] Whether or not this node and the other object
# are the same
def ==(other)
- self.class == other.class && value == other.value && silent == other.silent && loud == other.loud
+ self.class == other.class && value == other.value && type == other.type
end
# Returns `true` if this is a silent comment
@@ -58,10 +50,10 @@ def ==(other)
#
# @return [Boolean]
def invisible?
- if @loud
- return false
- else
- @silent || (style == :compressed)
+ case @type
+ when :loud; false
+ when :silent; true
+ else; style == :compressed
end
end
View
16 lib/sass/tree/visitors/convert.rb
@@ -71,33 +71,27 @@ def visit_comment(node)
else
content.gsub!(/\n( \*|\/\/)/, "\n ")
spaces = content.scan(/\n( *)/).map {|s| s.first.size}.min
- sep = node.silent ? "\n//" : "\n *"
+ sep = node.type == :silent ? "\n//" : "\n *"
if spaces >= 2
content.gsub(/\n /, sep)
else
content.gsub(/\n#{' ' * spaces}/, sep)
end
end
- content.gsub!(/\A\/\*/, '//') if node.silent
+ content.gsub!(/\A\/\*/, '//') if node.type == :silent
content.gsub!(/^/, tab_str)
content.rstrip + "\n"
else
spaces = (' ' * [@tabs - value[/^ */].size, 0].max)
- content = if node.silent
+ content = if node.type == :silent
value.gsub(/^[\/ ]\*/, '//').gsub(/ *\*\/$/, '')
else
value
end.gsub(/^/, spaces) + "\n"
content
end
- if node.loud
- if node.silent
- content.gsub!(%r{^\s*(//!?)}, '//!')
- else
- content.sub!(%r{^\s*(/\*)}, '/*!')
- end
- end
+ content.sub!(%r{^\s*(/\*)}, '/*!') if node.type == :loud
content
end
@@ -205,7 +199,7 @@ def visit_rule(node)
elsif @format == :scss
name = selector_to_scss(node.rule)
res = name + yield
- if node.children.last.is_a?(Sass::Tree::CommentNode) && node.children.last.silent
+ if node.children.last.is_a?(Sass::Tree::CommentNode) && node.children.last.type == :silent
res.slice!(-3..-1)
res << "\n" << tab_str << "}\n"
end
View
28 lib/sass/tree/visitors/perform.rb
@@ -55,8 +55,6 @@ def visit_root(node)
# Removes this node from the tree if it's a silent comment.
def visit_comment(node)
return [] if node.invisible?
- check_for_loud_silent_comment node
- check_for_comment_interp node
node.resolved_value = run_interp_no_strip(node.value)
node.resolved_value.gsub!(/\\([\\#])/, '\1')
node
@@ -349,30 +347,4 @@ def handle_include_loop!(node)
end.join("\n")
raise Sass::SyntaxError.new(msg)
end
-
- def check_for_loud_silent_comment(node)
- return unless node.loud && node.silent
- Sass::Util.sass_warn <<MESSAGE
-WARNING:
-On line #{node.line}#{" of '#{node.filename}'" if node.filename}
-`//` comments will no longer be allowed to use the `!` flag in Sass 3.2.
-Please change to `/*` comments.
-MESSAGE
- end
-
- def check_for_comment_interp(node)
- return if node.loud
- node.value.each do |e|
- next unless e.is_a?(String)
- e.scan(/(\\*)#\{/) do |esc|
- Sass::Util.sass_warn <<MESSAGE if esc.first.size.even?
-WARNING:
-On line #{node.line}#{" of '#{node.filename}'" if node.filename}
-Comments will evaluate the contents of interpolations (\#{ ... }) in Sass 3.2.
-Please escape the interpolation by adding a backslash before the `#`.
-MESSAGE
- return
- end
- end
- end
end
View
2 lib/sass/tree/visitors/to_css.rb
@@ -62,7 +62,7 @@ def visit_comment(node)
content = node.resolved_value.gsub(/^/, spaces).gsub(%r{^(\s*)//(.*)$}) do |md|
"#{$1}/*#{$2} */"
end
- content.gsub!(/\n +(\* *(?!\/))?/, ' ') if (node.style == :compact || node.style == :compressed) && !node.loud
+ content.gsub!(/\n +(\* *(?!\/))?/, ' ') if (node.style == :compact || node.style == :compressed) && node.type != :loud
content
end
View
9 test/sass/conversion_test.rb
@@ -1137,15 +1137,6 @@ def test_loud_comment_conversion
SASS
/*! \#{"interpolated"} */
SCSS
- silence_warnings {assert_renders(<<SASS, <<SCSS)}
-//! \#{"interpolated"}
-//!
-//! \#{"also interpolated"}
-SASS
-//! \#{"interpolated"}
-//!
-//! \#{"also interpolated"}
-SCSS
end
def test_content_conversion
View
35 test/sass/engine_test.rb
@@ -1577,23 +1577,6 @@ def test_loud_comment_in_compressed_mode
SASS
end
- def test_loud_comment_in_silent_comment
- silence_warnings {assert_equal <<CSS, render(<<SASS, :style => :compressed)}
-foo{color:blue;/* foo */
-/* bar */
-/* bip */
-/* baz */}
-CSS
-foo
- color: blue
- //! foo
- //! bar
- //!
- bip
- baz
-SASS
- end
-
def test_loud_comment_is_evaluated
assert_equal <<CSS, render(<<SASS)
/* Hue: 327.216deg */
@@ -2333,24 +2316,6 @@ def test_unknown_directive
SASS
end
- def test_comment_interpolation_warning
- assert_warning(<<END) {render("/* \#{foo}")}
-WARNING:
-On line 1 of 'test_comment_interpolation_warning_inline.sass'
-Comments will evaluate the contents of interpolations (\#{ ... }) in Sass 3.2.
-Please escape the interpolation by adding a backslash before the `#`.
-END
- end
-
- def test_loud_silent_comment_warning
- assert_warning(<<END) {render("//! \#{foo}")}
-WARNING:
-On line 1 of 'test_loud_silent_comment_warning_inline.sass'
-`//` comments will no longer be allowed to use the `!` flag in Sass 3.2.
-Please change to `/*` comments.
-END
- end
-
def test_loud_comment_interpolations_can_be_escaped
assert_equal <<CSS, render(<<SASS)
/* \#{foo} */

0 comments on commit 870d200

Please sign in to comment.
Something went wrong with that request. Please try again.