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

More helpful validation #473

Merged
merged 4 commits into from
Apr 13, 2017
Merged

More helpful validation #473

merged 4 commits into from
Apr 13, 2017

Conversation

Rich-Harris
Copy link
Member

Trying to clear out the easy-to-tackle stuff from the issues list. This closes #166, with some analysis of helpers and methods (and namespace, while I was at it):

  • Event handlers (on:click='foo()') are checked to ensure that foo is a valid method. Valid methods are set, fire and anything custom. this.* and event.* are also permitted
  • If foo doesn't exist on methods but it does exist on helpers, Svelte asks if it was put in the wrong place
  • We do some sanity checking on helpers to make sure that they're in the right place:
    • If a helper uses this.get('x') — common mistake — it errors, tells you to pass it in as an argument instead (we could also do this for computed values)
    • If it otherwise uses this, it errors, telling you that helper functions must be pure and have no access to the component instance, and suggesting that it belongs on methods
    • If the function length is zero and arguments is not used, it warns you that helpers should be pure
  • Invalid namespaces cause an error. Svelte will use fuzzy matching to try and guess what you meant, to help in case of typos like https instead of http.

@Rich-Harris Rich-Harris merged commit d4d7f6c into master Apr 13, 2017
@Rich-Harris Rich-Harris deleted the gh-166 branch April 13, 2017 00:15
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 this pull request may close these issues.

Help people distinguish between methods and helpers
1 participant