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

feat(terser - compress): drop_consle supports passing in an array of … #1445

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

dxhsmwqcwelllee
Copy link
Contributor

Now drop_console can only pass Boolean values.

image

This is the code in vtk.js, and Vtk Global is window;. If drop_console: true is configured, the console of window will be set to undefined. Because the addition of drop_console: true can also handle console.hasOwnProperty;, I think I can add an array option while supporting the boolean type, so that only the property contained in the array can be handled.

{
   drop_console:  ['log', 'debug', 'info', 'warn', 'error', 'time', 'timeEnd', 'group', 'groupEnd']
}

like this....

@dxhsmwqcwelllee
Copy link
Contributor Author

@fabiosantoscode

Comment on lines 484 to 498
if (isBoolean) {
var name = exp.expression;
while (name.expression) {
name = name.expression;
}
if (is_undeclared_ref(name) && name.name == "console") {
return make_node(AST_Undefined, self);
}

return;
}

if (options.indexOf(exp.property) === -1) {
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (isBoolean) {
var name = exp.expression;
while (name.expression) {
name = name.expression;
}
if (is_undeclared_ref(name) && name.name == "console") {
return make_node(AST_Undefined, self);
}
return;
}
if (options.indexOf(exp.property) === -1) {
return;
}
if (isArray && options.indexOf(exp.property) === -1) {
return;
}

Comment on lines 468 to 471
var isBoolean = typeof options === "boolean";
var isArray = Array.isArray(options);

if (!isArray && !isBoolean) return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
var isBoolean = typeof options === "boolean";
var isArray = Array.isArray(options);
if (!isArray && !isBoolean) return;
var isArray = Array.isArray(options);

We don't need to validate options here, since TS definitions and the docs can help people pass in the correct option.

Copy link
Collaborator

@fabiosantoscode fabiosantoscode left a comment

Choose a reason for hiding this comment

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

This is a useful addition!

I'd appreciate it if you could add this new option to the typescript definitions in the tools/ folder, and the docs in README.md

@dxhsmwqcwelllee
Copy link
Contributor Author

@fabiosantoscode I resubmitted all the changes you said。

Copy link
Collaborator

@fabiosantoscode fabiosantoscode left a comment

Choose a reason for hiding this comment

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

Great stuff! Thanks :)

@fabiosantoscode fabiosantoscode merged commit 50b9465 into terser:master Sep 19, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants