Skip to content

Commit 46b9b65

Browse files
committed
Remove ast-types dependency
1 parent 5103cc7 commit 46b9b65

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

lib/infer/finders.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var n = require('ast-types').namedTypes;
1+
var t = require('babel-types');
22

33
function findTarget(path) {
44

@@ -11,28 +11,22 @@ function findTarget(path) {
1111
}
1212

1313
// var x = TARGET;
14-
if (n.VariableDeclaration.check(path)) {
14+
if (t.isVariableDeclaration(path)) {
1515
return path.declarations[0].init;
1616
}
1717

1818
// foo.x = TARGET
19-
if (n.ExpressionStatement.check(path)) {
19+
if (t.isExpressionStatement(path)) {
2020
return path.expression.right;
2121
}
2222

2323
return path;
2424
}
2525

26-
function findType(node, type) {
27-
var target = findTarget(node);
28-
return n[type].check(target) && target;
29-
}
30-
3126
function findClass(node) {
3227
var target = findTarget(node);
33-
return (n.ClassDeclaration.check(target) || n.ClassExpression.check(target)) && target;
28+
return (t.isClassDeclaration(target) || t.isClassExpression(target)) && target;
3429
}
3530

3631
module.exports.findTarget = findTarget;
37-
module.exports.findType = findType;
3832
module.exports.findClass = findClass;

lib/infer/params.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var shouldSkipInference = require('./should_skip_inference'),
4+
t = require('babel-types'),
45
finders = require('./finders'),
56
flowDoctrine = require('../flow_doctrine');
67

@@ -142,9 +143,9 @@ function paramToDoc(param, comment, i, prefix) {
142143
*/
143144
module.exports = function () {
144145
return shouldSkipInference(function inferParams(comment) {
145-
var node = finders.findType(comment.context.ast, 'Function');
146+
var node = finders.findTarget(comment.context.ast);
146147

147-
if (!node) {
148+
if (!t.isFunction(node)) {
148149
return comment;
149150
}
150151

lib/infer/properties.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var shouldSkipInference = require('./should_skip_inference'),
4-
finders = require('./finders'),
4+
t = require('babel-types'),
55
flowDoctrine = require('../flow_doctrine');
66

77

@@ -58,10 +58,8 @@ module.exports = function () {
5858
}
5959
}
6060

61-
var node = finders.findType(comment.context.ast, 'TypeAlias');
62-
63-
if (node) {
64-
inferProperties(node.right, []);
61+
if (t.isTypeAlias(comment.context.ast)) {
62+
inferProperties(comment.context.ast.node.right, []);
6563
}
6664

6765
return comment;

lib/infer/return.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var finders = require('./finders'),
4+
t = require('babel-types'),
45
shouldSkipInference = require('./should_skip_inference'),
56
flowDoctrine = require('../flow_doctrine');
67

@@ -16,8 +17,9 @@ module.exports = function () {
1617
if (comment.returns) {
1718
return comment;
1819
}
19-
var fn = finders.findType(comment.context.ast, 'Function');
20-
if (fn.returnType &&
20+
var fn = finders.findTarget(comment.context.ast);
21+
if (t.isFunction(fn) &&
22+
fn.returnType &&
2123
fn.returnType.typeAnnotation) {
2224
comment.returns = [{
2325
type: flowDoctrine(fn.returnType.typeAnnotation)

lib/is_jsdoc_comment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* comments.
1010
*
1111
* @name isJSDocComment
12-
* @param {Object} comment an ast-types node of the comment
12+
* @param {Object} comment an ast node of the comment
1313
* @return {boolean} whether it is valid
1414
*/
1515
module.exports = function isJSDocComment(comment) {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
},
99
"dependencies": {
1010
"ansi-html": "0.0.5",
11-
"ast-types": "^0.8.12",
1211
"babel-core": "^6.5.2",
1312
"babel-preset-es2015": "^6.5.0",
1413
"babel-preset-react": "^6.5.0",

0 commit comments

Comments
 (0)