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

Compiler outputting ES2015 arrow functions #106

Closed
chrishutchinson opened this issue Dec 4, 2016 · 3 comments
Closed

Compiler outputting ES2015 arrow functions #106

chrishutchinson opened this issue Dec 4, 2016 · 3 comments

Comments

@chrishutchinson
Copy link

chrishutchinson commented Dec 4, 2016

Perhaps this is the expected behaviour, but my understanding was that the compiled output (after running svelte-cli compile ... should be ES5 only? Looking at #82 I'm guessing this shouldn't happen?

If so, the following simplified code gets compiled incorrectly.

<div>Hello, {{cappedName}}!</div>

<script>
  export default {
    data () {
      return {
        name: 'Chris'
      }
    },

    computed: {
      cappedName: name => name.toUpperCase()
    }
  };
</script>

ends up as:

var template = (function () {
  return {
    data () {
      return {
        name: 'Chris'
      }
    },

    computed: {
      cappedName: name => name.toUpperCase()
    }
  };
}());

Whereas I'd expect it to be something more like:

computed: {
  cappedName: function(name) { return name.toUpperCase(); }
}
@Rich-Harris
Copy link
Member

The compiler won't convert your JavaScript, it will only ensure that any additional generated JavaScript is ES5 only. At some point we might add pluggable transpilation, but in the meantime you would need to use a transpiler like Babel or Bublé after the Svelte compilation step, if you're targeting browsers without those features.

@chrishutchinson
Copy link
Author

@Rich-Harris: Perfect, this what I thought might be the case! I've been using Babel in the meantime to solve this problem, so that makes sense. 👍

Might there be somewhere sensible for this to live in the docs for anyone else in the future?

@Rich-Harris
Copy link
Member

Good idea – have added a note to the docs, it should appear here momentarily

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