( oldString: string, actualOldString: string, newString: string, )
| 102 | * otherwise it's a closing quote. |
| 103 | */ |
| 104 | export function preserveQuoteStyle( |
| 105 | oldString: string, |
| 106 | actualOldString: string, |
| 107 | newString: string, |
| 108 | ): string { |
| 109 | // If they're the same, no normalization happened |
| 110 | if (oldString === actualOldString) { |
| 111 | return newString |
| 112 | } |
| 113 | |
| 114 | // Detect which curly quote types were in the file |
| 115 | const hasDoubleQuotes = |
| 116 | actualOldString.includes(LEFT_DOUBLE_CURLY_QUOTE) || |
| 117 | actualOldString.includes(RIGHT_DOUBLE_CURLY_QUOTE) |
| 118 | const hasSingleQuotes = |
| 119 | actualOldString.includes(LEFT_SINGLE_CURLY_QUOTE) || |
| 120 | actualOldString.includes(RIGHT_SINGLE_CURLY_QUOTE) |
| 121 | |
| 122 | if (!hasDoubleQuotes && !hasSingleQuotes) { |
| 123 | return newString |
| 124 | } |
| 125 | |
| 126 | let result = newString |
| 127 | |
| 128 | if (hasDoubleQuotes) { |
| 129 | result = applyCurlyDoubleQuotes(result) |
| 130 | } |
| 131 | if (hasSingleQuotes) { |
| 132 | result = applyCurlySingleQuotes(result) |
| 133 | } |
| 134 | |
| 135 | return result |
| 136 | } |
| 137 | |
| 138 | function isOpeningContext(chars: string[], index: number): boolean { |
| 139 | if (index === 0) { |
no test coverage detected