Skip to content

Commit 72db8d0

Browse files
committed
Cleanup code and comments
1 parent aa73543 commit 72db8d0

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,25 +520,25 @@ function sortStringLiteral(
520520
let originalRawContent = raw.slice(1, -1)
521521
let originalValue = node.extra?.rawValue ?? node.value
522522

523-
// If the original had escaping, apply the same escaping pattern to the result
524-
let newRawContent = result
525-
526523
if (node.extra) {
524+
// The original list has ecapes so we ensure that the sorted list also
525+
// maintains those by replacing backslashes from escape sequences.
526+
//
527+
// It seems that TypeScript-based ASTs don't need this special handling
528+
// which is why this is guarded inside the `node.extra` check
527529
if (originalRawContent !== originalValue && originalValue.includes('\\')) {
528-
// The original was escaped, so we need to escape the result in the same way
529-
// But only escape backslashes that are followed by characters that form escape sequences
530-
newRawContent = result.replace(ESCAPE_SEQUENCE_PATTERN, '\\\\$1')
530+
result = result.replace(ESCAPE_SEQUENCE_PATTERN, '\\\\$1')
531531
}
532532

533533
// JavaScript (StringLiteral)
534534
node.extra = {
535535
...node.extra,
536536
rawValue: result,
537-
raw: quote + newRawContent + quote,
537+
raw: quote + result + quote,
538538
}
539539
} else {
540540
// TypeScript (Literal)
541-
node.raw = quote + newRawContent + quote
541+
node.raw = quote + result + quote
542542
}
543543

544544
return true

0 commit comments

Comments
 (0)