From 28c05b2861c03ebf5bf72eca206a1308513e9873 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 8 Mar 2019 09:00:00 -0800 Subject: [PATCH] fix: fix babel-runtime not found fixes #228 --- .babelrc | 4 +++- src/polyfills/classCallCheck.js | 5 +++++ src/polyfills/keys.js | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/polyfills/classCallCheck.js create mode 100644 src/polyfills/keys.js diff --git a/.babelrc b/.babelrc index 11c2e5f..fe082af 100644 --- a/.babelrc +++ b/.babelrc @@ -34,7 +34,9 @@ "babel-runtime/helpers/extends": "./src/polyfills/extends", "babel-runtime/helpers/inherits": "./src/polyfills/inherits", "babel-runtime/helpers/createClass": "./src/polyfills/createClass", - "babel-runtime/helpers/possibleConstructorReturn": "./src/polyfills/possibleConstructorReturn" + "babel-runtime/helpers/possibleConstructorReturn": "./src/polyfills/possibleConstructorReturn", + "babel-runtime/helpers/classCallCheck": "./src/polyfills/classCallCheck", + "babel-runtime/core-js/object/keys": "./src/polyfills/keys" } } ] diff --git a/src/polyfills/classCallCheck.js b/src/polyfills/classCallCheck.js new file mode 100644 index 0000000..aa83175 --- /dev/null +++ b/src/polyfills/classCallCheck.js @@ -0,0 +1,5 @@ +export default function(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError('Cannot call a class as a function') + } +} diff --git a/src/polyfills/keys.js b/src/polyfills/keys.js new file mode 100644 index 0000000..b683766 --- /dev/null +++ b/src/polyfills/keys.js @@ -0,0 +1,38 @@ +// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys +var hasOwnProperty = Object.prototype.hasOwnProperty, + hasDontEnumBug = !{ toString: null }.propertyIsEnumerable('toString'), + dontEnums = [ + 'toString', + 'toLocaleString', + 'valueOf', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'constructor', + ], + dontEnumsLength = dontEnums.length + +export default function(obj) { + if (typeof obj !== 'function' && (typeof obj !== 'object' || obj === null)) { + throw new TypeError('Object.keys called on non-object') + } + + var result = [], + prop, + i + + for (prop in obj) { + if (hasOwnProperty.call(obj, prop)) { + result.push(prop) + } + } + + if (hasDontEnumBug) { + for (i = 0; i < dontEnumsLength; i++) { + if (hasOwnProperty.call(obj, dontEnums[i])) { + result.push(dontEnums[i]) + } + } + } + return result +}