babel-plugin-es5-array-autopolyfill
Advanced tools
| { | ||
| "plugins": [ | ||
| ["../../../src", { | ||
| "polyfill": "es5-collection-methods" | ||
| }] | ||
| ] | ||
| } |
| obj.somMethid(1, 2, 3); | ||
| obj.somMethid2(1, 2, 3); | ||
| arr.test(2); |
| obj.somMethid(1, 2, 3); | ||
| obj.somMethid2(1, 2, 3); | ||
| arr.test(2); |
+26
-1
@@ -10,4 +10,26 @@ 'use strict'; | ||
| var usedMethods = {}; | ||
| return { | ||
| visitor: { | ||
| Program: { | ||
| enter: function enter(path) { | ||
| var usedMethods = {}; | ||
| }, | ||
| exit: function exit(path, state) { | ||
| var libName = state.opts.polyfill; | ||
| var methods = Object.keys(usedMethods).sort(); | ||
| if (methods.length === 0) { | ||
| return; | ||
| } | ||
| var specifiers = methods.map(function (el) { | ||
| return t.importSpecifier(t.identifier(prefix + el), t.identifier(el)); | ||
| }); | ||
| var importDecl = t.importDeclaration(specifiers, t.stringLiteral(libName)); | ||
| path.node.body = [importDecl].concat(path.node.body); | ||
| } | ||
| }, | ||
| CallExpression: function CallExpression(path) { | ||
@@ -20,2 +42,4 @@ var callee = path.node.callee; | ||
| if (t.isIdentifier(property) && replaceProperties.indexOf(property.name) >= 0) { | ||
| usedMethods[property.name] = true; | ||
| property.name = prefix + property.name; | ||
| path.replaceWith(t.callExpression(property, [callee.object].concat(path.node.arguments))); | ||
@@ -28,2 +52,3 @@ } | ||
| var replaceProperties = ['reduce', 'map', 'filter', 'forEach']; | ||
| var replaceProperties = ['reduce', 'map', 'filter', 'forEach']; | ||
| var prefix = "es5"; |
+1
-1
| { | ||
| "name": "babel-plugin-es5-array-autopolyfill", | ||
| "version": "1.0.0", | ||
| "version": "2.0.0", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
| { | ||
| "plugins": [ | ||
| ["../../../src", { | ||
| "transforms": [{ | ||
| "transform": "transform-lib" | ||
| }] | ||
| "polyfill": "es5-collection-methods" | ||
| }] | ||
| ] | ||
| } |
@@ -1,11 +0,12 @@ | ||
| map(arr, el => el + 1); | ||
| map(arr, (el, i) => el + i); | ||
| import { filter as es5filter, forEach as es5forEach, map as es5map, reduce as es5reduce } from "es5-collection-methods"; | ||
| es5map(arr, el => el + 1); | ||
| es5map(arr, (el, i) => el + i); | ||
| filter(arr, el => !el); | ||
| es5filter(arr, el => !el); | ||
| reduce(arr, (acc, el) => acc + el, {}); | ||
| es5reduce(arr, (acc, el) => acc + el, {}); | ||
| forEach(arr, el => t(el)); | ||
| forEach(arr, (el, i) => t(el, i)); | ||
| es5forEach(arr, el => t(el)); | ||
| es5forEach(arr, (el, i) => t(el, i)); | ||
| obj.somMethid(1, 2, 3); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4558
32.35%12
33.33%89
45.9%