speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
842 stars 90 forks source link

Error during transpilation: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "CallExpression" #173

Open mayeaux opened 7 years ago

mayeaux commented 7 years ago

During transpilation I receive this error:

Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "CallExpression"

With this file:

import { sendEmail } from '../lib/util/mailer';

sendEmail({
  to: process.argv[2],
  subject: process.argv[3],
  text: process.argv[4]
});

Any ideas?

mayeaux commented 7 years ago

Btw, I was able to fix this via:

+const to = process.argv[2];
 +const subject = process.argv[3];
 +const text = process.argv[4];

Loading the variables into memory first, and then using those variables. Not sure how to make this not throw in babel-rewire though

speedskater commented 7 years ago

@mrmayfield Thanks for reporting this issue and sorry for the late reply. The issue will be tackled, but won't be fixed before mid of march.

ETD-BIO commented 1 year ago

@mikesherov I got the same error with a salesforce lwc module :

function isRewireable(path, variableBinding) {
    var node = path.node,
            parent = path.parent;

    return variableBinding.referencePaths !== null &&
        !(parent.type === 'VariableDeclarator' && parent.id == node) &&
        !(parent.type === 'ForInStatement' && parent.left == node) &&
        ✅ !(parent.type === 'AssignmentExpression' && parent.left == node) &&
        !(parent.type === 'FunctionExpression' && parent.id === node) &&
        !(parent.type === 'MemberExpression' && parent.property === node) &&
        [...]
    }

Adding this line at src/babel-plugin-rewire.js among the return conditions of the function isRewireable fixed the error !