Skip to content

Commit eeb798d

Browse files
gurgundayJamieMason
authored andcommitted
fix: format static private methods correctly with classPropertiesAllowed: true
Closes #46 Closes #47
1 parent e39d1b0 commit eeb798d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/prefer-arrow-functions.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ const invalidAndHasBlockStatement = [
481481
output: 'class MyClass { render = (a, b) => { console.log(3); }; }',
482482
options: [{ classPropertiesAllowed: true }],
483483
},
484+
{
485+
code: 'class MyClass { #render(a, b) { console.log(3); } }',
486+
output: 'class MyClass { #render = (a, b) => { console.log(3); }; }',
487+
options: [{ classPropertiesAllowed: true }],
488+
},
489+
{
490+
code: 'class MyClass { static #render(a, b) { console.log(3); } }',
491+
output: 'class MyClass { static #render = (a, b) => { console.log(3); }; }',
492+
options: [{ classPropertiesAllowed: true }],
493+
},
484494
{
485495
code: 'class MyClass { static render(a, b) { console.log(3); } }',
486496
output: 'class MyClass { static render = (a, b) => { console.log(3); }; }',

src/prefer-arrow-functions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ export default {
280280
},
281281
':matches(ClassProperty, MethodDefinition, Property)[key.name][value.type="FunctionExpression"][kind!=/^(get|set|constructor)$/]':
282282
(node) => {
283-
const propName = node.key.name;
283+
const propName =
284+
node.key.type === 'PrivateIdentifier'
285+
? `#${node.key.name}`
286+
: node.key.name;
284287
const functionNode = node.value;
285288
const staticModifier = node.static ? 'static ' : '';
286289
if (

0 commit comments

Comments
 (0)