Skip to content
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

Using cut with carriage returns #30

Closed
pomber opened this issue Mar 22, 2024 · 1 comment · Fixed by #31
Closed

Using cut with carriage returns #30

pomber opened this issue Mar 22, 2024 · 1 comment · Fixed by #31

Comments

@pomber
Copy link
Contributor

pomber commented Mar 22, 2024

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
Copy link
Member

antfu commented Mar 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants