Removed `__splice` in the same manner
This commit is contained in:
parent
ca9e45e8af
commit
c498b7090e
|
@ -736,14 +736,16 @@
|
|||
return ".slice(" + from + ", " + to + plus_part + ")";
|
||||
};
|
||||
SliceNode.prototype.compile_splice = function compile_splice(o) {
|
||||
var _a, _b, array, call, exclusive, from, ref, replace, to;
|
||||
var _a, _b, args, array, call, exclusive, from, replace, rng, to, v;
|
||||
array = del(o, 'array');
|
||||
replace = del(o, 'replace');
|
||||
from = (typeof (_a = this.range.from) !== "undefined" && _a !== null) ? this.range.from : literal('null');
|
||||
to = (typeof (_b = this.range.to) !== "undefined" && _b !== null) ? this.range.to : literal('null');
|
||||
exclusive = this.range.exclusive ? 'true' : 'false';
|
||||
ref = new ValueNode(literal(o.scope.utility('splice')));
|
||||
call = new CallNode(ref, [literal(array), from, to, literal(exclusive), replace]);
|
||||
v = o.scope.free_variable();
|
||||
rng = new CallNode(new ValueNode(literal(o.scope.utility('range'))), [literal(array), from, to, literal(exclusive)]);
|
||||
args = literal("[(" + v + " = " + (rng.compile(o)) + ")[0], " + v + "[1] - " + v + "[0]].concat(" + (replace.compile(o)) + ")");
|
||||
call = new CallNode(new ValueNode(literal(array), [literal('.splice.apply')]), [literal(array), args]);
|
||||
return call.compile(o);
|
||||
};
|
||||
SliceNode.prototype.compile_slice = function compile_slice(o) {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n}",
|
||||
bind: "function(func, obj, args) {\n obj = obj || {};\n return (typeof args !== 'undefined' && args !== null) ? function() {\n return func.apply(obj, args.concat(" + (utilities.key('arraySlice')) + ".call(arguments, 0)));\n } : function() {\n return func.apply(obj, arguments);\n };\n}",
|
||||
range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n}",
|
||||
splice: "function(array, from, to, exclusive, replace) {\n return array.splice.apply(array, [(_a = " + (utilities.key('range')) + "(array, from, to, exclusive))[0], \n _a[1] - _a[0]].concat(replace));\n}",
|
||||
hasProp: 'Object.prototype.hasOwnProperty',
|
||||
arraySlice: 'Array.prototype.slice'
|
||||
};
|
||||
|
|
|
@ -546,8 +546,10 @@ exports.SliceNode: class SliceNode extends BaseNode
|
|||
from: if @range.from? then @range.from else literal('null')
|
||||
to: if @range.to? then @range.to else literal('null')
|
||||
exclusive: if @range.exclusive then 'true' else 'false'
|
||||
ref: new ValueNode literal(o.scope.utility('splice'))
|
||||
call: new CallNode ref, [literal(array), from, to, literal(exclusive), replace]
|
||||
v: o.scope.free_variable()
|
||||
rng: new CallNode new ValueNode(literal(o.scope.utility('range'))), [literal(array), from, to, literal(exclusive)]
|
||||
args: literal "[($v = ${rng.compile(o)})[0], $v[1] - $v[0]].concat(${replace.compile(o)})"
|
||||
call: new CallNode new ValueNode(literal(array), [literal('.splice.apply')]), [literal(array), args]
|
||||
call.compile(o)
|
||||
|
||||
compile_slice: (o) ->
|
||||
|
|
|
@ -40,12 +40,6 @@ exports.utilities: class utilities
|
|||
];
|
||||
}
|
||||
"""
|
||||
splice: """
|
||||
function(array, from, to, exclusive, replace) {
|
||||
return array.splice.apply(array, [(_a = ${utilities.key('range')}(array, from, to, exclusive))[0],
|
||||
_a[1] - _a[0]].concat(replace));
|
||||
}
|
||||
"""
|
||||
hasProp: 'Object.prototype.hasOwnProperty'
|
||||
arraySlice: 'Array.prototype.slice'
|
||||
}
|
Loading…
Reference in New Issue