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

Commit

Permalink
Exclude flow annotations from symbol identifiers (#5486)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnshulMalik authored and jasonLaster committed Mar 12, 2018
1 parent 3be6a54 commit 9789111
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/workers/parser/getSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ function extractSymbol(path: SimplePath, symbols) {
}
}

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

if (t.isClassMethod(path.parent)) {
// We want to include function params, but exclude the function name
if (t.isClassMethod(path.parent) && !path.inList) {
return;
}

Expand Down Expand Up @@ -255,7 +256,6 @@ function extractSymbol(path: SimplePath, symbols) {
if (t.isArrayPattern(node)) {
return;
}

symbols.identifiers.push({
name: node.name,
expression: node.name,
Expand Down
12 changes: 10 additions & 2 deletions src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ identifiers:
[(23, 6), (23, 11)] Ultra Ultra
[(25, 4), (25, 8)] [(25, 4), (25, 8)] this this
[(25, 9), (25, 16)] awesome awesome
[(28, 12), (28, 18)] person person
[(29, 4), (29, 11)] console console
[(29, 12), (29, 15)] log log
[(29, 19), (29, 25)] person person
Expand Down Expand Up @@ -159,6 +160,7 @@ identifiers:
[(1, 6), (1, 10)] Test Test
[(3, 4), (3, 8)] [(3, 4), (3, 8)] this this
[(3, 9), (3, 12)] foo foo
[(6, 6), (6, 7)] a a
[(7, 4), (7, 11)] console console
[(7, 12), (7, 15)] log log
[(7, 23), (7, 24)] a a
Expand Down Expand Up @@ -254,6 +256,7 @@ comments:
identifiers:
[(5, 6), (5, 11)] Punny Punny
[(6, 14), (6, 19)] props props
[(8, 4), (8, 8)] [(8, 4), (8, 8)] this this
[(8, 9), (8, 16)] onClick onClick
[(8, 19), (8, 23)] [(8, 19), (8, 23)] this this
Expand Down Expand Up @@ -680,10 +683,13 @@ hasJsx: false"

exports[`Parser.getSymbols flow 1`] = `
"functions:
[(2, 2), (4, 3)] renderHello(name) App
[(2, 2), (4, 3)] renderHello(name, action, ) App
variables:
[(2, 14), (2, 26)] name
[(2, 28), (2, 47)] action
[(2, 49), (2, 65)]
[(2, 51), (2, 56)] todos
callExpressions:
Expand All @@ -692,13 +698,15 @@ memberExpressions:
objectProperties:
[(2, 51), (2, 56)] todos todos
comments:
identifiers:
[(1, 6), (1, 9)] App App
[(2, 14), (2, 18)] name name
[(2, 28), (2, 34)] action action
[(3, 20), (3, 24)] name name
[(1, 18), (1, 27)] Component Component
Expand Down
2 changes: 1 addition & 1 deletion src/workers/parser/tests/fixtures/flow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class App extends Component {
renderHello(name: string) {
renderHello(name: string, action: ReduxAction, { todos }: Props) {
return `howdy ${name}`;
}
}
3 changes: 2 additions & 1 deletion src/workers/parser/tests/getSymbols.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import cases from "jest-in-case";
cases(
"Parser.getSymbols",
({ name, file, original, type }) => {
// console.log(formatSymbols(getSource(file, type)));
const source = original
? getOriginalSource(file, type)
: getSource(file, type);

// console.log(formatSymbols(source));
expect(formatSymbols(source)).toMatchSnapshot();
},
[
Expand Down

0 comments on commit 9789111

Please sign in to comment.