Paul Gschwendtner 25eaaa24b5 fix(@angular-devkit/build-angular): downlevel class properties when targeting Safari <=v15
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 `this` context when invoking methods, such as for
defining animations in the `ecmp` definition.

More details can be found here:
https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033

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 of
writing).

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 ecmp` into `static { this.ecmp = X }` when
`useDefineForClassFields = false` (which is the case for CLI apps). The
class properties plugin from Babel seems to handle this in an acceptable
way. Unlike actual static fields, Babel will not use helpers like
`defineProperty` for such extracted static blocks though. e.g.

See repro: https://gist.github.com/devversion/dec0dea26e348c509921bf62079b60be

```js
class Test {
  x = true;

  static b = true;
  static {
    this.a = true;
  }
}

// into

class X {
  constructor() {
    _defineProperty(this, "x", true);
  }
}
_defineProperty(X, "b", true);
X.a = true;
```

note that in practice TypeScript with `useDefineForClassFields = false`
will put non-static members into the constructor as normal assignments
regardless- so there would be no change by the Babel plugin.

Fixes #24355.
2022-12-02 09:05:29 +00:00
2021-11-12 10:59:11 +00:00
2019-01-18 11:58:02 -08:00
2021-11-12 10:59:11 +00:00
2021-04-28 16:05:49 -07:00

Angular CLI - The CLI tool for Angular.


Angular CLI logo

The Angular CLI is a command-line interface tool that you use to initialize, develop, scaffold,
and maintain Angular applications directly from a command shell.

cli.angular.io

Contributing Guidelines · Submit an Issue · Blog

CI status   Discord conversation


Documentation

Get started with Angular CLI, learn the fundamentals and explore advanced topics on our documentation website.

Development Setup

Prerequisites

Setting Up a Project

Install the Angular CLI globally:

npm install -g @angular/cli

Create workspace:

ng new [PROJECT NAME]

Run the application:

cd [PROJECT NAME]
ng serve

Angular is cross-platform, fast, scalable, has incredible tooling, and is loved by millions.

Quickstart

Get started in 5 minutes.

Ecosystem

angular ecosystem logos

Changelog

Learn about the latest improvements.

Upgrading

Check out our upgrade guide to find out the best way to upgrade your project.

Contributing

Contributing Guidelines

Read through our contributing guidelines to learn about our submission process, coding rules and more.

Want to Help?

Want to report a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues labeled as help wanted or good first issue.

Code of Conduct

Help us keep Angular open and inclusive. Please read and follow our Code of Conduct.

Developer Guide

Read through our developer guide to learn about how to build and test the Angular CLI locally.

Community

Join the conversation and help the community.

Packages

This is a monorepo which contains many tools and packages:

Tools

Project Package Version Links
Angular CLI @angular/cli latest README snapshot
Architect CLI @angular-devkit/architect-cli latest snapshot
Schematics CLI @angular-devkit/schematics-cli latest snapshot

Packages

Project Package Version Links
Architect @angular-devkit/architect latest README snapshot
Build Angular @angular-devkit/build-angular latest README snapshot
Build Webpack @angular-devkit/build-webpack latest README snapshot
Core @angular-devkit/core latest README snapshot
Schematics @angular-devkit/schematics latest README snapshot

Misc

Project Package Version Links
Angular Create @angular/create latest README
Webpack Angular Plugin @ngtools/webpack latest snapshot

Schematics

Project Package Version Links
Angular PWA Schematics @angular/pwa latest snapshot
Angular Schematics @schematics/angular latest snapshot

Love Angular CLI? Give our repo a star ⬆️.

Description
Languages
TypeScript 95%
Starlark 2.3%
JavaScript 1.3%
HTML 1%
EJS 0.3%