1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Closes #1064. Dot accesses force the next token to be an identifier.

This commit is contained in:
Timothy Jones 2011-01-22 19:29:07 +13:00
parent 3924c2f2bd
commit 06b0c7e928
3 changed files with 11 additions and 4 deletions

View file

@ -37,7 +37,7 @@
return (new Rewriter).rewrite(this.tokens);
};
Lexer.prototype.identifierToken = function() {
var colon, forcedIdentifier, id, input, match, prev, tag, _ref, _ref2;
var colon, forcedIdentifier, id, input, match, prev, tag, _ref, _ref2, _ref3;
if (!(match = IDENTIFIER.exec(this.chunk))) {
return 0;
}
@ -46,11 +46,11 @@
this.token('OWN', id);
return id.length;
}
forcedIdentifier = colon || (prev = last(this.tokens)) && !prev.spaced && ((_ref = prev[0]) === '.' || _ref === '?.' || _ref === '@' || _ref === '::');
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref = prev[0]) === '.' || _ref === '?.') || !prev.spaced && ((_ref2 = prev[0]) === '@' || _ref2 === '::'));
tag = 'IDENTIFIER';
if (__indexOf.call(JS_KEYWORDS, id) >= 0 || !forcedIdentifier && __indexOf.call(COFFEE_KEYWORDS, id) >= 0) {
tag = id.toUpperCase();
if (tag === 'WHEN' && (_ref2 = this.tag(), __indexOf.call(LINE_BREAK, _ref2) >= 0)) {
if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
tag = 'LEADING_WHEN';
} else if (tag === 'FOR') {
this.seenFor = true;

View file

@ -80,7 +80,8 @@ exports.Lexer = class Lexer
@token 'OWN', id
return id.length
forcedIdentifier = colon or
(prev = last @tokens) and not prev.spaced and prev[0] in ['.', '?.', '@', '::']
(prev = last @tokens) and (prev[0] in ['.', '?.'] or
not prev.spaced and prev[0] in ['@', '::'])
tag = 'IDENTIFIER'
if id in JS_KEYWORDS or

View file

@ -73,6 +73,12 @@ test "`?.` and `::` should continue lines", ->
#::
#?.foo
doesNotThrow -> CoffeeScript.compile """
oh. yes
oh. true
oh . return
"""
# Array Literals
test "indented array literals don't trigger whitespace rewriting", ->