This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Injector incorrectly infers injectables for ES6 classes #14789
Closed
Description
TL;DR: Using ES6 classes and Angular has a huge caveat. A temp workaround is to:
- always declare constructor
- declare constructor first
extractArgs
method relies on a regular expression to extract function arguments. However when instantiating an ES6 class, the regexp may fail. E.g.:
https://jsfiddle.net/ykmtej1j/
vs
https://jsfiddle.net/ykmtej1j/1/
In the first example the extractArgs
incorrectly infers method(wrongArgument)
as constructor (it's only looking for opening parenths).
Regular expression is not safe to use with ES6 classes. And unless there's a way to extract the constructor method at runtime, extractArgs
would need a real JS AST parser to correctly and reliably infer constructor arguments.