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

fix destructuring arguments #117

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Vorobeyko
Copy link

@Vorobeyko Vorobeyko commented Feb 22, 2020

Added parse arguments of function like:

({x, y}) => {}

Which return result.args = ['x', 'y']

@tunnckoCore Can you help me with tests?

@tunnckoCore
Copy link
Owner

tunnckoCore commented Feb 22, 2020

Hi and very thanks!

And yet, I'm not sure if this case really is "args". I always wonder what to do in such complex cases. That's probably the beauty of the plugins structure.

I really want to first publish the #72 / #67 (v6 release) and then consider what to do with these cases.

For now you can literally make another plugin like the following

export default () => (node, result) => {
  result.destructuredArgs = result.destructuredArgs || [];

  node.params.forEach((param) => {
    if (
      param.type === 'ObjectPattern' &&
      param.properties &&
      param.properties.length > 0
    ) {
      param.properties.forEach((prop) => {
        const { name } = prop.value;
        result.destructuredArgs.push(name);
      });
    }
  })

  return result
}

and if you want them all to be in result.args I guess you can just concat both arrays before the return result.

@tunnckoCore
Copy link
Owner

I update the tests, you just need to update the snapshots with Jest's -u flag.
Run hela test -u or yarn test -u and commit.

@tunnckoCore
Copy link
Owner

Actually, why not create a new file in plugins/destructured-args.js with above snippet and then update the plugins/initial.js to include it there like the other ones.

  import body from './body';
  import props from './props';
  import params from './params';
+ import destructured from './destructured-args';

and later

   result = props(app)(node, result);
   result = params(app)(node, result);
   result = body(app)(node, result);
+  result = destructured(app)(node, result);

But in anyway, a new published version probably won't be that soon that you may need it, so just use the above snippet.

@Vorobeyko
Copy link
Author

Thank you!!
I will do this)

@Vorobeyko
Copy link
Author

Vorobeyko commented Feb 23, 2020

@tunnckoCore HI!
How can I create custom plugin and plug in it at my repository?

@Vorobeyko
Copy link
Author

Vorobeyko commented Feb 23, 2020

oh) I found the bug on my code )
When I parsed class method.

class Obj {
  method({ locator, sec }) {}
}

I will fix this asap)

@Vorobeyko
Copy link
Author

Thank you!!
I will do this)

I found the decide)

@tunnckoCore
Copy link
Owner

tunnckoCore commented Feb 23, 2020

How can I create custom plugin and plug in it at my repository?

Just get your code from here and pass it to .use method directly for now.

https://github.com/tunnckoCore/opensource/tree/master/@packages/parse-function#use

GitHub
Delivering delightful digital solutions. Growing Open Source Monorepo of packages with combined ~50M/month downloads, semantically versioned following @conventional-commits. Fully powered by Jest, ...

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

Successfully merging this pull request may close these issues.

None yet

2 participants