Fixes #1066 -- interpolated strings are not implicit funcs

This commit is contained in:
Jeremy Ashkenas 2013-03-05 21:28:29 +13:00
parent 355754ed20
commit de8ec2beb0
5 changed files with 14 additions and 6 deletions

View File

@ -590,7 +590,7 @@
};
Lexer.prototype.interpolateString = function(str, options) {
var column, expr, heredoc, i, inner, interpolated, len, letter, lexedLength, line, locationToken, nested, offsetInChunk, pi, plusToken, popped, regex, strOffset, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
var column, expr, heredoc, i, inner, interpolated, len, letter, lexedLength, line, locationToken, nested, offsetInChunk, pi, plusToken, popped, regex, rparen, strOffset, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
if (options == null) {
options = {};
}
@ -680,7 +680,9 @@
}
}
if (interpolated) {
this.token(')', ')', offsetInChunk + lexedLength, 0);
rparen = this.makeToken(')', ')', offsetInChunk + lexedLength, 0);
rparen.stringEnd = true;
this.tokens.push(rparen);
}
return tokens;
};

View File

@ -267,7 +267,7 @@
}
stack.pop();
}
if ((__indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (__indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || __indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !((_ref = tokens[i + 1]) != null ? _ref.spaced : void 0) && !((_ref1 = tokens[i + 1]) != null ? _ref1.newLine : void 0))) {
if ((__indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced && !token.stringEnd || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (__indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || __indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !((_ref = tokens[i + 1]) != null ? _ref.spaced : void 0) && !((_ref1 = tokens[i + 1]) != null ? _ref1.newLine : void 0))) {
if (tag === '?') {
tag = token[0] = 'FUNC_EXIST';
}

View File

@ -589,7 +589,10 @@ exports.Lexer = class Lexer
@tokens.push token
else
@error "Unexpected #{tag}"
@token ')', ')', offsetInChunk + lexedLength, 0 if interpolated
if interpolated
rparen = @makeToken ')', ')', offsetInChunk + lexedLength, 0
rparen.stringEnd = true
@tokens.push rparen
tokens
# Pairs up a closing token, ensuring that all listed pairs of tokens are

View File

@ -213,7 +213,7 @@ class exports.Rewriter
# Recognize standard implicit calls like
# f a, f() b, f? c, h[0] d etc.
if (tag in IMPLICIT_FUNC and token.spaced or
if (tag in IMPLICIT_FUNC and token.spaced and not token.stringEnd or
tag is '?' and i > 0 and not tokens[i - 1].spaced) and
(nextTag in IMPLICIT_CALL or
nextTag in IMPLICIT_UNSPACED_CALL and

View File

@ -71,5 +71,8 @@ test "#1106: __proto__ compilation", ->
test "reference named hasOwnProperty", ->
CoffeeScript.compile 'hasOwnProperty = 0; a = 1'
test "#1055", ->
test "#1055: invalid keys in real (but not work-product) objects", ->
cantCompile "@key: value"
test "#1066: interpolated strings are not implicit functions", ->
cantCompile '"int#{er}polated" arg'