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

Better function scanning. #1579

Open
aomarks opened this issue Nov 14, 2017 · 9 comments
Open

Better function scanning. #1579

aomarks opened this issue Nov 14, 2017 · 9 comments

Comments

@aomarks
Copy link
Member

aomarks commented Nov 14, 2017

Analyzer doesn't currently find functions that are declared by assignment, which is a common pattern in Polymer core.

For example, we find Polymer.Async.timeOut.after, but not Polymer.Async.timeOut.run. The former is declared with a normal function declaration, while the latter is with an assignment with a bind call.

This is why the Polymer API docs are incomplete for some namespaces. For example, https://www.polymer-project.org/2.0/docs/api/namespaces/Polymer.Async.timeOut is missing run and cancel. Similar story for https://www.polymer-project.org/2.0/docs/api/namespaces/Polymer.Async.animationFrame and others.

I think what's going on is that Analyzer just looks for function declarations, so because the actual expression doesn't look like a function, it's not scanned at all. Scope analysis could solve this in a more principled way, but the simpler fix is to either pick up on the @return and @param annotations and assume that a function has been defined regardless of the actual expression syntax, or to require that such cases are annotated explicitly with something like @type {Function}.

As part of this, I think we should try to unify the function and method scanning logic, which obviously has a large overlap. A few features (e.g. rest parameters, optional parameters) are currently only supported for methods, so we'd also get those extended to functions by doing this refactoring.

@aomarks aomarks self-assigned this Nov 14, 2017
@rictic
Copy link
Contributor

rictic commented Nov 14, 2017

I think finding @return is enough. @param is tricky because events are also annotated with @param

@rictic
Copy link
Contributor

rictic commented Nov 14, 2017

Note: mixins may also be annotated with @return

@aomarks
Copy link
Member Author

aomarks commented Nov 14, 2017

@aomarks
Copy link
Member Author

aomarks commented Nov 14, 2017

Ah ok, good call. @justinfagnani was advocating for an explicit @type annotation anyway, so I guess we should do that then so it's totally unambiguous. Assuming adding a @type to a function is not a confusing thing for e.g. Closure...

@aomarks
Copy link
Member Author

aomarks commented Nov 29, 2017

How about @function http://usejsdoc.org/tags-function.html?

@aomarks
Copy link
Member Author

aomarks commented Nov 29, 2017

After starting to implement this, I found that we actually already support @function for exactly this use case (https://github.com/Polymer/polymer-analyzer/blob/master/src/javascript/function-scanner.ts#L97).

@justinfagnani
Copy link
Contributor

justinfagnani commented Dec 2, 2017

That's functions inside object literals though, do we have it for top-level statements too?

edit: sorry, I mixed this up with another issue related to @function :)

@aomarks
Copy link
Member Author

aomarks commented Dec 2, 2017

You're right that we don't support it for top-levels, though.

@aomarks aomarks removed their assignment Apr 13, 2018
@aomarks aomarks transferred this issue from Polymer/polymer-analyzer Jan 3, 2019
@stale
Copy link

stale bot commented Mar 3, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants