fix(core): remove duplicated EMPTY_ARRAY constant#40587
fix(core): remove duplicated EMPTY_ARRAY constant#40587cexbrayat wants to merge 0 commit intoangular:masterfrom
Conversation
ae19b74 to
83dd9d2
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
Smashing! Thanks @cexbrayat
packages/core/src/render3/empty.ts
Outdated
There was a problem hiding this comment.
Are we sure we don't mind that some EMPTY_ARRAYs will not be frozen in dev mode any more?
There was a problem hiding this comment.
No worries: it now uses EMPTY_ARRAY from util/empty.ts which does exactly the same (see https://github.com/angular/angular/blob/a6971ba89adc253bfa4260036ee4a1e0bd76159f/packages/core/src/util/empty.ts)
There was a problem hiding this comment.
Right. Then, are we sure we don't mind that some EMPTY_ARRAYs will now be frozen in dev mode? 😁
There was a problem hiding this comment.
Ha! That's a tougher question to answer 😃. I think it should be fine but do you see an area where it might be problematic?
There was a problem hiding this comment.
I would have thought that freezing in dev-mode is what we want. And possibly not bothering to freeze in prod mode.
The general idea being that we would catch errors that try to modify the object during testing in dev mode.
There was a problem hiding this comment.
Agreed. OOC: is one of the test suites running with ngDevMode enabled?
There was a problem hiding this comment.
My concern was more with operations that don't throw errors. For example, a = []; Object.freeze(a); a[0] = 'v'; will silently fail.
But looking at the code, there doesn't seem to be a place were EMPTY_ARRAY is modified. Ideally we should type it as ReadonlyArray, but this is out of scope for this PR 😃
There was a problem hiding this comment.
Oh I always thought that a frozen object/array would throw an error in that case. TIL!
There was a problem hiding this comment.
Actually in strict mode it will throw an error, apparently: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#freezing_arrays
There was a problem hiding this comment.
Ah, nice! That's more reassuring 😃
|
This happens to address #28229 :-D |
The codebase currently contains several `EMPTY_ARRAY` constants, and they can end up in the bundle of an application. A recent commit 6fbe219 tipped us off as it introduced several `noop` occurrences in the golden symbol files. After investigating with @petebacondarwin, we decided to remove the duplicated symbols. This probably shaves only a few bytes, but this commit removes the duplicated functions, by always using the one in `core/src/utils/empty`. PR Close #40587
The codebase currently contains several `EMPTY_ARRAY` constants, and they can end up in the bundle of an application. A recent commit 6fbe219 tipped us off as it introduced several `noop` occurrences in the golden symbol files. After investigating with @petebacondarwin, we decided to remove the duplicated symbols. This probably shaves only a few bytes, but this commit removes the duplicated functions, by always using the one in `core/src/utils/empty`. PR Close #40587
|
This change breaks |
|
Do not merge this PR until http://b/178744068 is resolved. (Has been resolved 2/1/2021) |
83dd9d2 to
6c05c80
Compare
|
@cexbrayat I've tried rebasing this PR using our tooling, but it detected that the original commit was already merged (and reverted later), so the rebase resulted in an empty branch :( I can restore actual changes using previously merged commits, but I'd like to ask if you're ok re-creating this PR, so that the change is submitted under your name. Note: I've also started a new presubmit and we'll use these results for the newly created PR. Please let me know if you can help with re-creating this PR or you want me to handle this. Thank you. |
|
@AndrewKushnir Sure, I opened #40991 let me know if that's OK. Thanks for your help Andrew |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The codebase currently contains several
EMPTY_ARRAYconstants,and they can end up in the bundle of an application.
A recent commit 6fbe219 tipped us off
as it introduced several
noopoccurrences in the golden symbol files.What is the new behavior?
After investigating with @petebacondarwin,
we decided to remove the duplicated symbols.
This probably shaves only a few bytes,
but this commit removes the duplicated functions,
by always using the one in
core/src/utils/empty.Does this PR introduce a breaking change?
Other information