Skip to content

Commit 22d8740

Browse files
committedApr 11, 2018
feat(inferTypes): Support class properties
Previously we did not properly infer params on methods that were located on class properties. This changes things so that we do. It carefully tries to avoid messing up the existing support of class type annotations, which are similar to class properties at the AST level, but do not have an associated node, only a type alias. Fixes #1043
1 parent 0d629d6 commit 22d8740

File tree

3 files changed

+376
-104
lines changed

3 files changed

+376
-104
lines changed
 

‎__tests__/__snapshots__/test.js.snap

+360-100
Large diffs are not rendered by default.

‎__tests__/fixture/es6.input.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
* This function destructures with defaults. It should not
33
* have any parameter descriptions.
44
*/
5-
function destructure(
6-
{ phoneNumbers = [], emailAddresses = [], ...params } = {}
7-
) {}
5+
function destructure({
6+
phoneNumbers = [],
7+
emailAddresses = [],
8+
...params
9+
} = {}) {}
810

911
/**
1012
* Similar, but with an array
@@ -43,6 +45,13 @@ class Sink {
4345
return 1;
4446
}
4547

48+
/**
49+
* This uses the class property transform
50+
*/
51+
classprop = (a: number): string => {
52+
return 'hi';
53+
};
54+
4655
/**
4756
* This method says hello
4857
*/

‎src/infer/finders.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ function findTarget(path: ?Object) {
2929
// foo.x = TARGET
3030
path = path.get('expression').get('right');
3131
} else if (t.isObjectProperty(path)) {
32-
// var foo = { x: TARGET };
32+
// var foo = { x: TARGET }; object property
33+
path = path.get('value');
34+
} else if (t.isClassProperty(path) && path.get('value').node) {
35+
// var foo = { x = TARGET }; class property
3336
path = path.get('value');
3437
}
3538

0 commit comments

Comments
 (0)
Please sign in to comment.