Skip to content

Commit 10df9f8

Browse files
committed
feature: @putout/plugin-apply-shorthand-properties: exclude default
1 parent 5b6a88f commit 10df9f8

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

packages/plugin-apply-shorthand-properties/lib/apply-shorthand-properties.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
const {
1010
isImportSpecifier,
1111
identifier,
12+
isStringLiteral,
1213
} = types;
1314

1415
export const report = () => `Use shorthand properties`;
@@ -38,7 +39,12 @@ export const traverse = ({push, options}) => ({
3839
});
3940
},
4041
'__object'(path) {
41-
for (const propPath of path.get('properties')) {
42+
const properties = path.get('properties');
43+
44+
if (hasDefault(properties))
45+
return;
46+
47+
for (const propPath of properties) {
4248
const {computed, shorthand} = propPath.node;
4349

4450
if (shorthand)
@@ -116,3 +122,12 @@ function getName(path) {
116122

117123
return '';
118124
}
125+
126+
function hasDefault(properties) {
127+
for (const property of properties) {
128+
if (isStringLiteral(property.node.value, {value: 'default'}))
129+
return true;
130+
}
131+
132+
return false;
133+
}

packages/plugin-apply-shorthand-properties/test/apply-shorthand-properties.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ test('plugin-apply-shorthand-properties: no report: spread', (t) => {
114114
t.end();
115115
});
116116

117+
test('plugin-apply-shorthand-properties: no report: default', (t) => {
118+
t.noReport('default');
119+
t.end();
120+
});
121+
117122
testWithRemove('plugin-apply-shorthand-properties: transform with options: assign', (t) => {
118123
t.transformWithOptions('assign', {
119124
rename: true,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const x = {
2+
a: 'a',
3+
b: 'b',
4+
default: 'default'
5+
};

0 commit comments

Comments
 (0)