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

Proper testing, this time.

This commit is contained in:
Timothy Jones 2010-10-21 14:37:58 +13:00
parent e694b41a94
commit f229f791a9
5 changed files with 18 additions and 19 deletions

View file

@ -302,23 +302,20 @@
return true;
};
Lexer.prototype.whitespaceToken = function() {
var match, prev;
if (!(match = WHITESPACE.exec(this.chunk))) {
var match, nline, prev;
if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.substring(0, 1) === '\n'))) {
return false;
}
prev = last(this.tokens);
if (prev) {
prev.spaced = true;
prev[match ? 'spaced' : 'newLine'] = true;
}
this.i += match[0].length;
return true;
if (match) {
this.i += match[0].length;
}
return !!match;
};
Lexer.prototype.newlineToken = function(newlines) {
var prev;
prev = last(this.tokens);
if (prev) {
prev.newLine = true;
}
if (this.tag() !== 'TERMINATOR') {
this.token('TERMINATOR', '\n');
}

View file

@ -201,7 +201,7 @@
if (prev && !prev.spaced && tag === '?') {
token.call = true;
}
if (!(callObject || ((prev != null) ? prev.spaced : undefined) && (prev.call || (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !token.spaced && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) {
if (!(callObject || ((prev != null) ? prev.spaced : undefined) && (prev.call || (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !(token.spaced || token.newLine) && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) {
return 1;
}
tokens.splice(i, 0, ['CALL_START', '(', token[2]]);

View file

@ -281,16 +281,14 @@ exports.Lexer = class Lexer
# Matches and consumes non-meaningful whitespace. Tag the previous token
# as being "spaced", because there are some cases where it makes a difference.
whitespaceToken: ->
return false unless match = WHITESPACE.exec @chunk
return false unless (match = WHITESPACE.exec @chunk) or nline = @chunk.substring(0, 1) is '\n'
prev = last @tokens
prev.spaced = true if prev
@i += match[0].length
true
prev[if match then 'spaced' else 'newLine'] = true if prev
@i += match[0].length if match
!!match
# Generate a newline token. Consecutive newlines get merged together.
newlineToken: (newlines) ->
prev = last @tokens
prev.newLine = true if prev
@token 'TERMINATOR', '\n' unless @tag() is 'TERMINATOR'
true

View file

@ -165,7 +165,7 @@ class exports.Rewriter
token.call = yes if prev and not prev.spaced and tag is '?'
return 1 unless callObject or
prev?.spaced and (prev.call or prev[0] in IMPLICIT_FUNC) and
(tag in IMPLICIT_CALL or not token.spaced and tag in IMPLICIT_UNSPACED_CALL)
(tag in IMPLICIT_CALL or not (token.spaced or token.newLine) and tag in IMPLICIT_UNSPACED_CALL)
tokens.splice i, 0, ['CALL_START', '(', token[2]]
@detectEnd i + (if callObject then 2 else 1), (token, i) ->
return yes if not seenSingle and token.fromThen

View file

@ -155,6 +155,10 @@ ok a() not in [b(),c()] and share is 3
# Operators should respect new lines as spaced.
a = 123 +
a = (123) +
456
ok a is 579
a = "1#{2}3" +
"456"
ok a is '123456'