From 363b1631f5a3455df85577cb6ebb9e5aec540942 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 15 Dec 2014 14:00:41 +1100 Subject: [PATCH] switch to core-js from es6-symbol and es6-shim Conflicts: lib/6to5/polyfill.js --- doc/polyfill.md | 9 ++++----- lib/6to5/polyfill.js | 41 ++++++++++------------------------------- package.json | 3 +-- test/transformation.js | 4 ++-- 4 files changed, 17 insertions(+), 40 deletions(-) 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 9e98ba264a..74d40a296c 100644 --- a/lib/6to5/polyfill.js +++ b/lib/6to5/polyfill.js @@ -1,37 +1,16 @@ /* jshint newcap: false */ +require("core-js/shim"); +require("./transformation/transformers/es6-generators/runtime"); + var ensureSymbol = function (key) { Symbol[key] = Symbol[key] || Symbol(); }; -var ensureProto = function (Constructor, key, val) { - var proto = Constructor.prototype; - proto[key] = proto[key] || val; -}; - -// - -if (typeof Symbol === "undefined") { - require("es6-symbol/implement"); -} - -require("es6-shim"); -require("./transformation/transformers/es6-generators/runtime"); - -// 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("species"); +ensureSymbol("hasInstance"); +ensureSymbol("isConcatSpreadable"); +ensureSymbol("isRegExp"); +ensureSymbol("toPrimitive"); +ensureSymbol("toStringTag"); +ensureSymbol("unscopables"); diff --git a/package.json b/package.json index 6b825114b2..7c00d4f611 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,7 @@ "ast-types": "0.6.5", "chokidar": "0.11.1", "commander": "2.5.0", - "es6-shim": "0.21.0", - "es6-symbol": "0.1.1", + "core-js": "^0.2.2", "estraverse": "1.8.0", "esutils": "1.1.6", "fs-readdir-recursive": "0.1.0", diff --git a/test/transformation.js b/test/transformation.js index 388097e447..582ef49e4c 100644 --- a/test/transformation.js +++ b/test/transformation.js @@ -7,6 +7,8 @@ var chai = require("chai"); var util = require("../lib/6to5/util"); var _ = require("lodash"); +require("../lib/6to5/polyfill"); + var run = function (task, done) { var actual = task.actual; var expect = task.expect; @@ -27,8 +29,6 @@ var run = function (task, done) { result = transform(execCode, getOpts(exec)); execCode = result.code; - require("../lib/6to5/polyfill"); - try { var fn = new Function("assert", "done", "genHelpers", execCode); fn(assert, done, genHelpers);