Skip to content

Commit 987cd63

Browse files
committed
feature(@putout/plugin-convert-quotes-to-backticks) add support of double backslash (xtermjs/xterm.js#3674)
1 parent 2e37fd7 commit 987cd63

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

packages/plugin-convert-quotes-to-backticks/lib/convert-quotes-to-backticks.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const {
1313
module.exports.report = () => `Use backticks instead of quotes`;
1414

1515
module.exports.fix = (path) => {
16-
const value = path.node.value.replace(/\n/g, '\\n');
16+
const value = path.node.value
17+
.replace(/\\/, '\\\\')
18+
.replace(/\n/g, '\\n');
1719

1820
replaceWith(path, TemplateLiteral([
1921
TemplateElement({
@@ -26,7 +28,9 @@ const {replaceWith} = operator;
2628

2729
module.exports.traverse = ({push}) => ({
2830
StringLiteral(path) {
29-
if (path.node.value.includes(`'`))
31+
const {value} = path.node;
32+
33+
if (value.includes(`'`))
3034
push(path);
3135
},
3236
});

packages/plugin-convert-quotes-to-backticks/test/convert-quotes-to-backticks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ test('plugin-convert-quotes-to-backtics: transform: newline', (t) => {
2222
t.end();
2323
});
2424

25+
test('plugin-convert-quotes-to-backtics: transform: backslash', (t) => {
26+
t.transform('backslash');
27+
t.end();
28+
});
29+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`hello'`.replace(/'/, `\\'`);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"hello'".replace(/'/, '\\\'');

0 commit comments

Comments
 (0)