Skip to content

Commit

Permalink
Ignore private class properties (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed May 3, 2019
1 parent 2fd59a6 commit a0824f0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/utils/__tests__/getClassMemberValuePath-test.js
Expand Up @@ -94,4 +94,29 @@ describe('getClassMemberValuePath', () => {
);
});
});

describe('PrivateClassProperty', () => {
it('ignores private class properties', () => {
const def = statement(`
class Foo {
#foo = 42;
}
`);

expect(getClassMemberValuePath(def, 'foo')).toBe(undefined);
});

it('finds "normal" class properties with private present', () => {
const def = statement(`
class Foo {
#private = 54;
foo = 42;
}
`);

expect(getClassMemberValuePath(def, 'foo')).toBe(
def.get('body', 'body', 1, 'value'),
);
});
});
});
1 change: 1 addition & 0 deletions src/utils/getClassMemberValuePath.js
Expand Up @@ -30,6 +30,7 @@ export default function getClassMemberValuePath(
memberPath =>
(!memberPath.node.computed ||
types.Literal.check(memberPath.node.key)) &&
!types.PrivateName.check(memberPath.node.key) &&
getNameOrValue(memberPath.get('key')) === memberName &&
memberPath.node.kind !== 'set',
)
Expand Down

0 comments on commit a0824f0

Please sign in to comment.