fixes #2055: destructuring assignment with `new`
This commit is contained in:
parent
97cd2dbc41
commit
7c56da26f6
|
@ -1013,9 +1013,9 @@
|
|||
var compiled, from, fromStr, to, toStr, _ref3;
|
||||
_ref3 = this.range, to = _ref3.to, from = _ref3.from;
|
||||
fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
|
||||
compiled = to && to.compile(o, LEVEL_ACCESS);
|
||||
compiled = to && to.compile(o, LEVEL_PAREN);
|
||||
if (to && !(!this.range.exclusive && +compiled === -1)) {
|
||||
toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? (+compiled + 1).toString() : "" + compiled + " + 1 || 9e9");
|
||||
toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? "" + (+compiled + 1) : (compiled = to.compile(o, LEVEL_ACCESS), "" + compiled + " + 1 || 9e9"));
|
||||
}
|
||||
return ".slice(" + fromStr + (toStr || '') + ")";
|
||||
};
|
||||
|
@ -2045,6 +2045,7 @@
|
|||
|
||||
Op.prototype.compileUnary = function(o) {
|
||||
var op, parts, plusMinus;
|
||||
if (o.level >= LEVEL_ACCESS) return (new Parens(this)).compile(o);
|
||||
parts = [op = this.operator];
|
||||
plusMinus = op === '+' || op === '-';
|
||||
if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {
|
||||
|
|
|
@ -759,13 +759,14 @@ exports.Slice = class Slice extends Base
|
|||
compileNode: (o) ->
|
||||
{to, from} = @range
|
||||
fromStr = from and from.compile(o, LEVEL_PAREN) or '0'
|
||||
compiled = to and to.compile o, LEVEL_ACCESS
|
||||
compiled = to and to.compile o, LEVEL_PAREN
|
||||
if to and not (not @range.exclusive and +compiled is -1)
|
||||
toStr = ', ' + if @range.exclusive
|
||||
compiled
|
||||
else if SIMPLENUM.test compiled
|
||||
(+compiled + 1).toString()
|
||||
"#{+compiled + 1}"
|
||||
else
|
||||
compiled = to.compile o, LEVEL_ACCESS
|
||||
"#{compiled} + 1 || 9e9"
|
||||
".slice(#{ fromStr }#{ toStr or '' })"
|
||||
|
||||
|
@ -1506,6 +1507,8 @@ exports.Op = class Op extends Base
|
|||
|
||||
# Compile a unary **Op**.
|
||||
compileUnary: (o) ->
|
||||
if o.level >= LEVEL_ACCESS
|
||||
return (new Parens this).compile o
|
||||
parts = [op = @operator]
|
||||
plusMinus = op in ['+', '-']
|
||||
parts.push ' ' if op in ['new', 'typeof', 'delete'] or
|
||||
|
|
|
@ -267,6 +267,10 @@ test "#1005: invalid identifiers allowed on LHS of destructuring assignment", ->
|
|||
CoffeeScript.compile "[@#{v}] = x"
|
||||
CoffeeScript.compile "[@#{v}...] = x"
|
||||
|
||||
test "#2055: destructuring assignment with `new`", ->
|
||||
{length} = new Array
|
||||
eq 0, length
|
||||
|
||||
|
||||
# Existential Assignment
|
||||
|
||||
|
|
Loading…
Reference in New Issue