k1r0s/kaop-ts

The Log decorator/annotation does not support AoT compilation

russcarver opened this issue ยท 6 comments

At https://github.com/k1r0s/kaop-ts/blob/master/docs/examples.md#log-decorator (and related linked documentation), you give an example that does not pass Angular5's AoT compilation. To get this to work, it should be:

import { afterMethod, IMetadata } from 'kaop-ts';

export function Log(): Function {
  return afterMethod((meta: IMetadata) => {
    const methodName = `${meta.target.constructor.name}::${meta.key}`;
    console.info(`log-decorator: ${methodName} invoked!`);
    console.info(`log-decorator: ${methodName} arguments -> `, meta.args);
    console.info(`log-decorator: ${methodName} result -> `, meta.result);
  });
}

Then, the decorator should be used as @Log() instead of @Log.

k1r0s commented

Hi @russcarver

I didn't try Angular5 yet. I worked with Angular 2/4

Seems like AOT build is refusing to recognize some custom decorators as I can see elsewhere

angular/angular#16023

Feel free to PR your solution to the docs
https://github.com/k1r0s/kaop-ts/blob/master/docs/examples.md

@k1r0s I think it is a bug - in v3.1.3.
when I was trying update to v3.1.3 my build was broken similar to @russcarver
currently I'm in production with angular@5.2.6 and AOT and kaop-ts@3.1.2.

k1r0s commented

thanks for the tip @voznik

I have to investigate this in deep.

The only change between these versions was that typings path was missing from package.json. That means 3.1.2 doesn't provide any call signatures and that could be the reason why this version is bypassing AOT compiler

https://github.com/k1r0s/kaop-ts/releases

@voznik can you share your package.json I tried using 5.2.6 with 3.12 and AOT and it's still failing when exporting a wrapper to the afterMethod

k1r0s commented

Hey

I want to fix this but im not able to reproduce the issue.

I created a project with the latest version of @angular/cli

Then I installed kaop-ts (latest version)

This is what I have so far:

k1r0s@k1r0s-K52JU:~/Works/kaop-fix$ npm ls | grep angular
โ”œโ”€โ”ฌ @angular/animations@5.2.9
โ”œโ”€โ”ฌ @angular/cli@1.7.4
โ”‚ โ”œโ”€โ”ฌ @angular-devkit/build-optimizer@0.3.2
โ”‚ โ”œโ”€โ”ฌ @angular-devkit/core@0.3.2
โ”‚ โ”œโ”€โ”€ @angular-devkit/schematics@0.3.2
โ”‚ โ”œโ”€โ”ฌ @schematics/angular@0.3.2
โ”œโ”€โ”€ @angular/common@5.2.9
โ”œโ”€โ”€ @angular/compiler@5.2.9
โ”œโ”€โ”ฌ @angular/compiler-cli@5.2.9
โ”œโ”€โ”€ @angular/core@5.2.9
โ”œโ”€โ”€ @angular/forms@5.2.9
โ”œโ”€โ”€ @angular/http@5.2.9
โ”œโ”€โ”€ @angular/language-service@5.2.9
โ”œโ”€โ”€ @angular/platform-browser@5.2.9
โ”œโ”€โ”€ @angular/platform-browser-dynamic@5.2.9
โ”œโ”€โ”€ @angular/router@5.2.9

Then I added an advice here

import { Component, OnInit } from '@angular/core';
import { afterMethod } from 'kaop-ts';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app';

  @afterMethod(meta => console.log("yooooolo"))
  public ngOnInit() {

  }
}

code works and Im able to run ng build --aot smoothly

can anyone confirm?

k1r0s commented

closing this due to inactivity