Skip to content

Commit f0a3c06

Browse files
authored
Ignore private class properties (#347)
1 parent 5582f91 commit f0a3c06

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
@@ -92,4 +92,29 @@ describe('getClassMemberValuePath', () => {
9292
);
9393
});
9494
});
95+
96+
describe('PrivateClassProperty', () => {
97+
it('ignores private class properties', () => {
98+
const def = statement(`
99+
class Foo {
100+
#foo = 42;
101+
}
102+
`);
103+
104+
expect(getClassMemberValuePath(def, 'foo')).toBe(undefined);
105+
});
106+
107+
it('finds "normal" class properties with private present', () => {
108+
const def = statement(`
109+
class Foo {
110+
#private = 54;
111+
foo = 42;
112+
}
113+
`);
114+
115+
expect(getClassMemberValuePath(def, 'foo')).toBe(
116+
def.get('body', 'body', 1, 'value'),
117+
);
118+
});
119+
});
95120
});

src/utils/getClassMemberValuePath.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function getClassMemberValuePath(
2727
memberPath =>
2828
(!memberPath.node.computed ||
2929
types.Literal.check(memberPath.node.key)) &&
30+
!types.PrivateName.check(memberPath.node.key) &&
3031
getNameOrValue(memberPath.get('key')) === memberName &&
3132
memberPath.node.kind !== 'set',
3233
)

0 commit comments

Comments
 (0)