WIP for walking ES6 nodes (accidental commit)

This commit is contained in:
Jeff Williams 2014-04-06 20:39:45 -07:00
parent c15f905ee4
commit a61cf5cc8a

View File

@ -39,6 +39,13 @@ function moveComments(source, target) {
function leafNode(node, parent, state, cb) {}
function unsupportedNode(node, parent, state, cb) {
var logger = require('jsdoc/util/logger');
logger.warn('JSDoc does not currently handle nodes of type %s. Source file: %s', node.type,
state.filename);
}
// TODO: docs
var walkers = exports.walkers = {};
@ -62,6 +69,8 @@ walkers[Syntax.ArrayPattern] = function arrayPattern(node, parent, state, cb) {
}
};
walkers[Syntax.ArrowFunctionExpression] = unsupportedNode;
walkers[Syntax.AssignmentExpression] = function assignmentExpression(node, parent, state, cb) {
cb(node.left, node, state);
cb(node.right, node, state);
@ -94,6 +103,14 @@ walkers[Syntax.CallExpression] = function callExpression(node, parent, state, cb
walkers[Syntax.CatchClause] = leafNode;
walkers[Syntax.ClassBody] = unsupportedNode;
walkers[Syntax.ClassDeclaration] = unsupportedNode;
walkers[Syntax.ClassExpression] = unsupportedNode;
walkers[Syntax.ClassHeritage] = unsupportedNode;
// TODO: verify correctness
walkers[Syntax.ComprehensionBlock] = walkers[Syntax.AssignmentExpression];
@ -128,6 +145,12 @@ walkers[Syntax.DoWhileStatement] = function doWhileStatement(node, parent, state
walkers[Syntax.EmptyStatement] = leafNode;
walkers[Syntax.ExportBatchSpecifier] = unsupportedNode;
walkers[Syntax.ExportDeclaration] = unsupportedNode;
walkers[Syntax.ExportSpecifier] = unsupportedNode;
walkers[Syntax.ExpressionStatement] = function expressionStatement(node, parent, state, cb) {
cb(node.expression, node, state);
};
@ -188,6 +211,10 @@ walkers[Syntax.IfStatement] = function ifStatement(node, parent, state, cb) {
}
};
walkers[Syntax.ImportDeclaration] = unsupportedNode;
walkers[Syntax.ImportSpecifier] = unsupportedNode;
walkers[Syntax.LabeledStatement] = function labeledStatement(node, parent, state, cb) {
cb(node.body, node, state);
};
@ -216,6 +243,10 @@ walkers[Syntax.MemberExpression] = function memberExpression(node, parent, state
cb(node.object, node, state);
};
walkers[Syntax.MethodDefinition] = unsupportedNode;
walkers[Syntax.ModuleDeclaration] = unsupportedNode;
walkers[Syntax.NewExpression] = walkers[Syntax.CallExpression];
walkers[Syntax.ObjectExpression] = function objectExpression(node, parent, state, cb) {
@ -247,6 +278,8 @@ walkers[Syntax.SequenceExpression] = function sequenceExpression(node, parent, s
}
};
walkers[Syntax.SpreadElement] = unsupportedNode;
walkers[Syntax.SwitchCase] = function switchCase(node, parent, state, cb) {
if (node.test) {
cb(node.test, node, state);
@ -265,6 +298,12 @@ walkers[Syntax.SwitchStatement] = function switchStatement(node, parent, state,
}
};
walkers[Syntax.TaggedTemplateExpression] = unsupportedNode;
walkers[Syntax.TemplateElement] = unsupportedNode;
walkers[Syntax.TemplateLiteral] = unsupportedNode;
walkers[Syntax.ThisExpression] = leafNode;
walkers[Syntax.ThrowStatement] = function throwStatement(node, parent, state, cb) {
@ -343,9 +382,10 @@ var Walker = exports.Walker = function(walkerFuncs) {
};
// TODO: docs
Walker.prototype._recurse = function(ast) {
Walker.prototype._recurse = function(filename, ast) {
// TODO: track variables/aliases during the walk
var state = {
filename: filename,
nodes: [],
scopes: []
};
@ -390,7 +430,7 @@ Walker.prototype._recurse = function(ast) {
// TODO: allow visitor.visit to prevent traversal of child nodes
// TODO: skip the AST root node to be consistent with Rhino?
Walker.prototype.recurse = function(filename, ast, visitor) {
var state = this._recurse(ast);
var state = this._recurse(filename, ast);
if (visitor) {
for (var i = 0, l = state.nodes.length; i < l; i++) {