angular/packages/compiler-cli/src
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
..
diagnostics build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
metadata feat(compiler-cli): add support for TypeScript 4.0 (#38076) 2020-08-24 13:06:59 -07:00
ngtsc fix(compiler-cli): generating invalid setClassMetadata call in ES5 for class with custom decorator (#39527) 2020-11-03 14:52:59 -08:00
transformers refactor(compiler-cli): attachComments() now expects a defined leadingComments array (#39076) 2020-10-06 11:33:55 -07:00
extract_i18n.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
language_services.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
main.ts style(compiler-cli): remove unused constant (#38441) 2020-08-13 13:32:41 -07:00
perform_compile.ts fix(ngcc): report a warning if ngcc tries to use a solution-style tsconfig (#38003) 2020-07-14 13:21:31 -07:00
perform_watch.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
tooling.ts refactor(compiler-cli): skip class decorators in tooling constructor parameters transform (#37545) 2020-06-15 12:47:57 -07:00
typescript_support.ts refactor(compiler): remove support for TypeScript 3.9 (#39313) 2020-10-19 14:34:45 -07:00
version.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00