diff --git a/doc/polyfill.md b/doc/polyfill.md index 631f9adb73..47bbbcd521 100644 --- a/doc/polyfill.md +++ b/doc/polyfill.md @@ -1,12 +1,11 @@ # Polyfill -6to5 includes a polyfill that includes the -[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and the -[es6-shim](https://github.com/paulmillr/es6-shim) and -[es6-symbol](https://github.com/medikoo/es6-symbol) polyfills. +6to5 includes a polyfill that includes a custom +[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and +[core.js](https://github.com/zloirock/core-js). This will emulate a full ES6 environment. This polyfill is automatically loaded -when using [6to5-node](usage.md#node). +when using [6to5-node](usage.md#node) and [6to5/register](usage.md#register-hook). ## Usage diff --git a/lib/6to5/polyfill.js b/lib/6to5/polyfill.js index f6253cf6e9..7fe5f07da6 100644 --- a/lib/6to5/polyfill.js +++ b/lib/6to5/polyfill.js @@ -1,53 +1,16 @@ /* jshint newcap: false, freeze: false */ +require("core-js/shim"); +require("./transformation/transformers/es6-generators/runtime"); + var ensureSymbol = function (key) { Symbol[key] = Symbol[key] || Symbol(key); }; -var ensureProto = function (Constructor, key, val) { - var proto = Constructor.prototype; - if (!proto[key]) { - Object.defineProperty(proto, key, { - value: val - }); - } -}; - -// - -if (typeof Symbol === "undefined") { - require("es6-symbol/implement"); - - var globSymbols = {}; - - Symbol.for = function (key) { - return globSymbols[key] = globSymbols[key] || Symbol(key); - }; - - Symbol.keyFor = function (sym) { - return sym.__description__; - }; -} - -require("es6-shim"); -require("./transformation/transformers/es6-generators/runtime"); - ensureSymbol("species"); - -// Abstract references - -ensureSymbol("referenceGet"); -ensureSymbol("referenceSet"); -ensureSymbol("referenceDelete"); - -ensureProto(Function, Symbol.referenceGet, function () { return this; }); - -ensureProto(Map, Symbol.referenceGet, Map.prototype.get); -ensureProto(Map, Symbol.referenceSet, Map.prototype.set); -ensureProto(Map, Symbol.referenceDelete, Map.prototype.delete); - -if (global.WeakMap) { - ensureProto(WeakMap, Symbol.referenceGet, WeakMap.prototype.get); - ensureProto(WeakMap, Symbol.referenceSet, WeakMap.prototype.set); - ensureProto(WeakMap, Symbol.referenceDelete, WeakMap.prototype.delete); -} +ensureSymbol("hasInstance"); +ensureSymbol("isConcatSpreadable"); +ensureSymbol("isRegExp"); +ensureSymbol("toPrimitive"); +ensureSymbol("toStringTag"); +ensureSymbol("unscopables");