Skip to content

Commit

Permalink
Fix ES2015 exports not counting an object as used (#217)
Browse files Browse the repository at this point in the history
Fixes #215
  • Loading branch information
futpib authored and sindresorhus committed Jan 26, 2019
1 parent 626af2b commit 6d5bb10
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rules/no-unused-properties.js
Expand Up @@ -123,12 +123,20 @@ const create = context => {

const nextReferences = references
.map(reference => {
const {parent} = reference.identifier;

if (reference.init) {
if (
parent.type === 'VariableDeclarator' &&
parent.parent.type === 'VariableDeclaration' &&
parent.parent.parent.type === 'ExportNamedDeclaration'
) {
return {identifier: parent};
}

return null;
}

const {parent} = reference.identifier;

if (parent.type === 'MemberExpression') {
if (
isMemberExpressionAssignment(parent) ||
Expand Down
9 changes: 9 additions & 0 deletions test/no-unused-properties.js
Expand Up @@ -280,6 +280,15 @@ var foo = {
};
export {foo};
`,

`
export const foo = {
a: 1,
b: 2
};
console.log(foo.a);
`,

`
var foo = {
a: 1
Expand Down

0 comments on commit 6d5bb10

Please sign in to comment.