mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05: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;
|
return true;
|
||||||
};
|
};
|
||||||
Lexer.prototype.commentToken = function() {
|
Lexer.prototype.commentToken = function() {
|
||||||
var comment, match;
|
var match;
|
||||||
if (!(match = this.chunk.match(COMMENT))) {
|
if (!(match = this.chunk.match(COMMENT))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.line += count(match[1], "\n");
|
this.line += count(match[1], "\n");
|
||||||
this.i += match[1].length;
|
this.i += match[1].length;
|
||||||
if (match[2]) {
|
if (match[2]) {
|
||||||
comment = this.sanitizeHeredoc(match[2], {
|
this.token('HERECOMMENT', this.sanitizeHeredoc(match[2], {
|
||||||
herecomment: true
|
herecomment: true
|
||||||
});
|
}));
|
||||||
this.token('HERECOMMENT', comment.split(MULTILINER));
|
|
||||||
this.token('TERMINATOR', '\n');
|
this.token('TERMINATOR', '\n');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -604,7 +603,7 @@
|
|||||||
HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/;
|
HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/;
|
||||||
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/;
|
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/;
|
||||||
WHITESPACE = /^([ \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 = /^((-|=)>)/;
|
CODE = /^((-|=)>)/;
|
||||||
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/;
|
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/;
|
||||||
LAST_DENTS = /\n([ \t]*)/g;
|
LAST_DENTS = /\n([ \t]*)/g;
|
||||||
|
|||||||
@@ -425,7 +425,7 @@
|
|||||||
})();
|
})();
|
||||||
exports.CommentNode = (function() {
|
exports.CommentNode = (function() {
|
||||||
CommentNode = function(_b) {
|
CommentNode = function(_b) {
|
||||||
this.lines = _b;
|
this.comment = _b;
|
||||||
CommentNode.__superClass__.constructor.call(this);
|
CommentNode.__superClass__.constructor.call(this);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@@ -438,9 +438,7 @@
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
CommentNode.prototype.compileNode = function(o) {
|
CommentNode.prototype.compileNode = function(o) {
|
||||||
var sep;
|
return this.tab + '/*' + this.comment.replace(/\r?\n/g, '\n' + this.tab) + '*/';
|
||||||
sep = this.tab + '// ';
|
|
||||||
return sep + this.lines.join('\n' + sep);
|
|
||||||
};
|
};
|
||||||
return CommentNode;
|
return CommentNode;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -145,8 +145,7 @@ exports.Lexer = class Lexer
|
|||||||
@line += count match[1], "\n"
|
@line += count match[1], "\n"
|
||||||
@i += match[1].length
|
@i += match[1].length
|
||||||
if match[2]
|
if match[2]
|
||||||
comment = @sanitizeHeredoc match[2], herecomment: true
|
@token 'HERECOMMENT', @sanitizeHeredoc match[2], herecomment: true
|
||||||
@token 'HERECOMMENT', comment.split MULTILINER
|
|
||||||
@token 'TERMINATOR', '\n'
|
@token 'TERMINATOR', '\n'
|
||||||
true
|
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})/
|
HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/
|
||||||
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/
|
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/
|
||||||
WHITESPACE = /^([ \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 = /^((-|=)>)/
|
CODE = /^((-|=)>)/
|
||||||
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/
|
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/
|
||||||
LAST_DENTS = /\n([ \t]*)/g
|
LAST_DENTS = /\n([ \t]*)/g
|
||||||
|
|||||||
@@ -392,15 +392,14 @@ exports.CommentNode = class CommentNode extends BaseNode
|
|||||||
class: 'CommentNode'
|
class: 'CommentNode'
|
||||||
isStatement: -> yes
|
isStatement: -> yes
|
||||||
|
|
||||||
constructor: (@lines) ->
|
constructor: (@comment) ->
|
||||||
super()
|
super()
|
||||||
|
|
||||||
makeReturn: ->
|
makeReturn: ->
|
||||||
this
|
this
|
||||||
|
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
sep = @tab + '// '
|
@tab + '/*' + @comment.replace(/\r?\n/g, '\n' + @tab) + '*/'
|
||||||
sep + @lines.join '\n' + sep
|
|
||||||
|
|
||||||
#### CallNode
|
#### CallNode
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user