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

Empty component 'computed' throws error. #452

Closed
taylorzane opened this issue Apr 4, 2017 · 2 comments
Closed

Empty component 'computed' throws error. #452

taylorzane opened this issue Apr 4, 2017 · 2 comments

Comments

@taylorzane
Copy link
Contributor

An empty component computed property causes svelte compiler to add an unnecessary recompute call without actually adding the recompute function.

Version: 1.13.6

Smallest failing example:

<script>
  export default {
    computed: {} 
  }
</script>

Error: recompute is not defined.

Seems like the error is going on here: src/generators/dom/index.js#L305-L309

In order to resolve this issue I see one of two options:

  1. Check to see if computed is an empty object.
    • I think I'd prefer this more since I (personally) like to scaffold a component before adding in the computed properties.
  2. Throw a warning at build time that an empty object for computed is invalid.

I'll be happy to submit a PR, I just wanted to figure out the best course of action.

@Conduitry
Copy link
Member

I think allowing an empty computed object is reasonable. It looks like replacing the templateProperties.computed condition you mentioned with computations.length should fix this.

@taylorzane
Copy link
Contributor Author

Great, I'll take care of that.

taylorzane added a commit to taylorzane/svelte that referenced this issue Apr 5, 2017
…an empty object to prevent the component from compiling.
Rich-Harris added a commit that referenced this issue Apr 5, 2017
Fixed empty component 'computed' from throwing error.
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

No branches or pull requests

2 participants