From 04ae9a9fd3bc514b537402cce62e1c5c31cf57c2 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Wed, 17 Apr 2019 12:29:50 -0700 Subject: [PATCH] Ignore private class properties --- .../__tests__/getClassMemberValuePath-test.js | 25 +++++++++++++++++++ src/utils/getClassMemberValuePath.js | 1 + 2 files changed, 26 insertions(+) diff --git a/src/utils/__tests__/getClassMemberValuePath-test.js b/src/utils/__tests__/getClassMemberValuePath-test.js index 703ab665302..3baa9c80e32 100644 --- a/src/utils/__tests__/getClassMemberValuePath-test.js +++ b/src/utils/__tests__/getClassMemberValuePath-test.js @@ -92,4 +92,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 303e8d70577..6e8275acac8 100644 --- a/src/utils/getClassMemberValuePath.js +++ b/src/utils/getClassMemberValuePath.js @@ -27,6 +27,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', )