Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-remove-console

Package Overview
Dependencies
Maintainers
5
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-remove-console - npm Package Compare versions

Comparing version 6.8.5 to 6.9.0-alpha.da60c6b8

31

lib/index.js

@@ -9,3 +9,3 @@ "use strict";

visitor: {
CallExpression(path) {
CallExpression(path, state) {
var callee = path.get("callee");

@@ -15,3 +15,3 @@

if (isConsole(callee)) {
if (isIncludedConsole(callee, state.opts.exclude)) {
// console.log()

@@ -23,3 +23,3 @@ if (path.parentPath.isExpressionStatement()) {

}
} else if (isConsoleBind(callee)) {
} else if (isIncludedConsoleBind(callee, state.opts.exclude)) {
// console.log.bind()

@@ -30,4 +30,4 @@ path.replaceWith(createNoop());

MemberExpression: {
exit(path) {
if (isConsole(path) && !path.parentPath.isMemberExpression()) {
exit(path, state) {
if (isIncludedConsole(path, state.opts.exclude) && !path.parentPath.isMemberExpression()) {
if (path.parentPath.isAssignmentExpression() && path.parentKey === "left") {

@@ -49,13 +49,26 @@ path.parentPath.get("right").replaceWith(createNoop());

function isConsole(memberExpr) {
function isExcluded(property, excludeArray) {
return excludeArray && excludeArray.some(function (name) {
return property.isIdentifier({ name });
});
}
function isIncludedConsole(memberExpr, excludeArray) {
var object = memberExpr.get("object");
var property = memberExpr.get("property");
if (isExcluded(property, excludeArray)) return false;
if (isGlobalConsoleId(object)) return true;
var property = memberExpr.get("property");
return isGlobalConsoleId(object.get("object")) && (property.isIdentifier({ name: "call" }) || property.isIdentifier({ name: "apply" }));
}
function isConsoleBind(memberExpr) {
function isIncludedConsoleBind(memberExpr, excludeArray) {
var object = memberExpr.get("object");
return object.isMemberExpression() && isGlobalConsoleId(object.get("object")) && memberExpr.get("property").isIdentifier({ name: "bind" });
if (!object.isMemberExpression()) return false;
if (isExcluded(object.get("property"), excludeArray)) return false;
return isGlobalConsoleId(object.get("object")) && memberExpr.get("property").isIdentifier({ name: "bind" });
}

@@ -62,0 +75,0 @@

{
"name": "babel-plugin-transform-remove-console",
"version": "6.8.5",
"version": "6.9.0-alpha.da60c6b8",
"description": "Remove all console.* calls.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -32,2 +32,3 @@ # babel-plugin-transform-remove-console

```json
// without options
{

@@ -38,2 +39,9 @@ "plugins": ["transform-remove-console"]

```json
// with options
{
"plugins": [ ["transform-remove-console", { "exclude": [ "error", "warn"] }] ]
}
```
### Via CLI

@@ -52,1 +60,5 @@

```
## Options
+ `exclude` - An array of console methods to exclude from removal.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc