Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a0824f0

Browse files
committedMay 3, 2019
Ignore private class properties (#347)
1 parent 2fd59a6 commit a0824f0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎src/utils/__tests__/getClassMemberValuePath-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,29 @@ describe('getClassMemberValuePath', () => {
9494
);
9595
});
9696
});
97+
98+
describe('PrivateClassProperty', () => {
99+
it('ignores private class properties', () => {
100+
const def = statement(`
101+
class Foo {
102+
#foo = 42;
103+
}
104+
`);
105+
106+
expect(getClassMemberValuePath(def, 'foo')).toBe(undefined);
107+
});
108+
109+
it('finds "normal" class properties with private present', () => {
110+
const def = statement(`
111+
class Foo {
112+
#private = 54;
113+
foo = 42;
114+
}
115+
`);
116+
117+
expect(getClassMemberValuePath(def, 'foo')).toBe(
118+
def.get('body', 'body', 1, 'value'),
119+
);
120+
});
121+
});
97122
});

‎src/utils/getClassMemberValuePath.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default function getClassMemberValuePath(
3030
memberPath =>
3131
(!memberPath.node.computed ||
3232
types.Literal.check(memberPath.node.key)) &&
33+
!types.PrivateName.check(memberPath.node.key) &&
3334
getNameOrValue(memberPath.get('key')) === memberName &&
3435
memberPath.node.kind !== 'set',
3536
)

0 commit comments

Comments
 (0)
Please sign in to comment.