fix(@angular-devkit/build-angular): downlevel class properties when targeting Safari <=v15#24357
Merged
angular-robot[bot] merged 1 commit intoangular:mainfrom Dec 2, 2022
Merged
Conversation
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Angular compiler is dependent on static fields being attached to
user-defined classes. e.g.
static ecmp = defineComponent.These static fields sometimes rely on variables from outside of the
class. e.g. the Angular compiler generates constants for content
projection that are then accessed in the static field initializer.
Surprisingly such access to these variables may break in Safari <=v15
when a page is loaded without devtools open. The bug (already solved in
v16 of Safari)- is very subtle, hard to re-reproduce but basically
variable scope tracking is broken. This bug is triggered by additional
parenthesis in the initializer expression. See:
https://bugs.webkit.org/show_bug.cgi?id=236843.
The TypeScript compiler may generate such additional parenthesis when
it tries to adjust the
thiscontext when invoking methods, such as fordefining animations in the
ecmpdefinition.More details can be found here:
#24355 (comment)
To ensure Angular applications are not subject to this bug when
targeting Safari <=v15. v15 Safari, both for iOS and Mac is still part of
the default CLI browserslist with
last 2 Safari majors(at time ofwriting).
Note that it is important that the Babel plugin properly handles the
downleveling of static block-defined members. TypeScript will transform
static fields, like
static ecmpintostatic { this.ecmp = X }whenuseDefineForClassFields = false(which is the case for CLI apps). Theclass properties plugin from Babel seems to handle this in an acceptable
way. Unlike actual static fields, Babel will not use helpers like
definePropertyfor such extracted static blocks though. e.g.See repro: https://gist.github.com/devversion/dec0dea26e348c509921bf62079b60be
note that in practice TypeScript with
useDefineForClassFields = falsewill put non-static members into the constructor as normal assignments
regardless- so there would be no change by the Babel plugin.
Fixes #24355