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.

Decorator usages no longer working with AOT when a function is passed as a parameter

See original GitHub issue

I’m submitting a…


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Given the following decorator:

export function foo(
  test: any
) {
  return (_target: any, _name: string, descriptor: PropertyDescriptor) => {
  };
}

And the following usage:

@foo(() => 5)
bar() {
}

I am getting the following error:

Error encountered in metadata generated for exported symbol 'xxx':
 C:/git/xxx/_artifact/xxx/xxx.ts:48:24: Metadata collected contains an error that will be reported at runtime: Lambda not supported.
  {"__symbolic":"error","message":"Lambda not supported","line":47,"character":23}

Changing the decorator usage to the following works:

@foo(5)
bar() {
}

This breaks when building AOT

Expected behavior

Function parameters in decorators worked before and are expected to work in 5.x.x

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

This functionality used to work correctly in 4.x.x

Environment


Angular version: 5.1.1


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 8.7.0 
- Platform:  Windows 

Others:

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
chuckjazcommented, Dec 20, 2017

@alan-agius4 I am writing the documentation for "strictMetadataEmit" today and it will land as part of my work on #20987.

In this case you can add

// @dynamic
export function foo(
  test: any
) {
  return (_target: any, _name: string, descriptor: PropertyDescriptor) => {
  };
}

Alternately, you can just not enable "strictMetadataEmit" which is off by default. Unless you are bundling a library for npm, you should not use this option.

I am closing this as this is working as intended and Angular 4 didn’t support this either and would emit the same error if you did not specify that the function was not intended to be used in an Angular annotation.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 13, 2019

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

Is it possible to pass arguments to a decorator while calling a ...
The decorators don't "exist" by the time the function is called. Decorators replace/augment the function definition by returning a new function.
Read more >
Untangling Python Decorators | Red's Digressions
Decorating Functions with Arguments. The naive decorator that we've implemented above will only work for functions that take no arguments.
Read more >
Understanding Python Decorators - Techblog
- When the decorator is executed, the wrapped function is no longer passed as an argument, as this has already happened at initialisation...
Read more >
The Ultimate Guide to Python Decorators, Part III
Implementing Decorator Arguments​​ Here you can see that my_decorator takes no arguments when it is used to decorate a function, but the ...
Read more >
Primer on Python Decorators
The problem is that the inner function wrapper_do_twice() does not take any arguments, but name="World" was passed to it. You could fix 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