1

I'm writing a plugin for webpack for extracting values from MyObject.myProperty = 'myValue'; expressions, and my hook doesn't tap for my expression. Here is the example code:

var zzz = (function () {
    function zzz() {
        return this;
    }
    zzz.MY_VAR = "My value";
    return zzz;
});

Here is how my code for the hook looks like:

parser.hooks.expression.for("zzz.MY_VAR").tap("MyPlugin", expr => {
    console.log(expr);
}

I also tried:

parser.hooks.evaluate.for("AssignmentExpression").tap("MyPlugin", expr => {
    console.log(expr);
}

Also without success.

I did some debugging, and find out that for some reason when JavascriptParser is calling getFreeInfoFromVariable() in getMemberExpressionInfo() it returns undefined. Because getVariableInfo() method return some scope details instead of VariableInfo instance or 'string'.

Am I missing something ? Is it possible to get value of the object's property via parser somehow ? Or maybe there is another way to do it ?

Tony
  • 5,797
  • 3
  • 26
  • 22

0 Answers0