@putout/plugin-remove-duplicate-keys 3.0.0 → 4.0.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.
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const {types} = require('putout');
3
+ const {types, operator} = require('putout');
4
4
  const fullstore = require('fullstore');
5
+
5
6
  const {
6
7
  isSpreadElement,
7
8
  isIdentifier,
@@ -9,9 +10,21 @@ const {
9
10
  isStringLiteral,
10
11
  } = types;
11
12
 
12
- const isSpreadId = (name) => (a) => isSpreadElement(a) && isIdentifier(a.argument, {name});
13
- const isObjectPropertyId = (name, computed) => (a) => isObjectProperty(a, {computed}) && isIdentifier(a.key, {name});
14
- const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStringLiteral(a.key, {value});
13
+ const {traverseProperties} = operator;
14
+
15
+ const isSpreadId = (name) => (a) => isSpreadElement(a) && isIdentifier(a.argument, {
16
+ name,
17
+ });
18
+
19
+ const isObjectPropertyId = (name, computed) => (a) => isObjectProperty(a, {
20
+ computed,
21
+ }) && isIdentifier(a.key, {
22
+ name,
23
+ });
24
+
25
+ const isObjectPropertyLiteral = (value) => (a) => isObjectProperty(a) && isStringLiteral(a.key, {
26
+ value,
27
+ });
15
28
 
16
29
  const store = fullstore([]);
17
30
 
@@ -27,11 +40,14 @@ module.exports.replace = () => ({
27
40
  });
28
41
 
29
42
  module.exports.match = () => ({
30
- __object: ({__object}) => {
43
+ __object: ({__object}, path) => {
31
44
  let is = false;
32
45
  const newProperties = [];
33
46
  const {properties} = __object;
34
- const reversed = properties.slice().reverse();
47
+
48
+ const reversed = properties
49
+ .slice()
50
+ .reverse();
35
51
 
36
52
  for (const prop of reversed) {
37
53
  if (isSpreadElement(prop) && isIdentifier(prop.argument)) {
@@ -48,16 +64,19 @@ module.exports.match = () => ({
48
64
  const {computed} = prop;
49
65
  const {name} = prop.key;
50
66
 
51
- if (name !== prop.value.name)
52
- continue;
53
-
54
- const isFirst = checkIfFirst(properties, newProperties, isObjectPropertyId, name, {
55
- computed,
67
+ const props = traverseProperties(path, name, {
68
+ firstLevel: true,
56
69
  });
57
70
 
58
- if (!isFirst) {
59
- is = true;
60
- continue;
71
+ if (props.length > 1) {
72
+ const isFirst = checkIfFirst(properties, newProperties, isObjectPropertyId, name, {
73
+ computed,
74
+ });
75
+
76
+ if (!isFirst) {
77
+ is = true;
78
+ continue;
79
+ }
61
80
  }
62
81
  }
63
82
 
@@ -87,4 +106,3 @@ function checkIfFirst(properties, newProperties, isFn, str, {computed} = {}) {
87
106
 
88
107
  return !newLength || oldLength <= 1;
89
108
  }
90
-
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-duplicate-keys",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
- "description": "putout plugin adds ability to find and remove duplicate keys",
6
+ "description": "🐊Putout plugin adds ability to find and remove duplicate keys",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-duplicate-keys#readme",
8
8
  "main": "lib/remove-duplicate-keys.js",
9
9
  "release": false,
@@ -35,21 +35,21 @@
35
35
  "key"
36
36
  ],
37
37
  "devDependencies": {
38
- "@putout/test": "^5.0.0",
39
- "c8": "^7.5.0",
38
+ "@putout/test": "^8.0.0",
39
+ "c8": "^8.0.0",
40
40
  "eslint": "^8.0.1",
41
- "eslint-plugin-node": "^11.0.0",
42
- "eslint-plugin-putout": "^14.0.0",
43
- "lerna": "^4.0.0",
44
- "madrun": "^9.0.0",
45
- "nodemon": "^2.0.1"
41
+ "eslint-plugin-n": "^16.0.0",
42
+ "eslint-plugin-putout": "^22.0.0",
43
+ "lerna": "^6.0.1",
44
+ "madrun": "^10.0.0",
45
+ "nodemon": "^3.0.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "putout": ">=25"
48
+ "putout": ">=34"
49
49
  },
50
50
  "license": "MIT",
51
51
  "engines": {
52
- "node": ">=16"
52
+ "node": ">=18"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"