Repository: TypeScript
Issue: Code Format with object spread in JavaScript files breaks
Labels: Bug,VS Code Tracked

_From @oshalygin on November 4, 2016 17:20_

- VSCode Version:
*1.7.1*
- OS Version:
*OSX 10.12.1
Steps to Reproduce:

_userReducer.spec.js_
```javascript
import {
    expect
} from "chai";
import * as actionTypes from "../actions/actionTypes";
import reducer from "./userReducer";


describe("Reducer::User", () => {
    const getInitialState = () => {
        return {};
    };
    const retrievedResponse = {
        data: {
            username: "testUser",
            firstName: "Foo",
            lastName: "Bar",
            customData: {
                permissions: {
                    inventory: true
                }
            }
        }
    };

    it("should retrieve the initial state if the action type is not registered with the reducer", () => {
        const action = {
            type: "UNKNOWN"
        };

        const expected = getInitialState();
        const actual = reducer(undefined, action); //eslint-disable-line no-undefined

        expect(actual).to.deep.equal(expected);
    });

    it("should retrieve the customData and persist it to the user object", () => {

        const action = {
            type: actionTypes.USER_SET,
            options: retrievedResponse
        };

        const user = reducer(undefined, action); //eslint-disable-line no-undefined
        const actual = user.permissions;

        expect(actual).to.exist; //eslint-disable-line no-unused-expressions

    });

    it("should replace the current state of the user object when USER_SET is dispatched", () => {
        const previousState = {
            permissions: {
                inventory: false
            }
        };

        const futureUserState = {...retrievedResponse,
        permissions: { inventory: true } };

        const action = {
            type: actionTypes.USER_SET,
            options: futureUserState
        };

        const expected = futureUserState.permissions.inventory;

        const user = reducer(previousState, action);
        const actual = user.permissions.inventory;

        expect(actual).to.equal(expected);

            });

        it("should return an empty user object if the data is null", () => {

            const futureUserState = {
                data: null
            };

            const action = {
                type: actionTypes.USER_SET,
                options: futureUserState
            };
            const expected = getInitialState();
            const actual = reducer(undefined, action); //eslint-disable-line no-undefined

            expect(actual).to.deep.equal(expected);

        });

    });
```

Thats what it looks like unformatted.  If I hit the auto format the code will look like this:
```javascript
import {
    expect
} from "chai";
import * as actionTypes from "../actions/actionTypes";
import reducer from "./userReducer";


describe("Reducer::User", () => {
    const getInitialState = () => {
        return {};
    };
    const retrievedResponse = {
        data: {
            username: "testUser",
            firstName: "Foo",
            lastName: "Bar",
            customData: {
                permissions: {
                    inventory: true
                }
            }
        }
    };

    it("should retrieve the initial state if the action type is not registered with the reducer", () => {
        const action = {
            type: "UNKNOWN"
        };

        const expected = getInitialState();
        const actual = reducer(undefined, action); //eslint-disable-line no-undefined

        expect(actual).to.deep.equal(expected);
    });

    it("should retrieve the customData and persist it to the user object", () => {

        const action = {
            type: actionTypes.USER_SET,
            options: retrievedResponse
        };

        const user = reducer(undefined, action); //eslint-disable-line no-undefined
        const actual = user.permissions;

        expect(actual).to.exist; //eslint-disable-line no-unused-expressions

    });

    it("should replace the current state of the user object when USER_SET is dispatched", () => {
        const previousState = {
            permissions: {
                inventory: false
            }
        };

        const futureUserState = {...retrievedResponse,
        permissions: { inventory: true } };

const action = {
    type: actionTypes.USER_SET,
    options: futureUserState
};

const expected = futureUserState.permissions.inventory;

const user = reducer(previousState, action);
const actual = user.permissions.inventory;

expect(actual).to.equal(expected);

            });

it("should return an empty user object if the data is null", () => {

    const futureUserState = {
        data: null
    };

    const action = {
        type: actionTypes.USER_SET,
        options: futureUserState
    };
    const expected = getInitialState();
    const actual = reducer(undefined, action); //eslint-disable-line no-undefined

    expect(actual).to.deep.equal(expected);

});

    });
```

Notice that after the object spread is used, everything goes sideways
```javascript
        const futureUserState = {...retrievedResponse,
        permissions: { inventory: true } };
```

TS Version
**2.1.0-dev.20161103**

Trace:
```
[Trace - 10:17:56 AM] Sending request: format (1249). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "/Users/admin/dev/myProject/client/reducers/userReducer.spec.js",
    "line": 1,
    "offset": 1,
    "endLine": 91,
    "endOffset": 8
}
[Trace - 10:17:56 AM] Response received: format (1249). Request took 5 ms. Success: true 
Result: [
    {
        "start": {
            "line": 60,
            "offset": 1
        },
        "end": {
            "line": 60,
            "offset": 9
        },
        "newText": ""
    },
    {
        "start": {
            "line": 61,
            "offset": 1
        },
        "end": {
            "line": 61,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 62,
            "offset": 1
        },
        "end": {
            "line": 62,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 63,
            "offset": 1
        },
        "end": {
            "line": 63,
            "offset": 9
        },
        "newText": ""
    },
    {
        "start": {
            "line": 65,
            "offset": 1
        },
        "end": {
            "line": 65,
            "offset": 9
        },
        "newText": ""
    },
    {
        "start": {
            "line": 67,
            "offset": 1
        },
        "end": {
            "line": 67,
            "offset": 9
        },
        "newText": ""
    },
    {
        "start": {
            "line": 68,
            "offset": 1
        },
        "end": {
            "line": 68,
            "offset": 9
        },
        "newText": ""
    },
    {
        "start": {
            "line": 70,
            "offset": 1
        },
        "end": {
            "line": 70,
            "offset": 9
        },
        "newText": ""
    },
    {
        "start": {
            "line": 74,
            "offset": 1
        },
        "end": {
            "line": 74,
            "offset": 9
        },
        "newText": ""
    },
    {
        "start": {
            "line": 76,
            "offset": 1
        },
        "end": {
            "line": 76,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 77,
            "offset": 1
        },
        "end": {
            "line": 77,
            "offset": 17
        },
        "newText": "        "
    },
    {
        "start": {
            "line": 78,
            "offset": 1
        },
        "end": {
            "line": 78,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 80,
            "offset": 1
        },
        "end": {
            "line": 80,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 81,
            "offset": 1
        },
        "end": {
            "line": 81,
            "offset": 17
        },
        "newText": "        "
    },
    {
        "start": {
            "line": 82,
            "offset": 1
        },
        "end": {
            "line": 82,
            "offset": 17
        },
        "newText": "        "
    },
    {
        "start": {
            "line": 83,
            "offset": 1
        },
        "end": {
            "line": 83,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 84,
            "offset": 1
        },
        "end": {
            "line": 84,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 85,
            "offset": 1
        },
        "end": {
            "line": 85,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 87,
            "offset": 1
        },
        "end": {
            "line": 87,
            "offset": 13
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 89,
            "offset": 1
        },
        "end": {
            "line": 89,
            "offset": 9
        },
        "newText": ""
    }
]
[Trace - 10:17:56 AM] Sending request: change (1250). Response expected: no. Current queue length: 0
Arguments: {
    "file": "/Users/admin/dev/myproject/client/reducers/userReducer.spec.js",
    "line": 89,
    "offset": 1,
    "endLine": 89,
    "endOffset": 9,
    "insertString": ""
}
[Trace - 10:17:56 AM] Sending request: change (1251). Response expected: no. Current queue length: 0
Arguments: {
    "file": "/Users/admin/dev/myproject/client/reducers/userReducer.spec.js",
    "line": 87,
    "offset": 5,
    "endLine": 87,
    "endOffset": 13,
    "insertString": ""
}
[Trace - 10:17:56 AM] Sending request: change (1252). Response expected: no. Current queue length: 0
Arguments: {
    "file": "/Users/admin/dev/myproject/client/reducers/userReducer.spec.js",
    "line": 85,
    "offset": 5,
    "endLine": 85,
    "endOffset": 13,
    "insertString": ""
}
[Trace - 10:17:56 AM] Sending request: change (1253). Response expected: no. Current queue length: 0
Arguments: {
    "file": "/Users/admin/dev/myproject/client/reducers/userReducer.spec.js",
    "line": 84,
    "offset": 5,
    "endLine": 84,
    "endOffset": 13,
    "insertString": ""
}
[Trace - 10:17:56 AM] Sending request: change (1254). Response expected: no. Current queue length: 0
Arguments: {
    "file": "/Users/admin/dev/myproject/client/reducers/userReducer.spec.js",
    "line": 83,
    "offset": 5,
    "endLine": 83,
    "endOffset": 13,
    "insertString": ""
}
[Trace - 10:17:56 AM] Sending request: change (1255). Response expected: no. Current queue length: 0
Arguments: {
    "file": "/Users/admin/dev/myproject/client/reducers/userReducer.spec.js",
    "line": 82,
    "offset": 9,
    "endLine": 82,
    "endOffset": 17,
    "insertString": ""
}
```

_Copied from original issue: Microsoft/vscode#15006_