diff --git a/src/utils/__tests__/getClassMemberValuePath-test.js b/src/utils/__tests__/getClassMemberValuePath-test.js index 535315ef937..6a1b154a4ef 100644 --- a/src/utils/__tests__/getClassMemberValuePath-test.js +++ b/src/utils/__tests__/getClassMemberValuePath-test.js @@ -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'), + ); + }); + }); }); diff --git a/src/utils/getClassMemberValuePath.js b/src/utils/getClassMemberValuePath.js index 1257bc9f986..9aa74bb1bfe 100644 --- a/src/utils/getClassMemberValuePath.js +++ b/src/utils/getClassMemberValuePath.js @@ -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', )