Created
February 18, 2020 10:40
-
-
Save mreinstein/fcd4d05119d2065170f5913a2cf67794 to your computer and use it in GitHub Desktop.
parse javascript from stdin as an AST and remove specific functions by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import escodegen from 'escodegen' | |
import esprima from 'esprima' | |
import estraverse from 'estraverse' | |
let src = '' | |
process.stdin.on('data', function (chunk) { | |
src += chunk | |
}) | |
process.stdin.on('end', function () { | |
let ast = esprima.parse(src) | |
ast = estraverse.replace(ast, { | |
enter: function (node) { | |
//if (node.type === 'Property' && (node.key.name === 'run') && node.value.type === 'FunctionExpression') | |
// this.remove() | |
if (node.type === 'Property' && node.method && node.key.name === 'preRunAction') | |
return this.remove() | |
if (node.type === 'Property' && node.method && node.key.name === 'postRunAction') | |
return this.remove() | |
if (node.type === 'Property' && node.method && node.key.name === 'run') | |
return this.remove() | |
} | |
}) | |
console.log(escodegen.generate(ast)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment