Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

feature/arrow-functions #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feature/arrow-functions #2

wants to merge 1 commit into from

Conversation

davemo
Copy link

@davemo davemo commented Feb 27, 2018

No description provided.

@aphix
Copy link

aphix commented Apr 24, 2018

Perhaps I'm misunderstanding the regex, but I don't believe this will parse functions written without parenthesis, e.g.

dep1 => result

Arrow support would be great though... Perhaps if I get the time, I'll submit a PR for async combinations of arrow+normal fns next =P

@davemo
Copy link
Author

davemo commented Apr 24, 2018

I think you're correct @aphix. This PR did add support for arrow functions that use parentheses, but not those without. Depending on the complexity of this feature I'm not sure it's worth it though, as you can just use (dep1) => result which isn't too many more characters :)

@aphix
Copy link

aphix commented Apr 25, 2018

Not sure if it will help, but this is a conversion I've written in the past to transform a standard func to an arrow func, perhaps it can be reversed:

const stringifyFuncAsArrowFunc = (func) => func.toString()
                                           .replace(/\(function/g, '(')
                                           .replace(/^function/g, '')
                                           .replace(/\{return/g, ' => ')
                                           .replace(/\}\)/g, ')')
                                           .replace(/\}$/g, '')
                                           .replace(/[ ]+/g,' ')
                                           .trim();

Edit: FWIW, it was made to inline some simple funcs into test descriptions, so it likely doesn't cover more complex cases-

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

Successfully merging this pull request may close these issues.

2 participants