Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 9789111

Browse files
AnshulMalikjasonLaster
authored andcommitted
Exclude flow annotations from symbol identifiers (#5486)
1 parent 3be6a54 commit 9789111

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/workers/parser/getSymbols.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,11 @@ function extractSymbol(path: SimplePath, symbols) {
216216
}
217217
}
218218

219-
if (t.isIdentifier(path)) {
219+
if (t.isIdentifier(path) && !t.isGenericTypeAnnotation(path.parent)) {
220220
let { start, end } = path.node.loc;
221221

222-
if (t.isClassMethod(path.parent)) {
222+
// We want to include function params, but exclude the function name
223+
if (t.isClassMethod(path.parent) && !path.inList) {
223224
return;
224225
}
225226

@@ -255,7 +256,6 @@ function extractSymbol(path: SimplePath, symbols) {
255256
if (t.isArrayPattern(node)) {
256257
return;
257258
}
258-
259259
symbols.identifiers.push({
260260
name: node.name,
261261
expression: node.name,

src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ identifiers:
7070
[(23, 6), (23, 11)] Ultra Ultra
7171
[(25, 4), (25, 8)] [(25, 4), (25, 8)] this this
7272
[(25, 9), (25, 16)] awesome awesome
73+
[(28, 12), (28, 18)] person person
7374
[(29, 4), (29, 11)] console console
7475
[(29, 12), (29, 15)] log log
7576
[(29, 19), (29, 25)] person person
@@ -159,6 +160,7 @@ identifiers:
159160
[(1, 6), (1, 10)] Test Test
160161
[(3, 4), (3, 8)] [(3, 4), (3, 8)] this this
161162
[(3, 9), (3, 12)] foo foo
163+
[(6, 6), (6, 7)] a a
162164
[(7, 4), (7, 11)] console console
163165
[(7, 12), (7, 15)] log log
164166
[(7, 23), (7, 24)] a a
@@ -254,6 +256,7 @@ comments:
254256
255257
identifiers:
256258
[(5, 6), (5, 11)] Punny Punny
259+
[(6, 14), (6, 19)] props props
257260
[(8, 4), (8, 8)] [(8, 4), (8, 8)] this this
258261
[(8, 9), (8, 16)] onClick onClick
259262
[(8, 19), (8, 23)] [(8, 19), (8, 23)] this this
@@ -680,10 +683,13 @@ hasJsx: false"
680683

681684
exports[`Parser.getSymbols flow 1`] = `
682685
"functions:
683-
[(2, 2), (4, 3)] renderHello(name) App
686+
[(2, 2), (4, 3)] renderHello(name, action, ) App
684687
685688
variables:
686689
[(2, 14), (2, 26)] name
690+
[(2, 28), (2, 47)] action
691+
[(2, 49), (2, 65)]
692+
[(2, 51), (2, 56)] todos
687693
688694
callExpressions:
689695
@@ -692,13 +698,15 @@ memberExpressions:
692698
693699
694700
objectProperties:
695-
701+
[(2, 51), (2, 56)] todos todos
696702
697703
comments:
698704
699705
700706
identifiers:
701707
[(1, 6), (1, 9)] App App
708+
[(2, 14), (2, 18)] name name
709+
[(2, 28), (2, 34)] action action
702710
[(3, 20), (3, 24)] name name
703711
[(1, 18), (1, 27)] Component Component
704712
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class App extends Component {
2-
renderHello(name: string) {
2+
renderHello(name: string, action: ReduxAction, { todos }: Props) {
33
return `howdy ${name}`;
44
}
55
}

src/workers/parser/tests/getSymbols.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import cases from "jest-in-case";
77
cases(
88
"Parser.getSymbols",
99
({ name, file, original, type }) => {
10-
// console.log(formatSymbols(getSource(file, type)));
1110
const source = original
1211
? getOriginalSource(file, type)
1312
: getSource(file, type);
13+
14+
// console.log(formatSymbols(source));
1415
expect(formatSymbols(source)).toMatchSnapshot();
1516
},
1617
[

0 commit comments

Comments
 (0)