Skip to content

Overlapping formatting edits returned for jsx #30898

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

Closed
mjbvz opened this issue Apr 12, 2019 · 2 comments
Closed

Overlapping formatting edits returned for jsx #30898

mjbvz opened this issue Apr 12, 2019 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Apr 12, 2019

TypeScript Version: 3.5.0-dev.20190412

Search Terms:

Code
Run format on the following js (note that the whitespace is significant):

const a = (
    <div
>x
        
    </div>
)

Bug
The returned response contains overlapping edits:

[Trace  - 2:02:46 PM] Response received: format (16). Request took 3 ms. Success: true 
Result: [
    {
        "start": {
            "line": 3,
            "offset": 1
        },
        "end": {
            "line": 3,
            "offset": 1
        },
        "newText": "    "
    },
    {
        "start": {
            "line": 4,
            "offset": 1
        },
        "end": {
            "line": 4,
            "offset": 8
        },
        "newText": "               "
    },
    {
        "start": {
            "line": 4,
            "offset": 1
        },
        "end": {
            "line": 4,
            "offset": 9
        },
        "newText": ""
    }
]

Playground Link:

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 12, 2019
@orta orta added the Rescheduled This issue was previously scheduled to an earlier milestone label May 12, 2020
@orta orta modified the milestones: TypeScript 3.9.1, TypeScript 4.0 May 12, 2020
@orta
Copy link
Contributor

orta commented Jul 13, 2020

It looks like we have always shipped overlapping edits in the formatter: #6666

When we consume edits ourselves in tests, we assume the order is important and edit the TextChanges to take into account the overlapping edits, which it seems is left to a client to do (at this point, I'd assume that clients all have the same system)

Because we consume in our tests this way, we have no idea how many places there are overlapping edits and so fixing it locally isn't really a good idea.

The right solution for this is to have a merging pass before we pass out the TextChanges to clients.

@RyanCavanaugh RyanCavanaugh removed this from the TypeScript 4.1.0 milestone Dec 11, 2020
@mjbvz
Copy link
Contributor Author

mjbvz commented Nov 16, 2021

Just tested using the example and it looks like this no longer happens with 4.5-rc

@mjbvz mjbvz closed this as completed Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

5 participants