Skip to content

Awilix incorrectly parses the constructor of a class if the word constructor is used before the constructor definition. #390

@udnes99

Description

@udnes99

This really obscure bug occurred after modifying one of our components.

After adding the this line to a function within our affected class, we started observing AwilixResolutionError: Failed to resolve 'name'.

        //... 
        throw new Error(
            `Unknown datatype: ${typeof valueOrEntity} -- Constructor: ${valueOrEntity?.constructor?.name}`
        );
    }

It turns out that this file had (mis) placed its constructor below this code in the class.
After a little while, we discovered that the error disappeared after moving the constructor() definition above the function containing that code. Thus it would seem that awilix incorrectly parses a file if the word constructor appears before the actual constructor implementation. Perhaps a pattern-match on constructor(...) would fix the issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions