Updating NPM dependencies

This commit is contained in:
Drew Heavner
2020-11-11 13:30:52 +00:00
committed by GitHub
parent 7a6fb66c63
commit bd487ef324
9068 changed files with 1400893 additions and 587661 deletions

View File

@@ -5,9 +5,10 @@
* LICENSE file in the root directory of this source tree.
*
*/
import { Visitor } from '@babel/traverse';
declare const _default: () => {
visitor: Visitor<{}>;
};
export = _default;
//# sourceMappingURL=index.d.ts.map
import type { PluginObj } from '@babel/core';
import { Identifier } from '@babel/types';
declare const _default: () => PluginObj<{
declareJestObjGetterIdentifier: () => Identifier;
jestObjGetterIdentifier?: Identifier;
}>;
export default _default;

View File

@@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAW,OAAO,EAAC,MAAM,iBAAiB,CAAC;;;;AAmJlD,kBA8BE"}

View File

@@ -1,5 +1,30 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.default = void 0;
function _template() {
const data = require('@babel/template');
_template = function () {
return data;
};
return data;
}
function _types() {
const data = require('@babel/types');
_types = function () {
return data;
};
return data;
}
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
@@ -7,81 +32,73 @@
* LICENSE file in the root directory of this source tree.
*
*/
// 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
const JEST_GLOBAL_NAME = 'jest';
const JEST_GLOBALS_MODULE_NAME = '@jest/globals';
const JEST_GLOBALS_MODULE_JEST_EXPORT_NAME = 'jest';
const hoistedVariables = new WeakSet(); // 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 JEST_GLOBAL = {
name: 'jest'
}; // TODO: Should be Visitor<{ids: Set<NodePath<Identifier>>}>, but `ReferencedIdentifier` doesn't exist
const ALLOWED_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 IDVisitor = {
ReferencedIdentifier(path) {
// @ts-ignore: passed as Visitor State
this.ids.add(path);
ReferencedIdentifier(path, {ids}) {
ids.add(path);
},
blacklist: ['TypeAnnotation', 'TSTypeAnnotation', 'TSTypeReference']
@@ -93,72 +110,76 @@ FUNCTIONS.mock = args => {
return args[0].isStringLiteral() || args[0].isLiteral();
} else if (args.length === 2 || args.length === 3) {
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();
const parentScope = moduleFactory.parentPath.scope; // @ts-ignore: Same as above: ReferencedIdentifier doesn't exist
const parentScope = moduleFactory.parentPath.scope; // @ts-expect-error: ReferencedIdentifier and blacklist are not known on visitors
moduleFactory.traverse(IDVisitor, {
ids
});
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (
var _iterator = ids[Symbol.iterator](), _step;
!(_iteratorNormalCompletion = (_step = _iterator.next()).done);
_iteratorNormalCompletion = true
) {
const id = _step.value;
const name = id.node.name;
let found = false;
let scope = id.scope;
for (const id of ids) {
const {name} = id.node;
let found = false;
let scope = id.scope;
while (scope !== parentScope) {
if (scope.bindings[name]) {
found = true;
break;
}
scope = scope.parent;
while (scope !== parentScope) {
if (scope.bindings[name]) {
found = true;
break;
}
if (!found) {
invariant(
(scope.hasGlobal(name) && WHITELISTED_IDENTIFIERS.has(name)) ||
/^mock/i.test(name) || // Allow istanbul's coverage variable to pass.
/^(?:__)?cov/.test(name),
scope = scope.parent;
}
if (!found) {
let isAllowedIdentifier =
(scope.hasGlobal(name) && ALLOWED_IDENTIFIERS.has(name)) ||
/^mock/i.test(name) || // Allow istanbul's coverage variable to pass.
/^(?:__)?cov/.test(name);
if (!isAllowedIdentifier) {
const binding = scope.bindings[name];
if (
binding === null || binding === void 0
? void 0
: binding.path.isVariableDeclarator()
) {
const {node} = binding.path;
const initNode = node.init;
if (initNode && binding.constant && scope.isPure(initNode, true)) {
hoistedVariables.add(node);
isAllowedIdentifier = true;
}
}
}
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(', ') +
'Allowed objects: ' +
Array.from(ALLOWED_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.'
'variable names prefixed with `mock` (case insensitive) are permitted.\n',
ReferenceError
);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return true;
@@ -174,35 +195,193 @@ FUNCTIONS.deepUnmock = args => args.length === 1 && args[0].isStringLiteral();
FUNCTIONS.disableAutomock = FUNCTIONS.enableAutomock = args =>
args.length === 0;
module.exports = () => {
const shouldHoistExpression = expr => {
if (!expr.isCallExpression()) {
return false;
}
const createJestObjectGetter = (0, _template().statement)`
function GETTER_NAME() {
const { JEST_GLOBALS_MODULE_JEST_EXPORT_NAME } = require("JEST_GLOBALS_MODULE_NAME");
GETTER_NAME = () => JEST_GLOBALS_MODULE_JEST_EXPORT_NAME;
return JEST_GLOBALS_MODULE_JEST_EXPORT_NAME;
}
`;
const callee = expr.get('callee');
const expressionArguments = expr.get('arguments'); // TODO: avoid type casts - the types can be arrays (is it possible to ignore that without casting?)
const isJestObject = expression => {
// global
if (
expression.isIdentifier() &&
expression.node.name === JEST_GLOBAL_NAME &&
!expression.scope.hasBinding(JEST_GLOBAL_NAME)
) {
return true;
} // import { jest } from '@jest/globals'
const object = callee.get('object');
const property = callee.get('property');
return (
property.isIdentifier() &&
FUNCTIONS[property.node.name] &&
(object.isIdentifier(JEST_GLOBAL) ||
(callee.isMemberExpression() && shouldHoistExpression(object))) &&
FUNCTIONS[property.node.name](expressionArguments)
);
};
if (
expression.referencesImport(
JEST_GLOBALS_MODULE_NAME,
JEST_GLOBALS_MODULE_JEST_EXPORT_NAME
)
) {
return true;
} // import * as JestGlobals from '@jest/globals'
const visitor = {
ExpressionStatement(path) {
if (shouldHoistExpression(path.get('expression'))) {
// @ts-ignore: private, magical property
path.node._blockHoist = Infinity;
if (
expression.isMemberExpression() &&
!expression.node.computed &&
expression.get('object').referencesImport(JEST_GLOBALS_MODULE_NAME, '*') &&
expression.node.property.type === 'Identifier' &&
expression.node.property.name === JEST_GLOBALS_MODULE_JEST_EXPORT_NAME
) {
return true;
}
return false;
};
const extractJestObjExprIfHoistable = expr => {
var _FUNCTIONS$propertyNa;
if (!expr.isCallExpression()) {
return null;
}
const callee = expr.get('callee');
const args = expr.get('arguments');
if (!callee.isMemberExpression() || callee.node.computed) {
return null;
}
const object = callee.get('object');
const property = callee.get('property');
const propertyName = property.node.name;
const jestObjExpr = isJestObject(object)
? object // The Jest object could be returned from another call since the functions are all chainable.
: extractJestObjExprIfHoistable(object);
if (!jestObjExpr) {
return null;
} // Important: Call the function check last
// It might throw an error to display to the user,
// which should only happen if we're already sure it's a call on the Jest object.
const functionLooksHoistable =
(_FUNCTIONS$propertyNa = FUNCTIONS[propertyName]) === null ||
_FUNCTIONS$propertyNa === void 0
? void 0
: _FUNCTIONS$propertyNa.call(FUNCTIONS, args);
return functionLooksHoistable ? jestObjExpr : null;
};
/* eslint-disable sort-keys */
var _default = () => ({
pre({path: program}) {
this.declareJestObjGetterIdentifier = () => {
if (this.jestObjGetterIdentifier) {
return this.jestObjGetterIdentifier;
}
this.jestObjGetterIdentifier = program.scope.generateUidIdentifier(
'getJestObj'
);
program.unshiftContainer('body', [
createJestObjectGetter({
GETTER_NAME: this.jestObjGetterIdentifier.name,
JEST_GLOBALS_MODULE_JEST_EXPORT_NAME,
JEST_GLOBALS_MODULE_NAME
})
]);
return this.jestObjGetterIdentifier;
};
},
visitor: {
ExpressionStatement(exprStmt) {
const jestObjExpr = extractJestObjExprIfHoistable(
exprStmt.get('expression')
);
if (jestObjExpr) {
jestObjExpr.replaceWith(
(0, _types().callExpression)(
this.declareJestObjGetterIdentifier(),
[]
)
);
}
}
};
return {
visitor
};
};
},
// in `post` to make sure we come after an import transform and can unshift above the `require`s
post({path: program}) {
const self = this;
visitBlock(program);
program.traverse({
BlockStatement: visitBlock
});
function visitBlock(block) {
// use a temporary empty statement instead of the real first statement, which may itself be hoisted
const [varsHoistPoint, callsHoistPoint] = block.unshiftContainer('body', [
(0, _types().emptyStatement)(),
(0, _types().emptyStatement)()
]);
block.traverse({
CallExpression: visitCallExpr,
VariableDeclarator: visitVariableDeclarator,
// do not traverse into nested blocks, or we'll hoist calls in there out to this block
// @ts-expect-error blacklist is not known
blacklist: ['BlockStatement']
});
callsHoistPoint.remove();
varsHoistPoint.remove();
function visitCallExpr(callExpr) {
var _self$jestObjGetterId;
const {
node: {callee}
} = callExpr;
if (
(0, _types().isIdentifier)(callee) &&
callee.name ===
((_self$jestObjGetterId = self.jestObjGetterIdentifier) === null ||
_self$jestObjGetterId === void 0
? void 0
: _self$jestObjGetterId.name)
) {
const mockStmt = callExpr.getStatementParent();
if (mockStmt) {
const mockStmtParent = mockStmt.parentPath;
if (mockStmtParent.isBlock()) {
const mockStmtNode = mockStmt.node;
mockStmt.remove();
callsHoistPoint.insertBefore(mockStmtNode);
}
}
}
}
function visitVariableDeclarator(varDecl) {
if (hoistedVariables.has(varDecl.node)) {
// should be assert function, but it's not. So let's cast below
varDecl.parentPath.assertVariableDeclaration();
const {kind, declarations} = varDecl.parent;
if (declarations.length === 1) {
varDecl.parentPath.remove();
} else {
varDecl.remove();
}
varsHoistPoint.insertBefore(
(0, _types().variableDeclaration)(kind, [varDecl.node])
);
}
}
}
}
});
/* eslint-enable */
exports.default = _default;

View File

@@ -1,43 +1,52 @@
{
"_from": "babel-plugin-jest-hoist@^24.9.0",
"_id": "babel-plugin-jest-hoist@24.9.0",
"_from": "babel-plugin-jest-hoist@^26.6.2",
"_id": "babel-plugin-jest-hoist@26.6.2",
"_inBundle": false,
"_integrity": "sha512-2EMA2P8Vp7lG0RAzr4HXqtYwacfMErOuv1U3wrvxHX6rD1sV6xS3WXG3r8TRQ2r6w8OhvSdWt+z41hQNwNm3Xw==",
"_integrity": "sha512-PO9t0697lNTmcEHH69mdtYiOIkkOlj9fySqfO3K1eCcdISevLAE0xY59VLLUj0SoiPiTX/JU2CYFpILydUa5Lw==",
"_location": "/babel-plugin-jest-hoist",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "babel-plugin-jest-hoist@^24.9.0",
"raw": "babel-plugin-jest-hoist@^26.6.2",
"name": "babel-plugin-jest-hoist",
"escapedName": "babel-plugin-jest-hoist",
"rawSpec": "^24.9.0",
"rawSpec": "^26.6.2",
"saveSpec": null,
"fetchSpec": "^24.9.0"
"fetchSpec": "^26.6.2"
},
"_requiredBy": [
"/babel-preset-jest"
],
"_resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-24.9.0.tgz",
"_shasum": "4f837091eb407e01447c8843cbec546d0002d756",
"_spec": "babel-plugin-jest-hoist@^24.9.0",
"_where": "/Users/drew.heavner/Documents/Github/upload-google-play/node_modules/babel-preset-jest",
"_resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-26.6.2.tgz",
"_shasum": "8185bd030348d254c6d7dd974355e6a28b21e62d",
"_spec": "babel-plugin-jest-hoist@^26.6.2",
"_where": "/home/codespace/workspace/upload-google-play/node_modules/babel-preset-jest",
"bugs": {
"url": "https://github.com/facebook/jest/issues"
},
"bundleDependencies": false,
"dependencies": {
"@babel/template": "^7.3.3",
"@babel/types": "^7.3.3",
"@types/babel__core": "^7.0.0",
"@types/babel__traverse": "^7.0.6"
},
"deprecated": false,
"description": "Babel plugin to hoist `jest.disableAutomock`, `jest.enableAutomock`, `jest.unmock`, `jest.mock`, calls above `import` statements. This plugin is automatically included when using [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jest).",
"devDependencies": {
"@babel/types": "^7.3.3"
"@babel/core": "^7.11.6",
"@babel/preset-react": "^7.12.1",
"@types/babel__template": "^7.0.2",
"@types/node": "*",
"@types/prettier": "^2.0.0",
"babel-plugin-tester": "^10.0.0",
"prettier": "^2.1.1"
},
"engines": {
"node": ">= 6"
"node": ">= 10.14.2"
},
"gitHead": "9ad0f4bc6b8bdd94989804226c28c9960d9da7d1",
"gitHead": "4c46930615602cbf983fb7e8e82884c282a624d5",
"homepage": "https://github.com/facebook/jest#readme",
"license": "MIT",
"main": "build/index.js",
@@ -51,5 +60,5 @@
"directory": "packages/babel-plugin-jest-hoist"
},
"types": "build/index.d.ts",
"version": "24.9.0"
"version": "26.6.2"
}