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

babel-plugin-jest-hoist

Package Overview
Dependencies
Maintainers
6
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-jest-hoist - npm Package Compare versions

Comparing version 25.0.0 to 25.1.0

2

build/index.d.ts

@@ -12,3 +12,3 @@ /**

};
export = _default;
export default _default;
//# sourceMappingURL=index.d.ts.map
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.default = void 0;
/**

@@ -11,68 +16,66 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

// Only used for types
// eslint-disable-next-line
// eslint-disable-next-line
const invariant = (condition, message) => {
if (!condition) {
throw new Error('babel-plugin-jest-hoist: ' + message);
}
}; // We allow `jest`, `expect`, `require`, all default Node.js globals and all
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-enable */
// We allow `jest`, `expect`, `require`, all default Node.js globals and all
// ES2015 built-ins to be used inside of a `jest.mock` factory.
// We also allow variables prefixed with `mock` as an escape-hatch.
const WHITELISTED_IDENTIFIERS = new Set([
'Array',
'ArrayBuffer',
'Boolean',
'DataView',
'Date',
'Error',
'EvalError',
'Float32Array',
'Float64Array',
'Function',
'Generator',
'GeneratorFunction',
'Infinity',
'Int16Array',
'Int32Array',
'Int8Array',
'InternalError',
'Intl',
'JSON',
'Map',
'Math',
'NaN',
'Number',
'Object',
'Promise',
'Proxy',
'RangeError',
'ReferenceError',
'Reflect',
'RegExp',
'Set',
'String',
'Symbol',
'SyntaxError',
'TypeError',
'URIError',
'Uint16Array',
'Uint32Array',
'Uint8Array',
'Uint8ClampedArray',
'WeakMap',
'WeakSet',
'arguments',
'console',
'expect',
'isNaN',
'jest',
'parseFloat',
'parseInt',
'require',
'undefined'
]);
Object.getOwnPropertyNames(global).forEach(name => {
WHITELISTED_IDENTIFIERS.add(name);
});
const WHITELISTED_IDENTIFIERS = new Set(
[
'Array',
'ArrayBuffer',
'Boolean',
'BigInt',
'DataView',
'Date',
'Error',
'EvalError',
'Float32Array',
'Float64Array',
'Function',
'Generator',
'GeneratorFunction',
'Infinity',
'Int16Array',
'Int32Array',
'Int8Array',
'InternalError',
'Intl',
'JSON',
'Map',
'Math',
'NaN',
'Number',
'Object',
'Promise',
'Proxy',
'RangeError',
'ReferenceError',
'Reflect',
'RegExp',
'Set',
'String',
'Symbol',
'SyntaxError',
'TypeError',
'URIError',
'Uint16Array',
'Uint32Array',
'Uint8Array',
'Uint8ClampedArray',
'WeakMap',
'WeakSet',
'arguments',
'console',
'expect',
'isNaN',
'jest',
'parseFloat',
'parseInt',
'require',
'undefined',
...Object.getOwnPropertyNames(global)
].sort()
);
const JEST_GLOBAL = {

@@ -97,6 +100,10 @@ name: 'jest'

const moduleFactory = args[1];
invariant(
moduleFactory.isFunction(),
'The second argument of `jest.mock` must be an inline function.'
);
if (!moduleFactory.isFunction()) {
throw moduleFactory.buildCodeFrameError(
'The second argument of `jest.mock` must be an inline function.\n',
TypeError
);
}
const ids = new Set();

@@ -124,18 +131,23 @@ const parentScope = moduleFactory.parentPath.scope; // @ts-ignore: Same as above: ReferencedIdentifier doesn't exist

if (!found) {
invariant(
const isAllowedIdentifier =
(scope.hasGlobal(name) && WHITELISTED_IDENTIFIERS.has(name)) ||
/^mock/i.test(name) || // Allow istanbul's coverage variable to pass.
/^(?:__)?cov/.test(name),
'The module factory of `jest.mock()` is not allowed to ' +
'reference any out-of-scope variables.\n' +
'Invalid variable access: ' +
name +
'\n' +
'Whitelisted objects: ' +
Array.from(WHITELISTED_IDENTIFIERS).join(', ') +
'.\n' +
'Note: This is a precaution to guard against uninitialized mock ' +
'variables. If it is ensured that the mock is required lazily, ' +
'variable names prefixed with `mock` (case insensitive) are permitted.'
);
/^(?:__)?cov/.test(name);
if (!isAllowedIdentifier) {
throw id.buildCodeFrameError(
'The module factory of `jest.mock()` is not allowed to ' +
'reference any out-of-scope variables.\n' +
'Invalid variable access: ' +
name +
'\n' +
'Whitelisted objects: ' +
Array.from(WHITELISTED_IDENTIFIERS).join(', ') +
'.\n' +
'Note: This is a precaution to guard against uninitialized mock ' +
'variables. If it is ensured that the mock is required lazily, ' +
'variable names prefixed with `mock` (case insensitive) are permitted.\n',
ReferenceError
);
}
}

@@ -157,3 +169,3 @@ }

module.exports = () => {
var _default = () => {
const shouldHoistExpression = expr => {

@@ -190,1 +202,3 @@ if (!expr.isCallExpression()) {

};
exports.default = _default;
{
"name": "babel-plugin-jest-hoist",
"version": "25.0.0",
"version": "25.1.0",
"repository": {

@@ -10,3 +10,3 @@ "type": "git",

"engines": {
"node": ">= 8"
"node": ">= 8.3"
},

@@ -25,3 +25,3 @@ "license": "MIT",

},
"gitHead": "ff9269be05fd8316e95232198fce3463bf2f270e"
"gitHead": "170eee11d03b0ed5c60077982fdbc3bafd403638"
}

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