babel-plugin-transform-remove-console
Advanced tools
Comparing version 6.8.5 to 6.9.0-alpha.da60c6b8
@@ -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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3651
62
62
3
1
1