twoslashes / twoslash

Markup for generating rich type information in your documentations ahead of time.
https://twoslash.netlify.app/
MIT License
506 stars 17 forks source link

Using `cut` with carriage returns #30

Closed pomber closed 6 months ago

pomber commented 6 months ago

Repro: https://stackblitz.com/~/edit/stackblitz-starters-9jr2ud

These two strings return different results:

function test(code) {
    const result = twoslasher(code)
    console.log("input code", JSON.stringify(code))
    console.log("output code", JSON.stringify(result.code))
    console.log("hover", result.hovers[0])
}

test("const a = 1\n// ---cut---\nconst b = 2")
test("const a = 1\r\n// ---cut---\r\nconst b = 2")
input code "const a = 1\n// ---cut---\nconst b = 2"
output code "const b = 2"
hover { line: 0, ... }

input code "const a = 1\r\n// ---cut---\r\nconst b = 2"
output code "\nconst b = 2"
hover { line: 1, ...}

I think the result should be the same for both cases. If you agree I can send a PR with a test and a fix.

antfu commented 6 months ago

Yeah it should be consider a bug - pr would be great, thank you!