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

refactor(zone.js): use .toString() directly for improved tree shakability #55412

Closed
wants to merge 1 commit into from

Conversation

dgp1130
Copy link
Contributor

@dgp1130 dgp1130 commented Apr 18, 2024

These lines were not tree shakable by Closure Compiler because .toString() is special cased as a "pure" function eligible to eliminated if it's return value is unused. However .toString.call circumvents this and makes Closure Compiler think the function may have side effects. Switching to .toString() should be fine here as process.toString() in Node outputs [object process] so this should be safe. Presumably the original motivation for this roundabout approach was for type safety reasons which no longer apply as _global is any.

At least I'm assuming the original reason was for type safety. @JiaLiPassion do you happen to have any historical context why we might have used {}.toString.call? It appears to have already been that way when Zone.js was synced into angular/angular.

@dgp1130 dgp1130 added action: review The PR is still awaiting reviews from at least one requested reviewer area: zones labels Apr 18, 2024
@ngbot ngbot bot added this to the Backlog milestone Apr 18, 2024
@dgp1130 dgp1130 changed the title refactor(zone.js): use Object.prototype.toString directly for improved tree shakability refactor(zone.js): use .toString() directly for improved tree shakability Apr 18, 2024
@dgp1130 dgp1130 closed this Apr 24, 2024
@dgp1130 dgp1130 deleted the zone-tree-shaking branch April 24, 2024 23:50
@dgp1130 dgp1130 restored the zone-tree-shaking branch April 29, 2024 23:52
@dgp1130
Copy link
Contributor Author

dgp1130 commented Apr 29, 2024

Whoops, accidentally deleted the branch.

@dgp1130 dgp1130 reopened this Apr 29, 2024
…ved tree shakability

These lines were not tree shakable by Closure Compiler because `.toString()` is special cased as a "pure" function eligible to eliminated if it's return value is unused. However `.toString.call` circumvents this and makes Closure Compiler think the function may have side effects. Switching to `.toString()` should be fine here as `process.toString()` in Node outputs `[object process]` so this should be safe. Presumably the original motivation for this roundabout approach was for type safety reasons which no longer apply as `_global` is `any`.
Copy link
Contributor

@JiaLiPassion JiaLiPassion left a comment

Choose a reason for hiding this comment

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

LGTM!

@dgp1130 dgp1130 added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release target: minor This PR is targeted for the next minor release target: major This PR is targeted for the next major release and removed action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release target: minor This PR is targeted for the next minor release labels Apr 30, 2024
@AndrewKushnir AndrewKushnir added target: minor This PR is targeted for the next minor release and removed target: major This PR is targeted for the next major release labels Apr 30, 2024
@AndrewKushnir
Copy link
Contributor

Presubmit.

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 3312727.

@dgp1130 dgp1130 deleted the zone-tree-shaking branch April 30, 2024 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: zones target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants