Decorator usages no longer working with AOT when a function is passed as a parameter
See original GitHub issueI’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:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
Alternately, you can just not enable
"strictMetadataEmit"
which is off by default. Unless you are bundling a library fornpm
, 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.
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.