Skip to content

Commit

Permalink
replace variable reference with constant value
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 1, 2020
1 parent bdff07a commit 9e088f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _getJestObj().mock("./App", () => () =>
void 0,
false,
{
fileName: _jsxFileName,
fileName: "/root/project/src/file.js",
lineNumber: 1,
columnNumber: 32
},
Expand Down
6 changes: 4 additions & 2 deletions packages/babel-plugin-jest-hoist/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ FUNCTIONS.mock = args => {
const initNode = binding.path.node.init;

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

isAllowedIdentifier = true;
}
}
Expand Down Expand Up @@ -286,7 +288,7 @@ export default (): PluginObj<{
visitor: {
ExpressionStatement(exprStmt) {
const jestObjExpr = extractJestObjExprIfHoistable(
exprStmt.get<'expression'>('expression'),
exprStmt.get('expression'),
);
if (jestObjExpr) {
jestObjExpr.replaceWith(
Expand Down

0 comments on commit 9e088f1

Please sign in to comment.