question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular Non AOT compiler doesn't emit class decorators in specific cases

See original GitHub issue

🐞 bug report

Affected Package

Angular Non AOT compiler (Jit Mode)

Is this a regression?

Yes, the very same scenario works on Angular 8.x

Description

Given that AOT is disabled ("aot": false in angular.json) Given a class that is responsible of configuring “class decorators”, if I decorate a regular typescript class with a decorator generated by that class, the compiled javascript doesn’t emit the class decorator properly.

class DecoratorBuilder {
  customClassDecorator<T extends { new (...args: any[]): {} }>(constructor: T) {
    console.log('Class Decorated');
    return class extends constructor {
      myName = 'Decorated Foobar';
    };
  }
}

export function ClassDecorators() {
  return new DecoratorBuilder();
}

@ClassDecorators().customClassDecorator
class MyNonAngularClass {
  myName = 'foobar';
}

🔬 Minimal Reproduction

https://github.com/ratoaq2/angular-non-aot-class-decorator

Just start the app: npm install npm start

access http://localhost:4200 You should see: Hello Decorated Foobar! But you see: Hello foobar!

If you enable "aot": true, it works correctly. But that’s not an option because I also face this issue in my spec tests where I can’t enable aot.

🔥 Exception or Error

No exception or error

🌍 Your Environment

Angular Version:


Angular CLI: 10.0.8
Node: 12.18.4
OS: win32 x64

Angular: 10.0.14
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: No

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.8
@angular-devkit/build-angular     0.1000.8
@angular-devkit/build-optimizer   0.1000.8
@angular-devkit/build-webpack     0.1000.8
@angular-devkit/core              10.0.8
@angular-devkit/schematics        10.0.8
@angular/cli                      10.0.8
@ngtools/webpack                  10.0.8
@schematics/angular               10.0.8
@schematics/update                0.1000.8
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0

Anything else relevant? It doesn’t seem to be a typescript issue

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, Nov 5, 2020

Actually it is caused by a transform (constructorParametersDownlevelTransform) that is held in the FW repository. So transferring back!

0reactions
angular-automatic-lock-bot[bot]commented, Dec 7, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ahead-of-time (AOT) compilation - Angular
The AOT compiler does not support function expressions and arrow functions, also called lambda functions. Consider the following component decorator:.
Read more >
Angular 4 AOT compiler does not support mixins
Sometimes I use Mixins to inject repeated functions like slugUrl() . But it doesn't work with angular 4 compiler. export function Mixin(decorators ......
Read more >
Ahead-of-time (AOT) Compilation - Halodoc Blog
Angular 9 introduce the Ahead Of Time (AOT) compiler and set as run time by default. In this article, we'll focus on the...
Read more >
The Ahead-of-Time (AOT) compiler - Angular - API Manual
The AOT compiler does not support function expressions and arrow functions, ... code to create instances of certain classes, support certain decorators, ...
Read more >
ngRx/Store and 5 silly mistakes - ITNEXT
#4. Exported reducer function is necessary as function calls are not supported by the AOT compiler (in Angular 8). The title of this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found