简体   繁体   中英

Babel plugin doesn't run as expected - output is not always shown

I have made a babel plugin that should find all functions with a specific name in order to get the input parameters. However, it doesn't run as I expect it to.

Right now I simply console.log the expected parameter, but they are not always found.

 module.exports = function ({ types: t }) { return { visitor: { CallExpression: function(path) { const node = path.node; console.log("name:", node.callee.name); if(node.callee.name === 'i18n') { const argumentNode = node.arguments[0]; if(t.isStringLiteral(argumentNode)){ console.log(argumentNode.value); } } } } }; };

In fact, the first console.log :

 console.log("name:", node.callee.name);

creates like 20 outputs, but I'm expecting way more.

In .babelrc , I have added my ast-crawler like this:

 { "plugins": [ "babel-plugin-add-module-exports", "ast-crawler" ], "presets": [ ["es2015"], "react", "stage-2" ] }

I have tried to change the order, but the result is the same.

Sometimes I get all the expected output, but why don't I always get it? Does babel only cache some of my code, so if I wait for x minutes I will get the expected output?

The issue was that babel cache was used.

 query: { cacheDirectory: '.babelcache' }

After removing the cache I got the expected output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM