diff --git a/lib/6to5/types/builder-keys.json b/lib/6to5/types/builder-keys.json index 98e5e24800..52aa00845e 100644 --- a/lib/6to5/types/builder-keys.json +++ b/lib/6to5/types/builder-keys.json @@ -1,33 +1,162 @@ { - "ArrayExpression": ["elements"], - "ArrowFunctionExpression": ["params", "body"], - "AssignmentExpression": ["operator", "left", "right"], - "BinaryExpression": ["operator", "left", "right"], - "BlockStatement": ["body"], - "CallExpression": ["callee", "arguments"], - "ConditionalExpression": ["test", "consequent", "alternate"], - "ExpressionStatement": ["expression"], - "File": ["program", "comments", "tokens"], - "FunctionExpression": ["id", "params", "body", "generator"], - "FunctionDeclaration": ["id", "params", "body", "generator"], - "Identifier": ["name"], - "IfStatement": ["test", "consequent", "alternate"], - "ImportDeclaration": ["specifiers", "source"], - "ImportSpecifier": ["id", "name"], - "Literal": ["value"], - "LogicalExpression": ["operator", "left", "right"], - "MemberExpression": ["object", "property", "computed"], - "MethodDefinition": ["key", "value", "computed", "kind"], - "NewExpression": ["callee", "arguments"], - "ObjectExpression": ["properties"], - "Program": ["body"], - "Property": ["kind", "key", "value", "computed"], - "ReturnStatement": ["argument"], - "SequenceExpression": ["expressions"], - "ThrowExpression": ["argument"], - "UnaryExpression": ["operator", "argument", "prefix"], - "VariableDeclaration": ["kind", "declarations"], - "VariableDeclarator": ["id", "init"], - "WithStatement": ["object", "body"], - "YieldExpression": ["argument", "delegate"] + "ArrayExpression": { + "elements": null + }, + + "ArrowFunctionExpression": { + "params": null, + "body": null + }, + + "AssignmentExpression": { + "operator": null, + "left": null, + "right": null + }, + + "BinaryExpression": { + "operator": null, + "left": null, + "right": null + }, + + "BlockStatement": { + "body": null + }, + + "CallExpression": { + "callee": null, + "arguments": null + }, + + "ConditionalExpression": { + "test": null, + "consequent": null, + "alternate": null + }, + + "ExpressionStatement": { + "expression": null + }, + + "File": { + "program": null, + "comments": null, + "tokens": null + }, + + "FunctionExpression": { + "id": null, + "params": null, + "body": null, + "generator": false + }, + + "FunctionDeclaration": { + "id": null, + "params": null, + "body": null, + "generator": false + }, + + "Identifier": { + "name": null + }, + + "IfStatement": { + "test": null, + "consequent": null, + "alternate": null + }, + + "ImportDeclaration": { + "specifiers": null, + "source": null + }, + + "ImportSpecifier": { + "id": null, + "name": null + }, + + "Literal": { + "value": null + }, + + "LogicalExpression": { + "operator": null, + "left": null, + "right": null + }, + + "MemberExpression": { + "object": null, + "property": null, + "computed": false + }, + + "MethodDefinition": { + "key": null, + "value": null, + "computed": false, + "kind": null + }, + + "NewExpression": { + "callee": null, + "arguments": null + }, + + "ObjectExpression": { + "properties": null + }, + + "Program": { + "body": null + }, + + "Property": { + "kind": null, + "key": null, + "value": null, + "computed": false + }, + + "ReturnStatement": { + "argument": null + }, + + "SequenceExpression": { + "expressions": null + }, + + "ThrowExpression": { + "argument": null + }, + + "UnaryExpression": { + "operator": null, + "argument": null, + "prefix": null + }, + + "VariableDeclaration": { + "kind": null, + "declarations": null + }, + + "VariableDeclarator": { + "id": null, + "init": null + }, + + "WithStatement": { + "object": null, + "body": null + }, + + "YieldExpression": { + "argument": null, + "delegate": null + } } diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index 0b90c56175..fb3a871b92 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -97,20 +97,29 @@ t.is = function (type, node, opts, skipAliasCheck) { // -t.BUILDER_KEYS = defaults(require("./builder-keys"), t.VISITOR_KEYS); +t.BUILDER_KEYS = require("./builder-keys"); + +each(t.VISITOR_KEYS, function (keys, type) { + if (t.BUILDER_KEYS[type]) return; + + var defs = {}; + each(keys, function (key) { + defs[key] = null; + }); + t.BUILDER_KEYS[type] = defs; +}); each(t.BUILDER_KEYS, function (keys, type) { t[type[0].toLowerCase() + type.slice(1)] = function () { - var args = arguments; var node = new Node; node.start = null; node.type = type; - for (var i = 0; i < keys.length; i++) { - var arg = args[i]; - if (arg === undefined) arg = false; + var i = 0; - var key = keys[i]; + for (var key in keys) { + var arg = arguments[i++]; + if (arg === undefined) arg = keys[key]; node[key] = arg; }