Skip to content
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

Merged

Conversation

kball
Copy link
Contributor

@kball kball commented Aug 13, 2017

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.

@kball kball requested a review from boopathi as a code owner August 13, 2017 22:46
Copy link
Contributor

@j-f1 j-f1 left a 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", () => {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@kball
Copy link
Contributor Author

kball commented Aug 14, 2017

Updated based on @j-f1's feedback

```json
// with options
{
"plugins": ["transform-remove-console": { "exclude": [ "error", "warn"] }]
Copy link
Member

@boopathi boopathi Aug 14, 2017

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) {
Copy link
Member

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.

@boopathi boopathi added the Tag: New Feature Pull Request adding a new feature label Aug 14, 2017
```json
// with options
{
"plugins": ["transform-remove-console", { "exclude": [ "error", "warn"] }]
Copy link
Member

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;
Copy link
Member

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 }));

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@boopathi
Copy link
Member

Thanks!. Looks good to me.

Looks like there are some formatting errors (prettier). You can fix this by running npm run format.

@@ -51,15 +51,7 @@ module.exports = function({ types: t }) {
}

function isExcluded(property, excludeArray) {
Copy link
Member

@vigneshshanmugam vigneshshanmugam Aug 15, 2017

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 }));
}

Copy link
Member

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

@boopathi boopathi merged commit 879c28f into babel:master Aug 17, 2017
@slorber
Copy link

slorber commented Aug 24, 2017

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?)

@perfey
Copy link

perfey commented Sep 5, 2017

babel-plugin-transform-remove-console@3.8.5 in npm did not support options?
I couldn't use it in my webpack. And I saw the code not newest in node_modules.

@slorber
Copy link

slorber commented Oct 2, 2017

Hey, published version 6.8.5 does not include this PR
will this PR be embedded in a published release soon?

@slorber
Copy link

slorber commented Oct 2, 2017

If you want to use this feature right now, you can use my release (make sure to verify I'm not a malicious hacker!)

"babel-plugin-transform-remove-console-seb": "6.8.6",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tag: New Feature Pull Request adding a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants