Skip to content

Commit ea7d203

Browse files
satya164danez
andcommitted
feat(typescript): skip private methods (#409)
Co-authored-by: Daniel Tschinder <[email protected]>
1 parent e960d8c commit ea7d203

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

src/__tests__/__snapshots__/main-test.js.snap

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,26 @@ Object {
13981398
"description": "This is a method",
13991399
"docblock": "This is a method",
14001400
"modifiers": Array [],
1401-
"name": "method",
1401+
"name": "foo",
1402+
"params": Array [
1403+
Object {
1404+
"name": "a",
1405+
"type": Object {
1406+
"name": "string",
1407+
},
1408+
},
1409+
],
1410+
"returns": Object {
1411+
"type": Object {
1412+
"name": "string",
1413+
},
1414+
},
1415+
},
1416+
Object {
1417+
"description": "This is a public method",
1418+
"docblock": "This is a public method",
1419+
"modifiers": Array [],
1420+
"name": "bar",
14021421
"params": Array [
14031422
Object {
14041423
"name": "a",

src/__tests__/fixtures/component_27.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ export default class TSComponent extends Component<Props> {
2323
/**
2424
* This is a method
2525
*/
26-
method(a: string): string {
26+
foo(a: string): string {
27+
return a;
28+
}
29+
30+
/**
31+
* This is a public method
32+
*/
33+
public bar(a: string): string {
34+
return a;
35+
}
36+
37+
/**
38+
* This is a private method
39+
*/
40+
private baz(a: string): string {
2741
return a;
2842
}
2943
}

src/utils/__tests__/__snapshots__/getMethodDocumentation-test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ Object {
1111
`;
1212

1313
exports[`getMethodDocumentation name ignores complex computed method name 1`] = `null`;
14+
15+
exports[`getMethodDocumentation parameters private ignores private typescript methods 1`] = `null`;

src/utils/__tests__/getMethodDocumentation-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,33 @@ describe('getMethodDocumentation', () => {
202202
);
203203
});
204204
});
205+
206+
describe('private', () => {
207+
it('ignores private typescript methods', () => {
208+
const def = statement(
209+
`
210+
class Foo {
211+
private foo() {}
212+
}
213+
`,
214+
{ parserOptions: { plugins: ['typescript'] } },
215+
);
216+
const method = def.get('body', 'body', 0);
217+
expect(getMethodDocumentation(method)).toMatchSnapshot();
218+
});
219+
220+
it.skip('ignores private methods', () => {
221+
const def = statement(
222+
`
223+
class Foo {
224+
#foo() {}
225+
}
226+
`,
227+
{ parserOptions: { plugins: ['classPrivateMethods'] } },
228+
);
229+
const method = def.get('body', 'body', 0);
230+
expect(getMethodDocumentation(method)).toMatchSnapshot();
231+
});
232+
});
205233
});
206234
});

src/utils/getMethodDocumentation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ function getMethodModifiers(methodPath) {
107107
export default function getMethodDocumentation(
108108
methodPath: NodePath,
109109
): ?MethodDocumentation {
110+
if (methodPath.node.accessibility === 'private') {
111+
return null;
112+
}
113+
110114
const name = getPropertyName(methodPath);
111115
if (!name) return null;
112116

0 commit comments

Comments
 (0)