function NodePath(value, parentPath, name) {
if (!(this instanceof NodePath)) {
throw new Error("NodePath constructor cannot be invoked without 'new'");
}
Path.call(this, value, parentPath, name);
}n/a
function Path(value, parentPath, name) {
if (!(this instanceof Path)) {
throw new Error("Path constructor cannot be invoked without 'new'");
}
if (parentPath) {
if (!(parentPath instanceof Path)) {
throw new Error("");
}
} else {
parentPath = null;
name = null;
}
// The value encapsulated by this Path, generally equal to
// parentPath.value[name] if we have a parentPath.
this.value = value;
// The immediate parent Path of this Path.
this.parentPath = parentPath;
// The name of the property of parentPath.value through which this
// Path's value was reached.
this.name = name;
// Calling path.get("child") multiple times always returns the same
// child Path object, for both performance and consistency reasons.
this.__childCache = null;
}n/a
function PathVisitor() {
if (!(this instanceof PathVisitor)) {
throw new Error(
"PathVisitor constructor cannot be invoked without 'new'"
);
}
// Permanent state.
this._reusableContextStack = [];
this._methodNameTable = computeMethodNameTable(this);
this._shouldVisitComments =
hasOwn.call(this._methodNameTable, "Block") ||
hasOwn.call(this._methodNameTable, "Line");
this.Context = makeContextConstructor(this);
// State reset every time PathVisitor.prototype.visit is called.
this._visiting = false;
this._changeReported = false;
}n/a
function Type(check, name) {
var self = this;
if (!(self instanceof Type)) {
throw new Error("Type constructor cannot be invoked without 'new'");
}
// Unfortunately we can't elegantly reuse isFunction and isString,
// here, because this code is executed while defining those types.
if (objToStr.call(check) !== funObjStr) {
throw new Error(check + " is not a function");
}
// The `name` parameter can be either a function or a string.
var nameObjStr = objToStr.call(name);
if (!(nameObjStr === funObjStr ||
nameObjStr === strObjStr)) {
throw new Error(name + " is neither a function nor a string");
}
Object.defineProperties(self, {
name: {value: name},
check: {
value: function (value, deep) {
var result = check.call(self, value, deep);
if (!result && deep && objToStr.call(deep) === funObjStr)
deep(self, value);
return result;
}
}
});
}n/a
function astNodesAreEquivalent(a, b, problemPath) {
if (isArray.check(problemPath)) {
problemPath.length = 0;
} else {
problemPath = null;
}
return areEquivalent(a, b, problemPath);
}n/a
defineMethod = function (name, func) {
var old = nodePrototype[name];
// Pass undefined as func to delete nodePrototype[name].
if (isUndefined.check(func)) {
delete nodePrototype[name];
} else {
isFunction.assert(func);
Object.defineProperty(nodePrototype, name, {
enumerable: true, // For discoverability.
configurable: true, // For delete proto[name].
value: func
});
}
return old;
}n/a
eachField = function (object, callback, context) {
getFieldNames(object).forEach(function (name) {
callback.call(this, name, getFieldValue(object, name));
}, context);
}...
}, context);
};
```
So here's how you might make a copy of an AST node:
```js
var copy = {};
require("ast-types").eachField(node, function(name, value) {
// Note that undefined fields will be visited too, according to
// the rules associated with node.type, and default field values
// will be substituted if appropriate.
copy[name] = value;
})
```
...finalize = function () {
Object.keys(defCache).forEach(function (name) {
defCache[name].finalize();
});
}...
.bases("Node")
.build("name", "program")
.field("name", string)
.field("program", def("Program"));
// Prevent further modifications to the File type (and any other
// types newly introduced by def(...)).
types.finalize();
// The b.file builder function is now available. It expects two
// arguments, as named by .build("name", "program") above.
var main = b.file("main.js", b.program([
// Pointless program contents included for extra color.
b.functionDeclaration(b.identifier("succ"), [
b.identifier("x")
...function getFieldNames(object) {
var d = Def.fromValue(object);
if (d) {
return d.fieldNames.slice(0);
}
if ("type" in object) {
throw new Error(
"did not recognize object of type " +
JSON.stringify(object.type)
);
}
return Object.keys(object);
}...
`getFieldValue`:
```js
var types = require("ast-types");
var partialFunExpr = { type: "FunctionExpression" };
// Even though partialFunExpr doesn't actually contain all the fields that
// are expected for a FunctionExpression, types.getFieldNames knows:
console.log(types.getFieldNames(partialFunExpr));
// [ 'type', 'id', 'params', 'body', 'generator', 'expression',
// 'defaults', 'rest', 'async' ]
// For fields that have default values, types.getFieldValue will return
// the default if the field is not actually defined.
console.log(types.getFieldValue(partialFunExpr, "generator"));
// false
...function getFieldValue(object, fieldName) {
var d = Def.fromValue(object);
if (d) {
var field = d.allFields[fieldName];
if (field) {
return field.getValue(object);
}
}
return object && object[fieldName];
}...
// are expected for a FunctionExpression, types.getFieldNames knows:
console.log(types.getFieldNames(partialFunExpr));
// [ 'type', 'id', 'params', 'body', 'generator', 'expression',
// 'defaults', 'rest', 'async' ]
// For fields that have default values, types.getFieldValue will return
// the default if the field is not actually defined.
console.log(types.getFieldValue(partialFunExpr, "generator"));
// false
```
Two more low-level helper functions, `eachField` and `someField`, are
defined in terms of `getFieldNames` and `getFieldValue`:
```js
// Iterate over all defined fields of an object, including those missing
...getSupertypeNames = function (typeName) {
if (!hasOwn.call(defCache, typeName)) {
throw new Error("");
}
var d = defCache[typeName];
if (d.finalized !== true) {
throw new Error("");
}
return d.supertypeList.slice(1);
}n/a
someField = function (object, callback, context) {
return getFieldNames(object).some(function (name) {
return callback.call(this, name, getFieldValue(object, name));
}, context);
}...
}
if (isArray.check(node)) {
return node.some(containsCallExpression);
}
if (n.Node.check(node)) {
return types.someField(node, function (name, child) {
return containsCallExpression(child);
});
}
return false;
}
...function use(plugin) {
var idx = used.indexOf(plugin);
if (idx === -1) {
idx = used.length;
used.push(plugin);
usedResult[idx] = plugin(fork);
}
return usedResult[idx];
}...
module.exports = function (fork) {
fork.use(require("./es7"));
var types = fork.use(require("../lib/types"));
var defaults = fork.use(require("../lib/shared")).defaults;
var def = types.Type.def;
var or = types.Type.or;
def("Noop")
...function visit(node, methods) {
return PathVisitor.fromMethodsObject(methods).visit(node);
}...
Here's a trivial example of how you might assert that `arguments.callee`
is never used in `ast`:
```js
var assert = require("assert");
var types = require("ast-types");
var n = types.namedTypes;
types.visit(ast, {
// This method will be called for any node with .type "MemberExpression":
visitMemberExpression: function(path) {
// Visitor methods receive a single argument, a NodePath object
// wrapping the node of interest.
var node = path.node;
if (n.Identifier.check(node.object) &&
...function NodePath(value, parentPath, name) {
if (!(this instanceof NodePath)) {
throw new Error("NodePath constructor cannot be invoked without 'new'");
}
Path.call(this, value, parentPath, name);
}n/a
_computeNode = function () {
var value = this.value;
if (n.Node.check(value)) {
return value;
}
var pp = this.parentPath;
return pp && pp.node || null;
}...
});
Object.defineProperties(NPp, {
node: {
get: function () {
Object.defineProperty(this, "node", {
configurable: true, // Enable deletion.
value: this._computeNode()
});
return this.node;
}
},
parent: {
..._computeParent = function () {
var value = this.value;
var pp = this.parentPath;
if (!n.Node.check(value)) {
while (pp && !n.Node.check(pp.value)) {
pp = pp.parentPath;
}
if (pp) {
pp = pp.parentPath;
}
}
while (pp && !n.Node.check(pp.value)) {
pp = pp.parentPath;
}
return pp || null;
}...
}
},
parent: {
get: function () {
Object.defineProperty(this, "parent", {
configurable: true, // Enable deletion.
value: this._computeParent()
});
return this.parent;
}
},
scope: {
..._computeScope = function () {
var value = this.value;
var pp = this.parentPath;
var scope = pp && pp.scope;
if (n.Node.check(value) &&
Scope.isEstablishedBy(value)) {
scope = new Scope(this, scope);
}
return scope || null;
}...
}
},
scope: {
get: function () {
Object.defineProperty(this, "scope", {
configurable: true, // Enable deletion.
value: this._computeScope()
});
return this.scope;
}
}
});
...canBeFirstInStatement = function () {
var node = this.node;
return !n.FunctionExpression.check(node)
&& !n.ObjectExpression.check(node);
}...
this.name === "callee" &&
parent.callee === node) {
return containsCallExpression(node);
}
}
if (assumeExpressionContext !== true &&
!this.canBeFirstInStatement() &&
this.firstInStatement())
return true;
return false;
};
function isBinary(node) {
...firstInStatement = function () {
return firstInStatement(this);
}...
parent.callee === node) {
return containsCallExpression(node);
}
}
if (assumeExpressionContext !== true &&
!this.canBeFirstInStatement() &&
this.firstInStatement())
return true;
return false;
};
function isBinary(node) {
return n.BinaryExpression.check(node)
...getValueProperty = function (name) {
return types.getFieldValue(this.value, name);
}...
// Lazily create the child cache. This also cheapens cache
// invalidation, since you can just reset path.__childCache to null.
return path.__childCache || (path.__childCache = Object.create(null));
}
function getChildPath(path, name) {
var cache = getChildCache(path);
var actualChildValue = path.getValueProperty(name);
var childPath = cache[name];
if (!hasOwn.call(cache, name) ||
// Ensure consistency between cache and reality.
childPath.value !== actualChildValue) {
childPath = cache[name] = new path.constructor(
actualChildValue, path, name
);
...needsParens = function (assumeExpressionContext) {
var pp = this.parentPath;
if (!pp) {
return false;
}
var node = this.value;
// Only expressions need parentheses.
if (!n.Expression.check(node)) {
return false;
}
// Identifiers never need parentheses.
if (node.type === "Identifier") {
return false;
}
while (!n.Node.check(pp.value)) {
pp = pp.parentPath;
if (!pp) {
return false;
}
}
var parent = pp.value;
switch (node.type) {
case "UnaryExpression":
case "SpreadElement":
case "SpreadProperty":
return parent.type === "MemberExpression"
&& this.name === "object"
&& parent.object === node;
case "BinaryExpression":
case "LogicalExpression":
switch (parent.type) {
case "CallExpression":
return this.name === "callee"
&& parent.callee === node;
case "UnaryExpression":
case "SpreadElement":
case "SpreadProperty":
return true;
case "MemberExpression":
return this.name === "object"
&& parent.object === node;
case "BinaryExpression":
case "LogicalExpression":
var po = parent.operator;
var pp = PRECEDENCE[po];
var no = node.operator;
var np = PRECEDENCE[no];
if (pp > np) {
return true;
}
if (pp === np && this.name === "right") {
if (parent.right !== node) {
throw new Error("Nodes must be equal");
}
return true;
}
default:
return false;
}
case "SequenceExpression":
switch (parent.type) {
case "ForStatement":
// Although parentheses wouldn't hurt around sequence
// expressions in the head of for loops, traditional style
// dictates that e.g. i++, j++ should not be wrapped with
// parentheses.
return false;
case "ExpressionStatement":
return this.name !== "expression";
default:
// Otherwise err on the side of overparenthesization, adding
// explicit exceptions above if this proves overzealous.
return true;
}
case "YieldExpression":
switch (parent.type) {
case "BinaryExpression":
case "LogicalExpression":
case "UnaryExpression":
case "SpreadElement":
case "SpreadProperty":
case "CallExpression":
case "MemberExpression":
case "NewExpression":
case "ConditionalExpression":
case "YieldExpression":
return true;
default:
return false;
}
case "Literal":
return parent.type === "MemberExpression"
&& isNumber.check(node.value)
&& this.name === "object"
&& parent.object === node;
case "AssignmentExpression":
case "ConditionalExpression":
switch (parent.type) {
case "UnaryExpression":
case "SpreadElement":
case "SpreadProperty":
case "BinaryExpression":
case "LogicalExpression":
return true;
case "CallExpression":
return this.name === "callee"
&& parent.callee === node;
case "ConditionalExpression":
return this.name === " ...n/a
prune = function () {
var remainingNodePath = this.parent;
this.replace();
return cleanUpNodesAfterPrune(remainingNodePath);
}...
path.get("elements", 2).replace(
b.identifier("foo"),
b.thisExpression()
);
// Remove a node and its parent if it would leave a redundant AST node:
//e.g. var t = 1, y =2; removing the `t` and `y` declarators results in `var undefined`.
path.prune(); //returns the closest parent `NodePath`.
// Remove a node from a list of nodes:
path.get("elements", 3).replace();
// Add three new nodes to the beginning of a list of nodes:
path.get("elements").unshift(a, b, c);
...replace = function () {
delete this.node;
delete this.parent;
delete this.scope;
return Path.prototype.replace.apply(this, arguments);
}...
// Similar to doing node.body.body.unshift(restVarDecl), except
// that the other NodePath objects wrapping body statements will
// have their indexes updated to accommodate the new statement.
path.get("body", "body").unshift(restVarDecl);
// Nullify node.rest now that we have simulated the behavior of
// the rest parameter using ordinary JavaScript.
path.get("rest").replace(null);
// There's nothing wrong with doing node.rest = null, but I wanted
// to point out that the above statement has the same effect.
assert.strictEqual(node.rest, null);
}
});
```
...function Path(value, parentPath, name) {
if (!(this instanceof Path)) {
throw new Error("Path constructor cannot be invoked without 'new'");
}
if (parentPath) {
if (!(parentPath instanceof Path)) {
throw new Error("");
}
} else {
parentPath = null;
name = null;
}
// The value encapsulated by this Path, generally equal to
// parentPath.value[name] if we have a parentPath.
this.value = value;
// The immediate parent Path of this Path.
this.parentPath = parentPath;
// The name of the property of parentPath.value through which this
// Path's value was reached.
this.name = name;
// Calling path.get("child") multiple times always returns the same
// child Path object, for both performance and consistency reasons.
this.__childCache = null;
}n/a
function each(callback, context) {
var childPaths = [];
var len = this.value.length;
var i = 0;
// Collect all the original child paths before invoking the callback.
for (var i = 0; i < len; ++i) {
if (hasOwn.call(this.value, i)) {
childPaths[i] = this.get(i);
}
}
// Invoke the callback on just the original child paths, regardless of
// any modifications made to the array by the callback. I chose these
// semantics over cleverly invoking the callback on new elements because
// this way is much easier to reason about.
context = context || this;
for (i = 0; i < len; ++i) {
if (hasOwn.call(childPaths, i)) {
callback.call(context, childPaths[i]);
}
}
}...
if (!(visitor instanceof PathVisitor)) {
throw new Error("");
}
var value = path.value;
if (isArray.check(value)) {
path.each(visitor.visitWithoutReset, visitor);
} else if (!isObject.check(value)) {
// No children to visit.
} else {
var childNames = types.getFieldNames(value);
// The .comments field of the Node type is hidden, so we only
// visit it if the visitor defines visitBlock or visitLine, and
...function filter(callback, context) {
var result = [];
this.each(function (childPath) {
if (callback.call(this, childPath)) {
result.push(childPath);
}
}, context);
return result;
}n/a
function get(name) {
var path = this;
var names = arguments;
var count = names.length;
for (var i = 0; i < count; ++i) {
path = getChildPath(path, names[i]);
}
return path;
}...
])
)
]);
// Similar to doing node.body.body.unshift(restVarDecl), except
// that the other NodePath objects wrapping body statements will
// have their indexes updated to accommodate the new statement.
path.get("body", "body").unshift(restVarDecl);
// Nullify node.rest now that we have simulated the behavior of
// the rest parameter using ordinary JavaScript.
path.get("rest").replace(null);
// There's nothing wrong with doing node.rest = null, but I wanted
// to point out that the above statement has the same effect.
...function getValueProperty(name) {
return this.value[name];
}...
// Lazily create the child cache. This also cheapens cache
// invalidation, since you can just reset path.__childCache to null.
return path.__childCache || (path.__childCache = Object.create(null));
}
function getChildPath(path, name) {
var cache = getChildCache(path);
var actualChildValue = path.getValueProperty(name);
var childPath = cache[name];
if (!hasOwn.call(cache, name) ||
// Ensure consistency between cache and reality.
childPath.value !== actualChildValue) {
childPath = cache[name] = new path.constructor(
actualChildValue, path, name
);
...function insertAfter(node) {
var pp = this.parentPath;
var argc = arguments.length;
var insertAtArgs = [this.name + 1];
for (var i = 0; i < argc; ++i) {
insertAtArgs.push(arguments[i]);
}
return pp.insertAt.apply(pp, insertAtArgs);
}...
// Remove and return the last node in a list of nodes:
path.get("elements").pop();
// Insert a new node before/after the seventh node in a list of nodes:
var seventh = path.get("elements", 6);
seventh.insertBefore(newNode);
seventh.insertAfter(newNode);
// Insert a new element at index 5 in a list of nodes:
path.get("elements").insertAt(5, newNode);
```
Scope
---
...function insertAt(index, node) {
var argc = arguments.length;
var move = getMoves(this, argc - 1, index);
if (move === emptyMoves) {
return this;
}
index = Math.max(index, 0);
for (var i = 1; i < argc; ++i) {
this.value[index + i - 1] = arguments[i];
}
move();
return this;
}...
// Insert a new node before/after the seventh node in a list of nodes:
var seventh = path.get("elements", 6);
seventh.insertBefore(newNode);
seventh.insertAfter(newNode);
// Insert a new element at index 5 in a list of nodes:
path.get("elements").insertAt(5, newNode);
```
Scope
---
The object exposed as `path.scope` during AST traversals provides
information about variable and function declarations in the scope that
...function insertBefore(node) {
var pp = this.parentPath;
var argc = arguments.length;
var insertAtArgs = [this.name];
for (var i = 0; i < argc; ++i) {
insertAtArgs.push(arguments[i]);
}
return pp.insertAt.apply(pp, insertAtArgs);
}...
path.get("elements").push(d, e);
// Remove and return the last node in a list of nodes:
path.get("elements").pop();
// Insert a new node before/after the seventh node in a list of nodes:
var seventh = path.get("elements", 6);
seventh.insertBefore(newNode);
seventh.insertAfter(newNode);
// Insert a new element at index 5 in a list of nodes:
path.get("elements").insertAt(5, newNode);
```
Scope
...function map(callback, context) {
var result = [];
this.each(function (childPath) {
result.push(callback.call(this, childPath));
}, context);
return result;
}...
if (problemPath.length === 0) {
if (a !== b) {
throw new Error("Nodes must be equal");
}
} else {
throw new Error(
"Nodes differ in the following path: " +
problemPath.map(subscriptForProperty).join("")
);
}
}
};
function subscriptForProperty(property) {
if (/[_$a-z][_$a-z0-9]*/i.test(property)) {
...function pop() {
isArray.assert(this.value);
var cache = getChildCache(this);
delete cache[this.value.length - 1];
delete cache.length;
return this.value.pop();
}...
// Remove and return the first node in a list of nodes:
path.get("elements").shift();
// Push two new nodes onto the end of a list of nodes:
path.get("elements").push(d, e);
// Remove and return the last node in a list of nodes:
path.get("elements").pop();
// Insert a new node before/after the seventh node in a list of nodes:
var seventh = path.get("elements", 6);
seventh.insertBefore(newNode);
seventh.insertAfter(newNode);
// Insert a new element at index 5 in a list of nodes:
...function push(node) {
isArray.assert(this.value);
delete getChildCache(this).length
return this.value.push.apply(this.value, arguments);
}...
// Add three new nodes to the beginning of a list of nodes:
path.get("elements").unshift(a, b, c);
// Remove and return the first node in a list of nodes:
path.get("elements").shift();
// Push two new nodes onto the end of a list of nodes:
path.get("elements").push(d, e);
// Remove and return the last node in a list of nodes:
path.get("elements").pop();
// Insert a new node before/after the seventh node in a list of nodes:
var seventh = path.get("elements", 6);
seventh.insertBefore(newNode);
...function replace(replacement) {
var results = [];
var parentValue = this.parentPath.value;
var parentCache = getChildCache(this.parentPath);
var count = arguments.length;
repairRelationshipWithParent(this);
if (isArray.check(parentValue)) {
var originalLength = parentValue.length;
var move = getMoves(this.parentPath, count - 1, this.name + 1);
var spliceArgs = [this.name, 1];
for (var i = 0; i < count; ++i) {
spliceArgs.push(arguments[i]);
}
var splicedOut = parentValue.splice.apply(parentValue, spliceArgs);
if (splicedOut[0] !== this.value) {
throw new Error("");
}
if (parentValue.length !== (originalLength - 1 + count)) {
throw new Error("");
}
move();
if (count === 0) {
delete this.value;
delete parentCache[this.name];
this.__childCache = null;
} else {
if (parentValue[this.name] !== replacement) {
throw new Error("");
}
if (this.value !== replacement) {
this.value = replacement;
this.__childCache = null;
}
for (i = 0; i < count; ++i) {
results.push(this.parentPath.get(this.name + i));
}
if (results[0] !== this) {
throw new Error("");
}
}
} else if (count === 1) {
if (this.value !== replacement) {
this.__childCache = null;
}
this.value = parentValue[this.name] = replacement;
results.push(this);
} else if (count === 0) {
delete parentValue[this.name];
delete this.value;
this.__childCache = null;
// Leave this path cached as parentCache[this.name], even though
// it no longer has a value defined.
} else {
throw new Error("Could not replace path");
}
return results;
}...
// Similar to doing node.body.body.unshift(restVarDecl), except
// that the other NodePath objects wrapping body statements will
// have their indexes updated to accommodate the new statement.
path.get("body", "body").unshift(restVarDecl);
// Nullify node.rest now that we have simulated the behavior of
// the rest parameter using ordinary JavaScript.
path.get("rest").replace(null);
// There's nothing wrong with doing node.rest = null, but I wanted
// to point out that the above statement has the same effect.
assert.strictEqual(node.rest, null);
}
});
```
...function shift() {
var move = getMoves(this, -1);
var result = this.value.shift();
move();
return result;
}...
// Remove a node from a list of nodes:
path.get("elements", 3).replace();
// Add three new nodes to the beginning of a list of nodes:
path.get("elements").unshift(a, b, c);
// Remove and return the first node in a list of nodes:
path.get("elements").shift();
// Push two new nodes onto the end of a list of nodes:
path.get("elements").push(d, e);
// Remove and return the last node in a list of nodes:
path.get("elements").pop();
...function unshift(node) {
var move = getMoves(this, arguments.length);
var result = this.value.unshift.apply(this.value, arguments);
move();
return result;
}...
b.callExpression(sliceExpr, [
b.identifier("arguments"),
b.literal(node.params.length)
])
)
]);
// Similar to doing node.body.body.unshift(restVarDecl), except
// that the other NodePath objects wrapping body statements will
// have their indexes updated to accommodate the new statement.
path.get("body", "body").unshift(restVarDecl);
// Nullify node.rest now that we have simulated the behavior of
// the rest parameter using ordinary JavaScript.
path.get("rest").replace(null);
...function PathVisitor() {
if (!(this instanceof PathVisitor)) {
throw new Error(
"PathVisitor constructor cannot be invoked without 'new'"
);
}
// Permanent state.
this._reusableContextStack = [];
this._methodNameTable = computeMethodNameTable(this);
this._shouldVisitComments =
hasOwn.call(this._methodNameTable, "Block") ||
hasOwn.call(this._methodNameTable, "Line");
this.Context = makeContextConstructor(this);
// State reset every time PathVisitor.prototype.visit is called.
this._visiting = false;
this._changeReported = false;
}n/a
function fromMethodsObject(methods) {
if (methods instanceof PathVisitor) {
return methods;
}
if (!isObject.check(methods)) {
// An empty visitor?
return new PathVisitor;
}
function Visitor() {
if (!(this instanceof Visitor)) {
throw new Error(
"Visitor constructor cannot be invoked without 'new'"
);
}
PathVisitor.call(this);
}
var Vp = Visitor.prototype = Object.create(PVp);
Vp.constructor = Visitor;
extend(Vp, methods);
extend(Visitor, PathVisitor);
isFunction.assert(Visitor.fromMethodsObject);
isFunction.assert(Visitor.visit);
return new Visitor;
}...
}
}
return target;
}
PathVisitor.visit = function visit(node, methods) {
return PathVisitor.fromMethodsObject(methods).visit(node);
};
var PVp = PathVisitor.prototype;
PVp.visit = function () {
if (this._visiting) {
throw new Error(
...function visit(node, methods) {
return PathVisitor.fromMethodsObject(methods).visit(node);
}...
Here's a trivial example of how you might assert that `arguments.callee`
is never used in `ast`:
```js
var assert = require("assert");
var types = require("ast-types");
var n = types.namedTypes;
types.visit(ast, {
// This method will be called for any node with .type "MemberExpression":
visitMemberExpression: function(path) {
// Visitor methods receive a single argument, a NodePath object
// wrapping the node of interest.
var node = path.node;
if (n.Identifier.check(node.object) &&
...function AbortRequest() {}...
return root;
};
PVp.AbortRequest = function AbortRequest() {};
PVp.abort = function () {
var visitor = this;
visitor._abortRequested = true;
var request = new visitor.AbortRequest();
// If you decide to catch this exception and stop it from propagating,
// make sure to call its cancel method to avoid silencing other
// exceptions that might be thrown later in the traversal.
request.cancel = function () {
visitor._abortRequested = false;
};
...abort = function () {
var visitor = this;
visitor._abortRequested = true;
var request = new visitor.AbortRequest();
// If you decide to catch this exception and stop it from propagating,
// make sure to call its cancel method to avoid silencing other
// exceptions that might be thrown later in the traversal.
request.cancel = function () {
visitor._abortRequested = false;
};
throw request;
}...
var result = false;
types.visit(funcNode, {
visitThisExpression: function(path) {
result = true;
// The quickest way to terminate the traversal is to call
// this.abort(), which throws a special exception (instanceof
// this.AbortRequest) that will be caught in the top-level
// types.visit method, so you don't have to worry about
// catching the exception yourself.
this.abort();
},
visitFunction: function(path) {
...acquireContext = function (path) {
if (this._reusableContextStack.length === 0) {
return new this.Context(path);
}
return this._reusableContextStack.pop().reset(path);
}...
var methodName = value &&
typeof value === "object" &&
typeof value.type === "string" &&
this._methodNameTable[value.type];
if (methodName) {
var context = this.acquireContext(path);
try {
return context.invokeVisitorMethod(methodName);
} finally {
this.releaseContext(context);
}
} else {
...releaseContext = function (context) {
if (!(context instanceof this.Context)) {
throw new Error("");
}
this._reusableContextStack.push(context);
context.currentPath = null;
}...
this._methodNameTable[value.type];
if (methodName) {
var context = this.acquireContext(path);
try {
return context.invokeVisitorMethod(methodName);
} finally {
this.releaseContext(context);
}
} else {
// If there was no visitor method to call, visit the children of
// this node generically.
return visitChildren(path, this);
}
...reportChanged = function () {
this._changeReported = true;
}...
return PathVisitor.fromMethodsObject(
newVisitor || this.visitor
).visitWithoutReset(path);
};
sharedContextProtoMethods.reportChanged = function reportChanged() {
this.visitor.reportChanged();
};
sharedContextProtoMethods.abort = function abort() {
this.needToCallTraverse = false;
this.visitor.abort();
};
...reset = function (path) {
// Empty stub; may be reassigned or overridden by subclasses.
}...
return path.value;
}
PVp.acquireContext = function (path) {
if (this._reusableContextStack.length === 0) {
return new this.Context(path);
}
return this._reusableContextStack.pop().reset(path);
};
PVp.releaseContext = function (context) {
if (!(context instanceof this.Context)) {
throw new Error("");
}
this._reusableContextStack.push(context);
...visit = function () {
if (this._visiting) {
throw new Error(
"Recursively calling visitor.visit(path) resets visitor state. " +
"Try this.visit(path) or this.traverse(path) instead."
);
}
// Private state that needs to be reset before every traversal.
this._visiting = true;
this._changeReported = false;
this._abortRequested = false;
var argc = arguments.length;
var args = new Array(argc)
for (var i = 0; i < argc; ++i) {
args[i] = arguments[i];
}
if (!(args[0] instanceof NodePath)) {
args[0] = new NodePath({root: args[0]}).get("root");
}
// Called with the same arguments as .visit.
this.reset.apply(this, args);
try {
var root = this.visitWithoutReset(args[0]);
var didNotThrow = true;
} finally {
this._visiting = false;
if (!didNotThrow && this._abortRequested) {
// If this.visitWithoutReset threw an exception and
// this._abortRequested was set to true, return the root of
// the AST instead of letting the exception propagate, so that
// client code does not have to provide a try-catch block to
// intercept the AbortRequest exception. Other kinds of
// exceptions will propagate without being intercepted and
// rethrown by a catch block, so their stacks will accurately
// reflect the original throwing context.
return args[0].value;
}
}
return root;
}...
Here's a trivial example of how you might assert that `arguments.callee`
is never used in `ast`:
```js
var assert = require("assert");
var types = require("ast-types");
var n = types.namedTypes;
types.visit(ast, {
// This method will be called for any node with .type "MemberExpression":
visitMemberExpression: function(path) {
// Visitor methods receive a single argument, a NodePath object
// wrapping the node of interest.
var node = path.node;
if (n.Identifier.check(node.object) &&
...visitWithoutReset = function (path) {
if (this instanceof this.Context) {
// Since this.Context.prototype === this, there's a chance we
// might accidentally call context.visitWithoutReset. If that
// happens, re-invoke the method against context.visitor.
return this.visitor.visitWithoutReset(path);
}
if (!(path instanceof NodePath)) {
throw new Error("");
}
var value = path.value;
var methodName = value &&
typeof value === "object" &&
typeof value.type === "string" &&
this._methodNameTable[value.type];
if (methodName) {
var context = this.acquireContext(path);
try {
return context.invokeVisitorMethod(methodName);
} finally {
this.releaseContext(context);
}
} else {
// If there was no visitor method to call, visit the children of
// this node generically.
return visitChildren(path, this);
}
}...
args[0] = new NodePath({root: args[0]}).get("root");
}
// Called with the same arguments as .visit.
this.reset.apply(this, args);
try {
var root = this.visitWithoutReset(args[0]);
var didNotThrow = true;
} finally {
this._visiting = false;
if (!didNotThrow && this._abortRequested) {
// If this.visitWithoutReset threw an exception and
// this._abortRequested was set to true, return the root of
...wasChangeReported = function () {
return this._changeReported;
}n/a
function Type(check, name) {
var self = this;
if (!(self instanceof Type)) {
throw new Error("Type constructor cannot be invoked without 'new'");
}
// Unfortunately we can't elegantly reuse isFunction and isString,
// here, because this code is executed while defining those types.
if (objToStr.call(check) !== funObjStr) {
throw new Error(check + " is not a function");
}
// The `name` parameter can be either a function or a string.
var nameObjStr = objToStr.call(name);
if (!(nameObjStr === funObjStr ||
nameObjStr === strObjStr)) {
throw new Error(name + " is neither a function nor a string");
}
Object.defineProperties(self, {
name: {value: name},
check: {
value: function (value, deep) {
var result = check.call(self, value, deep);
if (!result && deep && objToStr.call(deep) === funObjStr)
deep(self, value);
return result;
}
}
});
}n/a
def = function (typeName) {
isString.assert(typeName);
return hasOwn.call(defCache, typeName)
? defCache[typeName]
: defCache[typeName] = new Def(typeName);
}n/a
fromArray = function (arr) {
if (!isArray.check(arr)) {
throw new Error("");
}
if (arr.length !== 1) {
throw new Error("only one element type is permitted for typed arrays");
}
return toType(arr[0]).arrayOf();
}...
// The Def type is used as a helper for constructing compound
// interface types for AST nodes.
if (from instanceof Def)
return from.type;
// Support [ElemType] syntax.
if (isArray.check(from))
return Type.fromArray(from);
// Support { someField: FieldType, ... } syntax.
if (isObject.check(from))
return Type.fromObject(from);
if (isFunction.check(from)) {
var bicfIndex = builtInCtorFns.indexOf(from);
...fromObject = function (obj) {
var fields = Object.keys(obj).map(function (name) {
return new Field(name, obj[name]);
});
return new Type(function (value, deep) {
return isObject.check(value) && fields.every(function (field) {
return field.type.check(value[field.name], deep);
});
}, function () {
return "{ " + fields.join(", ") + " }";
});
}...
// Support [ElemType] syntax.
if (isArray.check(from))
return Type.fromArray(from);
// Support { someField: FieldType, ... } syntax.
if (isObject.check(from))
return Type.fromObject(from);
if (isFunction.check(from)) {
var bicfIndex = builtInCtorFns.indexOf(from);
if (bicfIndex >= 0) {
return builtInCtorTypes[bicfIndex];
}
...or = function () {
var types = [];
var len = arguments.length;
for (var i = 0; i < len; ++i)
types.push(toType(arguments[i]));
return new Type(function (value, deep) {
for (var i = 0; i < len; ++i)
if (types[i].check(value, deep))
return true;
return false;
}, function () {
return types.join(" | ");
});
}...
"null": function () { return null },
"emptyArray": function () { return [] },
"false": function () { return false },
"true": function () { return true },
"undefined": function () {}
};
var naiveIsPrimitive = Type.or(
builtin.string,
builtin.number,
builtin.boolean,
builtin.null,
builtin.undefined
);
...arrayOf = function () {
var elemType = this;
return new Type(function (value, deep) {
return isArray.check(value) && value.every(function (elem) {
return elemType.check(elem, deep);
});
}, function () {
return "[" + elemType + "]";
});
}...
Type.fromArray = function (arr) {
if (!isArray.check(arr)) {
throw new Error("");
}
if (arr.length !== 1) {
throw new Error("only one element type is permitted for typed arrays");
}
return toType(arr[0]).arrayOf();
};
Tp.arrayOf = function () {
var elemType = this;
return new Type(function (value, deep) {
return isArray.check(value) && value.every(function (elem) {
return elemType.check(elem, deep);
...assert = function (value, deep) {
if (!this.check(value, deep)) {
var str = shallowStringify(value);
throw new Error(str + " does not match type " + this);
}
return true;
}...
// rest parameters.
if (!node.rest) {
return;
}
// For the purposes of this example, we won't worry about functions
// with Expression bodies.
n.BlockStatement.assert(node.body);
// Use types.builders to build a variable declaration of the form
//
// var rest = Array.prototype.slice.call(arguments, n);
//
// where `rest` is the name of the rest parameter, and `n` is a
// numeric literal specifying the number of named parameters the
...toString = function () {
var name = this.name;
if (isString.check(name))
return name;
if (isFunction.check(name))
return name.call(this) + "";
return name + " type";
}...
}
} else {
prefix = "t$";
}
// Include this.depth in the name to make sure the name does not
// collide with any variables in nested/enclosing scopes.
prefix += this.depth.toString(36) + "$";
this.scan();
var index = 0;
while (this.declares(prefix + index)) {
++index;
}
...function astNodesAreEquivalent(a, b, problemPath) {
if (isArray.check(problemPath)) {
problemPath.length = 0;
} else {
problemPath = null;
}
return areEquivalent(a, b, problemPath);
}n/a
assert = function (a, b) {
var problemPath = [];
if (!astNodesAreEquivalent(a, b, problemPath)) {
if (problemPath.length === 0) {
if (a !== b) {
throw new Error("Nodes must be equal");
}
} else {
throw new Error(
"Nodes differ in the following path: " +
problemPath.map(subscriptForProperty).join("")
);
}
}
}...
// rest parameters.
if (!node.rest) {
return;
}
// For the purposes of this example, we won't worry about functions
// with Expression bodies.
n.BlockStatement.assert(node.body);
// Use types.builders to build a variable declaration of the form
//
// var rest = Array.prototype.slice.call(arguments, n);
//
// where `rest` is the name of the rest parameter, and `n` is a
// numeric literal specifying the number of named parameters the
...anyTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
arrayExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
arrayPattern = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
arrayStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
arrayTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
arrowFunctionExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
arrowFunctionStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
assignmentExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
assignmentPattern = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
assignmentStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
awaitExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
awaitStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
binaryExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
// arguments, as named by .build("name", "program") above.
var main = b.file("main.js", b.program([
// Pointless program contents included for extra color.
b.functionDeclaration(b.identifier("succ"), [
b.identifier("x")
], b.blockStatement([
b.returnStatement(
b.binaryExpression(
"+", b.identifier("x"), b.literal(1)
)
)
]))
]));
assert.strictEqual(main.name, "main.js");
...binaryStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
bindExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
bindStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
block = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
blockStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
---
```js
var assert = require("assert");
var n = require("ast-types").namedTypes;
var b = require("ast-types").builders;
var fooId = b.identifier("foo");
var ifFoo = b.ifStatement(fooId, b.blockStatement([
b.expressionStatement(b.callExpression(fooId, []))
]));
assert.ok(n.IfStatement.check(ifFoo));
assert.ok(n.Statement.check(ifFoo));
assert.ok(n.Node.check(ifFoo));
...booleanLiteral = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
booleanLiteralStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
booleanLiteralTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
booleanTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
breakStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
callExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
```js
var assert = require("assert");
var n = require("ast-types").namedTypes;
var b = require("ast-types").builders;
var fooId = b.identifier("foo");
var ifFoo = b.ifStatement(fooId, b.blockStatement([
b.expressionStatement(b.callExpression(fooId, []))
]));
assert.ok(n.IfStatement.check(ifFoo));
assert.ok(n.Statement.check(ifFoo));
assert.ok(n.Node.check(ifFoo));
assert.ok(n.BlockStatement.check(ifFoo.consequent));
...callStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
catchClause = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
classBody = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
classDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
classExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
classImplements = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
classMethod = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
classProperty = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
classPropertyDefinition = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
classStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
commentBlock = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
commentLine = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
comprehensionBlock = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
comprehensionExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
comprehensionStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
conditionalExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
conditionalStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
continueStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
debuggerStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareClass = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareExportAllDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareExportDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareFunction = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareInterface = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareModule = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareModuleExports = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareTypeAlias = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
declareVariable = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
decorator = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
directive = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
directiveLiteral = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
directiveLiteralStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
doExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
doStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
doWhileStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
emptyStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
emptyTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
existentialTypeParam = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
existsTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
exportAllDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
exportBatchSpecifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
exportDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
exportDefaultDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
exportDefaultSpecifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
exportNamedDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
exportNamespaceSpecifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
exportSpecifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
expressionStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
```js
var assert = require("assert");
var n = require("ast-types").namedTypes;
var b = require("ast-types").builders;
var fooId = b.identifier("foo");
var ifFoo = b.ifStatement(fooId, b.blockStatement([
b.expressionStatement(b.callExpression(fooId, []))
]));
assert.ok(n.IfStatement.check(ifFoo));
assert.ok(n.Statement.check(ifFoo));
assert.ok(n.Node.check(ifFoo));
assert.ok(n.BlockStatement.check(ifFoo.consequent));
...file = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
// Prevent further modifications to the File type (and any other
// types newly introduced by def(...)).
types.finalize();
// The b.file builder function is now available. It expects two
// arguments, as named by .build("name", "program") above.
var main = b.file("main.js", b.program([
// Pointless program contents included for extra color.
b.functionDeclaration(b.identifier("succ"), [
b.identifier("x")
], b.blockStatement([
b.returnStatement(
b.binaryExpression(
"+", b.identifier("x"), b.literal(1)
...forAwaitStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
forInStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
forOfStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
forStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
functionDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
// types newly introduced by def(...)).
types.finalize();
// The b.file builder function is now available. It expects two
// arguments, as named by .build("name", "program") above.
var main = b.file("main.js", b.program([
// Pointless program contents included for extra color.
b.functionDeclaration(b.identifier("succ"), [
b.identifier("x")
], b.blockStatement([
b.returnStatement(
b.binaryExpression(
"+", b.identifier("x"), b.literal(1)
)
)
...functionExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
functionStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
functionTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
functionTypeParam = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
generatorExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
generatorStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
genericTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
graphExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
graphIndexExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
graphIndexStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
graphStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
identifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
Basic Usage
---
```js
var assert = require("assert");
var n = require("ast-types").namedTypes;
var b = require("ast-types").builders;
var fooId = b.identifier("foo");
var ifFoo = b.ifStatement(fooId, b.blockStatement([
b.expressionStatement(b.callExpression(fooId, []))
]));
assert.ok(n.IfStatement.check(ifFoo));
assert.ok(n.Statement.check(ifFoo));
assert.ok(n.Node.check(ifFoo));
...identifierStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
ifStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
---
```js
var assert = require("assert");
var n = require("ast-types").namedTypes;
var b = require("ast-types").builders;
var fooId = b.identifier("foo");
var ifFoo = b.ifStatement(fooId, b.blockStatement([
b.expressionStatement(b.callExpression(fooId, []))
]));
assert.ok(n.IfStatement.check(ifFoo));
assert.ok(n.Statement.check(ifFoo));
assert.ok(n.Node.check(ifFoo));
...import = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
importDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
importDefaultSpecifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
importNamespaceSpecifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
importSpecifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
importStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
interfaceDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
interfaceExtends = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
intersectionTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxAttribute = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxClosingElement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxElement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxElementStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
jsxEmptyExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxEmptyStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
jsxExpressionContainer = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxExpressionContainerStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
jsxIdentifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxIdentifierStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
jsxMemberExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxMemberStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
jsxNamespacedName = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxOpeningElement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxSpreadAttribute = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxSpreadChild = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxSpreadChildStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
jsxText = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
jsxTextStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
labeledStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
letExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
letStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
line = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
literal = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
// numeric literal specifying the number of named parameters the
// function takes.
var restVarDecl = b.variableDeclaration("var", [
b.variableDeclarator(
node.rest,
b.callExpression(sliceExpr, [
b.identifier("arguments"),
b.literal(node.params.length)
])
)
]);
// Similar to doing node.body.body.unshift(restVarDecl), except
// that the other NodePath objects wrapping body statements will
// have their indexes updated to accommodate the new statement.
...literalStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
logicalExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
logicalStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
memberExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
Here's a slightly more involved example of transforming `...rest`
parameters into browser-runnable ES5 JavaScript:
```js
var b = types.builders;
// Reuse the same AST structure for Array.prototype.slice.call.
var sliceExpr = b.memberExpression(
b.memberExpression(
b.memberExpression(
b.identifier("Array"),
b.identifier("prototype"),
false
),
b.identifier("slice"),
...memberStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
memberTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
metaProperty = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
metaPropertyStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
methodDefinition = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
mixedTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
newExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
newStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
noop = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
nullLiteral = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
nullLiteralStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
nullLiteralTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
nullTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
nullableTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
numberLiteralTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
numberTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
numericLiteral = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
numericLiteralStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
numericLiteralTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
objectExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
objectMethod = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
objectPattern = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
objectProperty = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
objectStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
objectTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
objectTypeCallProperty = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
objectTypeIndexer = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
objectTypeProperty = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
parenthesizedExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
parenthesizedStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
position = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
program = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
// Prevent further modifications to the File type (and any other
// types newly introduced by def(...)).
types.finalize();
// The b.file builder function is now available. It expects two
// arguments, as named by .build("name", "program") above.
var main = b.file("main.js", b.program([
// Pointless program contents included for extra color.
b.functionDeclaration(b.identifier("succ"), [
b.identifier("x")
], b.blockStatement([
b.returnStatement(
b.binaryExpression(
"+", b.identifier("x"), b.literal(1)
...property = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
propertyPattern = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
qualifiedTypeIdentifier = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
regExpLiteral = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
regExpLiteralStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
restElement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
restProperty = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
returnStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
// The b.file builder function is now available. It expects two
// arguments, as named by .build("name", "program") above.
var main = b.file("main.js", b.program([
// Pointless program contents included for extra color.
b.functionDeclaration(b.identifier("succ"), [
b.identifier("x")
], b.blockStatement([
b.returnStatement(
b.binaryExpression(
"+", b.identifier("x"), b.literal(1)
)
)
]))
]));
...sequenceExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
sequenceStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
sourceLocation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
spreadElement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
spreadElementPattern = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
spreadProperty = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
spreadPropertyPattern = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
stringLiteral = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
stringLiteralStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
stringLiteralTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
stringTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
super = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
superStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
switchCase = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
switchStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
taggedTemplateExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
taggedTemplateStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
templateElement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
templateLiteral = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
templateLiteralStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
thisExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
// Now do some stuff that might rearrange the list, and this replacement
// remains safe:
fifth.replace(newerNode);
// Replace the third element in an array with two new nodes:
path.get("elements", 2).replace(
b.identifier("foo"),
b.thisExpression()
);
// Remove a node and its parent if it would leave a redundant AST node:
//e.g. var t = 1, y =2; removing the `t` and `y` declarators results in `var undefined`.
path.prune(); //returns the closest parent `NodePath`.
// Remove a node from a list of nodes:
...thisStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
thisTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
throwStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
tryStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
tupleTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
typeAlias = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
typeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
typeCastExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
typeCastStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
typeParameter = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
typeParameterDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
typeParameterInstantiation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
typeofTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
unaryExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
var consequent = ifStatement.get('consequent').value;
if (!consequent && !alternate) {
var testExpressionStatement = b.expressionStatement(testExpression);
ifStatement.replace(testExpressionStatement);
} else if (!consequent && alternate) {
var negatedTestExpression = b.unaryExpression('!', testExpression, true);
if (n.UnaryExpression.check(testExpression) && testExpression.operator === '!') {
negatedTestExpression = testExpression.argument;
}
ifStatement.get("test").replace(negatedTestExpression);
ifStatement.get("consequent").replace(alternate);
...unaryStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
unionTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
updateExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
updateStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a
variableDeclaration = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
// Use types.builders to build a variable declaration of the form
//
// var rest = Array.prototype.slice.call(arguments, n);
//
// where `rest` is the name of the rest parameter, and `n` is a
// numeric literal specifying the number of named parameters the
// function takes.
var restVarDecl = b.variableDeclaration("var", [
b.variableDeclarator(
node.rest,
b.callExpression(sliceExpr, [
b.identifier("arguments"),
b.literal(node.params.length)
])
)
...variableDeclarator = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}...
//
// var rest = Array.prototype.slice.call(arguments, n);
//
// where `rest` is the name of the rest parameter, and `n` is a
// numeric literal specifying the number of named parameters the
// function takes.
var restVarDecl = b.variableDeclaration("var", [
b.variableDeclarator(
node.rest,
b.callExpression(sliceExpr, [
b.identifier("arguments"),
b.literal(node.params.length)
])
)
]);
...voidTypeAnnotation = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
whileStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
withStatement = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
yieldExpression = function () {
var args = arguments;
var argc = args.length;
var built = Object.create(nodePrototype);
if (!self.finalized) {
throw new Error(
"attempting to instantiate unfinalized type " +
self.typeName
);
}
function add(param, i) {
if (hasOwn.call(built, param))
return;
var all = self.allFields;
if (!hasOwn.call(all, param)) {
throw new Error("" + param);
}
var field = all[param];
var type = field.type;
var value;
if (isNumber.check(i) && i < argc) {
value = args[i];
} else if (field.defaultFn) {
// Expose the partially-built object to the default
// function as its `this` object.
value = field.defaultFn.call(built);
} else {
var message = "no value or default function given for field " +
JSON.stringify(param) + " of " + self.typeName + "(" +
self.buildParams.map(function (name) {
return all[name];
}).join(", ") + ")";
throw new Error(message);
}
if (!type.check(value)) {
throw new Error(
shallowStringify(value) +
" does not match field " + field +
" of type " + self.typeName
);
}
// TODO Could attach getters and setters here to enforce
// dynamic type safety.
built[param] = value;
}
self.buildParams.forEach(function (param, i) {
add(param, i);
});
Object.keys(self.allFields).forEach(function (param) {
add(param); // Use the default value.
});
// Make sure that the "type" field was filled automatically.
if (built.type !== self.typeName) {
throw new Error("");
}
return built;
}n/a
yieldStatement = function () {
return builders.expressionStatement(wrapped.apply(builders, arguments));
}n/a