mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Issue #572. Flexible JavaScript block comments, compatible with JSDoc, YUI-compressor, and Google Closure compiler preservation syntax.
This commit is contained in:
@@ -163,17 +163,16 @@
|
||||
return true;
|
||||
};
|
||||
Lexer.prototype.commentToken = function() {
|
||||
var comment, match;
|
||||
var match;
|
||||
if (!(match = this.chunk.match(COMMENT))) {
|
||||
return false;
|
||||
}
|
||||
this.line += count(match[1], "\n");
|
||||
this.i += match[1].length;
|
||||
if (match[2]) {
|
||||
comment = this.sanitizeHeredoc(match[2], {
|
||||
this.token('HERECOMMENT', this.sanitizeHeredoc(match[2], {
|
||||
herecomment: true
|
||||
});
|
||||
this.token('HERECOMMENT', comment.split(MULTILINER));
|
||||
}));
|
||||
this.token('TERMINATOR', '\n');
|
||||
}
|
||||
return true;
|
||||
@@ -604,7 +603,7 @@
|
||||
HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/;
|
||||
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/;
|
||||
WHITESPACE = /^([ \t]+)/;
|
||||
COMMENT = /^(\s*\#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*\#{3}|(\s*#(?!##[^#])[^\n]*)+)/;
|
||||
COMMENT = /^(\s*\#{3}(?!#)([\s\S]*?)\#{3}[ \t]*\n|(\s*#(?!##[^#])[^\n]*)+)/;
|
||||
CODE = /^((-|=)>)/;
|
||||
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/;
|
||||
LAST_DENTS = /\n([ \t]*)/g;
|
||||
|
||||
@@ -425,7 +425,7 @@
|
||||
})();
|
||||
exports.CommentNode = (function() {
|
||||
CommentNode = function(_b) {
|
||||
this.lines = _b;
|
||||
this.comment = _b;
|
||||
CommentNode.__superClass__.constructor.call(this);
|
||||
return this;
|
||||
};
|
||||
@@ -438,9 +438,7 @@
|
||||
return this;
|
||||
};
|
||||
CommentNode.prototype.compileNode = function(o) {
|
||||
var sep;
|
||||
sep = this.tab + '// ';
|
||||
return sep + this.lines.join('\n' + sep);
|
||||
return this.tab + '/*' + this.comment.replace(/\r?\n/g, '\n' + this.tab) + '*/';
|
||||
};
|
||||
return CommentNode;
|
||||
})();
|
||||
|
||||
@@ -145,8 +145,7 @@ exports.Lexer = class Lexer
|
||||
@line += count match[1], "\n"
|
||||
@i += match[1].length
|
||||
if match[2]
|
||||
comment = @sanitizeHeredoc match[2], herecomment: true
|
||||
@token 'HERECOMMENT', comment.split MULTILINER
|
||||
@token 'HERECOMMENT', @sanitizeHeredoc match[2], herecomment: true
|
||||
@token 'TERMINATOR', '\n'
|
||||
true
|
||||
|
||||
@@ -521,7 +520,7 @@ NUMBER = /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-
|
||||
HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/
|
||||
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/
|
||||
WHITESPACE = /^([ \t]+)/
|
||||
COMMENT = /^(\s*\#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*\#{3}|(\s*#(?!##[^#])[^\n]*)+)/
|
||||
COMMENT = /^(\s*\#{3}(?!#)([\s\S]*?)\#{3}[ \t]*\n|(\s*#(?!##[^#])[^\n]*)+)/
|
||||
CODE = /^((-|=)>)/
|
||||
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/
|
||||
LAST_DENTS = /\n([ \t]*)/g
|
||||
|
||||
@@ -392,15 +392,14 @@ exports.CommentNode = class CommentNode extends BaseNode
|
||||
class: 'CommentNode'
|
||||
isStatement: -> yes
|
||||
|
||||
constructor: (@lines) ->
|
||||
constructor: (@comment) ->
|
||||
super()
|
||||
|
||||
makeReturn: ->
|
||||
this
|
||||
|
||||
compileNode: (o) ->
|
||||
sep = @tab + '// '
|
||||
sep + @lines.join '\n' + sep
|
||||
@tab + '/*' + @comment.replace(/\r?\n/g, '\n' + @tab) + '*/'
|
||||
|
||||
#### CallNode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user