Skip to content

Commit

Permalink
chore(xxx) xx
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed May 25, 2020
1 parent fca37d2 commit 4d6634e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions packages/plugin-remove-duplicate-keys/lib/remove-duplicate-keys.js
Expand Up @@ -29,17 +29,20 @@ module.exports.report = () => 'Duplicate keys should be avoided';

module.exports.match = () => ({
__object: ({__object}) => {
let is = false;
const newProps = [];
const {properties} = __object;

for (const prop of properties.reverse()) {
for (const prop of properties.slice().reverse()) {
if (isSpreadElement(prop) && isIdentifier(prop.argument)) {
const {name} = prop.argument;
const {length} = properties.filter(isSpreadId(name));
const newLength = newProps.filter(isSpreadId(name)).length;

if (newLength && length > 1)
if (newLength && length > 1) {
is = true;
continue;
}
}

if (isObjectProperty(prop) && isIdentifier(prop.key)) {
Expand All @@ -48,25 +51,29 @@ module.exports.match = () => ({
const {length} = properties.filter(isObjectPropertyId(name, computed));
const newLength = newProps.filter(isObjectPropertyId(name, computed)).length;

if (newLength && length > 1)
if (newLength && length > 1) {
is = true;
continue;
}
}

if (isObjectProperty(prop) && isStringLiteral(prop.key)) {
const {value} = prop.key;
const {length} = properties.filter(isObjectPropertyLiteral(value));
const newLength = newProps.filter(isObjectPropertyLiteral(value)).length;

if (newLength && length > 1)
if (newLength && length > 1) {
is = true;
continue;
}
}

newProps.unshift(prop);
}

store(newProps);

return true;
return is;
},
});

Expand Down
@@ -1,4 +1,4 @@
fn({
...b,
a,
a
});

0 comments on commit 4d6634e

Please sign in to comment.