10000 Fix ES6 support using Babel::Transpiler by felixbuenemann · Pull Request #5 · kikyous/rails-vue-loader · GitHub
[go: up one dir, main page]

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

Fix ES6 support using Babel::Transpiler #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

felixbuenemann
Copy link

Tested on sprockets 3.7.1 with sprockets-es6 0.9.2, but should also work on sprockets 4 which also uses the babel-transpiler gem for es6 support.

Tested on sprockets 3.7.1 with sprockets-es6 0.9.2, but should also work
on sprockets 4.x with babel-transpiler gem.

This also allows to use ES6 `export default` for defining components.
@felixbuenemann
Copy link
Author

2a9dbdf adds support for export default { } when defining components using <script lang="es6">.

@@ -30,7 +39,7 @@ def call(input)
map = result['sourceMap']

output << "'object' != typeof VComponents && (this.VComponents = {});
var module = { exports: null };
var module = { exports: null }, exports = {};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Babel uses the exports object to store exports and then assigns exports['default'] to module.exports.

@felixbuenemann
Copy link
Author

There's a problem with <script lang="es6">:

While it works fine for detecting ES6 in sprockets, it breaks tooling like Vetur in VSCode, which only support javascript, coffee and ts for the langattribute.

How about autodetecting if Babel::Transpiler is defined and if it is always use the ES6 parser unless lang="coffee" is specified?

Sending non-ES6 code through babel is pretty much a No-OP, so it doesn't really hurt.

@kikyous
Copy link
Owner
kikyous commented Jul 10, 2017

Thanks for your pr

@kikyous
Copy link
Owner
kikyous commented Jul 10, 2017

I think we can still use module.exports= in es6,

It is not unnecessary to support es6 export default

we just need a var to assign object to it

@felixbuenemann
Copy link
Author
felixbuenemann commented Jul 10, 2017

Your are right, module.exports still works in es6, but with the change it also works with export default which makes sense to use if you are writing es6. We only need the exports object because babel assumes it exists when using the export default syntax.

What do you think about auto-detection of es6 support?

I have already implemented it in my autodetect-es6 branch.

@kikyous
Copy link
Owner
kikyous commented Jul 10, 2017

I think auto-detection is not a good way.
how about

<script lang="javascript" es6>
module.exports = {
  name: 'app',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  }
}
</script>

@felixbuenemann
Copy link
Author

That could work, I'll have to try it out.

It could also be a implemented as a configuration setting.

@kikyous
Copy link
Owner
kikyous commented Jul 10, 2017

export default is ok.
but I think wo should split lang transpiler in to different files,
ex. coffee.rb, es6.rb ...

In this way, we can define export={} only when needed

@felixbuenemann
Copy link
Author

I thought about doing it, but I didn't see the point because it's only one extra object defined in the scope of the IIFE.

@kikyous
Copy link
Owner
< 6EF4 strong> kikyous commented Jul 10, 2017

we can do it later.

Split transpiler in to different files so we can have more clear code, and no extra object

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.

2 participants
0