Merge pull request #2116 from spicyj/nl-jsx-spread

Add newline before JSX spread when appropriate
This commit is contained in:
Paul O’Shannessy
2014-09-05 14:34:54 -07:00
2 changed files with 18 additions and 4 deletions
+14 -1
View File
@@ -379,12 +379,25 @@ describe('react jsx', function() {
'<Component { ... x } y\n' +
'={2 } z />';
var result =
'React.createElement(Component, Object.assign({}, x , {y: \n' +
'React.createElement(Component, Object.assign({}, x , {y: \n' +
'2, z: true}))';
expect(transform(code).code).toBe(result);
});
it('adds appropriate newlines when using spread attribute', function() {
var code =
'<Component\n' +
' {...this.props}\n' +
' sound="moo" />';
var result =
'React.createElement(Component, Object.assign({}, \n' +
' this.props, \n' +
' {sound: "moo"}))';
expect(transform(code).code).toBe(result);
});
it('should transform known hyphenated tags', function() {
var code = [
'/**',
+4 -3
View File
@@ -142,16 +142,17 @@ function visitReactTag(traverse, object, path, state) {
var isLast = index === attributesObject.length - 1;
if (attr.type === Syntax.XJSSpreadAttribute) {
// Plus 1 to skip `{`.
utils.move(attr.range[0] + 1, state);
// Close the previous object or initial object
if (!previousWasSpread) {
utils.append('}, ', state);
}
// Move to the expression start, ignoring everything except parenthesis
// and whitespace.
utils.catchup(attr.range[0], state, stripNonWhiteParen);
// Plus 1 to skip `{`.
utils.move(attr.range[0] + 1, state);
utils.catchup(attr.argument.range[0], state, stripNonWhiteParen);
traverse(attr.argument, path, state);