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

ES6 Module Loading Object Destructuring newlines #668

Closed
godd9170 opened this issue Apr 9, 2015 · 13 comments
Closed

ES6 Module Loading Object Destructuring newlines #668

godd9170 opened this issue Apr 9, 2015 · 13 comments

Comments

@godd9170
Copy link

godd9170 commented Apr 9, 2015

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Module_loading

var { ProjectStore } = require('../stores');

Becomes

var {
    ProjectStore
} = require('../stores');
@godd9170 godd9170 mentioned this issue Apr 9, 2015
@godd9170 godd9170 changed the title ES6 Module Loading Object Destructuring newlines [JSX support] ES6 Module Loading Object Destructuring newlines Apr 9, 2015
@bitwiseman
Copy link
Member

Thanks!

Poor formatting but not breaking, right?
Is this really a JSX issue or more a general ES6 issue?

@godd9170
Copy link
Author

No it certainly still runs just fine, I'd say it is best classed as an ES6 issue yeah.

@bitwiseman bitwiseman changed the title [JSX support] ES6 Module Loading Object Destructuring newlines ES6 Module Loading Object Destructuring newlines Apr 10, 2015
@darlanalves
Copy link

#315 Would fix this too I think

@bitwiseman
Copy link
Member

Partly, but var {...} = foo; is also something the beautifier doesn't really understand yet.

@darlanalves
Copy link

@bitwiseman I've tried to read the code and figure out how to implement #315, but it's way too much for a initial read.

If you point me how it's done maybe I can help :)

@bitwiseman
Copy link
Member

We treat all braces the basically the same when talking about expand or collapse.
You might try fixing just this scenario. I'd be happy to have your help. 😄 I'll get you some info in the next day or so.

@brantwedel
Copy link

I see alot of places where people don't expect a { Literal } is expanded to

{
  Literal
}

I think any "Objects" that consist of only Literals should not be broken, this would cover beautification of imports, exports, as well as shorthand objects where the Literal name is expanded, I think in all these situations it is expected to have a single line.

Maybe a config for collapse_literals to turn this on and off.

import { Thing, AnotherThing } from "things";

var { ThingOptions } = require('../options')

var name = "a thing name";

// expanded by some specs to: Thing.setOptions({ name: name });
Thing.setOptions({ name });
Thing.setOptions({
  name: name,
  version: ThingOptions.version
});

exports { Thing };

@hugoduraes
Copy link

@brantwedel 👍

@loopmode
Copy link

loopmode commented Jul 7, 2015

I currently use a naive patch as a workaround until a proper implementation. It works fine for me so far.
primitive, pragmatic.

// in Sublime Text, Preferences -> Browse Packages, find HTML-CSS-JS Prettify/scripts/node_modules/js-beautify/js/lib/beautify.js
// find the last line of the 'beautify' function, and place the next lines just before 'return sweet_code';

// es7 decorators
sweet_code = sweet_code.replace(/@\n/g, '@'); 
sweet_code = sweet_code.replace(/\)@\s/g, ')\n@'); 
sweet_code = sweet_code.replace(/    @    /g, '    @'); 
sweet_code = sweet_code.replace(/@\s/g, '\n@'); 
// destructuring imports
sweet_code = sweet_code.replace(/(import {\n)(\t|\s*)/g, '\import {'); 
sweet_code = sweet_code.replace(/\n}\nfrom\s/g, '} from '); 

https://gist.github.com/loopmode/d091bce3b76efaf15d63

@bitwiseman
Copy link
Member

@brantwedel - Interesting idea.

@loopmode - thanks for the workaround. As you say, primitive and pragmatic. 😄

@iksose
Copy link

iksose commented Aug 10, 2015

@loopmode Great fix, works in atom

@skulptur
Copy link

skulptur commented Oct 7, 2015

the fix works, thanks

@bitwiseman
Copy link
Member

This is sub-case of #511 and #382. Leaving open for reference.

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

No branches or pull requests

8 participants