Skip to content

Commit

Permalink
only move if not allowed access already
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 1, 2020
1 parent ca10a39 commit c09dcc7
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/babel-plugin-jest-hoist/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,27 @@ FUNCTIONS.mock = args => {
}

if (!found) {
const binding = scope.bindings[name];
let isAllowedIdentifier =
(scope.hasGlobal(name) && ALLOWED_IDENTIFIERS.has(name)) ||
/^mock/i.test(name) ||
// Allow istanbul's coverage variable to pass.
/^(?:__)?cov/.test(name);

if (binding) {
// @ts-expect-error `init` does not exist
const initNode = binding.path.node.init;
if (!isAllowedIdentifier) {
const binding = scope.bindings[name];

if (binding) {
// @ts-expect-error `init` does not exist
const initNode = binding.path.node.init;

if (binding.constant && scope.isPure(initNode, true)) {
// replace the reference with its constant value
id.replaceWith(initNode);
if (binding.constant && scope.isPure(initNode, true)) {
// replace the reference with its constant value
id.replaceWith(initNode);

found = true;
isAllowedIdentifier = true;
}
}
}
}

if (!found) {
const isAllowedIdentifier =
(scope.hasGlobal(name) && ALLOWED_IDENTIFIERS.has(name)) ||
/^mock/i.test(name) ||
// Allow istanbul's coverage variable to pass.
/^(?:__)?cov/.test(name);

if (!isAllowedIdentifier) {
throw id.buildCodeFrameError(
Expand Down

0 comments on commit c09dcc7

Please sign in to comment.