Fixing issue #1046.

This commit is contained in:
Jeremy Ashkenas 2011-01-15 10:57:50 -05:00
parent 7c7b9a4be1
commit 4c18ddf549
3 changed files with 16 additions and 9 deletions

View File

@ -480,7 +480,7 @@
throw new Error("missing " + (stack.pop()) + ", starting on line " + (this.line + 1));
};
Lexer.prototype.interpolateString = function(str, options) {
var expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value, _len, _ref, _ref2, _ref3;
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref, _ref2, _ref3;
if (options == null) {
options = {};
}
@ -509,11 +509,13 @@
if (((_ref = nested[0]) != null ? _ref[0] : void 0) === 'TERMINATOR') {
nested.shift();
}
if (nested.length > 1) {
nested.unshift(['(', '(']);
nested.push([')', ')']);
if (len = nested.length) {
if (len > 1) {
nested.unshift(['(', '(']);
nested.push([')', ')']);
}
tokens.push(['TOKENS', nested]);
}
tokens.push(['TOKENS', nested]);
}
i += expr.length;
pi = i + 1;

View File

@ -439,10 +439,11 @@ exports.Lexer = class Lexer
nested = new Lexer().tokenize inner, line: @line, rewrite: off
nested.pop()
nested.shift() if nested[0]?[0] is 'TERMINATOR'
if nested.length > 1
nested.unshift ['(', '(']
nested.push [')', ')']
tokens.push ['TOKENS', nested]
if len = nested.length
if len > 1
nested.unshift ['(', '(']
nested.push [')', ')']
tokens.push ['TOKENS', nested]
i += expr.length
pi = i + 1
tokens.push ['NEOSTRING', str.slice pi] if i > pi < str.length

View File

@ -101,3 +101,7 @@ eq ''' '\\\' ''', " '\\' "
eq """ "\\\" """, ' "\\" '
eq ''' <- keep these spaces -> ''', ' <- keep these spaces -> '
test "#1046, empty string interpolations", ->
eq "#{ }", ''