Skip to content

More helpful validation#473

Merged
Rich-Harris merged 4 commits intomasterfrom
gh-166
Apr 13, 2017
Merged

More helpful validation#473
Rich-Harris merged 4 commits intomasterfrom
gh-166

Conversation

@Rich-Harris
Copy link
Copy Markdown
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