@putout/plugin-remove-duplicate-keys 4.1.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,12 +6,16 @@ const fullstore = require('fullstore');
6
6
  const {
7
7
  isSpreadElement,
8
8
  isIdentifier,
9
+ isMemberExpression,
9
10
  isObjectProperty,
10
11
  isObjectPattern,
11
12
  isStringLiteral,
12
13
  } = types;
13
14
 
14
- const {traverseProperties} = operator;
15
+ const {
16
+ traverseProperties,
17
+ extract,
18
+ } = operator;
15
19
 
16
20
  const isSpreadId = (name) => (a) => isSpreadElement(a) && isIdentifier(a.argument, {
17
21
  name,
@@ -23,6 +27,10 @@ const isObjectPropertyId = (name, computed) => (a) => isObjectProperty(a, {
23
27
  name,
24
28
  });
25
29
 
30
+ const isMemberExpressionId = (name, computed) => (a) => isObjectProperty(a, {
31
+ computed,
32
+ }) && name === extract(a.key);
33
+
26
34
  const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStringLiteral(a.key, {
27
35
  value,
28
36
  });
@@ -94,6 +102,26 @@ module.exports.match = () => ({
94
102
  }
95
103
  }
96
104
 
105
+ if (isObjectProperty(prop) && isMemberExpression(prop.key)) {
106
+ const {computed} = prop;
107
+ const name = extract(prop.key);
108
+
109
+ const props = traverseProperties(path, name, {
110
+ firstLevel: true,
111
+ });
112
+
113
+ if (props.length > 1) {
114
+ const isFirst = checkIfFirst(properties, newProperties, isMemberExpressionId, name, {
115
+ computed,
116
+ });
117
+
118
+ if (!isFirst) {
119
+ is = true;
120
+ continue;
121
+ }
122
+ }
123
+ }
124
+
97
125
  newProperties.unshift(prop);
98
126
  }
99
127
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-duplicate-keys",
3
- "version": "4.1.0",
3
+ "version": "5.1.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to find and remove duplicate keys",
@@ -35,17 +35,17 @@
35
35
  "key"
36
36
  ],
37
37
  "devDependencies": {
38
- "@putout/test": "^8.0.0",
39
- "c8": "^8.0.0",
40
- "eslint": "^8.0.1",
41
- "eslint-plugin-n": "^16.0.0",
38
+ "@putout/test": "^9.0.0",
39
+ "c8": "^9.0.0",
40
+ "eslint": "^9.0.0-alpha.0",
41
+ "eslint-plugin-n": "^17.0.0-0",
42
42
  "eslint-plugin-putout": "^22.0.0",
43
43
  "lerna": "^6.0.1",
44
44
  "madrun": "^10.0.0",
45
45
  "nodemon": "^3.0.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "putout": ">=34"
48
+ "putout": ">=35"
49
49
  },
50
50
  "license": "MIT",
51
51
  "engines": {