Fixes #1066 -- interpolated strings are not implicit funcs
This commit is contained in:
parent
355754ed20
commit
de8ec2beb0
|
@ -590,7 +590,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Lexer.prototype.interpolateString = function(str, options) {
|
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) {
|
if (options == null) {
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
|
@ -680,7 +680,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (interpolated) {
|
if (interpolated) {
|
||||||
this.token(')', ')', offsetInChunk + lexedLength, 0);
|
rparen = this.makeToken(')', ')', offsetInChunk + lexedLength, 0);
|
||||||
|
rparen.stringEnd = true;
|
||||||
|
this.tokens.push(rparen);
|
||||||
}
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
};
|
};
|
||||||
|
|
|
@ -267,7 +267,7 @@
|
||||||
}
|
}
|
||||||
stack.pop();
|
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 === '?') {
|
if (tag === '?') {
|
||||||
tag = token[0] = 'FUNC_EXIST';
|
tag = token[0] = 'FUNC_EXIST';
|
||||||
}
|
}
|
||||||
|
|
|
@ -589,7 +589,10 @@ exports.Lexer = class Lexer
|
||||||
@tokens.push token
|
@tokens.push token
|
||||||
else
|
else
|
||||||
@error "Unexpected #{tag}"
|
@error "Unexpected #{tag}"
|
||||||
@token ')', ')', offsetInChunk + lexedLength, 0 if interpolated
|
if interpolated
|
||||||
|
rparen = @makeToken ')', ')', offsetInChunk + lexedLength, 0
|
||||||
|
rparen.stringEnd = true
|
||||||
|
@tokens.push rparen
|
||||||
tokens
|
tokens
|
||||||
|
|
||||||
# Pairs up a closing token, ensuring that all listed pairs of tokens are
|
# Pairs up a closing token, ensuring that all listed pairs of tokens are
|
||||||
|
|
|
@ -213,7 +213,7 @@ class exports.Rewriter
|
||||||
|
|
||||||
# Recognize standard implicit calls like
|
# Recognize standard implicit calls like
|
||||||
# f a, f() b, f? c, h[0] d etc.
|
# 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
|
tag is '?' and i > 0 and not tokens[i - 1].spaced) and
|
||||||
(nextTag in IMPLICIT_CALL or
|
(nextTag in IMPLICIT_CALL or
|
||||||
nextTag in IMPLICIT_UNSPACED_CALL and
|
nextTag in IMPLICIT_UNSPACED_CALL and
|
||||||
|
|
|
@ -71,5 +71,8 @@ test "#1106: __proto__ compilation", ->
|
||||||
test "reference named hasOwnProperty", ->
|
test "reference named hasOwnProperty", ->
|
||||||
CoffeeScript.compile 'hasOwnProperty = 0; a = 1'
|
CoffeeScript.compile 'hasOwnProperty = 0; a = 1'
|
||||||
|
|
||||||
test "#1055", ->
|
test "#1055: invalid keys in real (but not work-product) objects", ->
|
||||||
cantCompile "@key: value"
|
cantCompile "@key: value"
|
||||||
|
|
||||||
|
test "#1066: interpolated strings are not implicit functions", ->
|
||||||
|
cantCompile '"int#{er}polated" arg'
|
||||||
|
|
Loading…
Reference in New Issue