https://github.com/angular/angular
Revision b0bbc1f2320b2aecbad85b711647543b957da6cc authored by Kristiyan Kostadinov on 01 November 2020, 11:33:52 UTC, committed by Joey Perrott on 03 November 2020, 22:53:00 UTC
When a class with a custom decorator is transpiled to ES5, it looks something like this:

```
var SomeClass = (function() {
  function SomeClass() {...};
  var SomeClass_1 = __decorate([Decorator()], SomeClass);
  SomeClass = SomeClass_1;
  return SomeClass;
})();
```

The problem is that if the class also has an Angular decorator that refers to the class itself
(e.g. `{provide: someToken, useClass: SomeClass}`), the generated `setClassMetadata` code will
be emitted after the IIFE, but will still refer to the intermediate `SomeClass_1` variable from
inside the IIFE. This happens, because we generate the `setClassMetadata` call directly from
the source AST which contains identifiers that TS will rename when it emits the ES5 code.

These changes resolve the issue by looking through the metadata AST and cloning any `Identifier`
that is referring to the class. Since TS doesn't have references to the clone, it won't rename
it when transpiling to ES5.

Fixes #39509.

PR Close #39527
1 parent b6064c2
Raw File
Tip revision: b0bbc1f2320b2aecbad85b711647543b957da6cc authored by Kristiyan Kostadinov on 01 November 2020, 11:33:52 UTC
fix(compiler-cli): generating invalid setClassMetadata call in ES5 for class with custom decorator (#39527)
Tip revision: b0bbc1f
test-events.js
/**
 * @license
 * Copyright Google LLC All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://angular.io/license
 */

Zone[Zone.__symbol__('UNPATCHED_EVENTS')] = ['scroll'];
back to top