mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
[CS2] use _extends utility instead of Object.assign() for object spreads (#4675)
* _extends utility instead of Object.assign() * eqJS test for _extends * Test that a user-defined function named `_extends` doesn’t conflict with our utility function * IE8 polyfill note in docs
This commit is contained in:
committed by
Geoffrey Booth
parent
5525b2ba01
commit
b20e52da99
@@ -2242,7 +2242,7 @@
|
||||
// Object spread properties. https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md
|
||||
// `obj2 = {a: 1, obj..., c: 3, d: 4}` → `obj2 = Object.assign({}, {a: 1}, obj, {c: 3, d: 4})`
|
||||
compileSpread(o) {
|
||||
var addSlice, j, len1, prop, propSlices, props, slices, splatSlice;
|
||||
var _extends, addSlice, j, len1, prop, propSlices, props, slices, splatSlice;
|
||||
props = this.properties;
|
||||
// Store object spreads.
|
||||
splatSlice = [];
|
||||
@@ -2271,7 +2271,8 @@
|
||||
if (!(slices[0] instanceof Obj)) {
|
||||
slices.unshift(new Obj);
|
||||
}
|
||||
return (new Call(new Literal('Object.assign'), slices)).compileToFragments(o);
|
||||
_extends = new Value(new Literal(utility('_extends', o)));
|
||||
return (new Call(_extends, slices)).compileToFragments(o);
|
||||
}
|
||||
|
||||
compileCSXAttributes(o) {
|
||||
@@ -5546,6 +5547,9 @@
|
||||
boundMethodCheck: function() {
|
||||
return "function(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new Error('Bound instance method accessed before binding'); } }";
|
||||
},
|
||||
_extends: function() {
|
||||
return "Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }";
|
||||
},
|
||||
// Shortcuts to speed up the lookup time for native functions.
|
||||
hasProp: function() {
|
||||
return '{}.hasOwnProperty';
|
||||
|
||||
Reference in New Issue
Block a user