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

Prevent generating surrounding parenthesis for code in lines that has Javascript code literals #758

Closed
bianjp opened this issue Jul 29, 2015 · 3 comments
Labels

Comments

@bianjp
Copy link

bianjp commented Jul 29, 2015

Case 1:

``export default `` Ember.Route.extend do
     title: 'homepage'

produces

export default (Ember.Route.extend({
     title: 'homepage'
}));

Case 2:

``export default `` do
    name: 'title'
    initialize: !->

produces

export default ({
    name: 'title',
    initialize: function(){}
});

The resulting code fails to be processed by Babel.
It's caused by the parenthesis wrapping the exported content.

As a workaround, I use the following code for Case 1, but for Case 2, I have to declare a variable to hold the exported content and export that variable.

``export default ``
Ember.Route.extend do
    title: 'homepage'

It produces

export default
Ember.Route.extend({
    title: 'homepage'
});

and works well with Babel.

I wonder why wrap other code within parenthesis? And can I get rid of it? Though it's pretty trivial.
Or, I should create a issue for Babel instead?

I'm sure this won't be a problem after LiveScript natively support ES6 module, but it seems no schedule was made yet. See #705.

@bianjp bianjp changed the title Prevent generate surrounding parenthesis for code in lines that has Javascript code literals Prevent generating surrounding parenthesis for code in lines that has Javascript code literals Jul 29, 2015
@vendethiel
Copy link
Contributor

it wraps it because, due to its position, it's a function call

@heavyk
Copy link

heavyk commented Jul 29, 2015

for case 2, an exception would need to be made to check to see if CALL( is named default and (if you want to get really fancy) check to see if the parent is export and is also the root scope. not that big of a deal

for case 1 you can just add a semicolon to keep it on one line

``export default``; Ember.Route.extend do
     title: 'homepage'

@bianjp
Copy link
Author

bianjp commented Jul 30, 2015

Thanks. I understand it now.
Seems I have no choice but to expect LiveScript will natively support ES6 module soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants