Fixing #934 (at least partially).

This commit is contained in:
Jeremy Ashkenas 2010-12-15 22:59:28 -05:00
parent 3c558ebbee
commit 76e11e6f64
5 changed files with 15 additions and 4 deletions

View File

@ -604,7 +604,7 @@
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
WHITESPACE = /^[^\n\S]+/;
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
CODE = /^[-=]>/;
MULTI_DENT = /^(?:\n[^\n\S]*)+/;
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;

View File

@ -91,7 +91,7 @@
};
Base.prototype.containsPureStatement = function() {
return this.isPureStatement() || this.contains(function(node) {
return node.isPureStatement();
return node.isPureStatement() && !(node instanceof Comment);
});
};
Base.prototype.toString = function(idt, name) {

View File

@ -550,7 +550,7 @@ OPERATOR = /// ^ (
WHITESPACE = /^[^\n\S]+/
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/
CODE = /^[-=]>/

View File

@ -97,7 +97,8 @@ exports.Base = class Base
# Convenience for the most common use of contains. Does the node contain
# a pure statement?
containsPureStatement: ->
@isPureStatement() or @contains (node) -> node.isPureStatement()
@isPureStatement() or @contains (node) ->
node.isPureStatement() and node not instanceof Comment
# `toString` representation of the node, for inspecting the parse tree.
# This is what `coffee --nodes` prints out.

View File

@ -199,3 +199,13 @@ test "block comments inside class bodies", ->
b: ->
ok B.prototype.a instanceof Function
test "#934, block comments inside conditional bodies", ->
eq undefined, (if true
###
block comment
###
else
# comment
)