Skip to content

prefer-string-replace-all: Preserve escape #2667

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

Merged

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Jun 3, 2025

Fix #2666

I'm not confident with the current code, hope it won't break anything.

@fisker fisker force-pushed the prefer-string-replace-all-escape branch from cbd71c2 to c075ff7 Compare June 3, 2025 13:50
Comment on lines 44 to 58
if (kind === 'controlLetter' || kind === 'hexadecimalEscape') {
if (codePoint === 13) {
return String.raw`\r`;
}

if (codePoint === 10) {
return String.raw`\n`;
}

if (codePoint === 9) {
return String.raw`\t`;
}

return `\\u{${codePoint.toString(16)}}`;
}
Copy link
Collaborator Author

@fisker fisker Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rewrites \cX to \u{XX}, but except \r \n \t.

@fisker fisker marked this pull request as ready for review June 3, 2025 14:29
@sindresorhus sindresorhus merged commit 2310b50 into sindresorhus:main Jun 4, 2025
19 checks passed
@fisker fisker deleted the prefer-string-replace-all-escape branch June 4, 2025 11:56
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 this pull request may close these issues.

prefer-string-replace-all: preserve escape
2 participants