it won't work if you have something else in the same line after the console,
it won't work with if you do something like const fn = console.log (I mean it will remove the console, but the expression will become wrong).
I'd recommend instead using AST based tools like a webpack plugin, or a eslint custom rule, to detect a CallExpression with the callee being a MemberExpression with the object being console and the property log.
Suhail is a software developer specializing in full-stack web and mobile application development. He is interested in contributing to open source and building Web3 applications.
That's cool!
But this has a few issues:
const fn = console.log
(I mean it will remove the console, but the expression will become wrong).I'd recommend instead using AST based tools like a webpack plugin, or a eslint custom rule, to detect a
CallExpression
with the callee being aMemberExpression
with the object beingconsole
and the propertylog
.Thanks @ayc0
For multiline you need to use
console\.log\(([^)]+)\);
It still won't work for code snippet like those:
(As it contains a closing parenthesis)
console\.log\((.|\n)*?\);?
It matches anything until it encounters ) again, with an optional whitespace and ;