Skip to content

Commit

Permalink
Continue switching to babel 6
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Dec 1, 2015
1 parent de0c3c7 commit 2be7862
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/infer/kind.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -28,7 +28,7 @@ module.exports = function () {
}
}

types.visit(comment.context.ast, {
babel.traverse(comment.context.ast, {
visitClassDeclaration: function () {
comment.kind = 'class';
this.abort();
Expand All @@ -54,7 +54,7 @@ module.exports = function () {
this.traverse(path);
}
}
});
}, null, null, comment.context.ast.parentPath);

return comment;
});
Expand Down
23 changes: 10 additions & 13 deletions lib/parsers/javascript.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -15,25 +14,25 @@ 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']
});

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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 2be7862

Please sign in to comment.