Skip to content

Commit 2ca5ae4

Browse files
committed
fix changeStringReplaceToRegex: handle \n and \t
1 parent 063e7b6 commit 2ca5ae4

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

typescript/src/codeActions/custom/changeStringReplaceToRegex.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export default {
1717
if (!ts.isPropertyAccessExpression(node.parent.expression)) return
1818
if (node.parent.expression.name.text !== 'replace') return
1919
// though it does to much escaping and ideally should be simplified
20-
const edits: ts.TextChange[] = [{ span: nodeToSpan(node), newText: `/${escapeStringRegexp(node.text)}/` }]
20+
const edits: ts.TextChange[] = [
21+
{
22+
span: nodeToSpan(node),
23+
newText: `/${escapeStringRegexp(node.text).replaceAll('\n', '\\n').replaceAll('\t', '\\t').replaceAll('\r', '\\r')}/`,
24+
},
25+
]
2126
return {
2227
edits: [
2328
{

0 commit comments

Comments
 (0)