Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Commit

Permalink
always include web polyfills for now
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Dec 9, 2016
1 parent 370125e commit 96fdc57
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/transformPolyfillRequirePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ function isPolyfillSource(value) {
return value === "babel-polyfill" || value === "core-js";
}

const whitelist = [
"web.timers",
"web.immediate",
"web.dom.iterable"
];

export default function ({ types: t }) {
function createImportDeclaration(polyfill) {
let declar = t.importDeclaration([], t.stringLiteral(`core-js/modules/${polyfill}`));
Expand Down Expand Up @@ -60,7 +66,7 @@ export default function ({ types: t }) {
}

path.replaceWithMultiple(
createImports(state.opts.polyfills, "import", state.opts.regenerator)
createImports([...state.opts.polyfills, ...whitelist], "import", state.opts.regenerator)
);
}
},
Expand All @@ -81,7 +87,7 @@ to the "transform-polyfill-require" plugin
}

bodyPath.replaceWithMultiple(
createImports(state.opts.polyfills, "require", state.opts.regenerator)
createImports([...state.opts.polyfills, ...whitelist], "require", state.opts.regenerator)
);
}
});
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/plugin-options/filters-duplicates/expected.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import "core-js/modules/es6.typed.data-view";
import "core-js/modules/es6.reflect.apply";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
3 changes: 3 additions & 0 deletions test/fixtures/plugin-options/regenerator-false/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
5 changes: 4 additions & 1 deletion test/fixtures/plugin-options/regenerator-true/expected.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import "core-js/modules/regenerator-runtime/runtime";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/regenerator-runtime/runtime";
5 changes: 4 additions & 1 deletion test/fixtures/preset-options/core-js/expected.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import "core-js/modules/es7.string.pad-start";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
2 changes: 1 addition & 1 deletion test/fixtures/preset-options/empty-options/expected.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"use strict";

var a = "1";
var a = "1";
2 changes: 1 addition & 1 deletion test/fixtures/preset-options/modules-false/expected.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import a from "a";
import a from "a";
2 changes: 1 addition & 1 deletion test/fixtures/preset-options/no-options/expected.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"use strict";

var a = "1";
var a = "1";
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import "core-js/modules/es7.object.entries";
import "core-js/modules/es7.object.get-own-property-descriptors";
import "core-js/modules/es7.string.pad-start";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/regenerator-runtime/runtime";

Math.pow(1, 2);
Math.pow(1, 2);
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import "core-js/modules/es7.object.entries";
import "core-js/modules/es7.object.get-own-property-descriptors";
import "core-js/modules/es7.string.pad-start";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/regenerator-runtime/runtime";

Math.pow(1, 2);
Math.pow(1, 2);
5 changes: 4 additions & 1 deletion test/fixtures/preset-options/use-builtins-import/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import "core-js/modules/es7.string.pad-start";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";

1 ** 2;
1 ** 2;
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import "core-js/modules/es7.string.pad-start";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";

1 ** 2;
1 ** 2;
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ import "core-js/modules/es7.object.entries";
import "core-js/modules/es7.object.get-own-property-descriptors";
import "core-js/modules/es7.string.pad-start";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/regenerator-runtime/runtime";

Math.pow(1, 2);
Math.pow(1, 2);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ require("core-js/modules/es7.string.pad-start");

require("core-js/modules/es7.string.pad-end");

1 ** 2;
require("core-js/modules/web.timers");

require("core-js/modules/web.immediate");

require("core-js/modules/web.dom.iterable");

1 ** 2;
2 changes: 1 addition & 1 deletion test/fixtures/preset-options/whitelist/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ var _a = require("a");

var _a2 = _interopRequireDefault(_a);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

0 comments on commit 96fdc57

Please sign in to comment.