mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #2116 from spicyj/nl-jsx-spread
Add newline before JSX spread when appropriate
This commit is contained in:
+14
-1
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user