fix es6 visitor keys

This commit is contained in:
Sebastian McKenzie
2014-10-09 18:56:24 +11:00
parent 03a84a7de1
commit e7ef64a5ad
6 changed files with 126 additions and 72 deletions

View File

@@ -92,12 +92,14 @@ var buildNode = function (node) {
nodes.push(b.variableDeclaration("var", declars));
return node.declarations.map(function (declar) {
return _.compact(node.declarations.map(function (declar) {
if (!declar.init) return;
return util.template("assign", {
VALUE: declar.init,
KEY: declar.id
}, true);
});
}));
} else if (node.type === "ForInStatement" && node.left.type === "VariableDeclaration" && !node.left._ignoreBlockBindingHoist) {
var id = node.left.declarations[0].id;
node.left = id;

View File

@@ -22,7 +22,7 @@ var getMemberExpressionObject = function (node) {
var buildClass = function (node) {
var superName = node.superClass;
var className = node.id;
var className = node.id || b.identifier("Anonymous");
var superClassReference = node.superClass;

View File

@@ -1,46 +1,75 @@
{
"AssignmentExpression": ["left", "right"],
"ArrayExpression": ["elements"],
"ArrayPattern": ["elements"],
"ArrowFunctionExpression": ["params", "defaults", "rest", "body"],
"BlockStatement": ["body"],
"BinaryExpression": ["left", "right"],
"BreakStatement": ["label"],
"CallExpression": ["callee", "arguments"],
"CatchClause": ["param", "body"],
"ClassBody": ["body"],
"ClassDeclaration": ["id", "body", "superClass"],
"ClassExpression": ["id", "body", "superClass"],
"ConditionalExpression": ["test", "consequent", "alternate"],
"ContinueStatement": ["label"],
"DoWhileStatement": ["body", "test"],
"ExpressionStatement": ["expression"],
"ForStatement": ["init", "test", "update", "body"],
"ForInStatement": ["left", "right", "body"],
"ForOfStatement": ["left", "right", "body"],
"FunctionDeclaration": ["id", "params", "defaults", "rest", "body"],
"FunctionExpression": ["id", "params", "defaults", "rest", "body"],
"IfStatement": ["test", "consequent", "alternate"],
"LabeledStatement": ["label", "body"],
"LogicalExpression": ["left", "right"],
"MemberExpression": ["object", "property"],
"MethodDefinition": ["key", "value"],
"NewExpression": ["callee", "arguments"],
"ObjectExpression": ["properties"],
"ObjectPattern": ["properties"],
"Program": ["body"],
"Property": ["key", "value"],
"ReturnStatement": ["argument"],
"SequenceExpression": ["expressions"],
"SwitchStatement": ["discriminant", "cases"],
"SwitchCase": ["test", "consequent"],
"ThrowStatement": ["argument"],
"TryStatement": ["block", "handlers", "handler", "guardedHandlers", "finalizer"],
"UnaryExpression": ["argument"],
"UpdateExpression": ["argument"],
"VariableDeclaration": ["declarations"],
"VariableDeclarator": ["id", "init"],
"WhileStatement": ["test", "body"],
"WithStatement": ["object", "body"],
"YieldExpression": ["argument"]
"ArrayExpression": ["elements"],
"ArrayPattern": ["elements"],
"ArrowFunctionExpression": ["params", "defaults", "rest", "body"],
"AssignmentExpression": ["left", "right"],
"BinaryExpression": ["left", "right"],
"BlockStatement": ["body"],
"BreakStatement": ["label"],
"CallExpression": ["callee", "arguments"],
"CatchClause": ["param", "body"],
"ClassBody": ["body"],
"ClassDeclaration": ["id", "body", "superClass"],
"ClassExpression": ["id", "body", "superClass"],
"ClassProperty": ["key", "value"],
"ComprehensionBlock": ["left", "right", "body"],
"ComprehensionExpression": ["filter", "blocks", "body"],
"ConditionalExpression": ["test", "consequent", "alternate"],
"ContinueStatement": ["label"],
"DebuggerStatement": [],
"DoWhileStatement": ["body", "test"],
"EmptyStatement": [],
"ExportDeclaration": ["declaration", "specifiers", "source"],
"ExportBatchSpecifier": [],
"ExportSpecifier": ["id", "name"],
"ExpressionStatement": ["expression"],
"ForInStatement": ["left", "right", "body"],
"ForOfStatement": ["left", "right", "body"],
"ForStatement": ["init", "test", "update", "body"],
"FunctionDeclaration": ["id", "params", "defaults", "rest", "body"],
"FunctionExpression": ["id", "params", "defaults", "rest", "body"],
"Identifier": [],
"IfStatement": ["test", "consequent", "alternate"],
"ImportDeclaration": ["specifiers", "source"],
"ImportDefaultSpecifier": ["id"],
"ImportNamespaceSpecifier": ["id"],
"ImportSpecifier": ["id", "name"],
"LabeledStatement": ["label", "body"],
"Literal": [],
"LogicalExpression": ["left", "right"],
"MemberExpression": ["object", "property"],
"MethodDefinition": ["key", "value"],
"ModuleSpecifier": [],
"NewExpression": ["callee", "arguments"],
"ObjectExpression": ["properties"],
"ObjectPattern": ["properties"],
"ObjectTypeAnnotation": ["properties"],
"OptionalParameter": ["id"],
"ParametricTypeAnnotation": ["params"],
"ParametricallyTypedIdentifier": [],
"Program": ["body"],
"Property": ["key", "value"],
"ReturnStatement": ["argument"],
"SequenceExpression": ["expressions"],
"SpreadElement": ["argument"],
"SpreadProperty": ["argument"],
"SwitchCase": ["test", "consequent"],
"SwitchStatement": ["discriminant", "cases"],
"TaggedTemplateExpression": ["tag", "quasi"],
"TemplateElement": [],
"TemplateLiteral": ["quasis", "expressions"],
"ThisExpression": [],
"ThrowStatement": ["argument"],
"TryStatement": ["block", "handlers", "handler", "guardedHandlers", "finalizer"],
"TypeAnnotatedIdentifier": ["id", "annotation"],
"TypeAnnotation": ["id", "params", "returnType", "parametricType"],
"UnaryExpression": ["argument"],
"UpdateExpression": ["argument"],
"VariableDeclaration": ["declarations"],
"VariableDeclarator": ["id", "init"],
"VoidTypeAnnotation": [],
"WhileStatement": ["test", "body"],
"WithStatement": ["object", "body"],
"YieldExpression": ["argument"],
"AwaitExpression": ["argument"]
}

View File

@@ -1,8 +1,22 @@
module.exports = exports = 42;
module.exports = exports = {};
module.exports = exports = [];
module.exports = exports = foo;
module.exports = exports = function () {}
module.exports = exports = class {}
module.exports = exports = function () {
function Anonymous() {
}
return Anonymous;
}();
module.exports = exports = function foo () {}
module.exports = exports = class foo {}
module.exports = exports = function () {
function foo() {
}
return foo;
}();

View File

@@ -1,8 +1,8 @@
export var foo = 1;
export var foo = function () {};
export var bar;
export let foo = 2;
export let bar;
export const foo = 3;
export function foo () {}
export class foo {}
export var foo2 = function () {};
export var foo3;
export let foo4 = 2;
export let foo5;
export const foo6 = 3;
export function foo7 () {}
export class foo8 {}

View File

@@ -1,23 +1,32 @@
var foo = 1;
exports.foo = foo;
var foo;
var foo2;
var foo3;
var foo8;
(function () {
foo = 1;
exports.foo = foo;
var foo = function () {};
exports.foo = foo;
foo2 = function () {};
exports.foo2 = foo2;
var bar;
exports.bar = bar;
exports.foo3 = foo3;
let foo = 2;
exports.foo = foo;
var foo4 = 2;
exports.foo4 = foo4;
let bar;
exports.bar = bar;
var foo5;
exports.foo5 = foo5;
const foo = 3;
exports.foo = foo;
var foo6 = 3;
exports.foo6 = foo6;
function foo () {}
exports.foo = foo;
function foo7 () {}
exports.foo7 = foo7;
class foo {}
exports.foo = foo;
foo8 = function () {
function foo8() {
}
return foo8;
}();
exports.foo8 = foo8;
}());