4 ms·
This kind of static analysis is really easy to do with falafel: https://gist.github.com/substack/4735826 https://gist.github.com/substack/4735826 Program:
by substack 14y ago
This kind of static analysis is really easy to do with falafel:
https://gist.github.com/substack/4735826 https://gist.github.com/substack/4735826
Program:
var falafel = require('falafel');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/src.js', 'utf8');
var output = falafel(src, function (node) {
if (node.type === 'IfStatement'
&& node.test.type === 'MemberExpression'
&& node.test.object.name === 'Meteor'
&& node.test.property.name === 'isServer') {
node.update('');
}
});
console.log(output);
Input:
if (Meteor.isClient) {
console.log("I'm the client!");
}
if (Meteor.isServer) {
console.log("I'm the server!");
}
Output:
if (Meteor.isClient) {
console.log("I'm the client!");
}
This won't catch fancy things like Meteor['isServer'] or compound expressions but should be a good place to start.
edit: I had them backwards. Fixed now.
- javajosh 14y agoThat's really, really cool and is definitely a good start.