-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exclude option for transform-remove-console plugin #661
Add exclude option for transform-remove-console plugin #661
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Just a couple of things.
Can you update the README.md for this package to explain how to provide the options?
@@ -144,3 +145,65 @@ describe("remove-console-plugin", () => { | |||
` | |||
); | |||
}); | |||
|
|||
describe("remove-console-plugin with excludes argument", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests should be updated to use the thePlugin
function if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I was following the model from babel-plugin-minify-type-constructors
which did not when there were options, but digging into the function prototype looks like I can pass options into thePlugin
as well, will update.
Updated based on @j-f1's feedback |
```json | ||
// with options | ||
{ | ||
"plugins": ["transform-remove-console": { "exclude": [ "error", "warn"] }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
,
instead of :
and inside another array.
@@ -47,22 +50,40 @@ module.exports = function({ types: t }) { | |||
); | |||
} | |||
|
|||
function isConsole(memberExpr) { | |||
function isExcluded(property, state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't pass in the whole state
. Just pass in whatever is required by this function. This function shouldn't worry about the options being available at state.opts.exclude
. Just pass in the exclude array.
```json | ||
// with options | ||
{ | ||
"plugins": ["transform-remove-console", { "exclude": [ "error", "warn"] }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be [ ["transform-remove-console", { ... } ] ]
. It's an array of array of two items (name & options).
} | ||
}); | ||
} | ||
return exclude; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return excludeArray.some(name => property.isIdentifier({ name }));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Thanks!. Looks good to me. Looks like there are some formatting errors (prettier). You can fix this by running |
@@ -51,15 +51,7 @@ module.exports = function({ types: t }) { | |||
} | |||
|
|||
function isExcluded(property, excludeArray) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with default param.
function isExcluded(property, excludeArray = []) {
return excludeArray.some(name => property.isIdentifier({ name }));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lint also failed for the same function. Please do yarn run format
thanks for this PR it was also something I needed Do we have to use "minify" to get this option, or does it also work with normal babel plugins? (not sure but to me it looks like it's the name plugin in both case anyway no?) |
babel-plugin-transform-remove-console@3.8.5 in npm did not support options? |
Hey, published version 6.8.5 does not include this PR |
If you want to use this feature right now, you can use my release (make sure to verify I'm not a malicious hacker!)
|
An attempt to implement the extension requested in #598
Based on the unit tests I added, I believe this is working, however as this is my very first attempt at code within the babel ecosystem it is highly likely there are better ways to approach this. I welcome any and all feedback on how to improve this either functionally or idiomatically.