account for web.iterable (#283)
* account for web.iterable * extra test, remove unncessary warning
This commit is contained in:
parent
de29bb374f
commit
e4d2c4e346
@ -64,15 +64,6 @@ export default function({ types: t }) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Program(path, state) {
|
Program(path, state) {
|
||||||
if (!state.opts.polyfills) {
|
|
||||||
throw path.buildCodeFrameError(
|
|
||||||
`
|
|
||||||
There was an issue in "babel-preset-env" such that
|
|
||||||
the "polyfills" option was not correctly passed
|
|
||||||
to the "transform-polyfill-require" plugin
|
|
||||||
`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
path.get("body").forEach(bodyPath => {
|
path.get("body").forEach(bodyPath => {
|
||||||
if (isRequire(bodyPath)) {
|
if (isRequire(bodyPath)) {
|
||||||
bodyPath.replaceWithMultiple(
|
bodyPath.replaceWithMultiple(
|
||||||
|
|||||||
@ -78,16 +78,7 @@ Please remove the "import 'babel-polyfill'" call or use "useBuiltIns: 'entry'" i
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Program: {
|
Program: {
|
||||||
enter(path, state) {
|
enter(path) {
|
||||||
if (!state.opts.polyfills) {
|
|
||||||
throw path.buildCodeFrameError(
|
|
||||||
`
|
|
||||||
There was an issue in "babel-preset-env" such that
|
|
||||||
the "polyfills" option was not correctly passed
|
|
||||||
to the "transform-polyfill-require" plugin
|
|
||||||
`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
path.get("body").forEach(bodyPath => {
|
path.get("body").forEach(bodyPath => {
|
||||||
if (isRequire(bodyPath)) {
|
if (isRequire(bodyPath)) {
|
||||||
console.warn(
|
console.warn(
|
||||||
@ -102,8 +93,8 @@ Please remove the "require('babel-polyfill')" call or use "useBuiltIns: 'entry'"
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Symbol() -> _core.Symbol();
|
// Symbol()
|
||||||
// new Promise -> new _core.Promise
|
// new Promise
|
||||||
ReferencedIdentifier(path, state) {
|
ReferencedIdentifier(path, state) {
|
||||||
const { node, parent, scope } = path;
|
const { node, parent, scope } = path;
|
||||||
|
|
||||||
@ -115,7 +106,49 @@ Please remove the "require('babel-polyfill')" call or use "useBuiltIns: 'entry'"
|
|||||||
addUnsupported(path, state.opts.polyfills, builtIn, this.builtIns);
|
addUnsupported(path, state.opts.polyfills, builtIn, this.builtIns);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Array.from -> _core.Array.from
|
// arr[Symbol.iterator]()
|
||||||
|
CallExpression(path) {
|
||||||
|
// we can't compile this
|
||||||
|
if (path.node.arguments.length) return;
|
||||||
|
|
||||||
|
const callee = path.node.callee;
|
||||||
|
if (!t.isMemberExpression(callee)) return;
|
||||||
|
if (!callee.computed) return;
|
||||||
|
if (!path.get("callee.property").matchesPattern("Symbol.iterator")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
addImport(
|
||||||
|
path,
|
||||||
|
"babel-polyfill/lib/core-js/modules/web.dom.iterable",
|
||||||
|
this.builtIns,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Symbol.iterator in arr
|
||||||
|
BinaryExpression(path) {
|
||||||
|
if (path.node.operator !== "in") return;
|
||||||
|
if (!path.get("left").matchesPattern("Symbol.iterator")) return;
|
||||||
|
|
||||||
|
addImport(
|
||||||
|
path,
|
||||||
|
"babel-polyfill/lib/core-js/modules/web.dom.iterable",
|
||||||
|
this.builtIns,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
// yield*
|
||||||
|
YieldExpression(path) {
|
||||||
|
if (!path.node.delegate) return;
|
||||||
|
|
||||||
|
addImport(
|
||||||
|
path,
|
||||||
|
"babel-polyfill/lib/core-js/modules/web.dom.iterable",
|
||||||
|
this.builtIns,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Array.from
|
||||||
MemberExpression: {
|
MemberExpression: {
|
||||||
enter(path, state) {
|
enter(path, state) {
|
||||||
if (!path.isReferenced()) return;
|
if (!path.isReferenced()) return;
|
||||||
@ -134,6 +167,13 @@ Please remove the "require('babel-polyfill')" call or use "useBuiltIns: 'entry'"
|
|||||||
if (has(staticMethods, prop.name)) {
|
if (has(staticMethods, prop.name)) {
|
||||||
const builtIn = staticMethods[prop.name];
|
const builtIn = staticMethods[prop.name];
|
||||||
addUnsupported(path, state.opts.polyfills, builtIn, this.builtIns);
|
addUnsupported(path, state.opts.polyfills, builtIn, this.builtIns);
|
||||||
|
// if (obj.name === "Array" && prop.name === "from") {
|
||||||
|
// addImport(
|
||||||
|
// path,
|
||||||
|
// "babel-polyfill/lib/core-js/modules/web.dom.iterable",
|
||||||
|
// this.builtIns,
|
||||||
|
// );
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator-in/actual.js
vendored
Normal file
1
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator-in/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Symbol.iterator in arr
|
||||||
3
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator-in/expected.js
vendored
Normal file
3
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator-in/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import "babel-polyfill/lib/core-js/modules/es6.symbol";
|
||||||
|
import "babel-polyfill/lib/core-js/modules/web.dom.iterable";
|
||||||
|
Symbol.iterator in arr;
|
||||||
8
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator-in/options.json
vendored
Normal file
8
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator-in/options.json
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["../../../../lib", {
|
||||||
|
"useBuiltIns": true,
|
||||||
|
"modules": false
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
}
|
||||||
1
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator/actual.js
vendored
Normal file
1
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
arr[Symbol.iterator]()
|
||||||
3
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator/expected.js
vendored
Normal file
3
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import "babel-polyfill/lib/core-js/modules/es6.symbol";
|
||||||
|
import "babel-polyfill/lib/core-js/modules/web.dom.iterable";
|
||||||
|
arr[Symbol.iterator]();
|
||||||
8
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator/options.json
vendored
Normal file
8
experimental/babel-preset-env/test/fixtures/dom-iterable/symbol-iterator/options.json
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["../../../../lib", {
|
||||||
|
"useBuiltIns": true,
|
||||||
|
"modules": false
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
}
|
||||||
3
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-non-star/actual.js
vendored
Normal file
3
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-non-star/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
function* a() {
|
||||||
|
yield 1;
|
||||||
|
}
|
||||||
3
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-non-star/expected.js
vendored
Normal file
3
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-non-star/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
function* a() {
|
||||||
|
yield 1;
|
||||||
|
}
|
||||||
11
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-non-star/options.json
vendored
Normal file
11
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-non-star/options.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["../../../../lib", {
|
||||||
|
"useBuiltIns": true,
|
||||||
|
"targets": {
|
||||||
|
"chrome": 55
|
||||||
|
},
|
||||||
|
"modules": false
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
}
|
||||||
3
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-star/actual.js
vendored
Normal file
3
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-star/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
function* a() {
|
||||||
|
yield* 1;
|
||||||
|
}
|
||||||
4
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-star/expected.js
vendored
Normal file
4
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-star/expected.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import "babel-polyfill/lib/core-js/modules/web.dom.iterable";
|
||||||
|
function* a() {
|
||||||
|
yield* 1;
|
||||||
|
}
|
||||||
11
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-star/options.json
vendored
Normal file
11
experimental/babel-preset-env/test/fixtures/dom-iterable/yield-star/options.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["../../../../lib", {
|
||||||
|
"useBuiltIns": true,
|
||||||
|
"targets": {
|
||||||
|
"chrome": 55
|
||||||
|
},
|
||||||
|
"modules": false
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -9,4 +9,4 @@ d.fill.bind(); //.bind
|
|||||||
e.padStart.apply(); // .apply
|
e.padStart.apply(); // .apply
|
||||||
f.padEnd.call(); // .call
|
f.padEnd.call(); // .call
|
||||||
String.prototype.startsWith.call; // prototype.call
|
String.prototype.startsWith.call; // prototype.call
|
||||||
var { codePointAt, endsWith } = k; // destructuring
|
var { codePointAt, endsWith } = k; // destructuring
|
||||||
|
|||||||
@ -36,4 +36,4 @@ i[asdf]; // computed with identifier
|
|||||||
j["search"]; // computed with template
|
j["search"]; // computed with template
|
||||||
k[asdf3]; // computed with concat strings
|
k[asdf3]; // computed with concat strings
|
||||||
var _k2 = k,
|
var _k2 = k,
|
||||||
_a = _k2[asdf2]; // computed
|
_a = _k2[asdf2]; // computed
|
||||||
|
|||||||
@ -2,7 +2,6 @@ Array.from; // static method
|
|||||||
Map; // built-in
|
Map; // built-in
|
||||||
new Promise(); // new builtin
|
new Promise(); // new builtin
|
||||||
Symbol.match; // as member expression
|
Symbol.match; // as member expression
|
||||||
_arr[Symbol.iterator](); // Symbol.iterator
|
|
||||||
|
|
||||||
// no import
|
// no import
|
||||||
Array.asdf;
|
Array.asdf;
|
||||||
|
|||||||
@ -2,7 +2,6 @@ Array.from; // static method
|
|||||||
Map; // built-in
|
Map; // built-in
|
||||||
new Promise(); // new builtin
|
new Promise(); // new builtin
|
||||||
Symbol.match; // as member expression
|
Symbol.match; // as member expression
|
||||||
_arr[Symbol.iterator](); // Symbol.iterator
|
|
||||||
|
|
||||||
// no import
|
// no import
|
||||||
Array.asdf;
|
Array.asdf;
|
||||||
@ -23,4 +22,4 @@ function H(WeakMap) {
|
|||||||
var asdf = 'copyWithin';
|
var asdf = 'copyWithin';
|
||||||
i[asdf]; // computed with identifier
|
i[asdf]; // computed with identifier
|
||||||
j[`copyWithin`]; // computed with template
|
j[`copyWithin`]; // computed with template
|
||||||
var { [asdf]: _a } = k; // computed
|
var { [asdf]: _a } = k; // computed
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import "babel-polyfill/lib/core-js/modules/web.dom.iterable";
|
||||||
import "babel-polyfill/lib/core-js/modules/es6.symbol";
|
import "babel-polyfill/lib/core-js/modules/es6.symbol";
|
||||||
import "babel-polyfill/lib/core-js/modules/es6.regexp.match";
|
import "babel-polyfill/lib/core-js/modules/es6.regexp.match";
|
||||||
import "babel-polyfill/lib/core-js/modules/es6.promise";
|
import "babel-polyfill/lib/core-js/modules/es6.promise";
|
||||||
@ -22,4 +23,4 @@ _arr9[Symbol.iterator2]();
|
|||||||
G.assign; // static method
|
G.assign; // static method
|
||||||
function H(WeakMap) {
|
function H(WeakMap) {
|
||||||
var blah = new WeakMap();
|
var blah = new WeakMap();
|
||||||
} // shadowed
|
} // shadowed
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user