vox-core
Version:
Runtime de aplicaciones multiplataforma
1,709 lines (1,405 loc) • 946 kB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.entry = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// alter.js
// MIT licensed, see LICENSE file
// Copyright (c) 2013 Olov Lassus <olov.lassus@gmail.com>
var assert = require("assert");
var stableSort = require("stable");
// fragments is a list of {start: index, end: index, str: string to replace with}
function alter(str, fragments) {
"use strict";
var isArray = Array.isArray || function(v) {
return Object.prototype.toString.call(v) === "[object Array]";
};;
assert(typeof str === "string");
assert(isArray(fragments));
// stableSort isn't in-place so no need to copy array first
var sortedFragments = stableSort(fragments, function(a, b) {
return a.start - b.start;
});
var outs = [];
var pos = 0;
for (var i = 0; i < sortedFragments.length; i++) {
var frag = sortedFragments[i];
assert(pos <= frag.start);
assert(frag.start <= frag.end);
outs.push(str.slice(pos, frag.start));
outs.push(frag.str);
pos = frag.end;
}
if (pos < str.length) {
outs.push(str.slice(pos));
}
return outs.join("");
}
if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
module.exports = alter;
}
},{"assert":65,"stable":60}],2:[function(require,module,exports){
function traverse(root, options) {
"use strict";
options = options || {};
var pre = options.pre;
var post = options.post;
var skipProperty = options.skipProperty;
function visit(node, parent, prop, idx) {
if (!node || typeof node.type !== "string") {
return;
}
var res = undefined;
if (pre) {
res = pre(node, parent, prop, idx);
}
if (res !== false) {
for (var prop in node) {
if (skipProperty ? skipProperty(prop, node) : prop[0] === "$") {
continue;
}
var child = node[prop];
if (Array.isArray(child)) {
for (var i = 0; i < child.length; i++) {
visit(child[i], node, prop, i);
}
} else {
visit(child, node, prop);
}
}
}
if (post) {
post(node, parent, prop, idx);
}
}
visit(root, null);
};
if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
module.exports = traverse;
}
},{}],3:[function(require,module,exports){
require("./es7");
var types = require("../lib/types");
var defaults = require("../lib/shared").defaults;
var def = types.Type.def;
var or = types.Type.or;
def("Noop")
.bases("Node")
.build();
def("DoExpression")
.bases("Expression")
.build("body")
.field("body", [def("Statement")]);
def("Super")
.bases("Expression")
.build();
def("BindExpression")
.bases("Expression")
.build("object", "callee")
.field("object", or(def("Expression"), null))
.field("callee", def("Expression"));
def("Decorator")
.bases("Node")
.build("expression")
.field("expression", def("Expression"));
def("Property")
.field("decorators",
or([def("Decorator")], null),
defaults["null"]);
def("MethodDefinition")
.field("decorators",
or([def("Decorator")], null),
defaults["null"]);
def("MetaProperty")
.bases("Expression")
.build("meta", "property")
.field("meta", def("Identifier"))
.field("property", def("Identifier"));
def("ParenthesizedExpression")
.bases("Expression")
.build("expression")
.field("expression", def("Expression"));
def("ImportSpecifier")
.bases("ModuleSpecifier")
.build("imported", "local")
.field("imported", def("Identifier"));
def("ImportDefaultSpecifier")
.bases("ModuleSpecifier")
.build("local");
def("ImportNamespaceSpecifier")
.bases("ModuleSpecifier")
.build("local");
def("ExportDefaultDeclaration")
.bases("Declaration")
.build("declaration")
.field("declaration", or(def("Declaration"), def("Expression")));
def("ExportNamedDeclaration")
.bases("Declaration")
.build("declaration", "specifiers", "source")
.field("declaration", or(def("Declaration"), null))
.field("specifiers", [def("ExportSpecifier")], defaults.emptyArray)
.field("source", or(def("Literal"), null), defaults["null"]);
def("ExportSpecifier")
.bases("ModuleSpecifier")
.build("local", "exported")
.field("exported", def("Identifier"));
def("ExportNamespaceSpecifier")
.bases("Specifier")
.build("exported")
.field("exported", def("Identifier"));
def("ExportDefaultSpecifier")
.bases("Specifier")
.build("exported")
.field("exported", def("Identifier"));
def("ExportAllDeclaration")
.bases("Declaration")
.build("exported", "source")
.field("exported", or(def("Identifier"), null))
.field("source", def("Literal"));
def("CommentBlock")
.bases("Comment")
.build("value", /*optional:*/ "leading", "trailing");
def("CommentLine")
.bases("Comment")
.build("value", /*optional:*/ "leading", "trailing");
},{"../lib/shared":16,"../lib/types":17,"./es7":7}],4:[function(require,module,exports){
var types = require("../lib/types");
var Type = types.Type;
var def = Type.def;
var or = Type.or;
var shared = require("../lib/shared");
var defaults = shared.defaults;
var geq = shared.geq;
// Abstract supertype of all syntactic entities that are allowed to have a
// .loc field.
def("Printable")
.field("loc", or(
def("SourceLocation"),
null
), defaults["null"], true);
def("Node")
.bases("Printable")
.field("type", String)
.field("comments", or(
[def("Comment")],
null
), defaults["null"], true);
def("SourceLocation")
.build("start", "end", "source")
.field("start", def("Position"))
.field("end", def("Position"))
.field("source", or(String, null), defaults["null"]);
def("Position")
.build("line", "column")
.field("line", geq(1))
.field("column", geq(0));
def("File")
.bases("Node")
.build("program")
.field("program", def("Program"));
def("Program")
.bases("Node")
.build("body")
.field("body", [def("Statement")]);
def("Function")
.bases("Node")
.field("id", or(def("Identifier"), null), defaults["null"])
.field("params", [def("Pattern")])
.field("body", def("BlockStatement"));
def("Statement").bases("Node");
// The empty .build() here means that an EmptyStatement can be constructed
// (i.e. it's not abstract) but that it needs no arguments.
def("EmptyStatement").bases("Statement").build();
def("BlockStatement")
.bases("Statement")
.build("body")
.field("body", [def("Statement")]);
// TODO Figure out how to silently coerce Expressions to
// ExpressionStatements where a Statement was expected.
def("ExpressionStatement")
.bases("Statement")
.build("expression")
.field("expression", def("Expression"));
def("IfStatement")
.bases("Statement")
.build("test", "consequent", "alternate")
.field("test", def("Expression"))
.field("consequent", def("Statement"))
.field("alternate", or(def("Statement"), null), defaults["null"]);
def("LabeledStatement")
.bases("Statement")
.build("label", "body")
.field("label", def("Identifier"))
.field("body", def("Statement"));
def("BreakStatement")
.bases("Statement")
.build("label")
.field("label", or(def("Identifier"), null), defaults["null"]);
def("ContinueStatement")
.bases("Statement")
.build("label")
.field("label", or(def("Identifier"), null), defaults["null"]);
def("WithStatement")
.bases("Statement")
.build("object", "body")
.field("object", def("Expression"))
.field("body", def("Statement"));
def("SwitchStatement")
.bases("Statement")
.build("discriminant", "cases", "lexical")
.field("discriminant", def("Expression"))
.field("cases", [def("SwitchCase")])
.field("lexical", Boolean, defaults["false"]);
def("ReturnStatement")
.bases("Statement")
.build("argument")
.field("argument", or(def("Expression"), null));
def("ThrowStatement")
.bases("Statement")
.build("argument")
.field("argument", def("Expression"));
def("TryStatement")
.bases("Statement")
.build("block", "handler", "finalizer")
.field("block", def("BlockStatement"))
.field("handler", or(def("CatchClause"), null), function() {
return this.handlers && this.handlers[0] || null;
})
.field("handlers", [def("CatchClause")], function() {
return this.handler ? [this.handler] : [];
}, true) // Indicates this field is hidden from eachField iteration.
.field("guardedHandlers", [def("CatchClause")], defaults.emptyArray)
.field("finalizer", or(def("BlockStatement"), null), defaults["null"]);
def("CatchClause")
.bases("Node")
.build("param", "guard", "body")
.field("param", def("Pattern"))
.field("guard", or(def("Expression"), null), defaults["null"])
.field("body", def("BlockStatement"));
def("WhileStatement")
.bases("Statement")
.build("test", "body")
.field("test", def("Expression"))
.field("body", def("Statement"));
def("DoWhileStatement")
.bases("Statement")
.build("body", "test")
.field("body", def("Statement"))
.field("test", def("Expression"));
def("ForStatement")
.bases("Statement")
.build("init", "test", "update", "body")
.field("init", or(
def("VariableDeclaration"),
def("Expression"),
null))
.field("test", or(def("Expression"), null))
.field("update", or(def("Expression"), null))
.field("body", def("Statement"));
def("ForInStatement")
.bases("Statement")
.build("left", "right", "body")
.field("left", or(
def("VariableDeclaration"),
def("Expression")))
.field("right", def("Expression"))
.field("body", def("Statement"));
def("DebuggerStatement").bases("Statement").build();
def("Declaration").bases("Statement");
def("FunctionDeclaration")
.bases("Function", "Declaration")
.build("id", "params", "body")
.field("id", def("Identifier"));
def("FunctionExpression")
.bases("Function", "Expression")
.build("id", "params", "body");
def("VariableDeclaration")
.bases("Declaration")
.build("kind", "declarations")
.field("kind", or("var", "let", "const"))
.field("declarations", [def("VariableDeclarator")]);
def("VariableDeclarator")
.bases("Node")
.build("id", "init")
.field("id", def("Pattern"))
.field("init", or(def("Expression"), null));
// TODO Are all Expressions really Patterns?
def("Expression").bases("Node", "Pattern");
def("ThisExpression").bases("Expression").build();
def("ArrayExpression")
.bases("Expression")
.build("elements")
.field("elements", [or(def("Expression"), null)]);
def("ObjectExpression")
.bases("Expression")
.build("properties")
.field("properties", [def("Property")]);
// TODO Not in the Mozilla Parser API, but used by Esprima.
def("Property")
.bases("Node") // Want to be able to visit Property Nodes.
.build("kind", "key", "value")
.field("kind", or("init", "get", "set"))
.field("key", or(def("Literal"), def("Identifier")))
.field("value", def("Expression"));
def("SequenceExpression")
.bases("Expression")
.build("expressions")
.field("expressions", [def("Expression")]);
var UnaryOperator = or(
"-", "+", "!", "~",
"typeof", "void", "delete");
def("UnaryExpression")
.bases("Expression")
.build("operator", "argument", "prefix")
.field("operator", UnaryOperator)
.field("argument", def("Expression"))
// Esprima doesn't bother with this field, presumably because it's
// always true for unary operators.
.field("prefix", Boolean, defaults["true"]);
var BinaryOperator = or(
"==", "!=", "===", "!==",
"<", "<=", ">", ">=",
"<<", ">>", ">>>",
"+", "-", "*", "/", "%",
"&", // TODO Missing from the Parser API.
"|", "^", "in",
"instanceof", "..");
def("BinaryExpression")
.bases("Expression")
.build("operator", "left", "right")
.field("operator", BinaryOperator)
.field("left", def("Expression"))
.field("right", def("Expression"));
var AssignmentOperator = or(
"=", "+=", "-=", "*=", "/=", "%=",
"<<=", ">>=", ">>>=",
"|=", "^=", "&=");
def("AssignmentExpression")
.bases("Expression")
.build("operator", "left", "right")
.field("operator", AssignmentOperator)
.field("left", def("Pattern"))
.field("right", def("Expression"));
var UpdateOperator = or("++", "--");
def("UpdateExpression")
.bases("Expression")
.build("operator", "argument", "prefix")
.field("operator", UpdateOperator)
.field("argument", def("Expression"))
.field("prefix", Boolean);
var LogicalOperator = or("||", "&&");
def("LogicalExpression")
.bases("Expression")
.build("operator", "left", "right")
.field("operator", LogicalOperator)
.field("left", def("Expression"))
.field("right", def("Expression"));
def("ConditionalExpression")
.bases("Expression")
.build("test", "consequent", "alternate")
.field("test", def("Expression"))
.field("consequent", def("Expression"))
.field("alternate", def("Expression"));
def("NewExpression")
.bases("Expression")
.build("callee", "arguments")
.field("callee", def("Expression"))
// The Mozilla Parser API gives this type as [or(def("Expression"),
// null)], but null values don't really make sense at the call site.
// TODO Report this nonsense.
.field("arguments", [def("Expression")]);
def("CallExpression")
.bases("Expression")
.build("callee", "arguments")
.field("callee", def("Expression"))
// See comment for NewExpression above.
.field("arguments", [def("Expression")]);
def("MemberExpression")
.bases("Expression")
.build("object", "property", "computed")
.field("object", def("Expression"))
.field("property", or(def("Identifier"), def("Expression")))
.field("computed", Boolean, defaults["false"]);
def("Pattern").bases("Node");
def("SwitchCase")
.bases("Node")
.build("test", "consequent")
.field("test", or(def("Expression"), null))
.field("consequent", [def("Statement")]);
def("Identifier")
// But aren't Expressions and Patterns already Nodes? TODO Report this.
.bases("Node", "Expression", "Pattern")
.build("name")
.field("name", String);
def("Literal")
// But aren't Expressions already Nodes? TODO Report this.
.bases("Node", "Expression")
.build("value")
.field("value", or(String, Boolean, null, Number, RegExp))
.field("regex", or({
pattern: String,
flags: String
}, null), function() {
if (this.value instanceof RegExp) {
var flags = "";
if (this.value.ignoreCase) flags += "i";
if (this.value.multiline) flags += "m";
if (this.value.global) flags += "g";
return {
pattern: this.value.source,
flags: flags
};
}
return null;
});
// Abstract (non-buildable) comment supertype. Not a Node.
def("Comment")
.bases("Printable")
.field("value", String)
// A .leading comment comes before the node, whereas a .trailing
// comment comes after it. These two fields should not both be true,
// but they might both be false when the comment falls inside a node
// and the node has no children for the comment to lead or trail,
// e.g. { /*dangling*/ }.
.field("leading", Boolean, defaults["true"])
.field("trailing", Boolean, defaults["false"]);
},{"../lib/shared":16,"../lib/types":17}],5:[function(require,module,exports){
require("./core");
var types = require("../lib/types");
var def = types.Type.def;
var or = types.Type.or;
// Note that none of these types are buildable because the Mozilla Parser
// API doesn't specify any builder functions, and nobody uses E4X anymore.
def("XMLDefaultDeclaration")
.bases("Declaration")
.field("namespace", def("Expression"));
def("XMLAnyName").bases("Expression");
def("XMLQualifiedIdentifier")
.bases("Expression")
.field("left", or(def("Identifier"), def("XMLAnyName")))
.field("right", or(def("Identifier"), def("Expression")))
.field("computed", Boolean);
def("XMLFunctionQualifiedIdentifier")
.bases("Expression")
.field("right", or(def("Identifier"), def("Expression")))
.field("computed", Boolean);
def("XMLAttributeSelector")
.bases("Expression")
.field("attribute", def("Expression"));
def("XMLFilterExpression")
.bases("Expression")
.field("left", def("Expression"))
.field("right", def("Expression"));
def("XMLElement")
.bases("XML", "Expression")
.field("contents", [def("XML")]);
def("XMLList")
.bases("XML", "Expression")
.field("contents", [def("XML")]);
def("XML").bases("Node");
def("XMLEscape")
.bases("XML")
.field("expression", def("Expression"));
def("XMLText")
.bases("XML")
.field("text", String);
def("XMLStartTag")
.bases("XML")
.field("contents", [def("XML")]);
def("XMLEndTag")
.bases("XML")
.field("contents", [def("XML")]);
def("XMLPointTag")
.bases("XML")
.field("contents", [def("XML")]);
def("XMLName")
.bases("XML")
.field("contents", or(String, [def("XML")]));
def("XMLAttribute")
.bases("XML")
.field("value", String);
def("XMLCdata")
.bases("XML")
.field("contents", String);
def("XMLComment")
.bases("XML")
.field("contents", String);
def("XMLProcessingInstruction")
.bases("XML")
.field("target", String)
.field("contents", or(String, null));
},{"../lib/types":17,"./core":4}],6:[function(require,module,exports){
require("./core");
var types = require("../lib/types");
var def = types.Type.def;
var or = types.Type.or;
var defaults = require("../lib/shared").defaults;
def("Function")
.field("generator", Boolean, defaults["false"])
.field("expression", Boolean, defaults["false"])
.field("defaults", [or(def("Expression"), null)], defaults.emptyArray)
// TODO This could be represented as a RestElement in .params.
.field("rest", or(def("Identifier"), null), defaults["null"]);
// The ESTree way of representing a ...rest parameter.
def("RestElement")
.bases("Pattern")
.build("argument")
.field("argument", def("Pattern"));
def("SpreadElementPattern")
.bases("Pattern")
.build("argument")
.field("argument", def("Pattern"));
def("FunctionDeclaration")
.build("id", "params", "body", "generator", "expression");
def("FunctionExpression")
.build("id", "params", "body", "generator", "expression");
// The Parser API calls this ArrowExpression, but Esprima and all other
// actual parsers use ArrowFunctionExpression.
def("ArrowFunctionExpression")
.bases("Function", "Expression")
.build("params", "body", "expression")
// The forced null value here is compatible with the overridden
// definition of the "id" field in the Function interface.
.field("id", null, defaults["null"])
// Arrow function bodies are allowed to be expressions.
.field("body", or(def("BlockStatement"), def("Expression")))
// The current spec forbids arrow generators, so I have taken the
// liberty of enforcing that. TODO Report this.
.field("generator", false, defaults["false"]);
def("YieldExpression")
.bases("Expression")
.build("argument", "delegate")
.field("argument", or(def("Expression"), null))
.field("delegate", Boolean, defaults["false"]);
def("GeneratorExpression")
.bases("Expression")
.build("body", "blocks", "filter")
.field("body", def("Expression"))
.field("blocks", [def("ComprehensionBlock")])
.field("filter", or(def("Expression"), null));
def("ComprehensionExpression")
.bases("Expression")
.build("body", "blocks", "filter")
.field("body", def("Expression"))
.field("blocks", [def("ComprehensionBlock")])
.field("filter", or(def("Expression"), null));
def("ComprehensionBlock")
.bases("Node")
.build("left", "right", "each")
.field("left", def("Pattern"))
.field("right", def("Expression"))
.field("each", Boolean);
def("Property")
.field("key", or(def("Literal"), def("Identifier"), def("Expression")))
.field("value", or(def("Expression"), def("Pattern")))
.field("method", Boolean, defaults["false"])
.field("shorthand", Boolean, defaults["false"])
.field("computed", Boolean, defaults["false"]);
def("PropertyPattern")
.bases("Pattern")
.build("key", "pattern")
.field("key", or(def("Literal"), def("Identifier"), def("Expression")))
.field("pattern", def("Pattern"))
.field("computed", Boolean, defaults["false"]);
def("ObjectPattern")
.bases("Pattern")
.build("properties")
.field("properties", [or(def("PropertyPattern"), def("Property"))]);
def("ArrayPattern")
.bases("Pattern")
.build("elements")
.field("elements", [or(def("Pattern"), null)]);
def("MethodDefinition")
.bases("Declaration")
.build("kind", "key", "value", "static")
.field("kind", or("constructor", "method", "get", "set"))
.field("key", or(def("Literal"), def("Identifier"), def("Expression")))
.field("value", def("Function"))
.field("computed", Boolean, defaults["false"])
.field("static", Boolean, defaults["false"]);
def("SpreadElement")
.bases("Node")
.build("argument")
.field("argument", def("Expression"));
def("ArrayExpression")
.field("elements", [or(
def("Expression"),
def("SpreadElement"),
def("RestElement"),
null
)]);
def("NewExpression")
.field("arguments", [or(def("Expression"), def("SpreadElement"))]);
def("CallExpression")
.field("arguments", [or(def("Expression"), def("SpreadElement"))]);
// Note: this node type is *not* an AssignmentExpression with a Pattern on
// the left-hand side! The existing AssignmentExpression type already
// supports destructuring assignments. AssignmentPattern nodes may appear
// wherever a Pattern is allowed, and the right-hand side represents a
// default value to be destructured against the left-hand side, if no
// value is otherwise provided. For example: default parameter values.
def("AssignmentPattern")
.bases("Pattern")
.build("left", "right")
.field("left", def("Pattern"))
.field("right", def("Expression"));
var ClassBodyElement = or(
def("MethodDefinition"),
def("VariableDeclarator"),
def("ClassPropertyDefinition"),
def("ClassProperty")
);
def("ClassProperty")
.bases("Declaration")
.build("key")
.field("key", or(def("Literal"), def("Identifier"), def("Expression")))
.field("computed", Boolean, defaults["false"]);
def("ClassPropertyDefinition") // static property
.bases("Declaration")
.build("definition")
// Yes, Virginia, circular definitions are permitted.
.field("definition", ClassBodyElement);
def("ClassBody")
.bases("Declaration")
.build("body")
.field("body", [ClassBodyElement]);
def("ClassDeclaration")
.bases("Declaration")
.build("id", "body", "superClass")
.field("id", or(def("Identifier"), null))
.field("body", def("ClassBody"))
.field("superClass", or(def("Expression"), null), defaults["null"]);
def("ClassExpression")
.bases("Expression")
.build("id", "body", "superClass")
.field("id", or(def("Identifier"), null), defaults["null"])
.field("body", def("ClassBody"))
.field("superClass", or(def("Expression"), null), defaults["null"])
.field("implements", [def("ClassImplements")], defaults.emptyArray);
def("ClassImplements")
.bases("Node")
.build("id")
.field("id", def("Identifier"))
.field("superClass", or(def("Expression"), null), defaults["null"]);
// Specifier and ModuleSpecifier are abstract non-standard types
// introduced for definitional convenience.
def("Specifier").bases("Node");
// This supertype is shared/abused by both def/babel.js and
// def/esprima.js. In the future, it will be possible to load only one set
// of definitions appropriate for a given parser, but until then we must
// rely on default functions to reconcile the conflicting AST formats.
def("ModuleSpecifier")
.bases("Specifier")
// This local field is used by Babel/Acorn. It should not technically
// be optional in the Babel/Acorn AST format, but it must be optional
// in the Esprima AST format.
.field("local", or(def("Identifier"), null), defaults["null"])
// The id and name fields are used by Esprima. The id field should not
// technically be optional in the Esprima AST format, but it must be
// optional in the Babel/Acorn AST format.
.field("id", or(def("Identifier"), null), defaults["null"])
.field("name", or(def("Identifier"), null), defaults["null"]);
def("TaggedTemplateExpression")
.bases("Expression")
.build("tag", "quasi")
.field("tag", def("Expression"))
.field("quasi", def("TemplateLiteral"));
def("TemplateLiteral")
.bases("Expression")
.build("quasis", "expressions")
.field("quasis", [def("TemplateElement")])
.field("expressions", [def("Expression")]);
def("TemplateElement")
.bases("Node")
.build("value", "tail")
.field("value", {"cooked": String, "raw": String})
.field("tail", Boolean);
},{"../lib/shared":16,"../lib/types":17,"./core":4}],7:[function(require,module,exports){
require("./es6");
var types = require("../lib/types");
var def = types.Type.def;
var or = types.Type.or;
var builtin = types.builtInTypes;
var defaults = require("../lib/shared").defaults;
def("Function")
.field("async", Boolean, defaults["false"]);
def("SpreadProperty")
.bases("Node")
.build("argument")
.field("argument", def("Expression"));
def("ObjectExpression")
.field("properties", [or(def("Property"), def("SpreadProperty"))]);
def("SpreadPropertyPattern")
.bases("Pattern")
.build("argument")
.field("argument", def("Pattern"));
def("ObjectPattern")
.field("properties", [or(
def("Property"),
def("PropertyPattern"),
def("SpreadPropertyPattern")
)]);
def("AwaitExpression")
.bases("Expression")
.build("argument", "all")
.field("argument", or(def("Expression"), null))
.field("all", Boolean, defaults["false"]);
},{"../lib/shared":16,"../lib/types":17,"./es6":6}],8:[function(require,module,exports){
require("./es7");
var types = require("../lib/types");
var defaults = require("../lib/shared").defaults;
var def = types.Type.def;
var or = types.Type.or;
def("VariableDeclaration")
.field("declarations", [or(
def("VariableDeclarator"),
def("Identifier") // Esprima deviation.
)]);
def("Property")
.field("value", or(
def("Expression"),
def("Pattern") // Esprima deviation.
));
def("ArrayPattern")
.field("elements", [or(
def("Pattern"),
def("SpreadElement"),
null
)]);
def("ObjectPattern")
.field("properties", [or(
def("Property"),
def("PropertyPattern"),
def("SpreadPropertyPattern"),
def("SpreadProperty") // Used by Esprima.
)]);
// Like ModuleSpecifier, except type:"ExportSpecifier" and buildable.
// export {<id [as name]>} [from ...];
def("ExportSpecifier")
.bases("ModuleSpecifier")
.build("id", "name");
// export <*> from ...;
def("ExportBatchSpecifier")
.bases("Specifier")
.build();
// Like ModuleSpecifier, except type:"ImportSpecifier" and buildable.
// import {<id [as name]>} from ...;
def("ImportSpecifier")
.bases("ModuleSpecifier")
.build("id", "name");
// import <* as id> from ...;
def("ImportNamespaceSpecifier")
.bases("ModuleSpecifier")
.build("id");
// import <id> from ...;
def("ImportDefaultSpecifier")
.bases("ModuleSpecifier")
.build("id");
def("ExportDeclaration")
.bases("Declaration")
.build("default", "declaration", "specifiers", "source")
.field("default", Boolean)
.field("declaration", or(
def("Declaration"),
def("Expression"), // Implies default.
null
))
.field("specifiers", [or(
def("ExportSpecifier"),
def("ExportBatchSpecifier")
)], defaults.emptyArray)
.field("source", or(
def("Literal"),
null
), defaults["null"]);
def("ImportDeclaration")
.bases("Declaration")
.build("specifiers", "source")
.field("specifiers", [or(
def("ImportSpecifier"),
def("ImportNamespaceSpecifier"),
def("ImportDefaultSpecifier")
)], defaults.emptyArray)
.field("source", def("Literal"));
def("Block")
.bases("Comment")
.build("value", /*optional:*/ "leading", "trailing");
def("Line")
.bases("Comment")
.build("value", /*optional:*/ "leading", "trailing");
},{"../lib/shared":16,"../lib/types":17,"./es7":7}],9:[function(require,module,exports){
require("./es7");
var types = require("../lib/types");
var def = types.Type.def;
var or = types.Type.or;
var defaults = require("../lib/shared").defaults;
def("JSXAttribute")
.bases("Node")
.build("name", "value")
.field("name", or(def("JSXIdentifier"), def("JSXNamespacedName")))
.field("value", or(
def("Literal"), // attr="value"
def("JSXExpressionContainer"), // attr={value}
null // attr= or just attr
), defaults["null"]);
def("JSXIdentifier")
.bases("Identifier")
.build("name")
.field("name", String);
def("JSXNamespacedName")
.bases("Node")
.build("namespace", "name")
.field("namespace", def("JSXIdentifier"))
.field("name", def("JSXIdentifier"));
def("JSXMemberExpression")
.bases("MemberExpression")
.build("object", "property")
.field("object", or(def("JSXIdentifier"), def("JSXMemberExpression")))
.field("property", def("JSXIdentifier"))
.field("computed", Boolean, defaults.false);
var JSXElementName = or(
def("JSXIdentifier"),
def("JSXNamespacedName"),
def("JSXMemberExpression")
);
def("JSXSpreadAttribute")
.bases("Node")
.build("argument")
.field("argument", def("Expression"));
var JSXAttributes = [or(
def("JSXAttribute"),
def("JSXSpreadAttribute")
)];
def("JSXExpressionContainer")
.bases("Expression")
.build("expression")
.field("expression", def("Expression"));
def("JSXElement")
.bases("Expression")
.build("openingElement", "closingElement", "children")
.field("openingElement", def("JSXOpeningElement"))
.field("closingElement", or(def("JSXClosingElement"), null), defaults["null"])
.field("children", [or(
def("JSXElement"),
def("JSXExpressionContainer"),
def("JSXText"),
def("Literal") // TODO Esprima should return JSXText instead.
)], defaults.emptyArray)
.field("name", JSXElementName, function() {
// Little-known fact: the `this` object inside a default function
// is none other than the partially-built object itself, and any
// fields initialized directly from builder function arguments
// (like openingElement, closingElement, and children) are
// guaranteed to be available.
return this.openingElement.name;
}, true) // hidden from traversal
.field("selfClosing", Boolean, function() {
return this.openingElement.selfClosing;
}, true) // hidden from traversal
.field("attributes", JSXAttributes, function() {
return this.openingElement.attributes;
}, true); // hidden from traversal
def("JSXOpeningElement")
.bases("Node") // TODO Does this make sense? Can't really be an JSXElement.
.build("name", "attributes", "selfClosing")
.field("name", JSXElementName)
.field("attributes", JSXAttributes, defaults.emptyArray)
.field("selfClosing", Boolean, defaults["false"]);
def("JSXClosingElement")
.bases("Node") // TODO Same concern.
.build("name")
.field("name", JSXElementName);
def("JSXText")
.bases("Literal")
.build("value")
.field("value", String);
def("JSXEmptyExpression").bases("Expression").build();
// Type Annotations
def("Type").bases("Node");
def("AnyTypeAnnotation")
.bases("Type")
.build();
def("MixedTypeAnnotation")
.bases("Type")
.build();
def("VoidTypeAnnotation")
.bases("Type")
.build();
def("NumberTypeAnnotation")
.bases("Type")
.build();
def("NumberLiteralTypeAnnotation")
.bases("Type")
.build("value", "raw")
.field("value", Number)
.field("raw", String);
def("StringTypeAnnotation")
.bases("Type")
.build();
def("StringLiteralTypeAnnotation")
.bases("Type")
.build("value", "raw")
.field("value", String)
.field("raw", String);
def("BooleanTypeAnnotation")
.bases("Type")
.build();
def("BooleanLiteralTypeAnnotation")
.bases("Type")
.build("value", "raw")
.field("value", Boolean)
.field("raw", String);
def("TypeAnnotation")
.bases("Node")
.build("typeAnnotation")
.field("typeAnnotation", def("Type"));
def("NullableTypeAnnotation")
.bases("Type")
.build("typeAnnotation")
.field("typeAnnotation", def("Type"));
def("FunctionTypeAnnotation")
.bases("Type")
.build("params", "returnType", "rest", "typeParameters")
.field("params", [def("FunctionTypeParam")])
.field("returnType", def("Type"))
.field("rest", or(def("FunctionTypeParam"), null))
.field("typeParameters", or(def("TypeParameterDeclaration"), null));
def("FunctionTypeParam")
.bases("Node")
.build("name", "typeAnnotation", "optional")
.field("name", def("Identifier"))
.field("typeAnnotation", def("Type"))
.field("optional", Boolean);
def("ArrayTypeAnnotation")
.bases("Type")
.build("elementType")
.field("elementType", def("Type"));
def("ObjectTypeAnnotation")
.bases("Type")
.build("properties")
.field("properties", [def("ObjectTypeProperty")])
.field("indexers", [def("ObjectTypeIndexer")], defaults.emptyArray)
.field("callProperties",
[def("ObjectTypeCallProperty")],
defaults.emptyArray);
def("ObjectTypeProperty")
.bases("Node")
.build("key", "value", "optional")
.field("key", or(def("Literal"), def("Identifier")))
.field("value", def("Type"))
.field("optional", Boolean);
def("ObjectTypeIndexer")
.bases("Node")
.build("id", "key", "value")
.field("id", def("Identifier"))
.field("key", def("Type"))
.field("value", def("Type"));
def("ObjectTypeCallProperty")
.bases("Node")
.build("value")
.field("value", def("FunctionTypeAnnotation"))
.field("static", Boolean, false);
def("QualifiedTypeIdentifier")
.bases("Node")
.build("qualification", "id")
.field("qualification",
or(def("Identifier"),
def("QualifiedTypeIdentifier")))
.field("id", def("Identifier"));
def("GenericTypeAnnotation")
.bases("Type")
.build("id", "typeParameters")
.field("id", or(def("Identifier"), def("QualifiedTypeIdentifier")))
.field("typeParameters", or(def("TypeParameterInstantiation"), null));
def("MemberTypeAnnotation")
.bases("Type")
.build("object", "property")
.field("object", def("Identifier"))
.field("property",
or(def("MemberTypeAnnotation"),
def("GenericTypeAnnotation")));
def("UnionTypeAnnotation")
.bases("Type")
.build("types")
.field("types", [def("Type")]);
def("IntersectionTypeAnnotation")
.bases("Type")
.build("types")
.field("types", [def("Type")]);
def("TypeofTypeAnnotation")
.bases("Type")
.build("argument")
.field("argument", def("Type"));
def("Identifier")
.field("typeAnnotation", or(def("TypeAnnotation"), null), defaults["null"]);
def("TypeParameterDeclaration")
.bases("Node")
.build("params")
.field("params", [def("Identifier")]);
def("TypeParameterInstantiation")
.bases("Node")
.build("params")
.field("params", [def("Type")]);
def("Function")
.field("returnType",
or(def("TypeAnnotation"), null),
defaults["null"])
.field("typeParameters",
or(def("TypeParameterDeclaration"), null),
defaults["null"]);
def("ClassProperty")
.build("key", "value", "typeAnnotation", "static")
.field("value", or(def("Expression"), null))
.field("typeAnnotation", or(def("TypeAnnotation"), null))
.field("static", Boolean, defaults["false"]);
def("ClassImplements")
.field("typeParameters",
or(def("TypeParameterInstantiation"), null),
defaults["null"]);
def("InterfaceDeclaration")
.bases("Statement")
.build("id", "body", "extends")
.field("id", def("Identifier"))
.field("typeParameters",
or(def("TypeParameterDeclaration"), null),
defaults["null"])
.field("body", def("ObjectTypeAnnotation"))
.field("extends", [def("InterfaceExtends")]);
def("InterfaceExtends")
.bases("Node")
.build("id")
.field("id", def("Identifier"))
.field("typeParameters", or(def("TypeParameterInstantiation"), null));
def("TypeAlias")
.bases("Statement")
.build("id", "typeParameters", "right")
.field("id", def("Identifier"))
.field("typeParameters", or(def("TypeParameterDeclaration"), null))
.field("right", def("Type"));
def("TypeCastExpression")
.bases("Expression")
.build("expression", "typeAnnotation")
.field("expression", def("Expression"))
.field("typeAnnotation", def("TypeAnnotation"));
def("TupleTypeAnnotation")
.bases("Type")
.build("types")
.field("types", [def("Type")]);
def("DeclareVariable")
.bases("Statement")
.build("id")
.field("id", def("Identifier"));
def("DeclareFunction")
.bases("Statement")
.build("id")
.field("id", def("Identifier"));
def("DeclareClass")
.bases("InterfaceDeclaration")
.build("id");
def("DeclareModule")
.bases("Statement")
.build("id", "body")
.field("id", or(def("Identifier"), def("Literal")))
.field("body", def("BlockStatement"));
},{"../lib/shared":16,"../lib/types":17,"./es7":7}],10:[function(require,module,exports){
require("./core");
var types = require("../lib/types");
var def = types.Type.def;
var or = types.Type.or;
var shared = require("../lib/shared");
var geq = shared.geq;
var defaults = shared.defaults;
def("Function")
// SpiderMonkey allows expression closures: function(x) x+1
.field("body", or(def("BlockStatement"), def("Expression")));
def("ForInStatement")
.build("left", "right", "body", "each")
.field("each", Boolean, defaults["false"]);
def("ForOfStatement")
.bases("Statement")
.build("left", "right", "body")
.field("left", or(
def("VariableDeclaration"),
def("Expression")))
.field("right", def("Expression"))
.field("body", def("Statement"));
def("LetStatement")
.bases("Statement")
.build("head", "body")
// TODO Deviating from the spec by reusing VariableDeclarator here.
.field("head", [def("VariableDeclarator")])
.field("body", def("Statement"));
def("LetExpression")
.bases("Expression")
.build("head", "body")
// TODO Deviating from the spec by reusing VariableDeclarator here.
.field("head", [def("VariableDeclarator")])
.field("body", def("Expression"));
def("GraphExpression")
.bases("Expression")
.build("index", "expression")
.field("index", geq(0))
.field("expression", def("Literal"));
def("GraphIndexExpression")
.bases("Expression")
.build("index")
.field("index", geq(0));
},{"../lib/shared":16,"../lib/types":17,"./core":4}],11:[function(require,module,exports){
var types = require("../main");
var getFieldNames = types.getFieldNames;
var getFieldValue = types.getFieldValue;
var isArray = types.builtInTypes.array;
var isObject = types.builtInTypes.object;
var isDate = types.builtInTypes.Date;
var isRegExp = types.builtInTypes.RegExp;
var hasOwn = Object.prototype.hasOwnProperty;
function astNodesAreEquivalent(a, b, problemPath) {
if (isArray.check(problemPath)) {
problemPath.length = 0;
} else {
problemPath = null;
}
return areEquivalent(a, b, problemPath);
}
astNodesAreEquivalent.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("")
);
}
}
};
function subscriptForProperty(property) {
if (/[_$a-z][_$a-z0-9]*/i.test(property)) {
return "." + property;
}
return "[" + JSON.stringify(property) + "]";
}
function areEquivalent(a, b, problemPath) {
if (a === b) {
return true;
}
if (isArray.check(a)) {
return arraysAreEquivalent(a, b, problemPath);
}
if (isObject.check(a)) {
return objectsAreEquivalent(a, b, problemPath);
}
if (isDate.check(a)) {
return isDate.check(b) && (+a === +b);
}
if (isRegExp.check(a)) {
return isRegExp.check(b) && (
a.source === b.source &&
a.global === b.global &&
a.multiline === b.multiline &&
a.ignoreCase === b.ignoreCase
);
}
return a == b;
}
function arraysAreEquivalent(a, b, problemPath) {
isArray.assert(a);
var aLength = a.length;
if (!isArray.check(b) || b.length !== aLength) {
if (problemPath) {
problemPath.push("length");
}
return false;
}
for (var i = 0; i < aLength; ++i) {
if (problemPath) {
problemPath.push(i);
}
if (i in a !== i in b) {
return false;
}
if (!areEquivalent(a[i], b[i], problemPath)) {
return false;
}
if (problemPath) {
var problemPathTail = problemPath.pop();
if (problemPathTail !== i) {
throw new Error("" + problemPathTail);
}
}
}
return true;
}
function objectsAreEquivalent(a, b, problemPath) {
isObject.assert(a);
if (!isObject.check(b)) {
return false;
}
// Fast path for a common property of AST nodes.
if (a.type !== b.type) {
if (problemPath) {
problemPath.push("type");
}
return false;
}
var aNames = getFieldNames(a);
var aNameCount = aNames.length;
var bNames = getFieldNames(b);
var bNameCount = bNames.length;
if (aNameCount === bNameCount) {
for (var i = 0; i < aNameCount; ++i) {
var name = aNames[i];
var aChild = getFieldValue(a, name);
var bChild = getFieldValue(b, name);
if (problemPath) {
problemPath.push(name);
}
if (!areEquivalent(aChild, bChild, problemPath)) {
return false;
}
if (problemPath) {
var problemPathTail = problemPath.pop();
if (problemPathTail !== name) {
throw new Error("" + problemPathTail);
}
}
}
return true;
}
if (!problemPath) {
return false;
}
// Since aNameCount !== bNameCount, we need to find some name that's
// missing in aNames but present in bNames, or vice-versa.
var seenNames = Object.create(null);
for (i = 0; i < aNameCount; ++i) {
seenNames[aNames[i]] = true;
}
for (i = 0; i < bNameCount; ++i) {
name = bNames[i];
if (!hasOwn.call(seenNames, name)) {
problemPath.push(name);
return false;
}
delete seenNames[name];
}
for (name in seenNames) {
problemPath.push(name);
break;
}
return false;
}
module.exports = astNodesAreEquivalent;
},{"../main":18}],12:[function(require,module,exports){
var types = require("./types");
var n = types.namedTypes;
var b = types.builders;
var isNumber = types.builtInTypes.number;
var isArray = types.builtInTypes.array;
var Path = require("./path");
var Scope = require("./scope");
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);
}
var NPp = NodePath.prototype = Object.create(Path.prototype, {
constructor: {
value: NodePath,
enumerable: false,
writable: true,
configurable: true
}
});
Object.defineProperties(NPp, {
node: {
get: function() {
Object.defineProperty(this, "node", {
configurable: true, // Enable deletion.
value: this._computeNode()
});
return this.node;
}
},
parent: {
get: function() {
Object.defineProperty(this, "parent", {
configurable: true, // Enable deletion.
value: this._computeParent()
});
return this.parent;
}
},
scope: {
get: function() {
Object.defineProperty(this, "scope", {
configurable: true, // Enable deletion.
value: this._computeScope()
});
return this.scope;
}
}
});
NPp.replace = function() {
delete this.node;
delete this.parent;
delete this.scope;
return Path.prototype.replace.apply(this, arguments);
};
NPp.prune = function() {
var remainingNodePath = this.parent;
this.replace();
return cleanUpNodesAfterPrune(remainingNodePath);
};
// The value of the first ancestor Path whose value is a Node.
NPp._computeNode = function() {
var value = this.value;
if (n.Node.check(value)) {
return value;
}
var pp = this.parentPath;
return pp && pp.node || null;
};
// The first ancestor Path whose value is a Node distinct from this.node.
NPp._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;
};
// The closest enclosing scope that governs this node.
NPp._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;
};
NPp.getValueProperty = function(name) {
return types.getFieldValue(this.value, name);
};
/**
* Determine whether this.node needs to be wrapped in parentheses in order
* for a parser to reproduce the same local AST structure.
*
* For instance, in the expression `(1 + 2) * 3`, the BinaryExpression
* whose operator is "+" needs parentheses, because `1 + 2 * 3` would
* parse differently.
*
* If assumeExpressionContext === true, we don't worry about edge cases
* like an anonymous FunctionExpression appearing lexically first in its
* enclosing statement and thus needing parentheses to avoid being parsed
* as a FunctionDeclaration with a miss