mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Empty expression interpolations evaluate as empty strings now.
This commit is contained in:
parent
532464f7ae
commit
a5f69ef716
3 changed files with 22 additions and 14 deletions
12
lib/lexer.js
12
lib/lexer.js
|
@ -471,17 +471,21 @@
|
|||
tokens.push(['IDENTIFIER', interp]);
|
||||
i += group.length - 1;
|
||||
pi = i + 1;
|
||||
} else if (((expr = this.balanced_string(str.substring(i), ['${', '}']))) && expr.length > 3) {
|
||||
} else if (((expr = this.balanced_string(str.substring(i), ['${', '}'])))) {
|
||||
if (pi < i) {
|
||||
tokens.push(['STRING', quote + (str.substring(pi, i)) + quote]);
|
||||
}
|
||||
inner = expr.substring(2, expr.length - 1);
|
||||
if (inner.length) {
|
||||
nested = lexer.tokenize("(" + inner + ")", {
|
||||
rewrite: false,
|
||||
line: this.line
|
||||
});
|
||||
nested.pop();
|
||||
if (pi < i) {
|
||||
tokens.push(['STRING', quote + (str.substring(pi, i)) + quote]);
|
||||
}
|
||||
tokens.push(['TOKENS', nested]);
|
||||
} else {
|
||||
tokens.push(['STRING', quote + quote]);
|
||||
}
|
||||
i += expr.length - 1;
|
||||
pi = i + 1;
|
||||
}
|
||||
|
|
|
@ -349,12 +349,15 @@ exports.Lexer: class Lexer
|
|||
tokens.push ['IDENTIFIER', interp]
|
||||
i += group.length - 1
|
||||
pi: i + 1
|
||||
else if (expr: @balanced_string str.substring(i), ['${', '}']) and expr.length > 3
|
||||
else if (expr: @balanced_string str.substring(i), ['${', '}'])
|
||||
tokens.push ['STRING', "$quote${ str.substring(pi, i) }$quote"] if pi < i
|
||||
inner: expr.substring(2, expr.length - 1)
|
||||
if inner.length
|
||||
nested: lexer.tokenize "($inner)", {rewrite: no, line: @line}
|
||||
nested.pop()
|
||||
tokens.push ['STRING', "$quote${ str.substring(pi, i) }$quote"] if pi < i
|
||||
tokens.push ['TOKENS', nested]
|
||||
else
|
||||
tokens.push ['STRING', "$quote$quote"]
|
||||
i += expr.length - 1
|
||||
pi: i + 1
|
||||
i += 1
|
||||
|
|
|
@ -28,7 +28,8 @@ ok "Escaping \$last" is 'Escaping $last'
|
|||
ok "Escaping \${last}" is 'Escaping ${last}'
|
||||
|
||||
ok "$$" is '$$'
|
||||
ok "${}" is '${}'
|
||||
ok "${}" is ''
|
||||
ok "${}A${} ${} ${}B${}" is 'A B'
|
||||
ok "\\\\\$$" is '\\\\\$$'
|
||||
ok "\\\${}" is '\\${}'
|
||||
|
||||
|
|
Loading…
Reference in a new issue