angular-cn/packages/compiler-cli
Kristiyan Kostadinov 7e33cb9626 fix(compiler-cli): generating invalid setClassMetadata call in ES5 for class with custom decorator (#39527)
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
2020-11-03 14:52:59 -08:00
..
integrationtest refactor(core): add top 10 runtime error codes (#39188) 2020-10-28 10:05:01 -07:00
linker refactor(compiler-cli): linker - add Babel plugin, FileLinker and initial PartialLinkers (#39116) 2020-10-19 11:23:45 -07:00
ngcc refactor(compiler-cli): Track external component resources in ResourceRegistry (#39373) 2020-10-28 10:57:14 -07:00
src fix(compiler-cli): generating invalid setClassMetadata call in ES5 for class with custom decorator (#39527) 2020-11-03 14:52:59 -08:00
test fix(compiler-cli): generating invalid setClassMetadata call in ES5 for class with custom decorator (#39527) 2020-11-03 14:52:59 -08:00
BUILD.bazel build: upgrade angular build, integration/bazel and @angular/bazel package to rule_nodejs 2.2.0 (#39182) 2020-10-08 11:54:59 -07:00
index.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
package.json refactor(compiler): remove support for TypeScript 3.9 (#39313) 2020-10-19 14:34:45 -07:00
tsconfig-build.json build: reference zone.js from source directly instead of npm. (#33046) 2019-11-06 00:48:34 +00:00
tsconfig.json perf(ivy): ngcc - only find dependencies when targeting a single entry-point (#30525) 2019-07-09 09:40:46 -07:00