Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-polyfill-es-shims

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-polyfill-es-shims - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

31

lib/index.js

@@ -5,11 +5,6 @@ "use strict";

exports.default = void 0;
var _helperDefinePolyfillProvider = _interopRequireDefault(require("@babel/helper-define-polyfill-provider"));
var _polyfills = _interopRequireDefault(require("../data/polyfills.js"));
var _mappings = require("./mappings");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (0, _helperDefinePolyfillProvider.default)(function ({

@@ -31,3 +26,2 @@ shouldInjectPolyfill,

});
function createDescIterator(cb, instance) {

@@ -40,3 +34,2 @@ return (meta, utils, path) => {

if (!resolved) return;
if (instance && resolved.kind === "instance") {

@@ -46,8 +39,8 @@ instance(meta, resolved, utils, path);

}
for (const desc of resolved.desc) {
if (!(desc.exclude != null && desc.exclude(meta, path)) && shouldInjectPolyfill(desc.name)) {
cb(desc, utils, path); // Since global and static polyfills are unambiguous, we only need to
cb(desc, utils, path);
// Since global and static polyfills are unambiguous, we only need to
// inject the first non-excluded one.
if (resolved.kind !== "instance") {

@@ -60,3 +53,2 @@ break;

}
function injectDefault(desc, utils) {

@@ -67,3 +59,2 @@ assertDependency(desc.package, desc.version);

}
const seen = new WeakSet();

@@ -92,10 +83,8 @@ return {

const isGetter = resolved.desc[0].getter;
const matchesPolyfill = ({
name
}) => name.startsWith(meta.object);
let index = -1;
if ( // This is the actual method for sure.
if (
// This is the actual method for sure.
meta.kind === "property" && meta.placement === "prototype" && meta.object != null && (index = resolved.desc.findIndex(matchesPolyfill)) !== -1) {

@@ -105,3 +94,2 @@ const desc = resolved.desc[index];

const id = injectDefault(desc, utils);
if (isGetter) {

@@ -129,14 +117,10 @@ path.replaceWith(expr`${id}(${path.node.object})`);

} = path.node;
for (const desc of resolved.desc) {
var _parent;
const {
thisCheck
} = desc;
if (!thisCheck || desc.exclude != null && desc.exclude(meta) || !shouldInjectPolyfill(desc.name)) {
continue;
}
if (!tmp) {

@@ -149,3 +133,2 @@ tmp = path.scope.generateUidIdentifierBasedOnNode(object);

}
const id = injectDefault(desc, utils);

@@ -155,6 +138,4 @@ replacement = t.conditionalExpression(thisCheck(t.cloneNode(tmp)), isGetter ? expr`${id}(${t.cloneNode(tmp)})` : isCall ? id : expr`${id}.getPolyfill()`, replacement);

}
if (!parent) return;
replacement = expr`(${t.cloneNode(tmp)} = ${object}, ${replacement})`;
if (!isGetter && isCall) {

@@ -164,3 +145,2 @@ parent.alternate = expr`Function.call.bind(${parent.alternate})`;

}
path.replaceWith(replacement);

@@ -171,3 +151,2 @@ }

});
exports.default = _default;

53

lib/mappings.js

@@ -5,11 +5,6 @@ "use strict";

exports.StaticProperties = exports.InstanceProperties = exports.Globals = void 0;
var _babel = _interopRequireWildcard(require("@babel/core"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
const {

@@ -27,3 +22,2 @@ types: t,

exports.InstanceProperties = InstanceProperties;
const lessThanArgs = num => (meta, path) => {

@@ -40,3 +34,2 @@ const {

};
for (const [name, causeArgNum] of [["Error", 2], ["AggregateError", 3], ["EvalError", 2], ["RangeError", 2], ["ReferenceError", 2], ["SyntaxError", 2], ["TypeError", 2], ["URIError", 2]]) {

@@ -48,9 +41,8 @@ defineGlobal(name, "1.0.1", "error-cause", {

});
} // This needs to come after the AggregateError cause polyfill, since this
}
// This needs to come after the AggregateError cause polyfill, since this
// one polyfills less features.
defineGlobal("AggregateError", "1.0.2", "es-aggregate-error");
const DATE_VERSION = "2.0.0"; // MISSING DATA: defineGlobal("Date", DATE_VERSION, "date", { subfolder: "Date" });
const DATE_VERSION = "2.0.0";
// MISSING DATA: defineGlobal("Date", DATE_VERSION, "date", { subfolder: "Date" });
defineGlobal("globalThis", "1.0.0");

@@ -60,19 +52,14 @@ defineGlobal("parseInt", "2.0.0");

defineGlobal("Set", "1.1.0", "es-set");
const arrayCheck = thisObj => expr`Array.isArray(${thisObj})`;
const typeofCheck = type => thisObj => expr`typeof ${thisObj} === "${type}"`;
const instanceofCheck = Class => thisObj => expr`${thisObj} instanceof ${t.identifier(Class)}`;
const stringCheck = typeofCheck("string");
// const setCheck = instanceofCheck("Set");
const stringCheck = typeofCheck("string"); // const setCheck = instanceofCheck("Set");
const getter = {
getter: true
};
const excludeStatic = obj => ({
exclude: meta => meta.kind === "property" && meta.placement === "static" && meta.object === obj
});
const excludeObject = excludeStatic("Object");

@@ -96,4 +83,4 @@ defineStatic("Array", "from", "1.1.0");

});
defineInstance("Array", "indexOf", "1.0.1", arrayCheck); // MISSING DATA: defineInstance("Array", "join", "1.0.0", arrayCheck);
defineInstance("Array", "indexOf", "1.0.1", arrayCheck);
// MISSING DATA: defineInstance("Array", "join", "1.0.0", arrayCheck);
defineInstance("Array", "keys", "1.0.0", arrayCheck, excludeObject);

@@ -103,4 +90,4 @@ defineInstance("Array", "lastIndexOf", "1.0.0", arrayCheck);

defineInstance("Array", "reduce", "1.0.1", arrayCheck);
defineInstance("Array", "reduceRight", "1.0.1", arrayCheck); // MISSING DATA: defineInstance("Array", "slice", "1.0.0", arrayCheck);
defineInstance("Array", "reduceRight", "1.0.1", arrayCheck);
// MISSING DATA: defineInstance("Array", "slice", "1.0.0", arrayCheck);
defineInstance("Array", "some", "1.1.1", arrayCheck);

@@ -114,4 +101,4 @@ defineInstance("Array", "splice", "1.0.1", arrayCheck);

defineInstance("Array", "with", "1.0.1", arrayCheck);
for (const name of ["now" // MISSING DATA: "parse"
for (const name of ["now"
// MISSING DATA: "parse"
]) {

@@ -123,4 +110,4 @@ defineStatic("Date", name, DATE_VERSION, {

}
for (const name of [// MISSING DATA: "getFullYear",
for (const name of [
// MISSING DATA: "getFullYear",
// MISSING DATA: "getMonth",

@@ -140,3 +127,2 @@ // MISSING DATA: "getDate",

}
defineInstance("Function", "name", "1.1.2", typeofCheck("function"), getter);

@@ -176,3 +162,5 @@ defineStatic("Math", "acosh", "1.0.0");

defineStatic("Reflect", "getPrototypeOf", "1.0.0");
defineInstance("RegExp", "flags", "1.3.0", instanceofCheck("RegExp"), getter); // TODO: Uncomment when Stage 4
defineInstance("RegExp", "flags", "1.3.0", instanceofCheck("RegExp"), getter);
// TODO: Uncomment when Stage 4
// defineInstance("Set", "difference", "1.0.2", setCheck);

@@ -205,4 +193,5 @@ // defineInstance("Set", "intersection", "1.0.2", setCheck);

defineInstance("String", "trimStart", "1.0.0", stringCheck);
defineInstance("Symbol", "description", "1.0.2", instanceofCheck("Symbol"), getter); // Annex B
defineInstance("Symbol", "description", "1.0.2", instanceofCheck("Symbol"), getter);
// Annex B
for (const name of ["anchor", "big", "blink", "bold", "fixed", "fontcolor", "fontsize", "italics", "link", "small", "strike", "sub", "sup"]) {

@@ -214,3 +203,2 @@ defineInstance("String", name, "1.0.0", stringCheck, {

}
function createDescriptor(name, version, pkg = name.toLowerCase(), subfolder) {

@@ -224,3 +212,2 @@ return {

}
function defineGlobal(name, version, pkg, {

@@ -237,3 +224,2 @@ exclude,

}
function defineStatic(object, property, version, {

@@ -246,3 +232,2 @@ pkg,

}
function defineInstance(object, property, version, thisCheck, {

@@ -249,0 +234,0 @@ getter = false,

{
"name": "babel-plugin-polyfill-es-shims",
"version": "0.9.0",
"version": "0.9.1",
"description": "A Babel plugin to inject imports to es-shims polyfills",

@@ -29,7 +29,7 @@ "repository": {

"dependencies": {
"@babel/helper-define-polyfill-provider": "^0.4.0"
"@babel/helper-define-polyfill-provider": "^0.4.1"
},
"devDependencies": {
"@babel/core": "^7.17.8",
"@babel/helper-plugin-test-runner": "^7.16.7",
"@babel/core": "^7.22.6",
"@babel/helper-plugin-test-runner": "^7.22.5",
"array.from": "^1.1.0",

@@ -41,3 +41,3 @@ "math.clz32": "^1.0.0"

},
"gitHead": "391a1f4049fe1d6943ca8e91cf7e2e23f3f1ef73"
"gitHead": "74956db5d547985ac8e60bf1af56f4c61af12e4e"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc