Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working for an specific case of async fonction with destructured parameter #1036

Closed
sebaplaza opened this issue Jan 11, 2023 · 8 comments · Fixed by #1037
Closed

not working for an specific case of async fonction with destructured parameter #1036

sebaplaza opened this issue Jan 11, 2023 · 8 comments · Fixed by #1037

Comments

@sebaplaza
Copy link
Contributor

Hello,

reflect is not working in a specific case

  it('should returns object parameters from an async anonymous function declared inside an object', () => {
    const obj = {
      fn: async ({ param1, param2 }) => {
        return param1 + param2;
      },
    };

    const metadata = reflect(obj.fn);
    expect(metadata.parameters).toHaveLength(1);
  });

Thanks !

Note: continuation of #1027

@ktutnik
Copy link
Collaborator

ktutnik commented Jan 12, 2023

This issue was caused by the regex function that is used to identify the invalid function syntax failing. I believe this is further causing some issue for an inline (non lambda) function like below.

const obj = {
      fn: function (par1, par2) { }
};

I'm fixing this issue, and should be fixed asap.

@ktutnik
Copy link
Collaborator

ktutnik commented Jan 12, 2023

I fixed the issue, please try using version 1.1.2-canary.2

please confirm if above fixed your issue.

@sebaplaza
Copy link
Contributor Author

sebaplaza commented Jan 12, 2023

Thanks !

It's working for this case.

Anyway, i'm still having an issue with another specific case. But i struggle to reproduce it with a unit test.

If you want, we can close this issue and i can create another one when i will able to find an easy way to reproduce it.

Update: I found the failing case

  it('should return no parameters of a class with private getter properties and no constructor', () => {
    class MyClass {
      #options;

      get options() {
        return this.#options;
      }
    }

    const metadata = reflect(MyClass);
    expect(metadata).toBeDefined();
  });

I'm having this error

TypeError: attempted to get private field on non-instance

Same problem with a class with a constructor and parameters, is the getter the root of the problem.

@ktutnik
Copy link
Collaborator

ktutnik commented Jan 15, 2023

Hi @sebaplaza I found this issue is bug in my code. For a moment I found that this will causing error on a getter/setter which accessed private field. I will push a fix asap related to this.

do you have any issue related to this beside using getter/setter?

@sebaplaza
Copy link
Contributor Author

@ktutnik

no, no others issues related, thanks !

i create an issue to track this bug or is ok for you ?

@ktutnik
Copy link
Collaborator

ktutnik commented Jan 15, 2023

Yes I think its better in another ticket because its unrelated with the tittle. Thanks

@ktutnik
Copy link
Collaborator

ktutnik commented Jan 15, 2023

Please try using @plumier/reflect@1.1.2-canary.4 please confirm if its fixed your issue.

@ktutnik ktutnik reopened this Jan 15, 2023
@sebaplaza
Copy link
Contributor Author

Everything is working now

Thanks a lot !

Note: a made an issue to trace the problem (fixed)
#1040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants