[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:
Julian Rosse
2017-09-01 10:09:16 -04:00
committed by Geoffrey Booth
parent 5525b2ba01
commit b20e52da99
4 changed files with 41 additions and 3 deletions

View File

@@ -1530,7 +1530,8 @@ exports.Obj = class Obj extends Base
propSlices.push prop
addSlice()
slices.unshift new Obj unless slices[0] instanceof Obj
(new Call new Literal('Object.assign'), slices).compileToFragments o
_extends = new Value new Literal utility '_extends', o
(new Call _extends, slices).compileToFragments o
compileCSXAttributes: (o) ->
props = @properties
@@ -3728,6 +3729,19 @@ UTILITIES =
}
}
"
_extends: -> "
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: -> '{}.hasOwnProperty'