Skip to content

Commit f5ebcf9

Browse files
committed
feature: @putout/plugin-convert-quotes-to-backticks: check key
1 parent 63364fc commit f5ebcf9

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ module.exports.fix = (path) => {
1616
.replaceAll('\\', '\\\\')
1717
.replaceAll('\n', '\\n');
1818

19-
if (path.parentPath.isObjectProperty())
20-
path.parentPath.node.computed = true;
19+
const {parentPath} = path;
20+
21+
if (parentPath.isObjectProperty() && path === parentPath.get('key'))
22+
parentPath.node.computed = true;
2123

2224
replaceWith(path, TemplateLiteral([TemplateElement({
2325
raw: value,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export const replace = () => ({
22
[`''`]: '"")',
33
});
4+
5+
encode(value, {
6+
encodeQuote: `'`,
7+
});

packages/plugin-convert-quotes-to-backticks/test/fixture/object-key.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ export const replace = () => ({
22
'\'\'': '"")',
33
});
44

5+
encode(value, {
6+
encodeQuote: '\''
7+
});
8+

0 commit comments

Comments
 (0)