diff --git a/src/babel/transformation/templates/helper-get.js b/src/babel/transformation/templates/helper-get.js index 435b8c8615..2b622262e6 100644 --- a/src/babel/transformation/templates/helper-get.js +++ b/src/babel/transformation/templates/helper-get.js @@ -1,4 +1,6 @@ (function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { diff --git a/test/core/fixtures/transformation/spec.proto-to-assign/assignment-expression/expected.js b/test/core/fixtures/transformation/spec.proto-to-assign/assignment-expression/expected.js index 0980420528..6c0de8b0e6 100644 --- a/test/core/fixtures/transformation/spec.proto-to-assign/assignment-expression/expected.js +++ b/test/core/fixtures/transformation/spec.proto-to-assign/assignment-expression/expected.js @@ -2,10 +2,8 @@ var _foo, _foo$bar, _foo$bar2; -function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } +console.log((_foo = foo, babelHelpers.defaults(_foo, bar), _foo)); -console.log((_foo = foo, _defaults(_foo, bar), _foo)); +console.log((_foo$bar = foo[bar], babelHelpers.defaults(_foo$bar, bar), _foo$bar)); -console.log((_foo$bar = foo[bar], _defaults(_foo$bar, bar), _foo$bar)); - -console.log((_foo$bar2 = foo[bar()], _defaults(_foo$bar2, bar), _foo$bar2)); +console.log((_foo$bar2 = foo[bar()], babelHelpers.defaults(_foo$bar2, bar), _foo$bar2)); \ No newline at end of file diff --git a/test/core/fixtures/transformation/spec.proto-to-assign/assignment-statement/expected.js b/test/core/fixtures/transformation/spec.proto-to-assign/assignment-statement/expected.js index 29606945ba..81c57e2442 100644 --- a/test/core/fixtures/transformation/spec.proto-to-assign/assignment-statement/expected.js +++ b/test/core/fixtures/transformation/spec.proto-to-assign/assignment-statement/expected.js @@ -1,5 +1,3 @@ "use strict"; -function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } - -_defaults(obj, bar); \ No newline at end of file +babelHelpers.defaults(obj, bar); \ No newline at end of file diff --git a/test/core/fixtures/transformation/spec.proto-to-assign/class/expected.js b/test/core/fixtures/transformation/spec.proto-to-assign/class/expected.js index d308a11edc..9e179061d5 100644 --- a/test/core/fixtures/transformation/spec.proto-to-assign/class/expected.js +++ b/test/core/fixtures/transformation/spec.proto-to-assign/class/expected.js @@ -1,21 +1,11 @@ "use strict"; -var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - -function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _defaults(subClass, superClass); } - var Foo = (function (_Bar) { function Foo() { - _classCallCheck(this, Foo); - - _get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); + babelHelpers.classCallCheck(this, Foo); + babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); } - _inherits(Foo, _Bar); - + babelHelpers.inherits(Foo, _Bar); return Foo; })(Bar); \ No newline at end of file diff --git a/test/core/fixtures/transformation/spec.proto-to-assign/object-literal/expected.js b/test/core/fixtures/transformation/spec.proto-to-assign/object-literal/expected.js index d6e2b72e94..6a6b822bd7 100644 --- a/test/core/fixtures/transformation/spec.proto-to-assign/object-literal/expected.js +++ b/test/core/fixtures/transformation/spec.proto-to-assign/object-literal/expected.js @@ -1,13 +1,11 @@ "use strict"; -var _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; }; +var foo = babelHelpers._extends({}, bar); -var foo = _extends({}, bar); - -var foo = _extends({}, bar, { +var foo = babelHelpers._extends({}, bar, { bar: "foo" }); -var foo = _extends({}, bar, { +var foo = babelHelpers._extends({}, bar, { bar: "foo" -}); +}); \ No newline at end of file diff --git a/test/core/fixtures/transformation/spec.proto-to-assign/options.json b/test/core/fixtures/transformation/spec.proto-to-assign/options.json index d9ea3ea443..90567af4a8 100644 --- a/test/core/fixtures/transformation/spec.proto-to-assign/options.json +++ b/test/core/fixtures/transformation/spec.proto-to-assign/options.json @@ -1,3 +1,4 @@ { + "externalHelpers": true, "optional": ["spec.protoToAssign"] }