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
History
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
File Mode Size
.circleci
.devcontainer
.github
.ng-dev
.vscode
.yarn
aio
dev-infra
docs
goldens
integration
modules
packages
scripts
third_party
tools
.bazelignore -rw-r--r-- 4.3 KB
.bazelrc -rw-r--r-- 6.2 KB
.bazelversion -rw-r--r-- 213 bytes
.clang-format -rw-r--r-- 73 bytes
.editorconfig -rw-r--r-- 245 bytes
.gitattributes -rw-r--r-- 314 bytes
.gitignore -rw-r--r-- 837 bytes
.gitmessage -rw-r--r-- 7.2 KB
.mailmap -rw-r--r-- 51 bytes
.nvmrc -rw-r--r-- 8 bytes
.pullapprove.yml -rw-r--r-- 45.8 KB
.yarnrc -rw-r--r-- 128 bytes
BUILD.bazel -rw-r--r-- 1.8 KB
CHANGELOG.md -rw-r--r-- 756.6 KB
CODE_OF_CONDUCT.md -rw-r--r-- 1.1 KB
CONTRIBUTING.md -rw-r--r-- 14.9 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 4.3 KB
WORKSPACE -rw-r--r-- 4.0 KB
browser-providers.conf.js -rw-r--r-- 8.4 KB
gulpfile.js -rw-r--r-- 1.3 KB
karma-js.conf.js -rw-r--r-- 7.8 KB
package.json -rw-r--r-- 8.4 KB
test-events.js -rw-r--r-- 259 bytes
test-main.js -rw-r--r-- 11.3 KB
tslint.json -rw-r--r-- 2.3 KB
yarn.lock -rw-r--r-- 698.0 KB
yarn.lock.readme.md -rw-r--r-- 1.3 KB

README.md

back to top