diff --git a/lib/infer/kind.js b/lib/infer/kind.js index e715ff4d7..6dfb6dfb7 100644 --- a/lib/infer/kind.js +++ b/lib/infer/kind.js @@ -1,6 +1,6 @@ 'use strict'; -var types = require('ast-types'), +var babel = require('babel-core'), shouldSkipInference = require('./should_skip_inference'); var kindShorthands = ['class', 'constant', 'event', 'external', 'file', @@ -28,7 +28,7 @@ module.exports = function () { } } - types.visit(comment.context.ast, { + babel.traverse(comment.context.ast, { visitClassDeclaration: function () { comment.kind = 'class'; this.abort(); @@ -54,7 +54,7 @@ module.exports = function () { this.traverse(path); } } - }); + }, null, null, comment.context.ast.parentPath); return comment; }); diff --git a/lib/parsers/javascript.js b/lib/parsers/javascript.js index 2b1afbaac..de21d5134 100644 --- a/lib/parsers/javascript.js +++ b/lib/parsers/javascript.js @@ -1,7 +1,6 @@ 'use strict'; var babel = require('babel-core'), - types = require('ast-types'), extend = require('extend'), isJSDocComment = require('../../lib/is_jsdoc_comment'), parse = require('../../lib/parse'); @@ -15,7 +14,7 @@ var babel = require('babel-core'), */ function parseJavaScript(data) { var results = []; - var ast = babel.transform(data.source, { + var transformed = babel.transform(data.source, { code: false, presets: ['es2015', 'stage-0', 'react'] }); @@ -23,17 +22,17 @@ function parseJavaScript(data) { var visited = {}; function walkComments(ast, type, includeContext) { - types.visit(ast, { - visitNode: function (path) { + babel.traverse(ast, { + enter: function (path) { /** * Parse a comment with doctrine and decorate the result with file position and code context. * * @param {Object} comment the current state of the parsed JSDoc comment * @return {undefined} this emits data */ - function parseComment(comment) { + function parseComment(node, comment) { var context = { - loc: extend({}, path.value.loc), + loc: extend({}, node.loc), file: data.file }; // Avoid visiting the same comment twice as a leading @@ -65,18 +64,16 @@ function parseJavaScript(data) { } } - (path.value[type] || []) + (path.node[type] || []) .filter(isJSDocComment) - .forEach(parseComment); - - this.traverse(path); + .forEach(parseComment.bind(undefined, path.node)); } }); } - walkComments(ast, 'leadingComments', true); - walkComments(ast, 'innerComments', false); - walkComments(ast, 'trailingComments', false); + walkComments(transformed.ast, 'leadingComments', true); + walkComments(transformed.ast, 'innerComments', false); + walkComments(transformed.ast, 'trailingComments', false); return results; }