first commit
This commit is contained in:
5
build/node_modules/hydrolysis/LICENSE
generated
vendored
Normal file
5
build/node_modules/hydrolysis/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
38
build/node_modules/hydrolysis/README.md
generated
vendored
Normal file
38
build/node_modules/hydrolysis/README.md
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
[](https://npmjs.org/package/hydrolysis)
|
||||
[](https://travis-ci.org/Polymer/hydrolysis)
|
||||
# hydrolysis
|
||||
|
||||
Static analysis utilities for polymer.
|
||||
|
||||
## Install
|
||||
```
|
||||
npm install hydrolysis
|
||||
```
|
||||
|
||||
## Usage
|
||||
```js
|
||||
var hyd = require('hydrolysis');
|
||||
|
||||
hyd.Analyzer.analyze('path-to-polymer-element.html')
|
||||
.then(function(analyzer) {
|
||||
console.log(analyzer.elementsByTagName['my-element'])
|
||||
});
|
||||
```
|
||||
|
||||
For more detail, see the [API Docs](API.md).
|
||||
|
||||
|
||||
## Developing
|
||||
You need [wct](https://github.com/Polymer/web-component-tester) to run the tests.
|
||||
|
||||
Run a one-off build of the project:
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
|
||||
Or watch the source for changes, and rebuild each time a file is modified:
|
||||
|
||||
```sh
|
||||
npm run watch
|
||||
```
|
||||
29
build/node_modules/hydrolysis/index.js
generated
vendored
Normal file
29
build/node_modules/hydrolysis/index.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
/*jslint node: true */
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Static analysis for Polymer.
|
||||
* @namespace hydrolysis
|
||||
*/
|
||||
module.exports = {
|
||||
Analyzer: require('./lib/analyzer'),
|
||||
docs: require('./lib/ast-utils/docs'),
|
||||
FSResolver: require('./lib/loader/fs-resolver'),
|
||||
jsdoc: require('./lib/ast-utils/jsdoc'),
|
||||
Loader: require('./lib/loader/file-loader'),
|
||||
NoopResolver: require('./lib/loader/noop-resolver'),
|
||||
RedirectResolver: require('./lib/loader/redirect-resolver'),
|
||||
XHRResolver: require('./lib/loader/xhr-resolver'),
|
||||
StringResolver: require('./lib/loader/string-resolver'),
|
||||
_jsParse: require('./lib/ast-utils/js-parse'),
|
||||
_importParse: require('./lib/ast-utils/import-parse'),
|
||||
};
|
||||
773
build/node_modules/hydrolysis/lib/analyzer.js
generated
vendored
Normal file
773
build/node_modules/hydrolysis/lib/analyzer.js
generated
vendored
Normal file
@@ -0,0 +1,773 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
// jshint -W079
|
||||
var Promise = global.Promise || require('es6-promise').Promise;
|
||||
// jshint +W079
|
||||
|
||||
var dom5 = require('dom5');
|
||||
var url = require('url');
|
||||
|
||||
var docs = require('./ast-utils/docs');
|
||||
var FileLoader = require('./loader/file-loader');
|
||||
var importParse = require('./ast-utils/import-parse');
|
||||
var jsParse = require('./ast-utils/js-parse');
|
||||
var NoopResolver = require('./loader/noop-resolver');
|
||||
var StringResolver = require('./loader/string-resolver');
|
||||
|
||||
function reduceMetadata(m1, m2) {
|
||||
return {
|
||||
elements: m1.elements.concat(m2.elements),
|
||||
features: m1.features.concat(m2.features),
|
||||
behaviors: m1.behaviors.concat(m2.behaviors),
|
||||
};
|
||||
}
|
||||
|
||||
var EMPTY_METADATA = {elements: [], features: [], behaviors: []};
|
||||
|
||||
/**
|
||||
* Parse5's representation of a parsed html document
|
||||
* @typedef {Object} DocumentAST
|
||||
* @memberof hydrolysis
|
||||
*/
|
||||
|
||||
/**
|
||||
* espree's representation of a parsed html document
|
||||
* @typedef {Object} JSAST
|
||||
* @memberof hydrolysis
|
||||
*/
|
||||
|
||||
/**
|
||||
* Package of a parsed JS script
|
||||
* @typedef {Object} ParsedJS
|
||||
* @property {JSAST} ast The script's AST
|
||||
* @property {DocumentAST} scriptElement If inline, the script's containing tag.
|
||||
* @memberof hydrolysis
|
||||
*/
|
||||
|
||||
/**
|
||||
* The metadata for a single polymer element
|
||||
* @typedef {Object} ElementDescriptor
|
||||
* @memberof hydrolysis
|
||||
*/
|
||||
|
||||
/**
|
||||
* The metadata for a Polymer feature.
|
||||
* @typedef {Object} FeatureDescriptor
|
||||
* @memberof hydrolysis
|
||||
*/
|
||||
|
||||
/**
|
||||
* The metadata for a Polymer behavior mixin.
|
||||
* @typedef {Object} BehaviorDescriptor
|
||||
* @memberof hydrolysis
|
||||
*/
|
||||
|
||||
/**
|
||||
* The metadata for all features and elements defined in one document
|
||||
* @typedef {Object} DocumentDescriptor
|
||||
* @memberof hydrolysis
|
||||
* @property {Array<ElementDescriptor>} elements The elements from the document
|
||||
* @property {Array<FeatureDescriptor>} features The features from the document
|
||||
* @property {Array<FeatureDescriptor>} behaviors The behaviors from the document
|
||||
*/
|
||||
|
||||
/**
|
||||
* The metadata of an entire HTML document, in promises.
|
||||
* @typedef {Object} AnalyzedDocument
|
||||
* @memberof hydrolysis
|
||||
* @property {string} href The url of the document.
|
||||
* @property {Promise<ParsedImport>} htmlLoaded The parsed representation of
|
||||
* the doc. Use the `ast` property to get the full `parse5` ast
|
||||
*
|
||||
* @property {Promise<Array<string>>} depsLoaded Resolves to the list of this
|
||||
* Document's transitive import dependencies
|
||||
*
|
||||
* @property {Array<string>} depHrefs The direct dependencies of the document.
|
||||
*
|
||||
* @property {Promise<DocumentDescriptor>} metadataLoaded Resolves to the list of
|
||||
* this Document's import dependencies
|
||||
*/
|
||||
|
||||
/**
|
||||
* A database of Polymer metadata defined in HTML
|
||||
*
|
||||
* @constructor
|
||||
* @memberOf hydrolysis
|
||||
* @param {boolean} attachAST If true, attach a parse5 compliant AST
|
||||
* @param {FileLoader=} loader An optional `FileLoader` used to load external
|
||||
* resources
|
||||
*/
|
||||
var Analyzer = function Analyzer(attachAST,
|
||||
loader) {
|
||||
this.loader = loader;
|
||||
|
||||
/**
|
||||
* A list of all elements the `Analyzer` has metadata for.
|
||||
* @member {Array.<ElementDescriptor>}
|
||||
*/
|
||||
this.elements = [];
|
||||
|
||||
/**
|
||||
* A view into `elements`, keyed by tag name.
|
||||
* @member {Object.<string,ElementDescriptor>}
|
||||
*/
|
||||
this.elementsByTagName = {};
|
||||
|
||||
/**
|
||||
* A list of API features added to `Polymer.Base` encountered by the
|
||||
* analyzer.
|
||||
* @member {Array<FeatureDescriptor>}
|
||||
*/
|
||||
this.features = [];
|
||||
|
||||
/**
|
||||
* The behaviors collected by the analysis pass.
|
||||
*
|
||||
* @member {Array<BehaviorDescriptor>}
|
||||
*/
|
||||
this.behaviors = [];
|
||||
|
||||
/**
|
||||
* The behaviors collected by the analysis pass by name.
|
||||
*
|
||||
* @member {Object<string,BehaviorDescriptor>}
|
||||
*/
|
||||
this.behaviorsByName = {};
|
||||
|
||||
/**
|
||||
* A map, keyed by absolute path, of Document metadata.
|
||||
* @member {Object<string,AnalyzedDocument>}
|
||||
*/
|
||||
this.html = {};
|
||||
|
||||
/**
|
||||
* A map, keyed by path, of HTML document ASTs.
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parsedDocuments = {};
|
||||
|
||||
/**
|
||||
* A map, keyed by path, of JS script ASTs.
|
||||
*
|
||||
* If the path is an HTML file with multiple scripts, the entry will be an array of scripts.
|
||||
*
|
||||
* @type {Object<string,Array<ParsedJS>>}
|
||||
*/
|
||||
this.parsedScripts = {};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A map, keyed by path, of document content.
|
||||
* @type {Object}
|
||||
*/
|
||||
this._content = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for `Analyzer.analzye`
|
||||
* @typedef {Object} LoadOptions
|
||||
* @memberof hydrolysis
|
||||
* @property {boolean} noAnnotations Whether `annotate()` should be skipped.
|
||||
* @property {String=} content Content to resolve `href` to instead of loading
|
||||
* from the file system.
|
||||
* @property {boolean} clean Whether the generated descriptors should be cleaned
|
||||
* of redundant data.
|
||||
* @property {string=} resolver.
|
||||
* `xhr` to use XMLHttpRequest
|
||||
* `fs` to use the local filesystem.
|
||||
* `permissive` to use the local filesystem and return empty files when a
|
||||
* path can't be found.
|
||||
* Default is `fs` in node and `xhr` in the browser.
|
||||
* @property {function(string): boolean} filter A predicate function that
|
||||
* indicates which files should be ignored by the loader. By default all
|
||||
* files not located under the dirname of `href` will be ignored.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Shorthand for transitively loading and processing all imports beginning at
|
||||
* `href`.
|
||||
*
|
||||
* In order to properly filter paths, `href` _must_ be an absolute URI.
|
||||
*
|
||||
* @param {string} href The root import to begin loading from.
|
||||
* @param {LoadOptions=} options Any additional options for the load.
|
||||
* @return {Promise<Analyzer>} A promise that will resolve once `href` and its
|
||||
* dependencies have been loaded and analyzed.
|
||||
*/
|
||||
Analyzer.analyze = function analyze(href, options) {
|
||||
options = options || {};
|
||||
options.filter = options.filter || _defaultFilter(href);
|
||||
|
||||
var loader = new FileLoader();
|
||||
|
||||
var resolver = options.resolver;
|
||||
if (resolver === undefined) {
|
||||
if (typeof window === 'undefined') {
|
||||
resolver = 'fs';
|
||||
} else {
|
||||
resolver = 'xhr';
|
||||
}
|
||||
}
|
||||
var PrimaryResolver;
|
||||
if (resolver === 'fs') {
|
||||
PrimaryResolver = require('./loader/fs-resolver');
|
||||
} else if (resolver === 'xhr') {
|
||||
PrimaryResolver = require('./loader/xhr-resolver');
|
||||
} else if (resolver === 'permissive') {
|
||||
PrimaryResolver = require('./loader/error-swallowing-fs-resolver');
|
||||
} else {
|
||||
throw new Error("Resolver must be one of 'fs' or 'xhr'");
|
||||
}
|
||||
|
||||
loader.addResolver(new PrimaryResolver(options));
|
||||
if (options.content) {
|
||||
loader.addResolver(new StringResolver({url: href, content: options.content}));
|
||||
}
|
||||
loader.addResolver(new NoopResolver({test: options.filter}));
|
||||
|
||||
var analyzer = new this(null, loader);
|
||||
return analyzer.metadataTree(href).then(function(root) {
|
||||
if (!options.noAnnotations) {
|
||||
analyzer.annotate();
|
||||
}
|
||||
if (options.clean) {
|
||||
analyzer.clean();
|
||||
}
|
||||
return Promise.resolve(analyzer);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} href
|
||||
* @return {function(string): boolean}
|
||||
*/
|
||||
function _defaultFilter(href) {
|
||||
// Everything up to the last `/` or `\`.
|
||||
var base = href.match(/^(.*?)[^\/\\]*$/)[1];
|
||||
return function(uri) {
|
||||
return uri.indexOf(base) !== 0;
|
||||
};
|
||||
}
|
||||
|
||||
Analyzer.prototype.load = function load(href) {
|
||||
return this.loader.request(href).then(function(content) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
this._content[href] = content;
|
||||
resolve(this._parseHTML(content, href));
|
||||
}.bind(this), 0);
|
||||
}.bind(this)).catch(function(err){
|
||||
console.error("Error processing document at " + href);
|
||||
throw err;
|
||||
});
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an `AnalyzedDocument` representing the provided document
|
||||
* @private
|
||||
* @param {string} htmlImport Raw text of an HTML document
|
||||
* @param {string} href The document's URL.
|
||||
* @return {AnalyzedDocument} An `AnalyzedDocument`
|
||||
*/
|
||||
Analyzer.prototype._parseHTML = function _parseHTML(htmlImport,
|
||||
href) {
|
||||
if (href in this.html) {
|
||||
return this.html[href];
|
||||
}
|
||||
var depsLoaded = [];
|
||||
var depHrefs = [];
|
||||
var metadataLoaded = Promise.resolve(EMPTY_METADATA);
|
||||
var parsed;
|
||||
try {
|
||||
parsed = importParse(htmlImport, href);
|
||||
} catch (err) {
|
||||
console.error('Error parsing!');
|
||||
throw err;
|
||||
}
|
||||
var htmlLoaded = Promise.resolve(parsed);
|
||||
if (parsed.script) {
|
||||
metadataLoaded = this._processScripts(parsed.script, href);
|
||||
}
|
||||
var commentText = parsed.comment.map(function(comment){
|
||||
return dom5.getTextContent(comment);
|
||||
});
|
||||
var pseudoElements = docs.parsePseudoElements(commentText);
|
||||
pseudoElements.forEach(function(element){
|
||||
element.contentHref = href;
|
||||
this.elements.push(element);
|
||||
this.elementsByTagName[element.is] = element;
|
||||
}.bind(this));
|
||||
metadataLoaded = metadataLoaded.then(function(metadata){
|
||||
var metadataEntry = {
|
||||
elements: pseudoElements,
|
||||
features: [],
|
||||
behaviors: []
|
||||
};
|
||||
return [metadata, metadataEntry].reduce(reduceMetadata);
|
||||
});
|
||||
depsLoaded.push(metadataLoaded);
|
||||
|
||||
|
||||
if (this.loader) {
|
||||
var baseUri = href;
|
||||
if (parsed.base.length > 1) {
|
||||
console.error("Only one base tag per document!");
|
||||
throw "Multiple base tags in " + href;
|
||||
} else if (parsed.base.length == 1) {
|
||||
var baseHref = dom5.getAttribute(parsed.base[0], "href");
|
||||
if (baseHref) {
|
||||
baseHref = baseHref + "/";
|
||||
baseUri = url.resolve(baseUri, baseHref);
|
||||
}
|
||||
}
|
||||
parsed.import.forEach(function(link) {
|
||||
var linkurl = dom5.getAttribute(link, 'href');
|
||||
if (linkurl) {
|
||||
var resolvedUrl = url.resolve(baseUri, linkurl);
|
||||
depHrefs.push(resolvedUrl);
|
||||
depsLoaded.push(this._dependenciesLoadedFor(resolvedUrl, href));
|
||||
}
|
||||
}.bind(this));
|
||||
parsed.style.forEach(function(styleElement) {
|
||||
if (polymerExternalStyle(styleElement)) {
|
||||
var styleHref = dom5.getAttribute(styleElement, 'href');
|
||||
if (href) {
|
||||
styleHref = url.resolve(baseUri, styleHref);
|
||||
depsLoaded.push(this.loader.request(styleHref).then(function(content){
|
||||
this._content[styleHref] = content;
|
||||
}.bind(this)));
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
depsLoaded = Promise.all(depsLoaded)
|
||||
.then(function() {return depHrefs;})
|
||||
.catch(function(err) {throw err;});
|
||||
this.parsedDocuments[href] = parsed.ast;
|
||||
this.html[href] = {
|
||||
href: href,
|
||||
htmlLoaded: htmlLoaded,
|
||||
metadataLoaded: metadataLoaded,
|
||||
depHrefs: depHrefs,
|
||||
depsLoaded: depsLoaded
|
||||
};
|
||||
return this.html[href];
|
||||
};
|
||||
|
||||
Analyzer.prototype._processScripts = function _processScripts(scripts, href) {
|
||||
var scriptPromises = [];
|
||||
scripts.forEach(function(script) {
|
||||
scriptPromises.push(this._processScript(script, href));
|
||||
}.bind(this));
|
||||
return Promise.all(scriptPromises).then(function(metadataList) {
|
||||
return metadataList.reduce(reduceMetadata, EMPTY_METADATA);
|
||||
});
|
||||
};
|
||||
|
||||
Analyzer.prototype._processScript = function _processScript(script, href) {
|
||||
var src = dom5.getAttribute(script, 'src');
|
||||
var parsedJs;
|
||||
if (!src) {
|
||||
try {
|
||||
parsedJs = jsParse((script.childNodes.length) ? script.childNodes[0].value : '');
|
||||
} catch (err) {
|
||||
// Figure out the correct line number for the error.
|
||||
var line = 0;
|
||||
var col = 0;
|
||||
if (script.__ownerDocument && script.__ownerDocument == href) {
|
||||
line = script.__locationDetail.line - 1;
|
||||
col = script.__locationDetail.column - 1;
|
||||
}
|
||||
line += err.lineNumber;
|
||||
col += err.column;
|
||||
var message = "Error parsing script in " + href + " at " + line + ":" + col;
|
||||
message += "\n" + err.stack;
|
||||
var fixedErr = new Error(message);
|
||||
fixedErr.location = {line: line, column: col};
|
||||
fixedErr.ownerDocument = script.__ownerDocument;
|
||||
return Promise.reject(fixedErr);
|
||||
}
|
||||
if (parsedJs.elements) {
|
||||
parsedJs.elements.forEach(function(element) {
|
||||
element.scriptElement = script;
|
||||
element.contentHref = href;
|
||||
this.elements.push(element);
|
||||
if (element.is in this.elementsByTagName) {
|
||||
console.warn('Ignoring duplicate element definition: ' + element.is);
|
||||
} else {
|
||||
this.elementsByTagName[element.is] = element;
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
if (parsedJs.features) {
|
||||
parsedJs.features.forEach(function(feature){
|
||||
feature.contentHref = href;
|
||||
feature.scriptElement = script;
|
||||
});
|
||||
this.features = this.features.concat(parsedJs.features);
|
||||
}
|
||||
if (parsedJs.behaviors) {
|
||||
parsedJs.behaviors.forEach(function(behavior){
|
||||
behavior.contentHref = href;
|
||||
this.behaviorsByName[behavior.is] = behavior;
|
||||
this.behaviorsByName[behavior.symbol] = behavior;
|
||||
}.bind(this));
|
||||
this.behaviors = this.behaviors.concat(parsedJs.behaviors);
|
||||
}
|
||||
if (!Object.hasOwnProperty.call(this.parsedScripts, href)) {
|
||||
this.parsedScripts[href] = [];
|
||||
}
|
||||
var scriptElement;
|
||||
if (script.__ownerDocument && script.__ownerDocument == href) {
|
||||
scriptElement = script;
|
||||
}
|
||||
this.parsedScripts[href].push({
|
||||
ast: parsedJs.parsedScript,
|
||||
scriptElement: scriptElement
|
||||
});
|
||||
return parsedJs;
|
||||
}
|
||||
if (this.loader) {
|
||||
var resolvedSrc = url.resolve(href, src);
|
||||
return this.loader.request(resolvedSrc).then(function(content) {
|
||||
this._content[resolvedSrc] = content;
|
||||
var resolvedScript = Object.create(script);
|
||||
resolvedScript.childNodes = [{value: content}];
|
||||
resolvedScript.attrs = resolvedScript.attrs.slice();
|
||||
dom5.removeAttribute(resolvedScript, 'src');
|
||||
return this._processScript(resolvedScript, resolvedSrc);
|
||||
}.bind(this)).catch(function(err) {throw err;});
|
||||
} else {
|
||||
return Promise.resolve(EMPTY_METADATA);
|
||||
}
|
||||
};
|
||||
|
||||
Analyzer.prototype._dependenciesLoadedFor = function _dependenciesLoadedFor(href, root) {
|
||||
var found = {};
|
||||
if (root !== undefined) {
|
||||
found[root] = true;
|
||||
}
|
||||
return this._getDependencies(href, found).then(function(deps) {
|
||||
var depMetadataLoaded = [];
|
||||
var depPromises = deps.map(function(depHref){
|
||||
return this.load(depHref).then(function(htmlMonomer) {
|
||||
return htmlMonomer.metadataLoaded;
|
||||
});
|
||||
}.bind(this));
|
||||
return Promise.all(depPromises);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* List all the html dependencies for the document at `href`.
|
||||
* @param {string} href The href to get dependencies for.
|
||||
* @param {Object.<string,boolean>=} found An object keyed by URL of the
|
||||
* already resolved dependencies.
|
||||
* @param {boolean=} transitive Whether to load transitive
|
||||
* dependencies. Defaults to true.
|
||||
* @return {Array.<string>} A list of all the html dependencies.
|
||||
*/
|
||||
Analyzer.prototype._getDependencies = function _getDependencies(href, found, transitive) {
|
||||
if (found === undefined) {
|
||||
found = {};
|
||||
found[href] = true;
|
||||
}
|
||||
if (transitive === undefined) {
|
||||
transitive = true;
|
||||
}
|
||||
var deps = [];
|
||||
return this.load(href).then(function(htmlMonomer) {
|
||||
var transitiveDeps = [];
|
||||
htmlMonomer.depHrefs.forEach(function(depHref){
|
||||
if (found[depHref]) {
|
||||
return;
|
||||
}
|
||||
deps.push(depHref);
|
||||
found[depHref] = true;
|
||||
if (transitive) {
|
||||
transitiveDeps.push(this._getDependencies(depHref, found));
|
||||
}
|
||||
}.bind(this));
|
||||
return Promise.all(transitiveDeps);
|
||||
}.bind(this)).then(function(transitiveDeps) {
|
||||
var alldeps = transitiveDeps.reduce(function(a, b) {
|
||||
return a.concat(b);
|
||||
}, []).concat(deps);
|
||||
return alldeps;
|
||||
});
|
||||
};
|
||||
|
||||
function matchesDocumentFolder(descriptor, href) {
|
||||
if (!descriptor.contentHref) {
|
||||
return false;
|
||||
}
|
||||
var descriptorDoc = url.parse(descriptor.contentHref);
|
||||
if (!descriptorDoc || !descriptorDoc.pathname) {
|
||||
return false;
|
||||
}
|
||||
var searchDoc = url.parse(href);
|
||||
if (!searchDoc || !searchDoc.pathname) {
|
||||
return false;
|
||||
}
|
||||
var searchPath = searchDoc.pathname;
|
||||
var lastSlash = searchPath.lastIndexOf("/");
|
||||
if (lastSlash > 0) {
|
||||
searchPath = searchPath.slice(0, lastSlash);
|
||||
}
|
||||
return descriptorDoc.pathname.indexOf(searchPath) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the elements defined in the folder containing `href`.
|
||||
* @param {string} href path to search.
|
||||
* @return {Array.<ElementDescriptor>}
|
||||
*/
|
||||
Analyzer.prototype.elementsForFolder = function elementsForFolder(href) {
|
||||
return this.elements.filter(function(element){
|
||||
return matchesDocumentFolder(element, href);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the behaviors defined in the folder containing `href`.
|
||||
* @param {string} href path to search.
|
||||
* @return {Array.<BehaviorDescriptor>}
|
||||
*/
|
||||
Analyzer.prototype.behaviorsForFolder = function behaviorsForFolder(href) {
|
||||
return this.behaviors.filter(function(behavior){
|
||||
return matchesDocumentFolder(behavior, href);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves to a POJO representation of the import
|
||||
* tree, in a format that maintains the ordering of the HTML imports spec.
|
||||
* @param {string} href the import to get metadata for.
|
||||
* @return {Promise}
|
||||
*/
|
||||
Analyzer.prototype.metadataTree = function metadataTree(href) {
|
||||
return this.load(href).then(function(monomer){
|
||||
var loadedHrefs = {};
|
||||
loadedHrefs[href] = true;
|
||||
return this._metadataTree(monomer, loadedHrefs);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Analyzer.prototype._metadataTree = function _metadataTree(htmlMonomer,
|
||||
loadedHrefs) {
|
||||
if (loadedHrefs === undefined) {
|
||||
loadedHrefs = {};
|
||||
}
|
||||
return htmlMonomer.metadataLoaded.then(function(metadata) {
|
||||
metadata = {
|
||||
elements: metadata.elements,
|
||||
features: metadata.features,
|
||||
href: htmlMonomer.href
|
||||
};
|
||||
return htmlMonomer.depsLoaded.then(function(hrefs) {
|
||||
var depMetadata = [];
|
||||
hrefs.forEach(function(href) {
|
||||
var metadataPromise = Promise.resolve(true);
|
||||
if (depMetadata.length > 0) {
|
||||
metadataPromise = depMetadata[depMetadata.length - 1];
|
||||
}
|
||||
metadataPromise = metadataPromise.then(function() {
|
||||
if (!loadedHrefs[href]) {
|
||||
loadedHrefs[href] = true;
|
||||
return this._metadataTree(this.html[href], loadedHrefs);
|
||||
} else {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
}.bind(this));
|
||||
depMetadata.push(metadataPromise);
|
||||
}.bind(this));
|
||||
return Promise.all(depMetadata).then(function(importMetadata) {
|
||||
metadata.imports = importMetadata;
|
||||
return htmlMonomer.htmlLoaded.then(function(parsedHtml) {
|
||||
metadata.html = parsedHtml;
|
||||
if (metadata.elements) {
|
||||
metadata.elements.forEach(function(element) {
|
||||
attachDomModule(parsedHtml, element);
|
||||
});
|
||||
}
|
||||
return metadata;
|
||||
});
|
||||
});
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
function matchingImport(importElement) {
|
||||
var matchesTag = dom5.predicates.hasTagName(importElement.tagName);
|
||||
var matchesHref = dom5.predicates.hasAttrValue('href', dom5.getAttribute(importElement, 'href'));
|
||||
var matchesRel = dom5.predicates.hasAttrValue('rel', dom5.getAttribute(importElement, 'rel'));
|
||||
return dom5.predicates.AND(matchesTag, matchesHref, matchesRel);
|
||||
}
|
||||
|
||||
// TODO(ajo): Refactor out of vulcanize into dom5.
|
||||
var polymerExternalStyle = dom5.predicates.AND(
|
||||
dom5.predicates.hasTagName('link'),
|
||||
dom5.predicates.hasAttrValue('rel', 'import'),
|
||||
dom5.predicates.hasAttrValue('type', 'css')
|
||||
);
|
||||
|
||||
var externalScript = dom5.predicates.AND(
|
||||
dom5.predicates.hasTagName('script'),
|
||||
dom5.predicates.hasAttr('src')
|
||||
);
|
||||
|
||||
var isHtmlImportNode = dom5.predicates.AND(
|
||||
dom5.predicates.hasTagName('link'),
|
||||
dom5.predicates.hasAttrValue('rel', 'import'),
|
||||
dom5.predicates.NOT(
|
||||
dom5.predicates.hasAttrValue('type', 'css')
|
||||
)
|
||||
);
|
||||
|
||||
Analyzer.prototype._inlineStyles = function _inlineStyles(ast, href) {
|
||||
var cssLinks = dom5.queryAll(ast, polymerExternalStyle);
|
||||
cssLinks.forEach(function(link) {
|
||||
var linkHref = dom5.getAttribute(link, 'href');
|
||||
var uri = url.resolve(href, linkHref);
|
||||
var content = this._content[uri];
|
||||
var style = dom5.constructors.element('style');
|
||||
dom5.setTextContent(style, '\n' + content + '\n');
|
||||
dom5.replace(link, style);
|
||||
}.bind(this));
|
||||
return cssLinks.length > 0;
|
||||
};
|
||||
|
||||
Analyzer.prototype._inlineScripts = function _inlineScripts(ast, href) {
|
||||
var scripts = dom5.queryAll(ast, externalScript);
|
||||
scripts.forEach(function(script) {
|
||||
var scriptHref = dom5.getAttribute(script, 'src');
|
||||
var uri = url.resolve(href, scriptHref);
|
||||
var content = this._content[uri];
|
||||
var inlined = dom5.constructors.element('script');
|
||||
dom5.setTextContent(inlined, '\n' + content + '\n');
|
||||
dom5.replace(script, inlined);
|
||||
}.bind(this));
|
||||
return scripts.length > 0;
|
||||
};
|
||||
|
||||
Analyzer.prototype._inlineImports = function _inlineImports(ast, href, loaded) {
|
||||
var imports = dom5.queryAll(ast, isHtmlImportNode);
|
||||
imports.forEach(function(htmlImport) {
|
||||
var importHref = dom5.getAttribute(htmlImport, 'href');
|
||||
var uri = url.resolve(href, importHref);
|
||||
if (loaded[uri]) {
|
||||
dom5.remove(htmlImport);
|
||||
return;
|
||||
}
|
||||
var content = this.getLoadedAst(uri, loaded);
|
||||
dom5.replace(htmlImport, content);
|
||||
}.bind(this));
|
||||
return imports.length > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a promise resolving to a form of the AST with all links replaced
|
||||
* with the document they link to. .css and .script files become <style> and
|
||||
* <script>, respectively.
|
||||
*
|
||||
* The elements in the loaded document are unmodified from their original
|
||||
* documents.
|
||||
*
|
||||
* @param {string} href The document to load.
|
||||
* @param {Object.<string,boolean>=} loaded An object keyed by already loaded documents.
|
||||
* @return {Promise.<DocumentAST>}
|
||||
*/
|
||||
Analyzer.prototype.getLoadedAst = function getLoadedAst(href, loaded) {
|
||||
if (!loaded) {
|
||||
loaded = {};
|
||||
}
|
||||
loaded[href] = true;
|
||||
var parsedDocument = this.parsedDocuments[href];
|
||||
var analyzedDocument = this.html[href];
|
||||
var astCopy = dom5.parse(dom5.serialize(parsedDocument));
|
||||
// Whenever we inline something, reset inlined to true to know that anoather
|
||||
// inlining pass is needed;
|
||||
this._inlineStyles(astCopy, href);
|
||||
this._inlineScripts(astCopy, href);
|
||||
this._inlineImports(astCopy, href, loaded);
|
||||
return astCopy;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calls `dom5.nodeWalkAll` on each document that `Anayzler` has laoded.
|
||||
* @param {Object} predicate A dom5 predicate.
|
||||
* @return {Object}
|
||||
*/
|
||||
Analyzer.prototype.nodeWalkDocuments = function nodeWalkDocuments(predicate) {
|
||||
for (var href in this.parsedDocuments) {
|
||||
var match = dom5.nodeWalk(this.parsedDocuments[href], predicate);
|
||||
if (match) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calls `dom5.nodeWalkAll` on each document that `Anayzler` has laoded.
|
||||
* @param {Object} predicate A dom5 predicate.
|
||||
* @return {Object}
|
||||
*/
|
||||
Analyzer.prototype.nodeWalkAllDocuments = function nodeWalkDocuments(predicate) {
|
||||
var results = [];
|
||||
for (var href in this.parsedDocuments) {
|
||||
var newNodes = dom5.nodeWalkAll(this.parsedDocuments[href], predicate);
|
||||
results = results.concat(newNodes);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
/** Annotates all loaded metadata with its documentation. */
|
||||
Analyzer.prototype.annotate = function annotate() {
|
||||
if (this.features.length > 0) {
|
||||
var featureEl = docs.featureElement(this.features);
|
||||
this.elements.unshift(featureEl);
|
||||
this.elementsByTagName[featureEl.is] = featureEl;
|
||||
}
|
||||
var behaviorsByName = this.behaviorsByName;
|
||||
var elementHelper = function(descriptor){
|
||||
docs.annotateElement(descriptor, behaviorsByName);
|
||||
};
|
||||
this.elements.forEach(elementHelper);
|
||||
this.behaviors.forEach(elementHelper); // Same shape.
|
||||
this.behaviors.forEach(function(behavior){
|
||||
if (behavior.is !== behavior.symbol && behavior.symbol) {
|
||||
this.behaviorsByName[behavior.symbol] = undefined;
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
function attachDomModule(parsedImport, element) {
|
||||
var domModules = parsedImport['dom-module'];
|
||||
for (var i = 0, domModule; i < domModules.length; i++) {
|
||||
domModule = domModules[i];
|
||||
if (dom5.getAttribute(domModule, 'id') === element.is) {
|
||||
element.domModule = domModule;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Removes redundant properties from the collected descriptors. */
|
||||
Analyzer.prototype.clean = function clean() {
|
||||
this.elements.forEach(docs.cleanElement);
|
||||
};
|
||||
|
||||
module.exports = Analyzer;
|
||||
107
build/node_modules/hydrolysis/lib/ast-utils/analyze-properties.js
generated
vendored
Normal file
107
build/node_modules/hydrolysis/lib/ast-utils/analyze-properties.js
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
|
||||
var esutil = require('./esutil');
|
||||
var astValue = require('./ast-value');
|
||||
|
||||
var analyzeProperties = function(node) {
|
||||
|
||||
var analyzedProps = [];
|
||||
|
||||
if (node.type != 'ObjectExpression') {
|
||||
return analyzedProps;
|
||||
}
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
var property = node.properties[i];
|
||||
var prop = esutil.toPropertyDescriptor(property);
|
||||
prop.published = true;
|
||||
|
||||
if (property.value.type == 'ObjectExpression') {
|
||||
/**
|
||||
* Parse the expression inside a property object block.
|
||||
* property: {
|
||||
* key: {
|
||||
* type: String,
|
||||
* notify: true,
|
||||
* value: -1,
|
||||
* readOnly: true,
|
||||
* reflectToAttribute: true
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
for (var j = 0; j < property.value.properties.length; j++) {
|
||||
var propertyArg = property.value.properties[j];
|
||||
var propertyKey = esutil.objectKeyToString(propertyArg.key);
|
||||
|
||||
switch(propertyKey) {
|
||||
case 'type': {
|
||||
prop.type = esutil.objectKeyToString(propertyArg.value);
|
||||
if (prop.type === undefined) {
|
||||
throw {
|
||||
message: 'Invalid type in property object.',
|
||||
location: propertyArg.loc.start
|
||||
};
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'notify': {
|
||||
prop.notify = astValue.expressionToValue(propertyArg.value);
|
||||
if (prop.notify === undefined)
|
||||
prop.notify = astValue.CANT_CONVERT;
|
||||
}
|
||||
break;
|
||||
case 'observer': {
|
||||
prop.observer = astValue.expressionToValue(propertyArg.value);
|
||||
prop.observerNode = propertyArg.value;
|
||||
if (prop.observer === undefined)
|
||||
prop.observer = astValue.CANT_CONVERT;
|
||||
}
|
||||
break;
|
||||
case 'readOnly': {
|
||||
prop.readOnly = astValue.expressionToValue(propertyArg.value);
|
||||
if (prop.readOnly === undefined)
|
||||
prop.readOnly = astValue.CANT_CONVERT;
|
||||
}
|
||||
break;
|
||||
case 'reflectToAttribute': {
|
||||
prop.reflectToAttribute = astValue.expressionToValue(propertyArg);
|
||||
if (prop.reflectToAttribute === undefined)
|
||||
prop.reflectToAttribute = astValue.CANT_CONVERT;
|
||||
}
|
||||
break;
|
||||
case 'value': {
|
||||
prop.default = astValue.expressionToValue(propertyArg.value);
|
||||
if (prop.default === undefined)
|
||||
prop.default = astValue.CANT_CONVERT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!prop.type) {
|
||||
throw {
|
||||
message: 'Unable to determine name for property key.',
|
||||
location: node.loc.start
|
||||
};
|
||||
}
|
||||
|
||||
analyzedProps.push(prop);
|
||||
}
|
||||
return analyzedProps;
|
||||
};
|
||||
|
||||
|
||||
module.exports = analyzeProperties;
|
||||
|
||||
160
build/node_modules/hydrolysis/lib/ast-utils/ast-value.js
generated
vendored
Normal file
160
build/node_modules/hydrolysis/lib/ast-utils/ast-value.js
generated
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
|
||||
// useful tool to visualize AST: http://esprima.org/demo/parse.html
|
||||
|
||||
/**
|
||||
* converts literal: {"type": "Literal", "value": 5, "raw": "5" }
|
||||
* to string
|
||||
*/
|
||||
function literalToValue(literal) {
|
||||
return literal.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts unary to string
|
||||
* unary: { type: 'UnaryExpression', operator: '-', argument: { ... } }
|
||||
*/
|
||||
function unaryToValue(unary) {
|
||||
var argValue = expressionToValue(unary.argument);
|
||||
if (argValue === undefined)
|
||||
return;
|
||||
return unary.operator + argValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts identifier to its value
|
||||
* identifier { "type": "Identifier", "name": "Number }
|
||||
*/
|
||||
function identifierToValue(identifier) {
|
||||
return identifier.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function is a block statement.
|
||||
*/
|
||||
function functionDeclarationToValue(fn) {
|
||||
if (fn.body.type == "BlockStatement")
|
||||
return blockStatementToValue(fn.body);
|
||||
}
|
||||
|
||||
function functionExpressionToValue(fn) {
|
||||
if (fn.body.type == "BlockStatement")
|
||||
return blockStatementToValue(fn.body);
|
||||
}
|
||||
/**
|
||||
* Block statement: find last return statement, and return its value
|
||||
*/
|
||||
function blockStatementToValue(block) {
|
||||
for (var i=block.body.length - 1; i>= 0; i--) {
|
||||
if (block.body[i].type === "ReturnStatement")
|
||||
return returnStatementToValue(block.body[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates return's argument
|
||||
*/
|
||||
function returnStatementToValue(ret) {
|
||||
return expressionToValue(ret.argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enclose containing values in []
|
||||
*/
|
||||
function arrayExpressionToValue(arry) {
|
||||
var value = '[';
|
||||
for (var i=0; i<arry.elements.length; i++) {
|
||||
var v = expressionToValue(arry.elements[i]);
|
||||
if (v === undefined)
|
||||
continue;
|
||||
if (i !== 0)
|
||||
value += ', ';
|
||||
value += v;
|
||||
}
|
||||
value += ']';
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make it look like an object
|
||||
*/
|
||||
function objectExpressionToValue(obj) {
|
||||
var value = '{';
|
||||
for (var i=0; i<obj.properties.length; i++) {
|
||||
var k = expressionToValue(obj.properties[i].key);
|
||||
var v = expressionToValue(obj.properties[i].value);
|
||||
if (v === undefined)
|
||||
continue;
|
||||
if (i !== 0)
|
||||
value += ', ';
|
||||
value += '"' + k + '": ' + v;
|
||||
}
|
||||
value += '}';
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* BinaryExpressions are of the form "literal" + "literal"
|
||||
*/
|
||||
function binaryExpressionToValue(member) {
|
||||
if (member.operator == "+") {
|
||||
return expressionToValue(member.left) + expressionToValue(member.right);
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* MemberExpression references a variable with name
|
||||
*/
|
||||
function memberExpressionToValue(member) {
|
||||
return expressionToValue(member.object) + "." + expressionToValue(member.property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to get a value from expression. Handles Literal, UnaryExpression
|
||||
* returns undefined on failure
|
||||
* valueExpression example:
|
||||
* { type: "Literal",
|
||||
*/
|
||||
function expressionToValue(valueExpression) {
|
||||
switch(valueExpression.type) {
|
||||
case 'Literal':
|
||||
return literalToValue(valueExpression);
|
||||
case 'UnaryExpression':
|
||||
return unaryToValue(valueExpression);
|
||||
case 'Identifier':
|
||||
return identifierToValue(valueExpression);
|
||||
case 'FunctionDeclaration':
|
||||
return functionDeclarationToValue(valueExpression);
|
||||
case 'FunctionExpression':
|
||||
return functionExpressionToValue(valueExpression);
|
||||
case 'ArrayExpression':
|
||||
return arrayExpressionToValue(valueExpression);
|
||||
case 'ObjectExpression':
|
||||
return objectExpressionToValue(valueExpression);
|
||||
case 'Identifier':
|
||||
return identifierToValue(valueExpression);
|
||||
case 'MemberExpression':
|
||||
return memberExpressionToValue(valueExpression);
|
||||
case 'BinaryExpression':
|
||||
return binaryExpressionToValue(valueExpression);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var CANT_CONVERT = 'UNKNOWN';
|
||||
module.exports = {
|
||||
CANT_CONVERT: CANT_CONVERT,
|
||||
expressionToValue: expressionToValue
|
||||
};
|
||||
225
build/node_modules/hydrolysis/lib/ast-utils/behavior-finder.js
generated
vendored
Normal file
225
build/node_modules/hydrolysis/lib/ast-utils/behavior-finder.js
generated
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
var estraverse = require('estraverse');
|
||||
|
||||
var docs = require('./docs');
|
||||
var esutil = require('./esutil');
|
||||
var jsdoc = require('./jsdoc');
|
||||
var analyzeProperties = require('./analyze-properties');
|
||||
var astValue = require('./ast-value.js');
|
||||
var declarationPropertyHandlers = require('./declaration-property-handlers');
|
||||
|
||||
module.exports = function behaviorFinder() {
|
||||
/** @type {!Array<BehaviorDescriptor>} The behaviors we've found. */
|
||||
var behaviors = [];
|
||||
|
||||
var currentBehavior = null;
|
||||
var propertyHandlers = null;
|
||||
|
||||
/**
|
||||
* merges behavior with preexisting behavior with the same name.
|
||||
* here to support multiple @polymerBehavior tags referring
|
||||
* to same behavior. See iron-multi-selectable for example.
|
||||
*/
|
||||
function mergeBehavior(newBehavior) {
|
||||
var isBehaviorImpl = function(b) { // filter out BehaviorImpl
|
||||
return b.indexOf(newBehavior.is) === -1;
|
||||
};
|
||||
for (var i=0; i<behaviors.length; i++) {
|
||||
if (newBehavior.is !== behaviors[i].is)
|
||||
continue;
|
||||
// merge desc, longest desc wins
|
||||
if (newBehavior.desc) {
|
||||
if (behaviors[i].desc) {
|
||||
if (newBehavior.desc.length > behaviors[i].desc.length)
|
||||
behaviors[i].desc = newBehavior.desc;
|
||||
}
|
||||
else {
|
||||
behaviors[i].desc = newBehavior.desc;
|
||||
}
|
||||
}
|
||||
// merge demos
|
||||
behaviors[i].demos = (behaviors[i].demos || []).concat(newBehavior.demos || []);
|
||||
// merge events,
|
||||
behaviors[i].events = (behaviors[i].events || []).concat(newBehavior.events || []);
|
||||
// merge properties
|
||||
behaviors[i].properties = (behaviors[i].properties || []).concat(newBehavior.properties || []);
|
||||
// merge observers
|
||||
behaviors[i].observers = (behaviors[i].observers || []).concat(newBehavior.observers || []);
|
||||
// merge behaviors
|
||||
behaviors[i].behaviors =
|
||||
(behaviors[i].behaviors || []).concat(newBehavior.behaviors || [])
|
||||
.filter(isBehaviorImpl);
|
||||
return behaviors[i];
|
||||
}
|
||||
return newBehavior;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the expression representing a behavior from a node.
|
||||
*/
|
||||
function behaviorExpression(node) {
|
||||
switch(node.type) {
|
||||
case 'ExpressionStatement':
|
||||
return node.expression.right;
|
||||
case 'VariableDeclaration':
|
||||
return node.declarations.length > 0 ? node.declarations[0].init : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether an expression is a simple array containing only member
|
||||
* expressions or identifiers.
|
||||
*/
|
||||
function isSimpleBehaviorArray(expression) {
|
||||
if (!expression || expression.type !== 'ArrayExpression') return false;
|
||||
for (var i=0; i < expression.elements.length; i++) {
|
||||
if (expression.elements[i].type !== 'MemberExpression' &&
|
||||
expression.elements[i].type !== 'Identifier') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var templatizer = "Polymer.Templatizer";
|
||||
|
||||
var visitors = {
|
||||
|
||||
/**
|
||||
* Look for object declarations with @behavior in the docs.
|
||||
*/
|
||||
enterVariableDeclaration: function(node, parent) {
|
||||
if (node.declarations.length !== 1) return; // Ambiguous.
|
||||
this._initBehavior(node, function () {
|
||||
return esutil.objectKeyToString(node.declarations[0].id);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Look for object assignments with @polymerBehavior in the docs.
|
||||
*/
|
||||
enterAssignmentExpression: function(node, parent) {
|
||||
this._initBehavior(parent, function () {
|
||||
return esutil.objectKeyToString(node.left);
|
||||
});
|
||||
},
|
||||
|
||||
_parseChainedBehaviors: function(node) {
|
||||
// if current behavior is part of an array, it gets extended by other behaviors
|
||||
// inside the array. Ex:
|
||||
// Polymer.IronMultiSelectableBehavior = [ {....}, Polymer.IronSelectableBehavior]
|
||||
// We add these to behaviors array
|
||||
var expression = behaviorExpression(node);
|
||||
var chained = [];
|
||||
if (expression && expression.type === 'ArrayExpression') {
|
||||
for (var i=0; i < expression.elements.length; i++) {
|
||||
if (expression.elements[i].type === 'MemberExpression' ||
|
||||
expression.elements[i].type === 'Identifier') {
|
||||
chained.push(astValue.expressionToValue(expression.elements[i]));
|
||||
}
|
||||
}
|
||||
if (chained.length > 0)
|
||||
currentBehavior.behaviors = chained;
|
||||
}
|
||||
},
|
||||
|
||||
_initBehavior: function(node, getName) {
|
||||
var comment = esutil.getAttachedComment(node);
|
||||
var symbol = getName();
|
||||
// Quickly filter down to potential candidates.
|
||||
if (!comment || comment.indexOf('@polymerBehavior') === -1) {
|
||||
if (symbol !== templatizer) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
currentBehavior = {
|
||||
type: 'behavior',
|
||||
desc: comment,
|
||||
events: esutil.getEventComments(node).map( function(event) {
|
||||
return { desc: event};
|
||||
})
|
||||
};
|
||||
propertyHandlers = declarationPropertyHandlers(currentBehavior);
|
||||
|
||||
docs.annotateBehavior(currentBehavior);
|
||||
// Make sure that we actually parsed a behavior tag!
|
||||
if (!jsdoc.hasTag(currentBehavior.jsdoc, 'polymerBehavior') &&
|
||||
symbol !== templatizer) {
|
||||
currentBehavior = null;
|
||||
propertyHandlers = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var name = jsdoc.getTag(currentBehavior.jsdoc, 'polymerBehavior', 'name');
|
||||
currentBehavior.symbol = symbol;
|
||||
if (!name) {
|
||||
name = currentBehavior.symbol;
|
||||
}
|
||||
if (!name) {
|
||||
console.warn('Unable to determine name for @polymerBehavior:', comment);
|
||||
}
|
||||
currentBehavior.is = name;
|
||||
|
||||
this._parseChainedBehaviors(node);
|
||||
|
||||
currentBehavior = mergeBehavior(currentBehavior);
|
||||
propertyHandlers = declarationPropertyHandlers(currentBehavior);
|
||||
|
||||
// Some behaviors are just lists of other behaviors. If this is one then
|
||||
// add it to behaviors right away.
|
||||
if (isSimpleBehaviorArray(behaviorExpression(node))) {
|
||||
// TODO(ajo): Add a test to confirm the presence of `properties`
|
||||
if (!currentBehavior.observers) currentBehavior.observers = [];
|
||||
if (!currentBehavior.properties) currentBehavior.properties = [];
|
||||
if (behaviors.indexOf(currentBehavior) === -1)
|
||||
behaviors.push(currentBehavior);
|
||||
currentBehavior = null;
|
||||
propertyHandlers = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* We assume that the object expression after such an assignment is the
|
||||
* behavior's declaration. Seems to be a decent assumption for now.
|
||||
*/
|
||||
enterObjectExpression: function(node, parent) {
|
||||
if (!currentBehavior || currentBehavior.properties) return;
|
||||
|
||||
currentBehavior.properties = currentBehavior.properties || [];
|
||||
currentBehavior.observers = currentBehavior.observers || [];
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
var prop = node.properties[i];
|
||||
var name = esutil.objectKeyToString(prop.key);
|
||||
if (!name) {
|
||||
throw {
|
||||
message: 'Cant determine name for property key.',
|
||||
location: node.loc.start
|
||||
};
|
||||
}
|
||||
if (name in propertyHandlers) {
|
||||
propertyHandlers[name](prop.value);
|
||||
}
|
||||
else {
|
||||
currentBehavior.properties.push(esutil.toPropertyDescriptor(prop));
|
||||
}
|
||||
}
|
||||
behaviors.push(currentBehavior);
|
||||
currentBehavior = null;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
return {visitors: visitors, behaviors: behaviors};
|
||||
};
|
||||
68
build/node_modules/hydrolysis/lib/ast-utils/declaration-property-handlers.js
generated
vendored
Normal file
68
build/node_modules/hydrolysis/lib/ast-utils/declaration-property-handlers.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
|
||||
var astValue = require('./ast-value');
|
||||
var analyzeProperties = require('./analyze-properties');
|
||||
|
||||
/**
|
||||
* Returns an object containing functions that will annotate `declaration` with
|
||||
* the polymer-specificmeaning of the value nodes for the named properties.
|
||||
*
|
||||
* @param {ElementDescriptor} declaration The descriptor to annotate.
|
||||
* @return {object.<string,function>} An object containing property
|
||||
* handlers.
|
||||
*/
|
||||
function declarationPropertyHandlers(declaration) {
|
||||
return {
|
||||
is: function(node) {
|
||||
if (node.type == 'Literal') {
|
||||
declaration.is = node.value;
|
||||
}
|
||||
},
|
||||
properties: function(node) {
|
||||
|
||||
var props = analyzeProperties(node);
|
||||
|
||||
for (var i=0; i<props.length; i++) {
|
||||
declaration.properties.push(props[i]);
|
||||
}
|
||||
},
|
||||
behaviors: function(node) {
|
||||
if (node.type != 'ArrayExpression') {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i=0; i<node.elements.length; i++) {
|
||||
var v = astValue.expressionToValue(node.elements[i]);
|
||||
if (v === undefined)
|
||||
v = astValue.CANT_CONVERT;
|
||||
declaration.behaviors.push(v);
|
||||
}
|
||||
},
|
||||
observers: function(node) {
|
||||
if (node.type != 'ArrayExpression') {
|
||||
return;
|
||||
}
|
||||
for (var i=0; i<node.elements.length; i++) {
|
||||
var v = astValue.expressionToValue(node.elements[i]);
|
||||
if (v === undefined)
|
||||
v = astValue.CANT_CONVERT;
|
||||
declaration.observers.push({
|
||||
javascriptNode: node.elements[i],
|
||||
expression: v
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = declarationPropertyHandlers;
|
||||
485
build/node_modules/hydrolysis/lib/ast-utils/docs.js
generated
vendored
Normal file
485
build/node_modules/hydrolysis/lib/ast-utils/docs.js
generated
vendored
Normal file
@@ -0,0 +1,485 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
// jshint node:true
|
||||
|
||||
var jsdoc = require('./jsdoc');
|
||||
|
||||
var dom5 = require('dom5');
|
||||
|
||||
/** Properties on element prototypes that are purely configuration. */
|
||||
var ELEMENT_CONFIGURATION = [
|
||||
'attached',
|
||||
'attributeChanged',
|
||||
'configure',
|
||||
'constructor',
|
||||
'created',
|
||||
'detached',
|
||||
'enableCustomStyleProperties',
|
||||
'extends',
|
||||
'hostAttributes',
|
||||
'is',
|
||||
'listeners',
|
||||
'mixins',
|
||||
'properties',
|
||||
'ready',
|
||||
'registered'
|
||||
];
|
||||
|
||||
/** Tags understood by the annotation process, to be removed during `clean`. */
|
||||
var HANDLED_TAGS = [
|
||||
'param',
|
||||
'return',
|
||||
'type',
|
||||
];
|
||||
|
||||
/**
|
||||
* Annotates Hydrolysis descriptors, processing any `desc` properties as JSDoc.
|
||||
*
|
||||
* You probably want to use a more specialized version of this, such as
|
||||
* `annotateElement`.
|
||||
*
|
||||
* Processed JSDoc values will be made available via the `jsdoc` property on a
|
||||
* descriptor node.
|
||||
*
|
||||
* @param {Object} descriptor The descriptor node to process.
|
||||
* @return {Object} The descriptor that was given.
|
||||
*/
|
||||
function annotate(descriptor) {
|
||||
if (!descriptor || descriptor.jsdoc) return descriptor;
|
||||
|
||||
if (typeof descriptor.desc === 'string') {
|
||||
descriptor.jsdoc = jsdoc.parseJsdoc(descriptor.desc);
|
||||
// We want to present the normalized form of a descriptor.
|
||||
descriptor.jsdoc.orig = descriptor.desc;
|
||||
descriptor.desc = descriptor.jsdoc.description;
|
||||
}
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotates @event, @hero, & @demo tags
|
||||
*/
|
||||
function annotateElementHeader(descriptor) {
|
||||
if (descriptor.events) {
|
||||
descriptor.events.forEach(function(event) {
|
||||
_annotateEvent(event);
|
||||
});
|
||||
descriptor.events.sort( function(a,b) {
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
}
|
||||
descriptor.demos = [];
|
||||
if (descriptor.jsdoc && descriptor.jsdoc.tags) {
|
||||
descriptor.jsdoc.tags.forEach( function(tag) {
|
||||
switch(tag.tag) {
|
||||
case 'hero':
|
||||
descriptor.hero = tag.name || 'hero.png';
|
||||
break;
|
||||
case 'demo':
|
||||
descriptor.demos.push({
|
||||
desc: tag.description || 'demo',
|
||||
path: tag.name || 'demo/index.html'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function matchByName(propa, propb) {
|
||||
return propa.name == propb.name;
|
||||
}
|
||||
|
||||
function copyProperties(from, to, behaviorsByName) {
|
||||
if (from.properties) {
|
||||
from.properties.forEach(function(fromProp){
|
||||
for (var toProp, i = 0; i < to.properties.length; i++) {
|
||||
toProp = to.properties[i];
|
||||
if (fromProp.name === toProp.name) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
var newProp = {__fromBehavior: from.is};
|
||||
if (fromProp.__fromBehavior) {
|
||||
return;
|
||||
}
|
||||
Object.keys(fromProp).forEach(function(propertyField){
|
||||
newProp[propertyField] = fromProp[propertyField];
|
||||
});
|
||||
to.properties.push(newProp);
|
||||
});
|
||||
from.events.forEach(function(fromEvent){
|
||||
for (var toEvent, i = 0; i < to.events.length; i++) {
|
||||
toEvent = to.events[i];
|
||||
if (fromEvent.name === toEvent.name) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (fromEvent.__fromBehavior) {
|
||||
return;
|
||||
}
|
||||
var newEvent = Object.create(fromEvent);
|
||||
newEvent.__fromBehavior = from.is;
|
||||
to.events.push(newEvent);
|
||||
});
|
||||
}
|
||||
if (!from.behaviors) {
|
||||
return;
|
||||
}
|
||||
for (var i = from.behaviors.length - 1; i >= 0; i--) {
|
||||
var behavior = from.behaviors[i];
|
||||
var definedBehavior = behaviorsByName[behavior] || behaviorsByName[behavior.symbol];
|
||||
if (!definedBehavior) {
|
||||
console.warn("Behavior " + behavior + " not found when mixing " +
|
||||
"properties into " + to.is + "!");
|
||||
return;
|
||||
}
|
||||
copyProperties(definedBehavior, to, behaviorsByName);
|
||||
}
|
||||
}
|
||||
|
||||
function mixinBehaviors(descriptor, behaviorsByName) {
|
||||
if (descriptor.behaviors) {
|
||||
for (var i = descriptor.behaviors.length - 1; i >= 0; i--) {
|
||||
var behavior = descriptor.behaviors[i];
|
||||
if (!behaviorsByName[behavior]) {
|
||||
console.warn("Behavior " + behavior + " not found when mixing " +
|
||||
"properties into " + descriptor.is + "!");
|
||||
break;
|
||||
}
|
||||
var definedBehavior = behaviorsByName[behavior];
|
||||
copyProperties(definedBehavior, descriptor, behaviorsByName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotates documentation found within a Hydrolysis element descriptor. Also
|
||||
* supports behaviors.
|
||||
*
|
||||
* If the element was processed via `hydrolize`, the element's documentation
|
||||
* will also be extracted via its <dom-module>.
|
||||
*
|
||||
* @param {Object} descriptor The element descriptor.
|
||||
* @return {Object} The descriptor that was given.
|
||||
*/
|
||||
function annotateElement(descriptor, behaviorsByName) {
|
||||
if (!descriptor.desc && descriptor.type === 'element') {
|
||||
descriptor.desc = _findElementDocs(descriptor.is,
|
||||
descriptor.domModule,
|
||||
descriptor.scriptElement);
|
||||
}
|
||||
annotate(descriptor);
|
||||
|
||||
// The `<dom-module>` is too low level for most needs, and it is _not_
|
||||
// serializable. So we drop it now that we've extracted all the useful bits
|
||||
// from it.
|
||||
// TODO: Don't worry about serializability here, provide an API to get JSON.
|
||||
delete descriptor.domModule;
|
||||
|
||||
mixinBehaviors(descriptor, behaviorsByName);
|
||||
|
||||
// Descriptors that should have their `desc` properties parsed as JSDoc.
|
||||
descriptor.properties.forEach(function(property) {
|
||||
// Feature properties are special, configuration is really just a matter of
|
||||
// inheritance...
|
||||
annotateProperty(property, descriptor.abstract);
|
||||
});
|
||||
|
||||
// It may seem like overkill to always sort, but we have an assumption that
|
||||
// these properties are typically being consumed by user-visible tooling.
|
||||
// As such, it's good to have consistent output/ordering to aid the user.
|
||||
descriptor.properties.sort(function(a, b) {
|
||||
// Private properties are always last.
|
||||
if (a.private && !b.private) {
|
||||
return 1;
|
||||
} else if (!a.private && b.private) {
|
||||
return -1;
|
||||
// Otherwise, we're just sorting alphabetically.
|
||||
} else {
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
});
|
||||
|
||||
annotateElementHeader(descriptor);
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotates behavior descriptor.
|
||||
* @param {Object} descriptor behavior descriptor
|
||||
* @return {Object} descriptor passed in as param
|
||||
*/
|
||||
function annotateBehavior(descriptor, behaviorsByName) {
|
||||
annotate(descriptor);
|
||||
annotateElementHeader(descriptor);
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotates event documentation
|
||||
*/
|
||||
function _annotateEvent(descriptor) {
|
||||
annotate(descriptor);
|
||||
// process @event
|
||||
var eventTag = jsdoc.getTag(descriptor.jsdoc, 'event');
|
||||
descriptor.name = eventTag ? eventTag.description : "N/A";
|
||||
|
||||
// process @params
|
||||
descriptor.params = (descriptor.jsdoc.tags || [])
|
||||
.filter( function(tag) {
|
||||
return tag.tag === 'param';
|
||||
})
|
||||
.map( function(tag) {
|
||||
return {
|
||||
type: tag.type || "N/A",
|
||||
desc: tag.description,
|
||||
name: tag.name || "N/A"
|
||||
};
|
||||
});
|
||||
// process @params
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotates documentation found about a Hydrolysis property descriptor.
|
||||
*
|
||||
* @param {Object} descriptor The property descriptor.
|
||||
* @param {boolean} ignoreConfiguration If true, `configuration` is not set.
|
||||
* @return {Object} The descriptior that was given.
|
||||
*/
|
||||
function annotateProperty(descriptor, ignoreConfiguration) {
|
||||
annotate(descriptor);
|
||||
if (descriptor.name[0] === '_' || jsdoc.hasTag(descriptor.jsdoc, 'private')) {
|
||||
descriptor.private = true;
|
||||
}
|
||||
|
||||
if (!ignoreConfiguration && ELEMENT_CONFIGURATION.indexOf(descriptor.name) !== -1) {
|
||||
descriptor.private = true;
|
||||
descriptor.configuration = true;
|
||||
}
|
||||
|
||||
// @type JSDoc wins
|
||||
descriptor.type = jsdoc.getTag(descriptor.jsdoc, 'type', 'type') || descriptor.type;
|
||||
|
||||
if (descriptor.type.match(/^function/i)) {
|
||||
_annotateFunctionProperty(descriptor);
|
||||
}
|
||||
|
||||
// @default JSDoc wins
|
||||
var defaultTag = jsdoc.getTag(descriptor.jsdoc, 'default');
|
||||
if (defaultTag !== null) {
|
||||
var newDefault = (defaultTag.name || '') + (defaultTag.description || '');
|
||||
if (newDefault !== '') {
|
||||
descriptor.default = newDefault;
|
||||
}
|
||||
}
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
/** @param {Object} descriptor */
|
||||
function _annotateFunctionProperty(descriptor) {
|
||||
descriptor.function = true;
|
||||
|
||||
var returnTag = jsdoc.getTag(descriptor.jsdoc, 'return');
|
||||
if (returnTag) {
|
||||
descriptor.return = {
|
||||
type: returnTag.type,
|
||||
desc: returnTag.description,
|
||||
};
|
||||
}
|
||||
|
||||
var paramsByName = {};
|
||||
(descriptor.params || []).forEach(function(param) {
|
||||
paramsByName[param.name] = param;
|
||||
});
|
||||
(descriptor.jsdoc && descriptor.jsdoc.tags || []).forEach(function(tag) {
|
||||
if (tag.tag !== 'param') return;
|
||||
var param = paramsByName[tag.name];
|
||||
if (!param) {
|
||||
return;
|
||||
}
|
||||
|
||||
param.type = tag.type || param.type;
|
||||
param.desc = tag.description;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts raw features into an abstract `Polymer.Base` element.
|
||||
*
|
||||
* Note that docs on this element _are not processed_. You must call
|
||||
* `annotateElement` on it yourself if you wish that.
|
||||
*
|
||||
* @param {Array<FeatureDescriptor>} features
|
||||
* @return {ElementDescriptor}
|
||||
*/
|
||||
function featureElement(features) {
|
||||
var properties = features.reduce(function(result, feature) {
|
||||
return result.concat(feature.properties);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
type: 'element',
|
||||
is: 'Polymer.Base',
|
||||
abstract: true,
|
||||
properties: properties,
|
||||
desc: '`Polymer.Base` acts as a base prototype for all Polymer ' +
|
||||
'elements. It is composed via various calls to ' +
|
||||
'`Polymer.Base._addFeature()`.\n' +
|
||||
'\n' +
|
||||
'The properties reflected here are the combined view of all ' +
|
||||
'features found in this library. There may be more properties ' +
|
||||
'added via other libraries, as well.',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans redundant properties from a descriptor, assuming that you have already
|
||||
* called `annotate`.
|
||||
*
|
||||
* @param {Object} descriptor
|
||||
*/
|
||||
function clean(descriptor) {
|
||||
if (!descriptor.jsdoc) return;
|
||||
// The doctext was written to `descriptor.desc`
|
||||
delete descriptor.jsdoc.description;
|
||||
delete descriptor.jsdoc.orig;
|
||||
|
||||
var cleanTags = [];
|
||||
(descriptor.jsdoc.tags || []).forEach(function(tag) {
|
||||
// Drop any tags we've consumed.
|
||||
if (HANDLED_TAGS.indexOf(tag.tag) !== -1) return;
|
||||
cleanTags.push(tag);
|
||||
});
|
||||
|
||||
if (cleanTags.length === 0) {
|
||||
// No tags? no docs left!
|
||||
delete descriptor.jsdoc;
|
||||
} else {
|
||||
descriptor.jsdoc.tags = cleanTags;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans redundant properties from an element, assuming that you have already
|
||||
* called `annotateElement`.
|
||||
*
|
||||
* @param {ElementDescriptor|BehaviorDescriptor} element
|
||||
*/
|
||||
function cleanElement(element) {
|
||||
clean(element);
|
||||
element.properties.forEach(cleanProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans redundant properties from a property, assuming that you have already
|
||||
* called `annotateProperty`.
|
||||
*
|
||||
* @param {PropertyDescriptor} property
|
||||
*/
|
||||
function cleanProperty(property) {
|
||||
clean(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse elements defined only in comments.
|
||||
* @param {comments} Array<string> A list of comments to parse.
|
||||
* @return {ElementDescriptor} A list of pseudo-elements.
|
||||
*/
|
||||
function parsePseudoElements(comments) {
|
||||
var elements = [];
|
||||
comments.forEach(function(comment) {
|
||||
var parsed = jsdoc.parseJsdoc(comment);
|
||||
var pseudoTag = jsdoc.getTag(parsed, 'pseudoElement', 'name');
|
||||
if (pseudoTag) {
|
||||
parsed.is = pseudoTag;
|
||||
parsed.jsdoc = {description: parsed.description, tags: parsed.tags};
|
||||
parsed.properties = [];
|
||||
parsed.desc = parsed.description;
|
||||
parsed.description = undefined;
|
||||
parsed.tags = undefined;
|
||||
annotateElementHeader(parsed);
|
||||
elements.push(parsed);
|
||||
}
|
||||
});
|
||||
return elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} elementId
|
||||
* @param {DocumentAST} domModule
|
||||
* @param {DocumentAST} scriptElement The script that the element was defined in.
|
||||
*/
|
||||
function _findElementDocs(elementId, domModule, scriptElement) {
|
||||
// Note that we concatenate docs from all sources if we find them.
|
||||
// element can be defined in:
|
||||
// html comment right before dom-module
|
||||
// html commnet right before script defining the module, if dom-module is empty
|
||||
|
||||
var found = [];
|
||||
|
||||
// Do we have a HTML comment on the `<dom-module>` or `<script>`?
|
||||
//
|
||||
// Confusingly, with our current style, the comment will be attached to
|
||||
// `<head>`, rather than being a sibling to the `<dom-module>`
|
||||
var searchRoot = domModule || scriptElement;
|
||||
var parents = dom5.nodeWalkAllPrior(searchRoot, dom5.isCommentNode);
|
||||
var comment = parents.length > 0 ? parents[0] : null;
|
||||
if (comment && comment.data) {
|
||||
found.push(comment.data);
|
||||
}
|
||||
if (found.length === 0) return null;
|
||||
return found
|
||||
.filter(function(comment) {
|
||||
// skip @license comments
|
||||
if (comment && comment.indexOf('@license' === -1)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.map(jsdoc.unindent).join('\n');
|
||||
}
|
||||
|
||||
function _findLastChildNamed(name, parent) {
|
||||
var children = parent.childNodes;
|
||||
for (var i = children.length - 1, child; i >= 0; i--) {
|
||||
child = children[i];
|
||||
if (child.nodeName === name) return child;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO(nevir): parse5-utils!
|
||||
function _getNodeAttribute(node, name) {
|
||||
for (var i = 0, attr; i < node.attrs.length; i++) {
|
||||
attr = node.attrs[i];
|
||||
if (attr.name === name) {
|
||||
return attr.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
annotate: annotate,
|
||||
annotateElement: annotateElement,
|
||||
annotateBehavior: annotateBehavior,
|
||||
clean: clean,
|
||||
cleanElement: cleanElement,
|
||||
featureElement: featureElement,
|
||||
parsePseudoElements: parsePseudoElements
|
||||
};
|
||||
115
build/node_modules/hydrolysis/lib/ast-utils/element-finder.js
generated
vendored
Normal file
115
build/node_modules/hydrolysis/lib/ast-utils/element-finder.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
var estraverse = require('estraverse');
|
||||
|
||||
var esutil = require('./esutil');
|
||||
var findAlias = require('./find-alias');
|
||||
var analyzeProperties = require('./analyze-properties');
|
||||
var astValue = require('./ast-value');
|
||||
var declarationPropertyHandlers = require('./declaration-property-handlers');
|
||||
|
||||
var elementFinder = function elementFinder() {
|
||||
/**
|
||||
* The list of elements exported by each traversed script.
|
||||
*/
|
||||
var elements = [];
|
||||
|
||||
/**
|
||||
* The element being built during a traversal;
|
||||
*/
|
||||
var element = null;
|
||||
var propertyHandlers = null;
|
||||
|
||||
var visitors = {
|
||||
enterCallExpression: function enterCallExpression(node, parent) {
|
||||
var callee = node.callee;
|
||||
if (callee.type == 'Identifier') {
|
||||
|
||||
if (callee.name == 'Polymer') {
|
||||
element = {
|
||||
type: 'element',
|
||||
desc: esutil.getAttachedComment(parent),
|
||||
events: esutil.getEventComments(parent).map( function(event) {
|
||||
return {desc: event};
|
||||
})
|
||||
};
|
||||
propertyHandlers = declarationPropertyHandlers(element);
|
||||
}
|
||||
}
|
||||
},
|
||||
leaveCallExpression: function leaveCallExpression(node, parent) {
|
||||
var callee = node.callee;
|
||||
if (callee.type == 'Identifier') {
|
||||
if (callee.name == 'Polymer') {
|
||||
if (element) {
|
||||
elements.push(element);
|
||||
element = null;
|
||||
propertyHandlers = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
enterObjectExpression: function enterObjectExpression(node, parent) {
|
||||
if (element && !element.properties) {
|
||||
element.properties = [];
|
||||
element.behaviors = [];
|
||||
element.observers = [];
|
||||
var getters = {};
|
||||
var setters = {};
|
||||
var definedProperties = {};
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
var prop = node.properties[i];
|
||||
var name = esutil.objectKeyToString(prop.key);
|
||||
if (!name) {
|
||||
throw {
|
||||
message: 'Cant determine name for property key.',
|
||||
location: node.loc.start
|
||||
};
|
||||
}
|
||||
|
||||
if (name in propertyHandlers) {
|
||||
propertyHandlers[name](prop.value);
|
||||
continue;
|
||||
}
|
||||
var descriptor = esutil.toPropertyDescriptor(prop);
|
||||
if (descriptor.getter) {
|
||||
getters[descriptor.name] = descriptor;
|
||||
} else if (descriptor.setter) {
|
||||
setters[descriptor.name] = descriptor;
|
||||
} else {
|
||||
element.properties.push(esutil.toPropertyDescriptor(prop));
|
||||
}
|
||||
}
|
||||
Object.keys(getters).forEach(function(getter) {
|
||||
var get = getters[getter];
|
||||
definedProperties[get.name] = get;
|
||||
});
|
||||
Object.keys(setters).forEach(function(setter) {
|
||||
var set = setters[setter];
|
||||
if (!(set.name in definedProperties)) {
|
||||
definedProperties[set.name] = set;
|
||||
} else {
|
||||
definedProperties[set.name].setter = true;
|
||||
}
|
||||
});
|
||||
Object.keys(definedProperties).forEach(function(p){
|
||||
var prop = definedProperties[p];
|
||||
element.properties.push(p);
|
||||
});
|
||||
return estraverse.VisitorOption.Skip;
|
||||
}
|
||||
}
|
||||
};
|
||||
return {visitors: visitors, elements: elements};
|
||||
};
|
||||
|
||||
module.exports = elementFinder;
|
||||
178
build/node_modules/hydrolysis/lib/ast-utils/esutil.js
generated
vendored
Normal file
178
build/node_modules/hydrolysis/lib/ast-utils/esutil.js
generated
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
var estraverse = require("estraverse");
|
||||
|
||||
/**
|
||||
* Returns whether an Espree node matches a particular object path.
|
||||
*
|
||||
* e.g. you have a MemberExpression node, and want to see whether it represents
|
||||
* `Foo.Bar.Baz`:
|
||||
*
|
||||
* matchesCallExpression(node, ['Foo', 'Bar', 'Baz'])
|
||||
*
|
||||
* @param {Node} expression The Espree node to match against.
|
||||
* @param {Array<string>} path The path to look for.
|
||||
*/
|
||||
function matchesCallExpression(expression, path) {
|
||||
if (!expression.property || !expression.object) return;
|
||||
console.assert(path.length >= 2);
|
||||
|
||||
// Unravel backwards, make sure properties match each step of the way.
|
||||
if (expression.property.name !== path[path.length - 1]) return false;
|
||||
// We've got ourselves a final member expression.
|
||||
if (path.length == 2 && expression.object.type === 'Identifier') {
|
||||
return expression.object.name === path[0];
|
||||
}
|
||||
// Nested expressions.
|
||||
if (path.length > 2 && expression.object.type == 'MemberExpression') {
|
||||
return matchesCallExpression(expression.object, path.slice(0, path.length - 1));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} key The node representing an object key or expression.
|
||||
* @return {string} The name of that key.
|
||||
*/
|
||||
function objectKeyToString(key) {
|
||||
if (key.type == 'Identifier') {
|
||||
return key.name;
|
||||
}
|
||||
if (key.type == 'Literal') {
|
||||
return key.value;
|
||||
}
|
||||
if (key.type == 'MemberExpression') {
|
||||
return objectKeyToString(key.object) + '.' + objectKeyToString(key.property);
|
||||
}
|
||||
}
|
||||
|
||||
var CLOSURE_CONSTRUCTOR_MAP = {
|
||||
'Boolean': 'boolean',
|
||||
'Number': 'number',
|
||||
'String': 'string',
|
||||
};
|
||||
|
||||
/**
|
||||
* AST expression -> Closure type.
|
||||
*
|
||||
* Accepts literal values, and native constructors.
|
||||
*
|
||||
* @param {Node} node An Espree expression node.
|
||||
* @return {string} The type of that expression, in Closure terms.
|
||||
*/
|
||||
function closureType(node) {
|
||||
if (node.type.match(/Expression$/)) {
|
||||
return node.type.substr(0, node.type.length - 10);
|
||||
} else if (node.type === 'Literal') {
|
||||
return typeof node.value;
|
||||
} else if (node.type === 'Identifier') {
|
||||
return CLOSURE_CONSTRUCTOR_MAP[node.name] || node.name;
|
||||
} else {
|
||||
throw {
|
||||
message: 'Unknown Closure type for node: ' + node.type,
|
||||
location: node.loc.start,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @return {?string}
|
||||
*/
|
||||
function getAttachedComment(node) {
|
||||
var comments = getLeadingComments(node) || getLeadingComments(node.key);
|
||||
if (!comments) {
|
||||
return;
|
||||
}
|
||||
return comments[comments.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all comments from a tree defined with @event.
|
||||
* @param {Node} node [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
function getEventComments(node) {
|
||||
var eventComments = [];
|
||||
estraverse.traverse(node, {
|
||||
enter: function (node) {
|
||||
var comments = (node.leadingComments || []).concat(node.trailingComments || [])
|
||||
.map( function(commentAST) {
|
||||
return commentAST.value;
|
||||
})
|
||||
.filter( function(comment) {
|
||||
return comment.indexOf("@event") != -1;
|
||||
});
|
||||
eventComments = eventComments.concat(comments);
|
||||
}
|
||||
});
|
||||
// dedup
|
||||
return eventComments.filter( function(el, index, array) {
|
||||
return array.indexOf(el) === index;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @param
|
||||
* @return {Array.<string>}
|
||||
*/
|
||||
function getLeadingComments(node) {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
var comments = node.leadingComments;
|
||||
if (!comments || comments.length === 0) return;
|
||||
return comments.map(function(comment) {
|
||||
return comment.value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a parse5 Property AST node into its Hydrolysis representation.
|
||||
*
|
||||
* @param {Node} node
|
||||
* @return {PropertyDescriptor}
|
||||
*/
|
||||
function toPropertyDescriptor(node) {
|
||||
var type = closureType(node.value);
|
||||
if (type == "Function") {
|
||||
if (node.kind === "get" || node.kind === "set") {
|
||||
type = '';
|
||||
node[node.kind+"ter"] = true;
|
||||
}
|
||||
}
|
||||
var result = {
|
||||
name: objectKeyToString(node.key),
|
||||
type: type,
|
||||
desc: getAttachedComment(node),
|
||||
javascriptNode: node
|
||||
};
|
||||
|
||||
if (type === 'Function') {
|
||||
result.params = (node.value.params || []).map(function(param) {
|
||||
return {name: param.name};
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
closureType: closureType,
|
||||
getAttachedComment: getAttachedComment,
|
||||
getEventComments: getEventComments,
|
||||
matchesCallExpression: matchesCallExpression,
|
||||
objectKeyToString: objectKeyToString,
|
||||
toPropertyDescriptor: toPropertyDescriptor,
|
||||
};
|
||||
56
build/node_modules/hydrolysis/lib/ast-utils/feature-finder.js
generated
vendored
Normal file
56
build/node_modules/hydrolysis/lib/ast-utils/feature-finder.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
var estraverse = require('estraverse');
|
||||
|
||||
var esutil = require('./esutil');
|
||||
|
||||
var numFeatures = 0;
|
||||
|
||||
module.exports = function featureFinder() {
|
||||
/** @type {!Array<FeatureDescriptor>} The features we've found. */
|
||||
var features = [];
|
||||
|
||||
var visitors = {
|
||||
|
||||
enterCallExpression: function enterCallExpression(node, parent) {
|
||||
if (!esutil.matchesCallExpression(node.callee, ['Polymer', 'Base', '_addFeature'])) {
|
||||
return;
|
||||
}
|
||||
/** @type {!FeatureDescriptor} */
|
||||
var feature = {};
|
||||
this._extractDesc(feature, node, parent);
|
||||
this._extractProperties(feature, node, parent);
|
||||
|
||||
features.push(feature);
|
||||
},
|
||||
|
||||
_extractDesc: function _extractDesc(feature, node, parent) {
|
||||
feature.desc = esutil.getAttachedComment(parent);
|
||||
},
|
||||
|
||||
_extractProperties: function _extractProperties(feature, node, parent) {
|
||||
var featureNode = node.arguments[0];
|
||||
if (featureNode.type !== 'ObjectExpression') {
|
||||
console.warn(
|
||||
'Expected first argument to Polymer.Base._addFeature to be an object.',
|
||||
'Got', featureNode.type, 'instead.');
|
||||
return;
|
||||
}
|
||||
if (!featureNode.properties) return;
|
||||
|
||||
feature.properties = featureNode.properties.map(esutil.toPropertyDescriptor);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
return {visitors: visitors, features: features};
|
||||
};
|
||||
19
build/node_modules/hydrolysis/lib/ast-utils/find-alias.js
generated
vendored
Normal file
19
build/node_modules/hydrolysis/lib/ast-utils/find-alias.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
var findAlias = function findAlias(names, aliases, name) {
|
||||
if (!names) {
|
||||
return null;
|
||||
}
|
||||
return aliases[names.indexOf(name)];
|
||||
};
|
||||
|
||||
module.exports = findAlias;
|
||||
141
build/node_modules/hydrolysis/lib/ast-utils/import-parse.js
generated
vendored
Normal file
141
build/node_modules/hydrolysis/lib/ast-utils/import-parse.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
var dom5 = require('dom5');
|
||||
|
||||
var p = dom5.predicates;
|
||||
|
||||
var isHtmlImportNode = p.AND(
|
||||
p.hasTagName('link'),
|
||||
p.hasAttrValue('rel', 'import'),
|
||||
p.NOT(
|
||||
p.hasAttrValue('type', 'css')
|
||||
)
|
||||
);
|
||||
|
||||
var isStyleNode = p.OR(
|
||||
// inline style
|
||||
p.hasTagName('style'),
|
||||
// external stylesheet
|
||||
p.AND(
|
||||
p.hasTagName('link'),
|
||||
p.hasAttrValue('rel', 'stylesheet')
|
||||
),
|
||||
// polymer specific external stylesheet
|
||||
p.AND(
|
||||
p.hasTagName('link'),
|
||||
p.hasAttrValue('rel', 'import'),
|
||||
p.hasAttrValue('type', 'css')
|
||||
)
|
||||
);
|
||||
|
||||
var isJSScriptNode = p.AND(
|
||||
p.hasTagName('script'),
|
||||
p.OR(
|
||||
p.NOT(p.hasAttr('type')),
|
||||
p.hasAttrValue('type', 'text/javascript'),
|
||||
p.hasAttrValue('type', 'application/javascript')
|
||||
)
|
||||
);
|
||||
|
||||
function addNode(node, registry) {
|
||||
if (isHtmlImportNode(node)) {
|
||||
registry.import.push(node);
|
||||
} else if (isStyleNode(node)) {
|
||||
registry.style.push(node);
|
||||
} else if (isJSScriptNode(node)) {
|
||||
registry.script.push(node);
|
||||
} else if (node.tagName === 'base') {
|
||||
registry.base.push(node);
|
||||
} else if (node.tagName === 'template') {
|
||||
registry.template.push(node);
|
||||
} else if (node.tagName === 'dom-module') {
|
||||
registry['dom-module'].push(node);
|
||||
} else if (dom5.isCommentNode(node)) {
|
||||
registry.comment.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
function getLineAndColumn(string, charNumber) {
|
||||
if (charNumber > string.length) {
|
||||
return undefined;
|
||||
}
|
||||
// TODO(ajo): Caching the line lengths of each document could be much faster.
|
||||
var sliced = string.slice(0,charNumber+1);
|
||||
var split = sliced.split('\n');
|
||||
var line = split.length;
|
||||
var column = split[split.length - 1].length;
|
||||
return {line: line, column: column};
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse5's representation of a parsed html document.
|
||||
* @typedef {Object} DocumentAST
|
||||
*/
|
||||
|
||||
/**
|
||||
* The ASTs of the HTML elements needed to represent Polymer elements.
|
||||
* @typedef {Object} ParsedImport
|
||||
* @property {Array<DocumentAST>} template The entry points to the AST at each outermost template tag.
|
||||
* @property {Array<DocumentAST>} script The entry points to the AST at each script tag not inside a template.
|
||||
* @property {Array<DocumentAST>} style The entry points to the AST at style tag outside a template.
|
||||
* @property {Array<DocumentAST>} dom-module The entry points to the AST at each outermost dom-module element.
|
||||
* @property {DocumentAST} ast The full parse5 ast for the document.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parse html into ASTs.
|
||||
* @param {string} htmlString A utf8, html5 document containing polymer element or module definitons.
|
||||
* @param {string} href The path of the document.
|
||||
* @return {ParsedImport}
|
||||
*/
|
||||
var importParse = function importParse(htmlString, href) {
|
||||
var doc;
|
||||
try {
|
||||
doc = dom5.parse(htmlString, {locationInfo: true});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Add line/column information
|
||||
dom5.treeMap(doc, function(node) {
|
||||
if (node.__location && node.__location.start >= 0) {
|
||||
node.__locationDetail = getLineAndColumn(htmlString, node.__location.start);
|
||||
if (href) {
|
||||
node.__ownerDocument = href;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var registry = {
|
||||
base: [],
|
||||
template: [],
|
||||
script: [],
|
||||
style: [],
|
||||
import: [],
|
||||
'dom-module': [],
|
||||
comment: []};
|
||||
|
||||
var queue = [].concat(doc.childNodes);
|
||||
var nextNode;
|
||||
while (queue.length > 0) {
|
||||
nextNode = queue.shift();
|
||||
if (nextNode) {
|
||||
queue = queue.concat(nextNode.childNodes);
|
||||
addNode(nextNode, registry);
|
||||
}
|
||||
}
|
||||
registry.ast = doc;
|
||||
return registry;
|
||||
};
|
||||
|
||||
module.exports = importParse;
|
||||
95
build/node_modules/hydrolysis/lib/ast-utils/js-parse.js
generated
vendored
Normal file
95
build/node_modules/hydrolysis/lib/ast-utils/js-parse.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
/**
|
||||
* Finds and annotates the Polymer() and modulate() calls in javascript.
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
var espree = require('espree');
|
||||
var estraverse = require('estraverse');
|
||||
|
||||
var behaviorFinder = require('./behavior-finder');
|
||||
var elementFinder = require('./element-finder');
|
||||
var featureFinder = require('./feature-finder');
|
||||
|
||||
function traverse(visitorRegistries) {
|
||||
var visitor;
|
||||
function applyVisitors(name, node, parent) {
|
||||
var returnVal;
|
||||
for (var i = 0; i < visitorRegistries.length; i++) {
|
||||
if (name in visitorRegistries[i]) {
|
||||
returnVal = visitorRegistries[i][name](node, parent);
|
||||
if (returnVal) {
|
||||
return returnVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
enter: function(node, parent) {
|
||||
visitor = 'enter' + node.type;
|
||||
return applyVisitors(visitor, node, parent);
|
||||
},
|
||||
leave: function(node, parent) {
|
||||
visitor = 'leave' + node.type;
|
||||
return applyVisitors(visitor, node, parent);
|
||||
},
|
||||
fallback: 'iteration',
|
||||
};
|
||||
}
|
||||
|
||||
var jsParse = function jsParse(jsString) {
|
||||
var script = espree.parse(jsString, {
|
||||
attachComment: true,
|
||||
comment: true,
|
||||
loc: true,
|
||||
ecmaFeatures: {
|
||||
arrowFunctions: true,
|
||||
blockBindings: true,
|
||||
destructuring: true,
|
||||
regexYFlag: true,
|
||||
regexUFlag: true,
|
||||
templateStrings: true,
|
||||
binaryLiterals: true,
|
||||
unicodeCodePointEscapes: true,
|
||||
defaultParams: true,
|
||||
restParams: true,
|
||||
forOf: true,
|
||||
objectLiteralComputedProperties: true,
|
||||
objectLiteralShorthandMethods: true,
|
||||
objectLiteralShorthandProperties: true,
|
||||
objectLiteralDuplicateProperties: true,
|
||||
generators: true,
|
||||
spread: true,
|
||||
classes: true,
|
||||
modules: true,
|
||||
jsx: true,
|
||||
globalReturn: true,
|
||||
}
|
||||
});
|
||||
|
||||
var featureInfo = featureFinder();
|
||||
var behaviorInfo = behaviorFinder();
|
||||
var elementInfo = elementFinder();
|
||||
|
||||
var visitors = [featureInfo, behaviorInfo, elementInfo].map(function(info) {
|
||||
return info.visitors;
|
||||
});
|
||||
estraverse.traverse(script, traverse(visitors));
|
||||
|
||||
return {
|
||||
behaviors: behaviorInfo.behaviors,
|
||||
elements: elementInfo.elements,
|
||||
features: featureInfo.features,
|
||||
parsedScript: script
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = jsParse;
|
||||
223
build/node_modules/hydrolysis/lib/ast-utils/jsdoc.js
generated
vendored
Normal file
223
build/node_modules/hydrolysis/lib/ast-utils/jsdoc.js
generated
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
// jshint node: true
|
||||
'use strict';
|
||||
|
||||
var doctrine = require('doctrine');
|
||||
|
||||
/**
|
||||
* An annotated JSDoc block tag, all fields are optionally processed except for
|
||||
* the tag:
|
||||
*
|
||||
* @TAG {TYPE} NAME DESC
|
||||
*
|
||||
* `line` and `col` indicate the position of the first character of text that
|
||||
* the tag was extracted from - relative to the first character of the comment
|
||||
* contents (e.g. the value of `desc` on a descriptor node). Lines are
|
||||
* 1-indexed.
|
||||
*
|
||||
* @typedef {{
|
||||
* tag: string,
|
||||
* type: ?string,
|
||||
* name: ?string,
|
||||
* description: ?string,
|
||||
* }}
|
||||
*/
|
||||
var JsdocTag;
|
||||
|
||||
/**
|
||||
* The parsed representation of a JSDoc comment.
|
||||
*
|
||||
* @typedef {{
|
||||
* description: ?string,
|
||||
* tags: Array<JsdocTag>,
|
||||
* }}
|
||||
*/
|
||||
var JsdocAnnotation;
|
||||
|
||||
/**
|
||||
* doctrine configuration,
|
||||
* CURRENTLY UNUSED BECAUSE PRIVATE
|
||||
*/
|
||||
// function configureDoctrine() {
|
||||
|
||||
// // @hero [path/to/image]
|
||||
// doctrine.Rules['hero'] = ['parseNamePathOptional', 'ensureEnd'];
|
||||
|
||||
// // // @demo [path/to/demo] [Demo title]
|
||||
// doctrine.Rules['demo'] = ['parseNamePathOptional', 'parseDescription', 'ensureEnd'];
|
||||
|
||||
// // // @polymerBehavior [Polymer.BehaviorName]
|
||||
// doctrine.Rules['polymerBehavior'] = ['parseNamePathOptional', 'ensureEnd'];
|
||||
// }
|
||||
// configureDoctrine();
|
||||
|
||||
// @demo [path] [title]
|
||||
function parseDemo(tag) {
|
||||
var match = (tag.description || "").match(/^\s*(\S*)\s*(.*)$/);
|
||||
return {
|
||||
tag: 'demo',
|
||||
type: null,
|
||||
name: match ? match[1] : null,
|
||||
description: match ? match[2] : null
|
||||
};
|
||||
}
|
||||
|
||||
// @hero [path]
|
||||
function parseHero(tag) {
|
||||
return {
|
||||
tag: tag.title,
|
||||
type: null,
|
||||
name: tag.description,
|
||||
description: null
|
||||
};
|
||||
}
|
||||
|
||||
// @polymerBehavior [name]
|
||||
function parsePolymerBehavior(tag) {
|
||||
return {
|
||||
tag: tag.title,
|
||||
type: null,
|
||||
name: tag.description,
|
||||
description: null
|
||||
};
|
||||
}
|
||||
|
||||
// @pseudoElement name
|
||||
function parsePseudoElement(tag) {
|
||||
return {
|
||||
tag: tag.title,
|
||||
type: null,
|
||||
name: tag.description,
|
||||
description: null
|
||||
};
|
||||
}
|
||||
|
||||
var CUSTOM_TAGS = {
|
||||
demo: parseDemo,
|
||||
hero: parseHero,
|
||||
polymerBehavior: parsePolymerBehavior,
|
||||
pseudoElement: parsePseudoElement
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert doctrine tags to hydrolysis tag format
|
||||
*/
|
||||
function _tagsToHydroTags(tags) {
|
||||
if (!tags)
|
||||
return null;
|
||||
return tags.map( function(tag) {
|
||||
if (tag.title in CUSTOM_TAGS) {
|
||||
return CUSTOM_TAGS[tag.title](tag);
|
||||
}
|
||||
else {
|
||||
return {
|
||||
tag: tag.title,
|
||||
type: tag.type ? doctrine.type.stringify(tag.type) : null,
|
||||
name: tag.name,
|
||||
description: tag.description,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* removes leading *, and any space before it
|
||||
* @param {string} description -- js doc description
|
||||
*/
|
||||
function _removeLeadingAsterisks(description) {
|
||||
if ((typeof description) !== 'string')
|
||||
return description;
|
||||
|
||||
return description
|
||||
.split('\n')
|
||||
.map( function(line) {
|
||||
// remove leading '\s*' from each line
|
||||
var match = line.match(/^[\s]*\*\s?(.*)$/);
|
||||
return match ? match[1] : line;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a JSDoc string (minus opening/closing comment delimiters), extract its
|
||||
* description and tags.
|
||||
*
|
||||
* @param {string} docs
|
||||
* @return {?JsdocAnnotation}
|
||||
*/
|
||||
function parseJsdoc(docs) {
|
||||
docs = _removeLeadingAsterisks(docs);
|
||||
var d = doctrine.parse(docs, {
|
||||
unwrap: false,
|
||||
lineNumber: true,
|
||||
preserveWhitespace: true
|
||||
});
|
||||
return {
|
||||
description: d.description,
|
||||
tags: _tagsToHydroTags(d.tags)
|
||||
};
|
||||
}
|
||||
|
||||
// Utility
|
||||
|
||||
/**
|
||||
* @param {JsdocAnnotation} jsdoc
|
||||
* @param {string} tagName
|
||||
* @return {boolean}
|
||||
*/
|
||||
function hasTag(jsdoc, tagName) {
|
||||
if (!jsdoc || !jsdoc.tags) return false;
|
||||
return jsdoc.tags.some(function(tag) { return tag.tag === tagName; });
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first JSDoc tag matching `name` and returns its value at `key`.
|
||||
*
|
||||
* @param {JsdocAnnotation} jsdoc
|
||||
* @param {string} tagName
|
||||
* @param {string=} key If omitted, the entire tag object is returned.
|
||||
* @return {?string|Object}
|
||||
*/
|
||||
function getTag(jsdoc, tagName, key) {
|
||||
if (!jsdoc || !jsdoc.tags) return false;
|
||||
for (var i = 0; i < jsdoc.tags.length; i++) {
|
||||
var tag = jsdoc.tags[i];
|
||||
if (tag.tag === tagName) {
|
||||
return key ? tag[key] : tag;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?string} text
|
||||
* @return {?string}
|
||||
*/
|
||||
function unindent(text) {
|
||||
if (!text) return text;
|
||||
var lines = text.replace(/\t/g, ' ').split('\n');
|
||||
var indent = lines.reduce(function(prev, line) {
|
||||
if (/^\s*$/.test(line)) return prev; // Completely ignore blank lines.
|
||||
|
||||
var lineIndent = line.match(/^(\s*)/)[0].length;
|
||||
if (prev === null) return lineIndent;
|
||||
return lineIndent < prev ? lineIndent : prev;
|
||||
}, null);
|
||||
|
||||
return lines.map(function(l) { return l.substr(indent); }).join('\n');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getTag: getTag,
|
||||
hasTag: hasTag,
|
||||
parseJsdoc: parseJsdoc,
|
||||
unindent: unindent
|
||||
};
|
||||
30
build/node_modules/hydrolysis/lib/loader/error-swallowing-fs-resolver.js
generated
vendored
Normal file
30
build/node_modules/hydrolysis/lib/loader/error-swallowing-fs-resolver.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
// jshint node:true
|
||||
'use strict';
|
||||
|
||||
var FSResolver = require('./fs-resolver');
|
||||
|
||||
function ErrorSwallowingFSResolver(config) {
|
||||
FSResolver.call(this, config);
|
||||
}
|
||||
|
||||
ErrorSwallowingFSResolver.prototype = Object.create(FSResolver.prototype);
|
||||
|
||||
ErrorSwallowingFSResolver.prototype.accept = function(uri, deferred) {
|
||||
var reject = deferred.reject;
|
||||
deferred.reject = function(arg) {
|
||||
deferred.resolve("");
|
||||
};
|
||||
return FSResolver.prototype.accept.call(this, uri, deferred);
|
||||
};
|
||||
|
||||
module.exports = ErrorSwallowingFSResolver;
|
||||
99
build/node_modules/hydrolysis/lib/loader/file-loader.js
generated
vendored
Normal file
99
build/node_modules/hydrolysis/lib/loader/file-loader.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
// jshint node:true
|
||||
'use strict';
|
||||
|
||||
// jshint -W079
|
||||
// Promise polyfill
|
||||
var Promise = global.Promise || require('es6-promise').Promise;
|
||||
// jshint +W079
|
||||
|
||||
function Deferred() {
|
||||
var self = this;
|
||||
this.promise = new Promise(function(resolve, reject) {
|
||||
self.resolve = resolve;
|
||||
self.reject = reject;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* An object that knows how to resolve resources.
|
||||
* @typedef {Object} Resolver
|
||||
* @memberof hydrolysis
|
||||
* @property {function(string, Deferred): boolean} accept Attempt to resolve
|
||||
* `deferred` with the contents the specified URL. Returns false if the
|
||||
* Resolver is unable to resolve the URL.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* A FileLoader lets you resolve URLs with a set of potential resolvers.
|
||||
* @constructor
|
||||
* @memberof hydrolysis
|
||||
*/
|
||||
function FileLoader() {
|
||||
this.resolvers = [];
|
||||
// map url -> Deferred
|
||||
this.requests = {};
|
||||
}
|
||||
FileLoader.prototype = {
|
||||
|
||||
/**
|
||||
* Add an instance of a Resolver class to the list of url resolvers
|
||||
*
|
||||
* Ordering of resolvers is most to least recently added
|
||||
* The first resolver to "accept" the url wins.
|
||||
* @param {Resolver} resolver The resolver to add.
|
||||
*/
|
||||
addResolver: function(resolver) {
|
||||
this.resolvers.push(resolver);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a promise for an absolute url
|
||||
*
|
||||
* Url requests are deduplicated by the loader, returning the same Promise for
|
||||
* identical urls
|
||||
*
|
||||
* @param {string} url The absolute url to request.
|
||||
* @return {Promise.<string>} A promise that resolves to the contents of the URL.
|
||||
*/
|
||||
request: function(uri) {
|
||||
var promise;
|
||||
|
||||
if (!(uri in this.requests)) {
|
||||
var handled = false;
|
||||
var deferred = new Deferred();
|
||||
this.requests[uri] = deferred;
|
||||
|
||||
// loop backwards through resolvers until one "accepts" the request
|
||||
for (var i = this.resolvers.length - 1, r; i >= 0; i--) {
|
||||
r = this.resolvers[i];
|
||||
if (r.accept(uri, deferred)) {
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!handled) {
|
||||
deferred.reject(new Error('no resolver found for ' + uri));
|
||||
}
|
||||
|
||||
promise = deferred.promise;
|
||||
} else {
|
||||
promise = this.requests[uri].promise;
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = FileLoader;
|
||||
110
build/node_modules/hydrolysis/lib/loader/fs-resolver.js
generated
vendored
Normal file
110
build/node_modules/hydrolysis/lib/loader/fs-resolver.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
// jshint node:true
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var pathIsAbsolute = require('path-is-absolute');
|
||||
var url = require('url');
|
||||
|
||||
function getFile(filePath, deferred, secondPath) {
|
||||
fs.readFile(filePath, 'utf-8', function(err, content) {
|
||||
if (err) {
|
||||
if (secondPath) {
|
||||
getFile(secondPath, deferred);
|
||||
} else {
|
||||
console.log("ERROR finding " + filePath);
|
||||
deferred.reject(err);
|
||||
}
|
||||
} else {
|
||||
deferred.resolve(content);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if `patha` is a sibling or aunt of `pathb`.
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isSiblingOrAunt(patha, pathb) {
|
||||
var parent = path.dirname(patha);
|
||||
if (pathb.indexOf(patha) === -1 && pathb.indexOf(parent) === 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change `localPath` from a sibling of `basePath` to be a child of
|
||||
* `basePath` joined with `redirect`.
|
||||
* @return {string}
|
||||
*/
|
||||
function redirectSibling(basePath, localPath, redirect) {
|
||||
var parent = path.dirname(basePath);
|
||||
var redirected = path.join(basePath, redirect, localPath.slice(parent.length));
|
||||
return redirected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves requests via the file system.
|
||||
* @constructor
|
||||
* @memberof hydrolysis
|
||||
* @param {Object} config configuration options.
|
||||
* @param {string} config.host Hostname to match for absolute urls.
|
||||
* Matches "/" by default
|
||||
* @param {string} config.basePath Prefix directory for components in url.
|
||||
* Defaults to "/".
|
||||
* @param {string} config.root Filesystem root to search. Defaults to the
|
||||
* current working directory.
|
||||
* @param {string} config.redirect Where to redirect lookups to siblings.
|
||||
*/
|
||||
function FSResolver(config) {
|
||||
this.config = config || {};
|
||||
}
|
||||
FSResolver.prototype = {
|
||||
accept: function(uri, deferred) {
|
||||
var parsed = url.parse(uri);
|
||||
var host = this.config.host;
|
||||
var base = this.config.basePath && decodeURIComponent(this.config.basePath);
|
||||
var root = this.config.root && path.normalize(this.config.root);
|
||||
var redirect = this.config.redirect;
|
||||
|
||||
var local;
|
||||
|
||||
if (!parsed.hostname || parsed.hostname === host) {
|
||||
local = parsed.pathname;
|
||||
}
|
||||
if (local) {
|
||||
// un-escape HTML escapes
|
||||
local = decodeURIComponent(local);
|
||||
|
||||
if (base) {
|
||||
local = path.relative(base, local);
|
||||
}
|
||||
if (root) {
|
||||
local = path.join(root, local);
|
||||
}
|
||||
|
||||
var backup;
|
||||
if (redirect && isSiblingOrAunt(root, local)) {
|
||||
backup = redirectSibling(root, local, redirect);
|
||||
}
|
||||
|
||||
getFile(local, deferred, backup);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = FSResolver;
|
||||
44
build/node_modules/hydrolysis/lib/loader/noop-resolver.js
generated
vendored
Normal file
44
build/node_modules/hydrolysis/lib/loader/noop-resolver.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
// jshint node:true
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A resolver that resolves to null any uri matching config.
|
||||
* @constructor
|
||||
* @memberof hydrolysis
|
||||
* @param {string} config The url to `accept`.
|
||||
*/
|
||||
function NoopResolver(config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
NoopResolver.prototype = {
|
||||
|
||||
/**
|
||||
* @param {string} uri The absolute URI being requested.
|
||||
* @param {!Deferred} deferred The deferred promise that should be resolved if
|
||||
* this resolver handles the URI.
|
||||
* @return {boolean} Whether the URI is handled by this resolver.
|
||||
*/
|
||||
accept: function(uri, deferred) {
|
||||
if (!this.config.test) {
|
||||
if (uri.search(this.config) == -1) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this.config.test(uri)) return false;
|
||||
|
||||
deferred.resolve('');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = NoopResolver;
|
||||
106
build/node_modules/hydrolysis/lib/loader/redirect-resolver.js
generated
vendored
Normal file
106
build/node_modules/hydrolysis/lib/loader/redirect-resolver.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
// jshint node:true
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
|
||||
var FSResolver = require('./fs-resolver');
|
||||
|
||||
/**
|
||||
* A single redirect configuration
|
||||
* @param {Object} config The configuration object
|
||||
* @param {string} config.protocol The protocol this redirect matches.
|
||||
* @param {string} config.hostname The host name this redirect matches.
|
||||
* @param {string} config.path The part of the path to match and
|
||||
* replace with 'redirectPath'
|
||||
* @param {string} config.redirectPath The local filesystem path that should
|
||||
* replace "protocol://hosname/path/"
|
||||
*/
|
||||
function ProtocolRedirect(config){
|
||||
this.protocol = config.protocol;
|
||||
this.hostname = config.hostname;
|
||||
this.path = config.path;
|
||||
this.redirectPath = config.redirectPath;
|
||||
}
|
||||
|
||||
ProtocolRedirect.prototype = {
|
||||
/**
|
||||
* The protocol this redirect matches.
|
||||
* @type {string}
|
||||
*/
|
||||
protocol: null,
|
||||
/**
|
||||
* The host name this redirect matches.
|
||||
* @type {string}
|
||||
*/
|
||||
hostname: null,
|
||||
|
||||
/**
|
||||
* The part of the path to match and replace with 'redirectPath'
|
||||
* @type {string}
|
||||
*/
|
||||
path: null,
|
||||
|
||||
/**
|
||||
* The local filesystem path that should replace "protocol://hosname/path/"
|
||||
* @type {string}
|
||||
*/
|
||||
redirectPath: null,
|
||||
|
||||
redirect: function redirect(uri) {
|
||||
var parsed = url.parse(uri);
|
||||
if (this.protocol !== parsed.protocol) {
|
||||
return null;
|
||||
} else if (this.hostname !== parsed.hostname) {
|
||||
return null;
|
||||
} else if (parsed.pathname.indexOf(this.path) !== 0) {
|
||||
return null;
|
||||
}
|
||||
return path.join(this.redirectPath,
|
||||
parsed.pathname.slice(this.path.length));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolves protocol://hostname/path to the local filesystem.
|
||||
* @constructor
|
||||
* @memberof hydrolysis
|
||||
* @param {Object} config configuration options.
|
||||
* @param {string} config.root Filesystem root to search. Defaults to the
|
||||
* current working directory.
|
||||
* @param {Array.<ProtocolRedirect>} redirects A list of protocol redirects
|
||||
* for the resolver. They are checked for matching first-to-last.
|
||||
*/
|
||||
function RedirectResolver(config) {
|
||||
FSResolver.call(this, config);
|
||||
this.redirects = config.redirects || [];
|
||||
}
|
||||
|
||||
RedirectResolver.prototype = Object.create(FSResolver.prototype);
|
||||
|
||||
RedirectResolver.prototype.accept = function(uri, deferred) {
|
||||
for (var i = 0; i < this.redirects.length; i++) {
|
||||
var redirected = this.redirects[i].redirect(uri);
|
||||
if (redirected) {
|
||||
return FSResolver.prototype.accept.call(this, redirected, deferred);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
RedirectResolver.prototype.constructor = RedirectResolver;
|
||||
RedirectResolver.ProtocolRedirect = ProtocolRedirect;
|
||||
|
||||
|
||||
module.exports = RedirectResolver;
|
||||
54
build/node_modules/hydrolysis/lib/loader/string-resolver.js
generated
vendored
Normal file
54
build/node_modules/hydrolysis/lib/loader/string-resolver.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
// jshint node:true
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A resolver that resolves to `config.content` any uri matching config.
|
||||
* @constructor
|
||||
* @memberof hydrolysis
|
||||
* @param {string|RegExp} config.url The url or rejex to accept.
|
||||
* @param {string} config.content The content to serve for `url`.
|
||||
*/
|
||||
function StringResolver(config) {
|
||||
this.url = config.url;
|
||||
this.content = config.content;
|
||||
if (!this.url || !this.content) {
|
||||
throw new Error("Must provide a url and content to the string resolver.");
|
||||
}
|
||||
}
|
||||
|
||||
StringResolver.prototype = {
|
||||
|
||||
/**
|
||||
* @param {string} uri The absolute URI being requested.
|
||||
* @param {!Deferred} deferred The deferred promise that should be resolved if
|
||||
* this resolver handles the URI.
|
||||
* @return {boolean} Whether the URI is handled by this resolver.
|
||||
*/
|
||||
accept: function(uri, deferred) {
|
||||
if (this.url.test) {
|
||||
// this.url is a regex
|
||||
if (!this.url.test(uri)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// this.url is a string
|
||||
if (uri.search(this.url) == -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
deferred.resolve(this.content);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = StringResolver;
|
||||
53
build/node_modules/hydrolysis/lib/loader/xhr-resolver.js
generated
vendored
Normal file
53
build/node_modules/hydrolysis/lib/loader/xhr-resolver.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
// jshint node:true
|
||||
'use strict';
|
||||
|
||||
function getFile(url, deferred, config) {
|
||||
/* global XMLHttpRequest:false */
|
||||
var x = new XMLHttpRequest();
|
||||
x.onload = function() {
|
||||
var status = x.status || 0;
|
||||
if (status >= 200 && status < 300) {
|
||||
deferred.resolve(x.response);
|
||||
} else {
|
||||
deferred.reject('xhr status: ' + status);
|
||||
}
|
||||
};
|
||||
x.onerror = function(e) {
|
||||
deferred.reject(e);
|
||||
};
|
||||
x.open('GET', url, true);
|
||||
if (config && config.responseType) {
|
||||
x.responseType = config.responseType;
|
||||
}
|
||||
x.send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a resolver that requests resources over XHR.
|
||||
* @constructor
|
||||
* @memberof hydrolysis
|
||||
* @param {Object} config configuration arguments.
|
||||
* @param {string} config.responseType Type of object to be returned by the
|
||||
* XHR. Defaults to 'text', accepts 'document', 'arraybuffer', and 'json'.
|
||||
*/
|
||||
function XHRResolver(config) {
|
||||
this.config = config;
|
||||
}
|
||||
XHRResolver.prototype = {
|
||||
accept: function(uri, deferred) {
|
||||
getFile(uri, deferred, this.config);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = XHRResolver;
|
||||
1
build/node_modules/hydrolysis/node_modules/.bin/esparse
generated
vendored
Symbolic link
1
build/node_modules/hydrolysis/node_modules/.bin/esparse
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../espree/bin/esparse.js
|
||||
1
build/node_modules/hydrolysis/node_modules/.bin/esvalidate
generated
vendored
Symbolic link
1
build/node_modules/hydrolysis/node_modules/.bin/esvalidate
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../espree/bin/esvalidate.js
|
||||
9
build/node_modules/hydrolysis/node_modules/es6-promise/CHANGELOG.md
generated
vendored
Normal file
9
build/node_modules/hydrolysis/node_modules/es6-promise/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Master
|
||||
|
||||
# 2.0.0
|
||||
|
||||
* re-sync with RSVP. Many large performance improvements and bugfixes.
|
||||
|
||||
# 1.0.0
|
||||
|
||||
* first subset of RSVP
|
||||
19
build/node_modules/hydrolysis/node_modules/es6-promise/LICENSE
generated
vendored
Normal file
19
build/node_modules/hydrolysis/node_modules/es6-promise/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
61
build/node_modules/hydrolysis/node_modules/es6-promise/README.md
generated
vendored
Normal file
61
build/node_modules/hydrolysis/node_modules/es6-promise/README.md
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
# ES6-Promise (subset of [rsvp.js](https://github.com/tildeio/rsvp.js))
|
||||
|
||||
This is a polyfill of the [ES6 Promise](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-constructor). The implementation is a subset of [rsvp.js](https://github.com/tildeio/rsvp.js), if you're wanting extra features and more debugging options, check out the [full library](https://github.com/tildeio/rsvp.js).
|
||||
|
||||
For API details and how to use promises, see the <a href="http://www.html5rocks.com/en/tutorials/es6/promises/">JavaScript Promises HTML5Rocks article</a>.
|
||||
|
||||
## Downloads
|
||||
|
||||
* [es6-promise](https://raw.githubusercontent.com/jakearchibald/es6-promise/master/dist/es6-promise.js)
|
||||
* [es6-promise-min](https://raw.githubusercontent.com/jakearchibald/es6-promise/master/dist/es6-promise.min.js)
|
||||
|
||||
## Node.js
|
||||
|
||||
To install:
|
||||
|
||||
```sh
|
||||
npm install es6-promise
|
||||
```
|
||||
|
||||
To use:
|
||||
|
||||
```js
|
||||
var Promise = require('es6-promise').Promise;
|
||||
```
|
||||
|
||||
## Usage in IE<9
|
||||
|
||||
`catch` is a reserved word in IE<9, meaning `promise.catch(func)` throws a syntax error. To work around this, you can use a string to access the property as shown in the following example.
|
||||
|
||||
However, please remember that such technique is already provided by most common minifiers, making the resulting code safe for old browsers and production:
|
||||
|
||||
```js
|
||||
promise['catch'](function(err) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
Or use `.then` instead:
|
||||
|
||||
```js
|
||||
promise.then(undefined, function(err) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
## Auto-polyfill
|
||||
|
||||
To polyfill the global environment (either in Node or in the browser via CommonJS) use the following code snippet:
|
||||
|
||||
```js
|
||||
require('es6-promise').polyfill();
|
||||
```
|
||||
|
||||
Notice that we don't assign the result of `polyfill()` to any variable. The `polyfill()` method will patch the global environment (in this case to the `Promise` name) when called.
|
||||
|
||||
## Building & Testing
|
||||
|
||||
* `npm run build` to build
|
||||
* `npm test` to run tests
|
||||
* `npm start` to run a build watcher, and webserver to test
|
||||
* `npm run test:server` for a testem test runner and watching builder
|
||||
972
build/node_modules/hydrolysis/node_modules/es6-promise/dist/es6-promise.js
generated
vendored
Normal file
972
build/node_modules/hydrolysis/node_modules/es6-promise/dist/es6-promise.js
generated
vendored
Normal file
@@ -0,0 +1,972 @@
|
||||
/*!
|
||||
* @overview es6-promise - a tiny implementation of Promises/A+.
|
||||
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
|
||||
* @license Licensed under MIT license
|
||||
* See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
|
||||
* @version 2.3.0
|
||||
*/
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
function lib$es6$promise$utils$$objectOrFunction(x) {
|
||||
return typeof x === 'function' || (typeof x === 'object' && x !== null);
|
||||
}
|
||||
|
||||
function lib$es6$promise$utils$$isFunction(x) {
|
||||
return typeof x === 'function';
|
||||
}
|
||||
|
||||
function lib$es6$promise$utils$$isMaybeThenable(x) {
|
||||
return typeof x === 'object' && x !== null;
|
||||
}
|
||||
|
||||
var lib$es6$promise$utils$$_isArray;
|
||||
if (!Array.isArray) {
|
||||
lib$es6$promise$utils$$_isArray = function (x) {
|
||||
return Object.prototype.toString.call(x) === '[object Array]';
|
||||
};
|
||||
} else {
|
||||
lib$es6$promise$utils$$_isArray = Array.isArray;
|
||||
}
|
||||
|
||||
var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray;
|
||||
var lib$es6$promise$asap$$len = 0;
|
||||
var lib$es6$promise$asap$$toString = {}.toString;
|
||||
var lib$es6$promise$asap$$vertxNext;
|
||||
var lib$es6$promise$asap$$customSchedulerFn;
|
||||
|
||||
var lib$es6$promise$asap$$asap = function asap(callback, arg) {
|
||||
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
|
||||
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg;
|
||||
lib$es6$promise$asap$$len += 2;
|
||||
if (lib$es6$promise$asap$$len === 2) {
|
||||
// If len is 2, that means that we need to schedule an async flush.
|
||||
// If additional callbacks are queued before the queue is flushed, they
|
||||
// will be processed by this flush that we are scheduling.
|
||||
if (lib$es6$promise$asap$$customSchedulerFn) {
|
||||
lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush);
|
||||
} else {
|
||||
lib$es6$promise$asap$$scheduleFlush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$setScheduler(scheduleFn) {
|
||||
lib$es6$promise$asap$$customSchedulerFn = scheduleFn;
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$setAsap(asapFn) {
|
||||
lib$es6$promise$asap$$asap = asapFn;
|
||||
}
|
||||
|
||||
var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined;
|
||||
var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {};
|
||||
var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
|
||||
var lib$es6$promise$asap$$isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
||||
|
||||
// test for web worker but not in IE10
|
||||
var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
|
||||
typeof importScripts !== 'undefined' &&
|
||||
typeof MessageChannel !== 'undefined';
|
||||
|
||||
// node
|
||||
function lib$es6$promise$asap$$useNextTick() {
|
||||
var nextTick = process.nextTick;
|
||||
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
||||
// setImmediate should be used instead instead
|
||||
var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);
|
||||
if (Array.isArray(version) && version[1] === '0' && version[2] === '10') {
|
||||
nextTick = setImmediate;
|
||||
}
|
||||
return function() {
|
||||
nextTick(lib$es6$promise$asap$$flush);
|
||||
};
|
||||
}
|
||||
|
||||
// vertx
|
||||
function lib$es6$promise$asap$$useVertxTimer() {
|
||||
return function() {
|
||||
lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush);
|
||||
};
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$useMutationObserver() {
|
||||
var iterations = 0;
|
||||
var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush);
|
||||
var node = document.createTextNode('');
|
||||
observer.observe(node, { characterData: true });
|
||||
|
||||
return function() {
|
||||
node.data = (iterations = ++iterations % 2);
|
||||
};
|
||||
}
|
||||
|
||||
// web worker
|
||||
function lib$es6$promise$asap$$useMessageChannel() {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.onmessage = lib$es6$promise$asap$$flush;
|
||||
return function () {
|
||||
channel.port2.postMessage(0);
|
||||
};
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$useSetTimeout() {
|
||||
return function() {
|
||||
setTimeout(lib$es6$promise$asap$$flush, 1);
|
||||
};
|
||||
}
|
||||
|
||||
var lib$es6$promise$asap$$queue = new Array(1000);
|
||||
function lib$es6$promise$asap$$flush() {
|
||||
for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) {
|
||||
var callback = lib$es6$promise$asap$$queue[i];
|
||||
var arg = lib$es6$promise$asap$$queue[i+1];
|
||||
|
||||
callback(arg);
|
||||
|
||||
lib$es6$promise$asap$$queue[i] = undefined;
|
||||
lib$es6$promise$asap$$queue[i+1] = undefined;
|
||||
}
|
||||
|
||||
lib$es6$promise$asap$$len = 0;
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$attemptVertex() {
|
||||
try {
|
||||
var r = require;
|
||||
var vertx = r('vertx');
|
||||
lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
||||
return lib$es6$promise$asap$$useVertxTimer();
|
||||
} catch(e) {
|
||||
return lib$es6$promise$asap$$useSetTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
var lib$es6$promise$asap$$scheduleFlush;
|
||||
// Decide what async method to use to triggering processing of queued callbacks:
|
||||
if (lib$es6$promise$asap$$isNode) {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick();
|
||||
} else if (lib$es6$promise$asap$$BrowserMutationObserver) {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver();
|
||||
} else if (lib$es6$promise$asap$$isWorker) {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel();
|
||||
} else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertex();
|
||||
} else {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$noop() {}
|
||||
|
||||
var lib$es6$promise$$internal$$PENDING = void 0;
|
||||
var lib$es6$promise$$internal$$FULFILLED = 1;
|
||||
var lib$es6$promise$$internal$$REJECTED = 2;
|
||||
|
||||
var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject();
|
||||
|
||||
function lib$es6$promise$$internal$$selfFullfillment() {
|
||||
return new TypeError("You cannot resolve a promise with itself");
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$cannotReturnOwn() {
|
||||
return new TypeError('A promises callback cannot return that same promise.');
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$getThen(promise) {
|
||||
try {
|
||||
return promise.then;
|
||||
} catch(error) {
|
||||
lib$es6$promise$$internal$$GET_THEN_ERROR.error = error;
|
||||
return lib$es6$promise$$internal$$GET_THEN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
|
||||
try {
|
||||
then.call(value, fulfillmentHandler, rejectionHandler);
|
||||
} catch(e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) {
|
||||
lib$es6$promise$asap$$asap(function(promise) {
|
||||
var sealed = false;
|
||||
var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) {
|
||||
if (sealed) { return; }
|
||||
sealed = true;
|
||||
if (thenable !== value) {
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
} else {
|
||||
lib$es6$promise$$internal$$fulfill(promise, value);
|
||||
}
|
||||
}, function(reason) {
|
||||
if (sealed) { return; }
|
||||
sealed = true;
|
||||
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
||||
|
||||
if (!sealed && error) {
|
||||
sealed = true;
|
||||
lib$es6$promise$$internal$$reject(promise, error);
|
||||
}
|
||||
}, promise);
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) {
|
||||
if (thenable._state === lib$es6$promise$$internal$$FULFILLED) {
|
||||
lib$es6$promise$$internal$$fulfill(promise, thenable._result);
|
||||
} else if (thenable._state === lib$es6$promise$$internal$$REJECTED) {
|
||||
lib$es6$promise$$internal$$reject(promise, thenable._result);
|
||||
} else {
|
||||
lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) {
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
}, function(reason) {
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable) {
|
||||
if (maybeThenable.constructor === promise.constructor) {
|
||||
lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
|
||||
} else {
|
||||
var then = lib$es6$promise$$internal$$getThen(maybeThenable);
|
||||
|
||||
if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
|
||||
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
|
||||
} else if (then === undefined) {
|
||||
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
|
||||
} else if (lib$es6$promise$utils$$isFunction(then)) {
|
||||
lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then);
|
||||
} else {
|
||||
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$resolve(promise, value) {
|
||||
if (promise === value) {
|
||||
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFullfillment());
|
||||
} else if (lib$es6$promise$utils$$objectOrFunction(value)) {
|
||||
lib$es6$promise$$internal$$handleMaybeThenable(promise, value);
|
||||
} else {
|
||||
lib$es6$promise$$internal$$fulfill(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$publishRejection(promise) {
|
||||
if (promise._onerror) {
|
||||
promise._onerror(promise._result);
|
||||
}
|
||||
|
||||
lib$es6$promise$$internal$$publish(promise);
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$fulfill(promise, value) {
|
||||
if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
|
||||
|
||||
promise._result = value;
|
||||
promise._state = lib$es6$promise$$internal$$FULFILLED;
|
||||
|
||||
if (promise._subscribers.length !== 0) {
|
||||
lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$reject(promise, reason) {
|
||||
if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
|
||||
promise._state = lib$es6$promise$$internal$$REJECTED;
|
||||
promise._result = reason;
|
||||
|
||||
lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise);
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
|
||||
var subscribers = parent._subscribers;
|
||||
var length = subscribers.length;
|
||||
|
||||
parent._onerror = null;
|
||||
|
||||
subscribers[length] = child;
|
||||
subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment;
|
||||
subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection;
|
||||
|
||||
if (length === 0 && parent._state) {
|
||||
lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$publish(promise) {
|
||||
var subscribers = promise._subscribers;
|
||||
var settled = promise._state;
|
||||
|
||||
if (subscribers.length === 0) { return; }
|
||||
|
||||
var child, callback, detail = promise._result;
|
||||
|
||||
for (var i = 0; i < subscribers.length; i += 3) {
|
||||
child = subscribers[i];
|
||||
callback = subscribers[i + settled];
|
||||
|
||||
if (child) {
|
||||
lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail);
|
||||
} else {
|
||||
callback(detail);
|
||||
}
|
||||
}
|
||||
|
||||
promise._subscribers.length = 0;
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$ErrorObject() {
|
||||
this.error = null;
|
||||
}
|
||||
|
||||
var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject();
|
||||
|
||||
function lib$es6$promise$$internal$$tryCatch(callback, detail) {
|
||||
try {
|
||||
return callback(detail);
|
||||
} catch(e) {
|
||||
lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e;
|
||||
return lib$es6$promise$$internal$$TRY_CATCH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) {
|
||||
var hasCallback = lib$es6$promise$utils$$isFunction(callback),
|
||||
value, error, succeeded, failed;
|
||||
|
||||
if (hasCallback) {
|
||||
value = lib$es6$promise$$internal$$tryCatch(callback, detail);
|
||||
|
||||
if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) {
|
||||
failed = true;
|
||||
error = value.error;
|
||||
value = null;
|
||||
} else {
|
||||
succeeded = true;
|
||||
}
|
||||
|
||||
if (promise === value) {
|
||||
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn());
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
value = detail;
|
||||
succeeded = true;
|
||||
}
|
||||
|
||||
if (promise._state !== lib$es6$promise$$internal$$PENDING) {
|
||||
// noop
|
||||
} else if (hasCallback && succeeded) {
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
} else if (failed) {
|
||||
lib$es6$promise$$internal$$reject(promise, error);
|
||||
} else if (settled === lib$es6$promise$$internal$$FULFILLED) {
|
||||
lib$es6$promise$$internal$$fulfill(promise, value);
|
||||
} else if (settled === lib$es6$promise$$internal$$REJECTED) {
|
||||
lib$es6$promise$$internal$$reject(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$initializePromise(promise, resolver) {
|
||||
try {
|
||||
resolver(function resolvePromise(value){
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
}, function rejectPromise(reason) {
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
});
|
||||
} catch(e) {
|
||||
lib$es6$promise$$internal$$reject(promise, e);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
|
||||
var enumerator = this;
|
||||
|
||||
enumerator._instanceConstructor = Constructor;
|
||||
enumerator.promise = new Constructor(lib$es6$promise$$internal$$noop);
|
||||
|
||||
if (enumerator._validateInput(input)) {
|
||||
enumerator._input = input;
|
||||
enumerator.length = input.length;
|
||||
enumerator._remaining = input.length;
|
||||
|
||||
enumerator._init();
|
||||
|
||||
if (enumerator.length === 0) {
|
||||
lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
|
||||
} else {
|
||||
enumerator.length = enumerator.length || 0;
|
||||
enumerator._enumerate();
|
||||
if (enumerator._remaining === 0) {
|
||||
lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lib$es6$promise$$internal$$reject(enumerator.promise, enumerator._validationError());
|
||||
}
|
||||
}
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._validateInput = function(input) {
|
||||
return lib$es6$promise$utils$$isArray(input);
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._validationError = function() {
|
||||
return new Error('Array Methods must be provided an Array');
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._init = function() {
|
||||
this._result = new Array(this.length);
|
||||
};
|
||||
|
||||
var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
|
||||
var enumerator = this;
|
||||
|
||||
var length = enumerator.length;
|
||||
var promise = enumerator.promise;
|
||||
var input = enumerator._input;
|
||||
|
||||
for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
|
||||
enumerator._eachEntry(input[i], i);
|
||||
}
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
|
||||
var enumerator = this;
|
||||
var c = enumerator._instanceConstructor;
|
||||
|
||||
if (lib$es6$promise$utils$$isMaybeThenable(entry)) {
|
||||
if (entry.constructor === c && entry._state !== lib$es6$promise$$internal$$PENDING) {
|
||||
entry._onerror = null;
|
||||
enumerator._settledAt(entry._state, i, entry._result);
|
||||
} else {
|
||||
enumerator._willSettleAt(c.resolve(entry), i);
|
||||
}
|
||||
} else {
|
||||
enumerator._remaining--;
|
||||
enumerator._result[i] = entry;
|
||||
}
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
|
||||
var enumerator = this;
|
||||
var promise = enumerator.promise;
|
||||
|
||||
if (promise._state === lib$es6$promise$$internal$$PENDING) {
|
||||
enumerator._remaining--;
|
||||
|
||||
if (state === lib$es6$promise$$internal$$REJECTED) {
|
||||
lib$es6$promise$$internal$$reject(promise, value);
|
||||
} else {
|
||||
enumerator._result[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (enumerator._remaining === 0) {
|
||||
lib$es6$promise$$internal$$fulfill(promise, enumerator._result);
|
||||
}
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
|
||||
var enumerator = this;
|
||||
|
||||
lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
|
||||
enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
|
||||
}, function(reason) {
|
||||
enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
|
||||
});
|
||||
};
|
||||
function lib$es6$promise$promise$all$$all(entries) {
|
||||
return new lib$es6$promise$enumerator$$default(this, entries).promise;
|
||||
}
|
||||
var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all;
|
||||
function lib$es6$promise$promise$race$$race(entries) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
|
||||
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
||||
|
||||
if (!lib$es6$promise$utils$$isArray(entries)) {
|
||||
lib$es6$promise$$internal$$reject(promise, new TypeError('You must pass an array to race.'));
|
||||
return promise;
|
||||
}
|
||||
|
||||
var length = entries.length;
|
||||
|
||||
function onFulfillment(value) {
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
}
|
||||
|
||||
function onRejection(reason) {
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
}
|
||||
|
||||
for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
|
||||
lib$es6$promise$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
|
||||
function lib$es6$promise$promise$resolve$$resolve(object) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
|
||||
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
||||
return object;
|
||||
}
|
||||
|
||||
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
||||
lib$es6$promise$$internal$$resolve(promise, object);
|
||||
return promise;
|
||||
}
|
||||
var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
|
||||
function lib$es6$promise$promise$reject$$reject(reason) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
return promise;
|
||||
}
|
||||
var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
|
||||
|
||||
var lib$es6$promise$promise$$counter = 0;
|
||||
|
||||
function lib$es6$promise$promise$$needsResolver() {
|
||||
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
||||
}
|
||||
|
||||
function lib$es6$promise$promise$$needsNew() {
|
||||
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
||||
}
|
||||
|
||||
var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise;
|
||||
/**
|
||||
Promise objects represent the eventual result of an asynchronous operation. The
|
||||
primary way of interacting with a promise is through its `then` method, which
|
||||
registers callbacks to receive either a promise's eventual value or the reason
|
||||
why the promise cannot be fulfilled.
|
||||
|
||||
Terminology
|
||||
-----------
|
||||
|
||||
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
||||
- `thenable` is an object or function that defines a `then` method.
|
||||
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
||||
- `exception` is a value that is thrown using the throw statement.
|
||||
- `reason` is a value that indicates why a promise was rejected.
|
||||
- `settled` the final resting state of a promise, fulfilled or rejected.
|
||||
|
||||
A promise can be in one of three states: pending, fulfilled, or rejected.
|
||||
|
||||
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
||||
state. Promises that are rejected have a rejection reason and are in the
|
||||
rejected state. A fulfillment value is never a thenable.
|
||||
|
||||
Promises can also be said to *resolve* a value. If this value is also a
|
||||
promise, then the original promise's settled state will match the value's
|
||||
settled state. So a promise that *resolves* a promise that rejects will
|
||||
itself reject, and a promise that *resolves* a promise that fulfills will
|
||||
itself fulfill.
|
||||
|
||||
|
||||
Basic Usage:
|
||||
------------
|
||||
|
||||
```js
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
// on success
|
||||
resolve(value);
|
||||
|
||||
// on failure
|
||||
reject(reason);
|
||||
});
|
||||
|
||||
promise.then(function(value) {
|
||||
// on fulfillment
|
||||
}, function(reason) {
|
||||
// on rejection
|
||||
});
|
||||
```
|
||||
|
||||
Advanced Usage:
|
||||
---------------
|
||||
|
||||
Promises shine when abstracting away asynchronous interactions such as
|
||||
`XMLHttpRequest`s.
|
||||
|
||||
```js
|
||||
function getJSON(url) {
|
||||
return new Promise(function(resolve, reject){
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', url);
|
||||
xhr.onreadystatechange = handler;
|
||||
xhr.responseType = 'json';
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
xhr.send();
|
||||
|
||||
function handler() {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 200) {
|
||||
resolve(this.response);
|
||||
} else {
|
||||
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
getJSON('/posts.json').then(function(json) {
|
||||
// on fulfillment
|
||||
}, function(reason) {
|
||||
// on rejection
|
||||
});
|
||||
```
|
||||
|
||||
Unlike callbacks, promises are great composable primitives.
|
||||
|
||||
```js
|
||||
Promise.all([
|
||||
getJSON('/posts'),
|
||||
getJSON('/comments')
|
||||
]).then(function(values){
|
||||
values[0] // => postsJSON
|
||||
values[1] // => commentsJSON
|
||||
|
||||
return values;
|
||||
});
|
||||
```
|
||||
|
||||
@class Promise
|
||||
@param {function} resolver
|
||||
Useful for tooling.
|
||||
@constructor
|
||||
*/
|
||||
function lib$es6$promise$promise$$Promise(resolver) {
|
||||
this._id = lib$es6$promise$promise$$counter++;
|
||||
this._state = undefined;
|
||||
this._result = undefined;
|
||||
this._subscribers = [];
|
||||
|
||||
if (lib$es6$promise$$internal$$noop !== resolver) {
|
||||
if (!lib$es6$promise$utils$$isFunction(resolver)) {
|
||||
lib$es6$promise$promise$$needsResolver();
|
||||
}
|
||||
|
||||
if (!(this instanceof lib$es6$promise$promise$$Promise)) {
|
||||
lib$es6$promise$promise$$needsNew();
|
||||
}
|
||||
|
||||
lib$es6$promise$$internal$$initializePromise(this, resolver);
|
||||
}
|
||||
}
|
||||
|
||||
lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default;
|
||||
lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default;
|
||||
lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default;
|
||||
lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default;
|
||||
lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler;
|
||||
lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap;
|
||||
lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap;
|
||||
|
||||
lib$es6$promise$promise$$Promise.prototype = {
|
||||
constructor: lib$es6$promise$promise$$Promise,
|
||||
|
||||
/**
|
||||
The primary way of interacting with a promise is through its `then` method,
|
||||
which registers callbacks to receive either a promise's eventual value or the
|
||||
reason why the promise cannot be fulfilled.
|
||||
|
||||
```js
|
||||
findUser().then(function(user){
|
||||
// user is available
|
||||
}, function(reason){
|
||||
// user is unavailable, and you are given the reason why
|
||||
});
|
||||
```
|
||||
|
||||
Chaining
|
||||
--------
|
||||
|
||||
The return value of `then` is itself a promise. This second, 'downstream'
|
||||
promise is resolved with the return value of the first promise's fulfillment
|
||||
or rejection handler, or rejected if the handler throws an exception.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return user.name;
|
||||
}, function (reason) {
|
||||
return 'default name';
|
||||
}).then(function (userName) {
|
||||
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
||||
// will be `'default name'`
|
||||
});
|
||||
|
||||
findUser().then(function (user) {
|
||||
throw new Error('Found user, but still unhappy');
|
||||
}, function (reason) {
|
||||
throw new Error('`findUser` rejected and we're unhappy');
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}, function (reason) {
|
||||
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
||||
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
||||
});
|
||||
```
|
||||
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
throw new PedagogicalException('Upstream error');
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}, function (reason) {
|
||||
// The `PedgagocialException` is propagated all the way down to here
|
||||
});
|
||||
```
|
||||
|
||||
Assimilation
|
||||
------------
|
||||
|
||||
Sometimes the value you want to propagate to a downstream promise can only be
|
||||
retrieved asynchronously. This can be achieved by returning a promise in the
|
||||
fulfillment or rejection handler. The downstream promise will then be pending
|
||||
until the returned promise is settled. This is called *assimilation*.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return findCommentsByAuthor(user);
|
||||
}).then(function (comments) {
|
||||
// The user's comments are now available
|
||||
});
|
||||
```
|
||||
|
||||
If the assimliated promise rejects, then the downstream promise will also reject.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return findCommentsByAuthor(user);
|
||||
}).then(function (comments) {
|
||||
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
||||
}, function (reason) {
|
||||
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
||||
});
|
||||
```
|
||||
|
||||
Simple Example
|
||||
--------------
|
||||
|
||||
Synchronous Example
|
||||
|
||||
```javascript
|
||||
var result;
|
||||
|
||||
try {
|
||||
result = findResult();
|
||||
// success
|
||||
} catch(reason) {
|
||||
// failure
|
||||
}
|
||||
```
|
||||
|
||||
Errback Example
|
||||
|
||||
```js
|
||||
findResult(function(result, err){
|
||||
if (err) {
|
||||
// failure
|
||||
} else {
|
||||
// success
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Promise Example;
|
||||
|
||||
```javascript
|
||||
findResult().then(function(result){
|
||||
// success
|
||||
}, function(reason){
|
||||
// failure
|
||||
});
|
||||
```
|
||||
|
||||
Advanced Example
|
||||
--------------
|
||||
|
||||
Synchronous Example
|
||||
|
||||
```javascript
|
||||
var author, books;
|
||||
|
||||
try {
|
||||
author = findAuthor();
|
||||
books = findBooksByAuthor(author);
|
||||
// success
|
||||
} catch(reason) {
|
||||
// failure
|
||||
}
|
||||
```
|
||||
|
||||
Errback Example
|
||||
|
||||
```js
|
||||
|
||||
function foundBooks(books) {
|
||||
|
||||
}
|
||||
|
||||
function failure(reason) {
|
||||
|
||||
}
|
||||
|
||||
findAuthor(function(author, err){
|
||||
if (err) {
|
||||
failure(err);
|
||||
// failure
|
||||
} else {
|
||||
try {
|
||||
findBoooksByAuthor(author, function(books, err) {
|
||||
if (err) {
|
||||
failure(err);
|
||||
} else {
|
||||
try {
|
||||
foundBooks(books);
|
||||
} catch(reason) {
|
||||
failure(reason);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(error) {
|
||||
failure(err);
|
||||
}
|
||||
// success
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Promise Example;
|
||||
|
||||
```javascript
|
||||
findAuthor().
|
||||
then(findBooksByAuthor).
|
||||
then(function(books){
|
||||
// found books
|
||||
}).catch(function(reason){
|
||||
// something went wrong
|
||||
});
|
||||
```
|
||||
|
||||
@method then
|
||||
@param {Function} onFulfilled
|
||||
@param {Function} onRejected
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
then: function(onFulfillment, onRejection) {
|
||||
var parent = this;
|
||||
var state = parent._state;
|
||||
|
||||
if (state === lib$es6$promise$$internal$$FULFILLED && !onFulfillment || state === lib$es6$promise$$internal$$REJECTED && !onRejection) {
|
||||
return this;
|
||||
}
|
||||
|
||||
var child = new this.constructor(lib$es6$promise$$internal$$noop);
|
||||
var result = parent._result;
|
||||
|
||||
if (state) {
|
||||
var callback = arguments[state - 1];
|
||||
lib$es6$promise$asap$$asap(function(){
|
||||
lib$es6$promise$$internal$$invokeCallback(state, child, callback, result);
|
||||
});
|
||||
} else {
|
||||
lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
/**
|
||||
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
||||
as the catch block of a try/catch statement.
|
||||
|
||||
```js
|
||||
function findAuthor(){
|
||||
throw new Error('couldn't find that author');
|
||||
}
|
||||
|
||||
// synchronous
|
||||
try {
|
||||
findAuthor();
|
||||
} catch(reason) {
|
||||
// something went wrong
|
||||
}
|
||||
|
||||
// async with promises
|
||||
findAuthor().catch(function(reason){
|
||||
// something went wrong
|
||||
});
|
||||
```
|
||||
|
||||
@method catch
|
||||
@param {Function} onRejection
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
'catch': function(onRejection) {
|
||||
return this.then(null, onRejection);
|
||||
}
|
||||
};
|
||||
function lib$es6$promise$polyfill$$polyfill() {
|
||||
var local;
|
||||
|
||||
if (typeof global !== 'undefined') {
|
||||
local = global;
|
||||
} else if (typeof self !== 'undefined') {
|
||||
local = self;
|
||||
} else {
|
||||
try {
|
||||
local = Function('return this')();
|
||||
} catch (e) {
|
||||
throw new Error('polyfill failed because global object is unavailable in this environment');
|
||||
}
|
||||
}
|
||||
|
||||
var P = local.Promise;
|
||||
|
||||
if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) {
|
||||
return;
|
||||
}
|
||||
|
||||
local.Promise = lib$es6$promise$promise$$default;
|
||||
}
|
||||
var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill;
|
||||
|
||||
var lib$es6$promise$umd$$ES6Promise = {
|
||||
'Promise': lib$es6$promise$promise$$default,
|
||||
'polyfill': lib$es6$promise$polyfill$$default
|
||||
};
|
||||
|
||||
/* global define:true module:true window: true */
|
||||
if (typeof define === 'function' && define['amd']) {
|
||||
define(function() { return lib$es6$promise$umd$$ES6Promise; });
|
||||
} else if (typeof module !== 'undefined' && module['exports']) {
|
||||
module['exports'] = lib$es6$promise$umd$$ES6Promise;
|
||||
} else if (typeof this !== 'undefined') {
|
||||
this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise;
|
||||
}
|
||||
|
||||
lib$es6$promise$polyfill$$default();
|
||||
}).call(this);
|
||||
|
||||
9
build/node_modules/hydrolysis/node_modules/es6-promise/dist/es6-promise.min.js
generated
vendored
Normal file
9
build/node_modules/hydrolysis/node_modules/es6-promise/dist/es6-promise.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
11727
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/browserify.js
generated
vendored
Normal file
11727
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/browserify.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
965
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/es6-promise.js
generated
vendored
Normal file
965
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/es6-promise.js
generated
vendored
Normal file
@@ -0,0 +1,965 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
function lib$es6$promise$utils$$objectOrFunction(x) {
|
||||
return typeof x === 'function' || (typeof x === 'object' && x !== null);
|
||||
}
|
||||
|
||||
function lib$es6$promise$utils$$isFunction(x) {
|
||||
return typeof x === 'function';
|
||||
}
|
||||
|
||||
function lib$es6$promise$utils$$isMaybeThenable(x) {
|
||||
return typeof x === 'object' && x !== null;
|
||||
}
|
||||
|
||||
var lib$es6$promise$utils$$_isArray;
|
||||
if (!Array.isArray) {
|
||||
lib$es6$promise$utils$$_isArray = function (x) {
|
||||
return Object.prototype.toString.call(x) === '[object Array]';
|
||||
};
|
||||
} else {
|
||||
lib$es6$promise$utils$$_isArray = Array.isArray;
|
||||
}
|
||||
|
||||
var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray;
|
||||
var lib$es6$promise$asap$$len = 0;
|
||||
var lib$es6$promise$asap$$toString = {}.toString;
|
||||
var lib$es6$promise$asap$$vertxNext;
|
||||
var lib$es6$promise$asap$$customSchedulerFn;
|
||||
|
||||
var lib$es6$promise$asap$$asap = function asap(callback, arg) {
|
||||
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
|
||||
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg;
|
||||
lib$es6$promise$asap$$len += 2;
|
||||
if (lib$es6$promise$asap$$len === 2) {
|
||||
// If len is 2, that means that we need to schedule an async flush.
|
||||
// If additional callbacks are queued before the queue is flushed, they
|
||||
// will be processed by this flush that we are scheduling.
|
||||
if (lib$es6$promise$asap$$customSchedulerFn) {
|
||||
lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush);
|
||||
} else {
|
||||
lib$es6$promise$asap$$scheduleFlush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$setScheduler(scheduleFn) {
|
||||
lib$es6$promise$asap$$customSchedulerFn = scheduleFn;
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$setAsap(asapFn) {
|
||||
lib$es6$promise$asap$$asap = asapFn;
|
||||
}
|
||||
|
||||
var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined;
|
||||
var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {};
|
||||
var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
|
||||
var lib$es6$promise$asap$$isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
||||
|
||||
// test for web worker but not in IE10
|
||||
var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
|
||||
typeof importScripts !== 'undefined' &&
|
||||
typeof MessageChannel !== 'undefined';
|
||||
|
||||
// node
|
||||
function lib$es6$promise$asap$$useNextTick() {
|
||||
var nextTick = process.nextTick;
|
||||
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
||||
// setImmediate should be used instead instead
|
||||
var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);
|
||||
if (Array.isArray(version) && version[1] === '0' && version[2] === '10') {
|
||||
nextTick = setImmediate;
|
||||
}
|
||||
return function() {
|
||||
nextTick(lib$es6$promise$asap$$flush);
|
||||
};
|
||||
}
|
||||
|
||||
// vertx
|
||||
function lib$es6$promise$asap$$useVertxTimer() {
|
||||
return function() {
|
||||
lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush);
|
||||
};
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$useMutationObserver() {
|
||||
var iterations = 0;
|
||||
var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush);
|
||||
var node = document.createTextNode('');
|
||||
observer.observe(node, { characterData: true });
|
||||
|
||||
return function() {
|
||||
node.data = (iterations = ++iterations % 2);
|
||||
};
|
||||
}
|
||||
|
||||
// web worker
|
||||
function lib$es6$promise$asap$$useMessageChannel() {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.onmessage = lib$es6$promise$asap$$flush;
|
||||
return function () {
|
||||
channel.port2.postMessage(0);
|
||||
};
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$useSetTimeout() {
|
||||
return function() {
|
||||
setTimeout(lib$es6$promise$asap$$flush, 1);
|
||||
};
|
||||
}
|
||||
|
||||
var lib$es6$promise$asap$$queue = new Array(1000);
|
||||
function lib$es6$promise$asap$$flush() {
|
||||
for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) {
|
||||
var callback = lib$es6$promise$asap$$queue[i];
|
||||
var arg = lib$es6$promise$asap$$queue[i+1];
|
||||
|
||||
callback(arg);
|
||||
|
||||
lib$es6$promise$asap$$queue[i] = undefined;
|
||||
lib$es6$promise$asap$$queue[i+1] = undefined;
|
||||
}
|
||||
|
||||
lib$es6$promise$asap$$len = 0;
|
||||
}
|
||||
|
||||
function lib$es6$promise$asap$$attemptVertex() {
|
||||
try {
|
||||
var r = require;
|
||||
var vertx = r('vertx');
|
||||
lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
||||
return lib$es6$promise$asap$$useVertxTimer();
|
||||
} catch(e) {
|
||||
return lib$es6$promise$asap$$useSetTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
var lib$es6$promise$asap$$scheduleFlush;
|
||||
// Decide what async method to use to triggering processing of queued callbacks:
|
||||
if (lib$es6$promise$asap$$isNode) {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick();
|
||||
} else if (lib$es6$promise$asap$$BrowserMutationObserver) {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver();
|
||||
} else if (lib$es6$promise$asap$$isWorker) {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel();
|
||||
} else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertex();
|
||||
} else {
|
||||
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$noop() {}
|
||||
|
||||
var lib$es6$promise$$internal$$PENDING = void 0;
|
||||
var lib$es6$promise$$internal$$FULFILLED = 1;
|
||||
var lib$es6$promise$$internal$$REJECTED = 2;
|
||||
|
||||
var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject();
|
||||
|
||||
function lib$es6$promise$$internal$$selfFullfillment() {
|
||||
return new TypeError("You cannot resolve a promise with itself");
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$cannotReturnOwn() {
|
||||
return new TypeError('A promises callback cannot return that same promise.');
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$getThen(promise) {
|
||||
try {
|
||||
return promise.then;
|
||||
} catch(error) {
|
||||
lib$es6$promise$$internal$$GET_THEN_ERROR.error = error;
|
||||
return lib$es6$promise$$internal$$GET_THEN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
|
||||
try {
|
||||
then.call(value, fulfillmentHandler, rejectionHandler);
|
||||
} catch(e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) {
|
||||
lib$es6$promise$asap$$asap(function(promise) {
|
||||
var sealed = false;
|
||||
var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) {
|
||||
if (sealed) { return; }
|
||||
sealed = true;
|
||||
if (thenable !== value) {
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
} else {
|
||||
lib$es6$promise$$internal$$fulfill(promise, value);
|
||||
}
|
||||
}, function(reason) {
|
||||
if (sealed) { return; }
|
||||
sealed = true;
|
||||
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
||||
|
||||
if (!sealed && error) {
|
||||
sealed = true;
|
||||
lib$es6$promise$$internal$$reject(promise, error);
|
||||
}
|
||||
}, promise);
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) {
|
||||
if (thenable._state === lib$es6$promise$$internal$$FULFILLED) {
|
||||
lib$es6$promise$$internal$$fulfill(promise, thenable._result);
|
||||
} else if (thenable._state === lib$es6$promise$$internal$$REJECTED) {
|
||||
lib$es6$promise$$internal$$reject(promise, thenable._result);
|
||||
} else {
|
||||
lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) {
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
}, function(reason) {
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable) {
|
||||
if (maybeThenable.constructor === promise.constructor) {
|
||||
lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
|
||||
} else {
|
||||
var then = lib$es6$promise$$internal$$getThen(maybeThenable);
|
||||
|
||||
if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
|
||||
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
|
||||
} else if (then === undefined) {
|
||||
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
|
||||
} else if (lib$es6$promise$utils$$isFunction(then)) {
|
||||
lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then);
|
||||
} else {
|
||||
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$resolve(promise, value) {
|
||||
if (promise === value) {
|
||||
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFullfillment());
|
||||
} else if (lib$es6$promise$utils$$objectOrFunction(value)) {
|
||||
lib$es6$promise$$internal$$handleMaybeThenable(promise, value);
|
||||
} else {
|
||||
lib$es6$promise$$internal$$fulfill(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$publishRejection(promise) {
|
||||
if (promise._onerror) {
|
||||
promise._onerror(promise._result);
|
||||
}
|
||||
|
||||
lib$es6$promise$$internal$$publish(promise);
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$fulfill(promise, value) {
|
||||
if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
|
||||
|
||||
promise._result = value;
|
||||
promise._state = lib$es6$promise$$internal$$FULFILLED;
|
||||
|
||||
if (promise._subscribers.length !== 0) {
|
||||
lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$reject(promise, reason) {
|
||||
if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
|
||||
promise._state = lib$es6$promise$$internal$$REJECTED;
|
||||
promise._result = reason;
|
||||
|
||||
lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise);
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
|
||||
var subscribers = parent._subscribers;
|
||||
var length = subscribers.length;
|
||||
|
||||
parent._onerror = null;
|
||||
|
||||
subscribers[length] = child;
|
||||
subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment;
|
||||
subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection;
|
||||
|
||||
if (length === 0 && parent._state) {
|
||||
lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$publish(promise) {
|
||||
var subscribers = promise._subscribers;
|
||||
var settled = promise._state;
|
||||
|
||||
if (subscribers.length === 0) { return; }
|
||||
|
||||
var child, callback, detail = promise._result;
|
||||
|
||||
for (var i = 0; i < subscribers.length; i += 3) {
|
||||
child = subscribers[i];
|
||||
callback = subscribers[i + settled];
|
||||
|
||||
if (child) {
|
||||
lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail);
|
||||
} else {
|
||||
callback(detail);
|
||||
}
|
||||
}
|
||||
|
||||
promise._subscribers.length = 0;
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$ErrorObject() {
|
||||
this.error = null;
|
||||
}
|
||||
|
||||
var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject();
|
||||
|
||||
function lib$es6$promise$$internal$$tryCatch(callback, detail) {
|
||||
try {
|
||||
return callback(detail);
|
||||
} catch(e) {
|
||||
lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e;
|
||||
return lib$es6$promise$$internal$$TRY_CATCH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) {
|
||||
var hasCallback = lib$es6$promise$utils$$isFunction(callback),
|
||||
value, error, succeeded, failed;
|
||||
|
||||
if (hasCallback) {
|
||||
value = lib$es6$promise$$internal$$tryCatch(callback, detail);
|
||||
|
||||
if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) {
|
||||
failed = true;
|
||||
error = value.error;
|
||||
value = null;
|
||||
} else {
|
||||
succeeded = true;
|
||||
}
|
||||
|
||||
if (promise === value) {
|
||||
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn());
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
value = detail;
|
||||
succeeded = true;
|
||||
}
|
||||
|
||||
if (promise._state !== lib$es6$promise$$internal$$PENDING) {
|
||||
// noop
|
||||
} else if (hasCallback && succeeded) {
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
} else if (failed) {
|
||||
lib$es6$promise$$internal$$reject(promise, error);
|
||||
} else if (settled === lib$es6$promise$$internal$$FULFILLED) {
|
||||
lib$es6$promise$$internal$$fulfill(promise, value);
|
||||
} else if (settled === lib$es6$promise$$internal$$REJECTED) {
|
||||
lib$es6$promise$$internal$$reject(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$$internal$$initializePromise(promise, resolver) {
|
||||
try {
|
||||
resolver(function resolvePromise(value){
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
}, function rejectPromise(reason) {
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
});
|
||||
} catch(e) {
|
||||
lib$es6$promise$$internal$$reject(promise, e);
|
||||
}
|
||||
}
|
||||
|
||||
function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
|
||||
var enumerator = this;
|
||||
|
||||
enumerator._instanceConstructor = Constructor;
|
||||
enumerator.promise = new Constructor(lib$es6$promise$$internal$$noop);
|
||||
|
||||
if (enumerator._validateInput(input)) {
|
||||
enumerator._input = input;
|
||||
enumerator.length = input.length;
|
||||
enumerator._remaining = input.length;
|
||||
|
||||
enumerator._init();
|
||||
|
||||
if (enumerator.length === 0) {
|
||||
lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
|
||||
} else {
|
||||
enumerator.length = enumerator.length || 0;
|
||||
enumerator._enumerate();
|
||||
if (enumerator._remaining === 0) {
|
||||
lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lib$es6$promise$$internal$$reject(enumerator.promise, enumerator._validationError());
|
||||
}
|
||||
}
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._validateInput = function(input) {
|
||||
return lib$es6$promise$utils$$isArray(input);
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._validationError = function() {
|
||||
return new Error('Array Methods must be provided an Array');
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._init = function() {
|
||||
this._result = new Array(this.length);
|
||||
};
|
||||
|
||||
var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
|
||||
var enumerator = this;
|
||||
|
||||
var length = enumerator.length;
|
||||
var promise = enumerator.promise;
|
||||
var input = enumerator._input;
|
||||
|
||||
for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
|
||||
enumerator._eachEntry(input[i], i);
|
||||
}
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
|
||||
var enumerator = this;
|
||||
var c = enumerator._instanceConstructor;
|
||||
|
||||
if (lib$es6$promise$utils$$isMaybeThenable(entry)) {
|
||||
if (entry.constructor === c && entry._state !== lib$es6$promise$$internal$$PENDING) {
|
||||
entry._onerror = null;
|
||||
enumerator._settledAt(entry._state, i, entry._result);
|
||||
} else {
|
||||
enumerator._willSettleAt(c.resolve(entry), i);
|
||||
}
|
||||
} else {
|
||||
enumerator._remaining--;
|
||||
enumerator._result[i] = entry;
|
||||
}
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
|
||||
var enumerator = this;
|
||||
var promise = enumerator.promise;
|
||||
|
||||
if (promise._state === lib$es6$promise$$internal$$PENDING) {
|
||||
enumerator._remaining--;
|
||||
|
||||
if (state === lib$es6$promise$$internal$$REJECTED) {
|
||||
lib$es6$promise$$internal$$reject(promise, value);
|
||||
} else {
|
||||
enumerator._result[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (enumerator._remaining === 0) {
|
||||
lib$es6$promise$$internal$$fulfill(promise, enumerator._result);
|
||||
}
|
||||
};
|
||||
|
||||
lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
|
||||
var enumerator = this;
|
||||
|
||||
lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
|
||||
enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
|
||||
}, function(reason) {
|
||||
enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
|
||||
});
|
||||
};
|
||||
function lib$es6$promise$promise$all$$all(entries) {
|
||||
return new lib$es6$promise$enumerator$$default(this, entries).promise;
|
||||
}
|
||||
var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all;
|
||||
function lib$es6$promise$promise$race$$race(entries) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
|
||||
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
||||
|
||||
if (!lib$es6$promise$utils$$isArray(entries)) {
|
||||
lib$es6$promise$$internal$$reject(promise, new TypeError('You must pass an array to race.'));
|
||||
return promise;
|
||||
}
|
||||
|
||||
var length = entries.length;
|
||||
|
||||
function onFulfillment(value) {
|
||||
lib$es6$promise$$internal$$resolve(promise, value);
|
||||
}
|
||||
|
||||
function onRejection(reason) {
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
}
|
||||
|
||||
for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
|
||||
lib$es6$promise$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
|
||||
function lib$es6$promise$promise$resolve$$resolve(object) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
|
||||
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
||||
return object;
|
||||
}
|
||||
|
||||
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
||||
lib$es6$promise$$internal$$resolve(promise, object);
|
||||
return promise;
|
||||
}
|
||||
var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
|
||||
function lib$es6$promise$promise$reject$$reject(reason) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
||||
lib$es6$promise$$internal$$reject(promise, reason);
|
||||
return promise;
|
||||
}
|
||||
var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
|
||||
|
||||
var lib$es6$promise$promise$$counter = 0;
|
||||
|
||||
function lib$es6$promise$promise$$needsResolver() {
|
||||
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
||||
}
|
||||
|
||||
function lib$es6$promise$promise$$needsNew() {
|
||||
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
||||
}
|
||||
|
||||
var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise;
|
||||
/**
|
||||
Promise objects represent the eventual result of an asynchronous operation. The
|
||||
primary way of interacting with a promise is through its `then` method, which
|
||||
registers callbacks to receive either a promise's eventual value or the reason
|
||||
why the promise cannot be fulfilled.
|
||||
|
||||
Terminology
|
||||
-----------
|
||||
|
||||
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
||||
- `thenable` is an object or function that defines a `then` method.
|
||||
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
||||
- `exception` is a value that is thrown using the throw statement.
|
||||
- `reason` is a value that indicates why a promise was rejected.
|
||||
- `settled` the final resting state of a promise, fulfilled or rejected.
|
||||
|
||||
A promise can be in one of three states: pending, fulfilled, or rejected.
|
||||
|
||||
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
||||
state. Promises that are rejected have a rejection reason and are in the
|
||||
rejected state. A fulfillment value is never a thenable.
|
||||
|
||||
Promises can also be said to *resolve* a value. If this value is also a
|
||||
promise, then the original promise's settled state will match the value's
|
||||
settled state. So a promise that *resolves* a promise that rejects will
|
||||
itself reject, and a promise that *resolves* a promise that fulfills will
|
||||
itself fulfill.
|
||||
|
||||
|
||||
Basic Usage:
|
||||
------------
|
||||
|
||||
```js
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
// on success
|
||||
resolve(value);
|
||||
|
||||
// on failure
|
||||
reject(reason);
|
||||
});
|
||||
|
||||
promise.then(function(value) {
|
||||
// on fulfillment
|
||||
}, function(reason) {
|
||||
// on rejection
|
||||
});
|
||||
```
|
||||
|
||||
Advanced Usage:
|
||||
---------------
|
||||
|
||||
Promises shine when abstracting away asynchronous interactions such as
|
||||
`XMLHttpRequest`s.
|
||||
|
||||
```js
|
||||
function getJSON(url) {
|
||||
return new Promise(function(resolve, reject){
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', url);
|
||||
xhr.onreadystatechange = handler;
|
||||
xhr.responseType = 'json';
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
xhr.send();
|
||||
|
||||
function handler() {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 200) {
|
||||
resolve(this.response);
|
||||
} else {
|
||||
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
getJSON('/posts.json').then(function(json) {
|
||||
// on fulfillment
|
||||
}, function(reason) {
|
||||
// on rejection
|
||||
});
|
||||
```
|
||||
|
||||
Unlike callbacks, promises are great composable primitives.
|
||||
|
||||
```js
|
||||
Promise.all([
|
||||
getJSON('/posts'),
|
||||
getJSON('/comments')
|
||||
]).then(function(values){
|
||||
values[0] // => postsJSON
|
||||
values[1] // => commentsJSON
|
||||
|
||||
return values;
|
||||
});
|
||||
```
|
||||
|
||||
@class Promise
|
||||
@param {function} resolver
|
||||
Useful for tooling.
|
||||
@constructor
|
||||
*/
|
||||
function lib$es6$promise$promise$$Promise(resolver) {
|
||||
this._id = lib$es6$promise$promise$$counter++;
|
||||
this._state = undefined;
|
||||
this._result = undefined;
|
||||
this._subscribers = [];
|
||||
|
||||
if (lib$es6$promise$$internal$$noop !== resolver) {
|
||||
if (!lib$es6$promise$utils$$isFunction(resolver)) {
|
||||
lib$es6$promise$promise$$needsResolver();
|
||||
}
|
||||
|
||||
if (!(this instanceof lib$es6$promise$promise$$Promise)) {
|
||||
lib$es6$promise$promise$$needsNew();
|
||||
}
|
||||
|
||||
lib$es6$promise$$internal$$initializePromise(this, resolver);
|
||||
}
|
||||
}
|
||||
|
||||
lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default;
|
||||
lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default;
|
||||
lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default;
|
||||
lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default;
|
||||
lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler;
|
||||
lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap;
|
||||
lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap;
|
||||
|
||||
lib$es6$promise$promise$$Promise.prototype = {
|
||||
constructor: lib$es6$promise$promise$$Promise,
|
||||
|
||||
/**
|
||||
The primary way of interacting with a promise is through its `then` method,
|
||||
which registers callbacks to receive either a promise's eventual value or the
|
||||
reason why the promise cannot be fulfilled.
|
||||
|
||||
```js
|
||||
findUser().then(function(user){
|
||||
// user is available
|
||||
}, function(reason){
|
||||
// user is unavailable, and you are given the reason why
|
||||
});
|
||||
```
|
||||
|
||||
Chaining
|
||||
--------
|
||||
|
||||
The return value of `then` is itself a promise. This second, 'downstream'
|
||||
promise is resolved with the return value of the first promise's fulfillment
|
||||
or rejection handler, or rejected if the handler throws an exception.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return user.name;
|
||||
}, function (reason) {
|
||||
return 'default name';
|
||||
}).then(function (userName) {
|
||||
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
||||
// will be `'default name'`
|
||||
});
|
||||
|
||||
findUser().then(function (user) {
|
||||
throw new Error('Found user, but still unhappy');
|
||||
}, function (reason) {
|
||||
throw new Error('`findUser` rejected and we're unhappy');
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}, function (reason) {
|
||||
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
||||
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
||||
});
|
||||
```
|
||||
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
throw new PedagogicalException('Upstream error');
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}, function (reason) {
|
||||
// The `PedgagocialException` is propagated all the way down to here
|
||||
});
|
||||
```
|
||||
|
||||
Assimilation
|
||||
------------
|
||||
|
||||
Sometimes the value you want to propagate to a downstream promise can only be
|
||||
retrieved asynchronously. This can be achieved by returning a promise in the
|
||||
fulfillment or rejection handler. The downstream promise will then be pending
|
||||
until the returned promise is settled. This is called *assimilation*.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return findCommentsByAuthor(user);
|
||||
}).then(function (comments) {
|
||||
// The user's comments are now available
|
||||
});
|
||||
```
|
||||
|
||||
If the assimliated promise rejects, then the downstream promise will also reject.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return findCommentsByAuthor(user);
|
||||
}).then(function (comments) {
|
||||
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
||||
}, function (reason) {
|
||||
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
||||
});
|
||||
```
|
||||
|
||||
Simple Example
|
||||
--------------
|
||||
|
||||
Synchronous Example
|
||||
|
||||
```javascript
|
||||
var result;
|
||||
|
||||
try {
|
||||
result = findResult();
|
||||
// success
|
||||
} catch(reason) {
|
||||
// failure
|
||||
}
|
||||
```
|
||||
|
||||
Errback Example
|
||||
|
||||
```js
|
||||
findResult(function(result, err){
|
||||
if (err) {
|
||||
// failure
|
||||
} else {
|
||||
// success
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Promise Example;
|
||||
|
||||
```javascript
|
||||
findResult().then(function(result){
|
||||
// success
|
||||
}, function(reason){
|
||||
// failure
|
||||
});
|
||||
```
|
||||
|
||||
Advanced Example
|
||||
--------------
|
||||
|
||||
Synchronous Example
|
||||
|
||||
```javascript
|
||||
var author, books;
|
||||
|
||||
try {
|
||||
author = findAuthor();
|
||||
books = findBooksByAuthor(author);
|
||||
// success
|
||||
} catch(reason) {
|
||||
// failure
|
||||
}
|
||||
```
|
||||
|
||||
Errback Example
|
||||
|
||||
```js
|
||||
|
||||
function foundBooks(books) {
|
||||
|
||||
}
|
||||
|
||||
function failure(reason) {
|
||||
|
||||
}
|
||||
|
||||
findAuthor(function(author, err){
|
||||
if (err) {
|
||||
failure(err);
|
||||
// failure
|
||||
} else {
|
||||
try {
|
||||
findBoooksByAuthor(author, function(books, err) {
|
||||
if (err) {
|
||||
failure(err);
|
||||
} else {
|
||||
try {
|
||||
foundBooks(books);
|
||||
} catch(reason) {
|
||||
failure(reason);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(error) {
|
||||
failure(err);
|
||||
}
|
||||
// success
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Promise Example;
|
||||
|
||||
```javascript
|
||||
findAuthor().
|
||||
then(findBooksByAuthor).
|
||||
then(function(books){
|
||||
// found books
|
||||
}).catch(function(reason){
|
||||
// something went wrong
|
||||
});
|
||||
```
|
||||
|
||||
@method then
|
||||
@param {Function} onFulfilled
|
||||
@param {Function} onRejected
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
then: function(onFulfillment, onRejection) {
|
||||
var parent = this;
|
||||
var state = parent._state;
|
||||
|
||||
if (state === lib$es6$promise$$internal$$FULFILLED && !onFulfillment || state === lib$es6$promise$$internal$$REJECTED && !onRejection) {
|
||||
return this;
|
||||
}
|
||||
|
||||
var child = new this.constructor(lib$es6$promise$$internal$$noop);
|
||||
var result = parent._result;
|
||||
|
||||
if (state) {
|
||||
var callback = arguments[state - 1];
|
||||
lib$es6$promise$asap$$asap(function(){
|
||||
lib$es6$promise$$internal$$invokeCallback(state, child, callback, result);
|
||||
});
|
||||
} else {
|
||||
lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
/**
|
||||
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
||||
as the catch block of a try/catch statement.
|
||||
|
||||
```js
|
||||
function findAuthor(){
|
||||
throw new Error('couldn't find that author');
|
||||
}
|
||||
|
||||
// synchronous
|
||||
try {
|
||||
findAuthor();
|
||||
} catch(reason) {
|
||||
// something went wrong
|
||||
}
|
||||
|
||||
// async with promises
|
||||
findAuthor().catch(function(reason){
|
||||
// something went wrong
|
||||
});
|
||||
```
|
||||
|
||||
@method catch
|
||||
@param {Function} onRejection
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
'catch': function(onRejection) {
|
||||
return this.then(null, onRejection);
|
||||
}
|
||||
};
|
||||
function lib$es6$promise$polyfill$$polyfill() {
|
||||
var local;
|
||||
|
||||
if (typeof global !== 'undefined') {
|
||||
local = global;
|
||||
} else if (typeof self !== 'undefined') {
|
||||
local = self;
|
||||
} else {
|
||||
try {
|
||||
local = Function('return this')();
|
||||
} catch (e) {
|
||||
throw new Error('polyfill failed because global object is unavailable in this environment');
|
||||
}
|
||||
}
|
||||
|
||||
var P = local.Promise;
|
||||
|
||||
if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) {
|
||||
return;
|
||||
}
|
||||
|
||||
local.Promise = lib$es6$promise$promise$$default;
|
||||
}
|
||||
var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill;
|
||||
|
||||
var lib$es6$promise$umd$$ES6Promise = {
|
||||
'Promise': lib$es6$promise$promise$$default,
|
||||
'polyfill': lib$es6$promise$polyfill$$default
|
||||
};
|
||||
|
||||
/* global define:true module:true window: true */
|
||||
if (typeof define === 'function' && define['amd']) {
|
||||
define(function() { return lib$es6$promise$umd$$ES6Promise; });
|
||||
} else if (typeof module !== 'undefined' && module['exports']) {
|
||||
module['exports'] = lib$es6$promise$umd$$ES6Promise;
|
||||
} else if (typeof this !== 'undefined') {
|
||||
this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise;
|
||||
}
|
||||
|
||||
lib$es6$promise$polyfill$$default();
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=es6-promise.js.map
|
||||
1
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/es6-promise.min.js
generated
vendored
Normal file
1
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/es6-promise.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
25
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/index.html
generated
vendored
Normal file
25
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/index.html
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>rsvp.js Tests</title>
|
||||
<link rel="stylesheet" href="mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="json3.js"></script>
|
||||
<script src="mocha.js"></script>
|
||||
<script src="/testem.js"></script>
|
||||
<script>
|
||||
mocha.setup({
|
||||
ui: 'bdd',
|
||||
timeout: 200,
|
||||
ignoreLeaks: true
|
||||
});
|
||||
</script>
|
||||
<script src="browserify.js"></script>
|
||||
<script>
|
||||
if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
|
||||
else { mocha.run(); }
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
902
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/json3.js
generated
vendored
Normal file
902
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/json3.js
generated
vendored
Normal file
@@ -0,0 +1,902 @@
|
||||
/*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */
|
||||
;(function () {
|
||||
// Detect the `define` function exposed by asynchronous module loaders. The
|
||||
// strict `define` check is necessary for compatibility with `r.js`.
|
||||
var isLoader = typeof define === "function" && define.amd;
|
||||
|
||||
// A set of types used to distinguish objects from primitives.
|
||||
var objectTypes = {
|
||||
"function": true,
|
||||
"object": true
|
||||
};
|
||||
|
||||
// Detect the `exports` object exposed by CommonJS implementations.
|
||||
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
||||
|
||||
// Use the `global` object exposed by Node (including Browserify via
|
||||
// `insert-module-globals`), Narwhal, and Ringo as the default context,
|
||||
// and the `window` object in browsers. Rhino exports a `global` function
|
||||
// instead.
|
||||
var root = objectTypes[typeof window] && window || this,
|
||||
freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == "object" && global;
|
||||
|
||||
if (freeGlobal && (freeGlobal["global"] === freeGlobal || freeGlobal["window"] === freeGlobal || freeGlobal["self"] === freeGlobal)) {
|
||||
root = freeGlobal;
|
||||
}
|
||||
|
||||
// Public: Initializes JSON 3 using the given `context` object, attaching the
|
||||
// `stringify` and `parse` functions to the specified `exports` object.
|
||||
function runInContext(context, exports) {
|
||||
context || (context = root["Object"]());
|
||||
exports || (exports = root["Object"]());
|
||||
|
||||
// Native constructor aliases.
|
||||
var Number = context["Number"] || root["Number"],
|
||||
String = context["String"] || root["String"],
|
||||
Object = context["Object"] || root["Object"],
|
||||
Date = context["Date"] || root["Date"],
|
||||
SyntaxError = context["SyntaxError"] || root["SyntaxError"],
|
||||
TypeError = context["TypeError"] || root["TypeError"],
|
||||
Math = context["Math"] || root["Math"],
|
||||
nativeJSON = context["JSON"] || root["JSON"];
|
||||
|
||||
// Delegate to the native `stringify` and `parse` implementations.
|
||||
if (typeof nativeJSON == "object" && nativeJSON) {
|
||||
exports.stringify = nativeJSON.stringify;
|
||||
exports.parse = nativeJSON.parse;
|
||||
}
|
||||
|
||||
// Convenience aliases.
|
||||
var objectProto = Object.prototype,
|
||||
getClass = objectProto.toString,
|
||||
isProperty, forEach, undef;
|
||||
|
||||
// Test the `Date#getUTC*` methods. Based on work by @Yaffle.
|
||||
var isExtended = new Date(-3509827334573292);
|
||||
try {
|
||||
// The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
|
||||
// results for certain dates in Opera >= 10.53.
|
||||
isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
|
||||
// Safari < 2.0.2 stores the internal millisecond time value correctly,
|
||||
// but clips the values returned by the date methods to the range of
|
||||
// signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).
|
||||
isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
|
||||
} catch (exception) {}
|
||||
|
||||
// Internal: Determines whether the native `JSON.stringify` and `parse`
|
||||
// implementations are spec-compliant. Based on work by Ken Snyder.
|
||||
function has(name) {
|
||||
if (has[name] !== undef) {
|
||||
// Return cached feature test result.
|
||||
return has[name];
|
||||
}
|
||||
var isSupported;
|
||||
if (name == "bug-string-char-index") {
|
||||
// IE <= 7 doesn't support accessing string characters using square
|
||||
// bracket notation. IE 8 only supports this for primitives.
|
||||
isSupported = "a"[0] != "a";
|
||||
} else if (name == "json") {
|
||||
// Indicates whether both `JSON.stringify` and `JSON.parse` are
|
||||
// supported.
|
||||
isSupported = has("json-stringify") && has("json-parse");
|
||||
} else {
|
||||
var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';
|
||||
// Test `JSON.stringify`.
|
||||
if (name == "json-stringify") {
|
||||
var stringify = exports.stringify, stringifySupported = typeof stringify == "function" && isExtended;
|
||||
if (stringifySupported) {
|
||||
// A test function object with a custom `toJSON` method.
|
||||
(value = function () {
|
||||
return 1;
|
||||
}).toJSON = value;
|
||||
try {
|
||||
stringifySupported =
|
||||
// Firefox 3.1b1 and b2 serialize string, number, and boolean
|
||||
// primitives as object literals.
|
||||
stringify(0) === "0" &&
|
||||
// FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object
|
||||
// literals.
|
||||
stringify(new Number()) === "0" &&
|
||||
stringify(new String()) == '""' &&
|
||||
// FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or
|
||||
// does not define a canonical JSON representation (this applies to
|
||||
// objects with `toJSON` properties as well, *unless* they are nested
|
||||
// within an object or array).
|
||||
stringify(getClass) === undef &&
|
||||
// IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and
|
||||
// FF 3.1b3 pass this test.
|
||||
stringify(undef) === undef &&
|
||||
// Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,
|
||||
// respectively, if the value is omitted entirely.
|
||||
stringify() === undef &&
|
||||
// FF 3.1b1, 2 throw an error if the given value is not a number,
|
||||
// string, array, object, Boolean, or `null` literal. This applies to
|
||||
// objects with custom `toJSON` methods as well, unless they are nested
|
||||
// inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`
|
||||
// methods entirely.
|
||||
stringify(value) === "1" &&
|
||||
stringify([value]) == "[1]" &&
|
||||
// Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of
|
||||
// `"[null]"`.
|
||||
stringify([undef]) == "[null]" &&
|
||||
// YUI 3.0.0b1 fails to serialize `null` literals.
|
||||
stringify(null) == "null" &&
|
||||
// FF 3.1b1, 2 halts serialization if an array contains a function:
|
||||
// `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3
|
||||
// elides non-JSON values from objects and arrays, unless they
|
||||
// define custom `toJSON` methods.
|
||||
stringify([undef, getClass, null]) == "[null,null,null]" &&
|
||||
// Simple serialization test. FF 3.1b1 uses Unicode escape sequences
|
||||
// where character escape codes are expected (e.g., `\b` => `\u0008`).
|
||||
stringify({ "a": [value, true, false, null, "\x00\b\n\f\r\t"] }) == serialized &&
|
||||
// FF 3.1b1 and b2 ignore the `filter` and `width` arguments.
|
||||
stringify(null, value) === "1" &&
|
||||
stringify([1, 2], null, 1) == "[\n 1,\n 2\n]" &&
|
||||
// JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly
|
||||
// serialize extended years.
|
||||
stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' &&
|
||||
// The milliseconds are optional in ES 5, but required in 5.1.
|
||||
stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' &&
|
||||
// Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
|
||||
// four-digit years instead of six-digit years. Credits: @Yaffle.
|
||||
stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' &&
|
||||
// Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond
|
||||
// values less than 1000. Credits: @Yaffle.
|
||||
stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"';
|
||||
} catch (exception) {
|
||||
stringifySupported = false;
|
||||
}
|
||||
}
|
||||
isSupported = stringifySupported;
|
||||
}
|
||||
// Test `JSON.parse`.
|
||||
if (name == "json-parse") {
|
||||
var parse = exports.parse;
|
||||
if (typeof parse == "function") {
|
||||
try {
|
||||
// FF 3.1b1, b2 will throw an exception if a bare literal is provided.
|
||||
// Conforming implementations should also coerce the initial argument to
|
||||
// a string prior to parsing.
|
||||
if (parse("0") === 0 && !parse(false)) {
|
||||
// Simple parsing test.
|
||||
value = parse(serialized);
|
||||
var parseSupported = value["a"].length == 5 && value["a"][0] === 1;
|
||||
if (parseSupported) {
|
||||
try {
|
||||
// Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.
|
||||
parseSupported = !parse('"\t"');
|
||||
} catch (exception) {}
|
||||
if (parseSupported) {
|
||||
try {
|
||||
// FF 4.0 and 4.0.1 allow leading `+` signs and leading
|
||||
// decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow
|
||||
// certain octal literals.
|
||||
parseSupported = parse("01") !== 1;
|
||||
} catch (exception) {}
|
||||
}
|
||||
if (parseSupported) {
|
||||
try {
|
||||
// FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal
|
||||
// points. These environments, along with FF 3.1b1 and 2,
|
||||
// also allow trailing commas in JSON objects and arrays.
|
||||
parseSupported = parse("1.") !== 1;
|
||||
} catch (exception) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (exception) {
|
||||
parseSupported = false;
|
||||
}
|
||||
}
|
||||
isSupported = parseSupported;
|
||||
}
|
||||
}
|
||||
return has[name] = !!isSupported;
|
||||
}
|
||||
|
||||
if (!has("json")) {
|
||||
// Common `[[Class]]` name aliases.
|
||||
var functionClass = "[object Function]",
|
||||
dateClass = "[object Date]",
|
||||
numberClass = "[object Number]",
|
||||
stringClass = "[object String]",
|
||||
arrayClass = "[object Array]",
|
||||
booleanClass = "[object Boolean]";
|
||||
|
||||
// Detect incomplete support for accessing string characters by index.
|
||||
var charIndexBuggy = has("bug-string-char-index");
|
||||
|
||||
// Define additional utility methods if the `Date` methods are buggy.
|
||||
if (!isExtended) {
|
||||
var floor = Math.floor;
|
||||
// A mapping between the months of the year and the number of days between
|
||||
// January 1st and the first of the respective month.
|
||||
var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
||||
// Internal: Calculates the number of days between the Unix epoch and the
|
||||
// first day of the given month.
|
||||
var getDay = function (year, month) {
|
||||
return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);
|
||||
};
|
||||
}
|
||||
|
||||
// Internal: Determines if a property is a direct property of the given
|
||||
// object. Delegates to the native `Object#hasOwnProperty` method.
|
||||
if (!(isProperty = objectProto.hasOwnProperty)) {
|
||||
isProperty = function (property) {
|
||||
var members = {}, constructor;
|
||||
if ((members.__proto__ = null, members.__proto__ = {
|
||||
// The *proto* property cannot be set multiple times in recent
|
||||
// versions of Firefox and SeaMonkey.
|
||||
"toString": 1
|
||||
}, members).toString != getClass) {
|
||||
// Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but
|
||||
// supports the mutable *proto* property.
|
||||
isProperty = function (property) {
|
||||
// Capture and break the object's prototype chain (see section 8.6.2
|
||||
// of the ES 5.1 spec). The parenthesized expression prevents an
|
||||
// unsafe transformation by the Closure Compiler.
|
||||
var original = this.__proto__, result = property in (this.__proto__ = null, this);
|
||||
// Restore the original prototype chain.
|
||||
this.__proto__ = original;
|
||||
return result;
|
||||
};
|
||||
} else {
|
||||
// Capture a reference to the top-level `Object` constructor.
|
||||
constructor = members.constructor;
|
||||
// Use the `constructor` property to simulate `Object#hasOwnProperty` in
|
||||
// other environments.
|
||||
isProperty = function (property) {
|
||||
var parent = (this.constructor || constructor).prototype;
|
||||
return property in this && !(property in parent && this[property] === parent[property]);
|
||||
};
|
||||
}
|
||||
members = null;
|
||||
return isProperty.call(this, property);
|
||||
};
|
||||
}
|
||||
|
||||
// Internal: Normalizes the `for...in` iteration algorithm across
|
||||
// environments. Each enumerated key is yielded to a `callback` function.
|
||||
forEach = function (object, callback) {
|
||||
var size = 0, Properties, members, property;
|
||||
|
||||
// Tests for bugs in the current environment's `for...in` algorithm. The
|
||||
// `valueOf` property inherits the non-enumerable flag from
|
||||
// `Object.prototype` in older versions of IE, Netscape, and Mozilla.
|
||||
(Properties = function () {
|
||||
this.valueOf = 0;
|
||||
}).prototype.valueOf = 0;
|
||||
|
||||
// Iterate over a new instance of the `Properties` class.
|
||||
members = new Properties();
|
||||
for (property in members) {
|
||||
// Ignore all properties inherited from `Object.prototype`.
|
||||
if (isProperty.call(members, property)) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
Properties = members = null;
|
||||
|
||||
// Normalize the iteration algorithm.
|
||||
if (!size) {
|
||||
// A list of non-enumerable properties inherited from `Object.prototype`.
|
||||
members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"];
|
||||
// IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable
|
||||
// properties.
|
||||
forEach = function (object, callback) {
|
||||
var isFunction = getClass.call(object) == functionClass, property, length;
|
||||
var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || isProperty;
|
||||
for (property in object) {
|
||||
// Gecko <= 1.0 enumerates the `prototype` property of functions under
|
||||
// certain conditions; IE does not.
|
||||
if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) {
|
||||
callback(property);
|
||||
}
|
||||
}
|
||||
// Manually invoke the callback for each non-enumerable property.
|
||||
for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property));
|
||||
};
|
||||
} else if (size == 2) {
|
||||
// Safari <= 2.0.4 enumerates shadowed properties twice.
|
||||
forEach = function (object, callback) {
|
||||
// Create a set of iterated properties.
|
||||
var members = {}, isFunction = getClass.call(object) == functionClass, property;
|
||||
for (property in object) {
|
||||
// Store each property name to prevent double enumeration. The
|
||||
// `prototype` property of functions is not enumerated due to cross-
|
||||
// environment inconsistencies.
|
||||
if (!(isFunction && property == "prototype") && !isProperty.call(members, property) && (members[property] = 1) && isProperty.call(object, property)) {
|
||||
callback(property);
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// No bugs detected; use the standard `for...in` algorithm.
|
||||
forEach = function (object, callback) {
|
||||
var isFunction = getClass.call(object) == functionClass, property, isConstructor;
|
||||
for (property in object) {
|
||||
if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) {
|
||||
callback(property);
|
||||
}
|
||||
}
|
||||
// Manually invoke the callback for the `constructor` property due to
|
||||
// cross-environment inconsistencies.
|
||||
if (isConstructor || isProperty.call(object, (property = "constructor"))) {
|
||||
callback(property);
|
||||
}
|
||||
};
|
||||
}
|
||||
return forEach(object, callback);
|
||||
};
|
||||
|
||||
// Public: Serializes a JavaScript `value` as a JSON string. The optional
|
||||
// `filter` argument may specify either a function that alters how object and
|
||||
// array members are serialized, or an array of strings and numbers that
|
||||
// indicates which properties should be serialized. The optional `width`
|
||||
// argument may be either a string or number that specifies the indentation
|
||||
// level of the output.
|
||||
if (!has("json-stringify")) {
|
||||
// Internal: A map of control characters and their escaped equivalents.
|
||||
var Escapes = {
|
||||
92: "\\\\",
|
||||
34: '\\"',
|
||||
8: "\\b",
|
||||
12: "\\f",
|
||||
10: "\\n",
|
||||
13: "\\r",
|
||||
9: "\\t"
|
||||
};
|
||||
|
||||
// Internal: Converts `value` into a zero-padded string such that its
|
||||
// length is at least equal to `width`. The `width` must be <= 6.
|
||||
var leadingZeroes = "000000";
|
||||
var toPaddedString = function (width, value) {
|
||||
// The `|| 0` expression is necessary to work around a bug in
|
||||
// Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`.
|
||||
return (leadingZeroes + (value || 0)).slice(-width);
|
||||
};
|
||||
|
||||
// Internal: Double-quotes a string `value`, replacing all ASCII control
|
||||
// characters (characters with code unit values between 0 and 31) with
|
||||
// their escaped equivalents. This is an implementation of the
|
||||
// `Quote(value)` operation defined in ES 5.1 section 15.12.3.
|
||||
var unicodePrefix = "\\u00";
|
||||
var quote = function (value) {
|
||||
var result = '"', index = 0, length = value.length, useCharIndex = !charIndexBuggy || length > 10;
|
||||
var symbols = useCharIndex && (charIndexBuggy ? value.split("") : value);
|
||||
for (; index < length; index++) {
|
||||
var charCode = value.charCodeAt(index);
|
||||
// If the character is a control character, append its Unicode or
|
||||
// shorthand escape sequence; otherwise, append the character as-is.
|
||||
switch (charCode) {
|
||||
case 8: case 9: case 10: case 12: case 13: case 34: case 92:
|
||||
result += Escapes[charCode];
|
||||
break;
|
||||
default:
|
||||
if (charCode < 32) {
|
||||
result += unicodePrefix + toPaddedString(2, charCode.toString(16));
|
||||
break;
|
||||
}
|
||||
result += useCharIndex ? symbols[index] : value.charAt(index);
|
||||
}
|
||||
}
|
||||
return result + '"';
|
||||
};
|
||||
|
||||
// Internal: Recursively serializes an object. Implements the
|
||||
// `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
|
||||
var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
|
||||
var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
|
||||
try {
|
||||
// Necessary for host object support.
|
||||
value = object[property];
|
||||
} catch (exception) {}
|
||||
if (typeof value == "object" && value) {
|
||||
className = getClass.call(value);
|
||||
if (className == dateClass && !isProperty.call(value, "toJSON")) {
|
||||
if (value > -1 / 0 && value < 1 / 0) {
|
||||
// Dates are serialized according to the `Date#toJSON` method
|
||||
// specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
|
||||
// for the ISO 8601 date time string format.
|
||||
if (getDay) {
|
||||
// Manually compute the year, month, date, hours, minutes,
|
||||
// seconds, and milliseconds if the `getUTC*` methods are
|
||||
// buggy. Adapted from @Yaffle's `date-shim` project.
|
||||
date = floor(value / 864e5);
|
||||
for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
|
||||
for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
|
||||
date = 1 + date - getDay(year, month);
|
||||
// The `time` value specifies the time within the day (see ES
|
||||
// 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
|
||||
// to compute `A modulo B`, as the `%` operator does not
|
||||
// correspond to the `modulo` operation for negative numbers.
|
||||
time = (value % 864e5 + 864e5) % 864e5;
|
||||
// The hours, minutes, seconds, and milliseconds are obtained by
|
||||
// decomposing the time within the day. See section 15.9.1.10.
|
||||
hours = floor(time / 36e5) % 24;
|
||||
minutes = floor(time / 6e4) % 60;
|
||||
seconds = floor(time / 1e3) % 60;
|
||||
milliseconds = time % 1e3;
|
||||
} else {
|
||||
year = value.getUTCFullYear();
|
||||
month = value.getUTCMonth();
|
||||
date = value.getUTCDate();
|
||||
hours = value.getUTCHours();
|
||||
minutes = value.getUTCMinutes();
|
||||
seconds = value.getUTCSeconds();
|
||||
milliseconds = value.getUTCMilliseconds();
|
||||
}
|
||||
// Serialize extended years correctly.
|
||||
value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
|
||||
"-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
|
||||
// Months, dates, hours, minutes, and seconds should have two
|
||||
// digits; milliseconds should have three.
|
||||
"T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
|
||||
// Milliseconds are optional in ES 5.0, but required in 5.1.
|
||||
"." + toPaddedString(3, milliseconds) + "Z";
|
||||
} else {
|
||||
value = null;
|
||||
}
|
||||
} else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
|
||||
// Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
|
||||
// `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
|
||||
// ignores all `toJSON` methods on these objects unless they are
|
||||
// defined directly on an instance.
|
||||
value = value.toJSON(property);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
// If a replacement function was provided, call it to obtain the value
|
||||
// for serialization.
|
||||
value = callback.call(object, property, value);
|
||||
}
|
||||
if (value === null) {
|
||||
return "null";
|
||||
}
|
||||
className = getClass.call(value);
|
||||
if (className == booleanClass) {
|
||||
// Booleans are represented literally.
|
||||
return "" + value;
|
||||
} else if (className == numberClass) {
|
||||
// JSON numbers must be finite. `Infinity` and `NaN` are serialized as
|
||||
// `"null"`.
|
||||
return value > -1 / 0 && value < 1 / 0 ? "" + value : "null";
|
||||
} else if (className == stringClass) {
|
||||
// Strings are double-quoted and escaped.
|
||||
return quote("" + value);
|
||||
}
|
||||
// Recursively serialize objects and arrays.
|
||||
if (typeof value == "object") {
|
||||
// Check for cyclic structures. This is a linear search; performance
|
||||
// is inversely proportional to the number of unique nested objects.
|
||||
for (length = stack.length; length--;) {
|
||||
if (stack[length] === value) {
|
||||
// Cyclic structures cannot be serialized by `JSON.stringify`.
|
||||
throw TypeError();
|
||||
}
|
||||
}
|
||||
// Add the object to the stack of traversed objects.
|
||||
stack.push(value);
|
||||
results = [];
|
||||
// Save the current indentation level and indent one additional level.
|
||||
prefix = indentation;
|
||||
indentation += whitespace;
|
||||
if (className == arrayClass) {
|
||||
// Recursively serialize array elements.
|
||||
for (index = 0, length = value.length; index < length; index++) {
|
||||
element = serialize(index, value, callback, properties, whitespace, indentation, stack);
|
||||
results.push(element === undef ? "null" : element);
|
||||
}
|
||||
result = results.length ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
|
||||
} else {
|
||||
// Recursively serialize object members. Members are selected from
|
||||
// either a user-specified list of property names, or the object
|
||||
// itself.
|
||||
forEach(properties || value, function (property) {
|
||||
var element = serialize(property, value, callback, properties, whitespace, indentation, stack);
|
||||
if (element !== undef) {
|
||||
// According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
|
||||
// is not the empty string, let `member` {quote(property) + ":"}
|
||||
// be the concatenation of `member` and the `space` character."
|
||||
// The "`space` character" refers to the literal space
|
||||
// character, not the `space` {width} argument provided to
|
||||
// `JSON.stringify`.
|
||||
results.push(quote(property) + ":" + (whitespace ? " " : "") + element);
|
||||
}
|
||||
});
|
||||
result = results.length ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
|
||||
}
|
||||
// Remove the object from the traversed object stack.
|
||||
stack.pop();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// Public: `JSON.stringify`. See ES 5.1 section 15.12.3.
|
||||
exports.stringify = function (source, filter, width) {
|
||||
var whitespace, callback, properties, className;
|
||||
if (objectTypes[typeof filter] && filter) {
|
||||
if ((className = getClass.call(filter)) == functionClass) {
|
||||
callback = filter;
|
||||
} else if (className == arrayClass) {
|
||||
// Convert the property names array into a makeshift set.
|
||||
properties = {};
|
||||
for (var index = 0, length = filter.length, value; index < length; value = filter[index++], ((className = getClass.call(value)), className == stringClass || className == numberClass) && (properties[value] = 1));
|
||||
}
|
||||
}
|
||||
if (width) {
|
||||
if ((className = getClass.call(width)) == numberClass) {
|
||||
// Convert the `width` to an integer and create a string containing
|
||||
// `width` number of space characters.
|
||||
if ((width -= width % 1) > 0) {
|
||||
for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
|
||||
}
|
||||
} else if (className == stringClass) {
|
||||
whitespace = width.length <= 10 ? width : width.slice(0, 10);
|
||||
}
|
||||
}
|
||||
// Opera <= 7.54u2 discards the values associated with empty string keys
|
||||
// (`""`) only if they are used directly within an object member list
|
||||
// (e.g., `!("" in { "": 1})`).
|
||||
return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []);
|
||||
};
|
||||
}
|
||||
|
||||
// Public: Parses a JSON source string.
|
||||
if (!has("json-parse")) {
|
||||
var fromCharCode = String.fromCharCode;
|
||||
|
||||
// Internal: A map of escaped control characters and their unescaped
|
||||
// equivalents.
|
||||
var Unescapes = {
|
||||
92: "\\",
|
||||
34: '"',
|
||||
47: "/",
|
||||
98: "\b",
|
||||
116: "\t",
|
||||
110: "\n",
|
||||
102: "\f",
|
||||
114: "\r"
|
||||
};
|
||||
|
||||
// Internal: Stores the parser state.
|
||||
var Index, Source;
|
||||
|
||||
// Internal: Resets the parser state and throws a `SyntaxError`.
|
||||
var abort = function () {
|
||||
Index = Source = null;
|
||||
throw SyntaxError();
|
||||
};
|
||||
|
||||
// Internal: Returns the next token, or `"$"` if the parser has reached
|
||||
// the end of the source string. A token may be a string, number, `null`
|
||||
// literal, or Boolean literal.
|
||||
var lex = function () {
|
||||
var source = Source, length = source.length, value, begin, position, isSigned, charCode;
|
||||
while (Index < length) {
|
||||
charCode = source.charCodeAt(Index);
|
||||
switch (charCode) {
|
||||
case 9: case 10: case 13: case 32:
|
||||
// Skip whitespace tokens, including tabs, carriage returns, line
|
||||
// feeds, and space characters.
|
||||
Index++;
|
||||
break;
|
||||
case 123: case 125: case 91: case 93: case 58: case 44:
|
||||
// Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at
|
||||
// the current position.
|
||||
value = charIndexBuggy ? source.charAt(Index) : source[Index];
|
||||
Index++;
|
||||
return value;
|
||||
case 34:
|
||||
// `"` delimits a JSON string; advance to the next character and
|
||||
// begin parsing the string. String tokens are prefixed with the
|
||||
// sentinel `@` character to distinguish them from punctuators and
|
||||
// end-of-string tokens.
|
||||
for (value = "@", Index++; Index < length;) {
|
||||
charCode = source.charCodeAt(Index);
|
||||
if (charCode < 32) {
|
||||
// Unescaped ASCII control characters (those with a code unit
|
||||
// less than the space character) are not permitted.
|
||||
abort();
|
||||
} else if (charCode == 92) {
|
||||
// A reverse solidus (`\`) marks the beginning of an escaped
|
||||
// control character (including `"`, `\`, and `/`) or Unicode
|
||||
// escape sequence.
|
||||
charCode = source.charCodeAt(++Index);
|
||||
switch (charCode) {
|
||||
case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114:
|
||||
// Revive escaped control characters.
|
||||
value += Unescapes[charCode];
|
||||
Index++;
|
||||
break;
|
||||
case 117:
|
||||
// `\u` marks the beginning of a Unicode escape sequence.
|
||||
// Advance to the first character and validate the
|
||||
// four-digit code point.
|
||||
begin = ++Index;
|
||||
for (position = Index + 4; Index < position; Index++) {
|
||||
charCode = source.charCodeAt(Index);
|
||||
// A valid sequence comprises four hexdigits (case-
|
||||
// insensitive) that form a single hexadecimal value.
|
||||
if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {
|
||||
// Invalid Unicode escape sequence.
|
||||
abort();
|
||||
}
|
||||
}
|
||||
// Revive the escaped character.
|
||||
value += fromCharCode("0x" + source.slice(begin, Index));
|
||||
break;
|
||||
default:
|
||||
// Invalid escape sequence.
|
||||
abort();
|
||||
}
|
||||
} else {
|
||||
if (charCode == 34) {
|
||||
// An unescaped double-quote character marks the end of the
|
||||
// string.
|
||||
break;
|
||||
}
|
||||
charCode = source.charCodeAt(Index);
|
||||
begin = Index;
|
||||
// Optimize for the common case where a string is valid.
|
||||
while (charCode >= 32 && charCode != 92 && charCode != 34) {
|
||||
charCode = source.charCodeAt(++Index);
|
||||
}
|
||||
// Append the string as-is.
|
||||
value += source.slice(begin, Index);
|
||||
}
|
||||
}
|
||||
if (source.charCodeAt(Index) == 34) {
|
||||
// Advance to the next character and return the revived string.
|
||||
Index++;
|
||||
return value;
|
||||
}
|
||||
// Unterminated string.
|
||||
abort();
|
||||
default:
|
||||
// Parse numbers and literals.
|
||||
begin = Index;
|
||||
// Advance past the negative sign, if one is specified.
|
||||
if (charCode == 45) {
|
||||
isSigned = true;
|
||||
charCode = source.charCodeAt(++Index);
|
||||
}
|
||||
// Parse an integer or floating-point value.
|
||||
if (charCode >= 48 && charCode <= 57) {
|
||||
// Leading zeroes are interpreted as octal literals.
|
||||
if (charCode == 48 && ((charCode = source.charCodeAt(Index + 1)), charCode >= 48 && charCode <= 57)) {
|
||||
// Illegal octal literal.
|
||||
abort();
|
||||
}
|
||||
isSigned = false;
|
||||
// Parse the integer component.
|
||||
for (; Index < length && ((charCode = source.charCodeAt(Index)), charCode >= 48 && charCode <= 57); Index++);
|
||||
// Floats cannot contain a leading decimal point; however, this
|
||||
// case is already accounted for by the parser.
|
||||
if (source.charCodeAt(Index) == 46) {
|
||||
position = ++Index;
|
||||
// Parse the decimal component.
|
||||
for (; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
|
||||
if (position == Index) {
|
||||
// Illegal trailing decimal.
|
||||
abort();
|
||||
}
|
||||
Index = position;
|
||||
}
|
||||
// Parse exponents. The `e` denoting the exponent is
|
||||
// case-insensitive.
|
||||
charCode = source.charCodeAt(Index);
|
||||
if (charCode == 101 || charCode == 69) {
|
||||
charCode = source.charCodeAt(++Index);
|
||||
// Skip past the sign following the exponent, if one is
|
||||
// specified.
|
||||
if (charCode == 43 || charCode == 45) {
|
||||
Index++;
|
||||
}
|
||||
// Parse the exponential component.
|
||||
for (position = Index; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
|
||||
if (position == Index) {
|
||||
// Illegal empty exponent.
|
||||
abort();
|
||||
}
|
||||
Index = position;
|
||||
}
|
||||
// Coerce the parsed value to a JavaScript number.
|
||||
return +source.slice(begin, Index);
|
||||
}
|
||||
// A negative sign may only precede numbers.
|
||||
if (isSigned) {
|
||||
abort();
|
||||
}
|
||||
// `true`, `false`, and `null` literals.
|
||||
if (source.slice(Index, Index + 4) == "true") {
|
||||
Index += 4;
|
||||
return true;
|
||||
} else if (source.slice(Index, Index + 5) == "false") {
|
||||
Index += 5;
|
||||
return false;
|
||||
} else if (source.slice(Index, Index + 4) == "null") {
|
||||
Index += 4;
|
||||
return null;
|
||||
}
|
||||
// Unrecognized token.
|
||||
abort();
|
||||
}
|
||||
}
|
||||
// Return the sentinel `$` character if the parser has reached the end
|
||||
// of the source string.
|
||||
return "$";
|
||||
};
|
||||
|
||||
// Internal: Parses a JSON `value` token.
|
||||
var get = function (value) {
|
||||
var results, hasMembers;
|
||||
if (value == "$") {
|
||||
// Unexpected end of input.
|
||||
abort();
|
||||
}
|
||||
if (typeof value == "string") {
|
||||
if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") {
|
||||
// Remove the sentinel `@` character.
|
||||
return value.slice(1);
|
||||
}
|
||||
// Parse object and array literals.
|
||||
if (value == "[") {
|
||||
// Parses a JSON array, returning a new JavaScript array.
|
||||
results = [];
|
||||
for (;; hasMembers || (hasMembers = true)) {
|
||||
value = lex();
|
||||
// A closing square bracket marks the end of the array literal.
|
||||
if (value == "]") {
|
||||
break;
|
||||
}
|
||||
// If the array literal contains elements, the current token
|
||||
// should be a comma separating the previous element from the
|
||||
// next.
|
||||
if (hasMembers) {
|
||||
if (value == ",") {
|
||||
value = lex();
|
||||
if (value == "]") {
|
||||
// Unexpected trailing `,` in array literal.
|
||||
abort();
|
||||
}
|
||||
} else {
|
||||
// A `,` must separate each array element.
|
||||
abort();
|
||||
}
|
||||
}
|
||||
// Elisions and leading commas are not permitted.
|
||||
if (value == ",") {
|
||||
abort();
|
||||
}
|
||||
results.push(get(value));
|
||||
}
|
||||
return results;
|
||||
} else if (value == "{") {
|
||||
// Parses a JSON object, returning a new JavaScript object.
|
||||
results = {};
|
||||
for (;; hasMembers || (hasMembers = true)) {
|
||||
value = lex();
|
||||
// A closing curly brace marks the end of the object literal.
|
||||
if (value == "}") {
|
||||
break;
|
||||
}
|
||||
// If the object literal contains members, the current token
|
||||
// should be a comma separator.
|
||||
if (hasMembers) {
|
||||
if (value == ",") {
|
||||
value = lex();
|
||||
if (value == "}") {
|
||||
// Unexpected trailing `,` in object literal.
|
||||
abort();
|
||||
}
|
||||
} else {
|
||||
// A `,` must separate each object member.
|
||||
abort();
|
||||
}
|
||||
}
|
||||
// Leading commas are not permitted, object property names must be
|
||||
// double-quoted strings, and a `:` must separate each property
|
||||
// name and value.
|
||||
if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") {
|
||||
abort();
|
||||
}
|
||||
results[value.slice(1)] = get(lex());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
// Unexpected token encountered.
|
||||
abort();
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
// Internal: Updates a traversed object member.
|
||||
var update = function (source, property, callback) {
|
||||
var element = walk(source, property, callback);
|
||||
if (element === undef) {
|
||||
delete source[property];
|
||||
} else {
|
||||
source[property] = element;
|
||||
}
|
||||
};
|
||||
|
||||
// Internal: Recursively traverses a parsed JSON object, invoking the
|
||||
// `callback` function for each value. This is an implementation of the
|
||||
// `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.
|
||||
var walk = function (source, property, callback) {
|
||||
var value = source[property], length;
|
||||
if (typeof value == "object" && value) {
|
||||
// `forEach` can't be used to traverse an array in Opera <= 8.54
|
||||
// because its `Object#hasOwnProperty` implementation returns `false`
|
||||
// for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`).
|
||||
if (getClass.call(value) == arrayClass) {
|
||||
for (length = value.length; length--;) {
|
||||
update(value, length, callback);
|
||||
}
|
||||
} else {
|
||||
forEach(value, function (property) {
|
||||
update(value, property, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
return callback.call(source, property, value);
|
||||
};
|
||||
|
||||
// Public: `JSON.parse`. See ES 5.1 section 15.12.2.
|
||||
exports.parse = function (source, callback) {
|
||||
var result, value;
|
||||
Index = 0;
|
||||
Source = "" + source;
|
||||
result = get(lex());
|
||||
// If a JSON string contains multiple tokens, it is invalid.
|
||||
if (lex() != "$") {
|
||||
abort();
|
||||
}
|
||||
// Reset the parser state.
|
||||
Index = Source = null;
|
||||
return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
exports["runInContext"] = runInContext;
|
||||
return exports;
|
||||
}
|
||||
|
||||
if (freeExports && !isLoader) {
|
||||
// Export for CommonJS environments.
|
||||
runInContext(root, freeExports);
|
||||
} else {
|
||||
// Export for web browsers and JavaScript engines.
|
||||
var nativeJSON = root.JSON,
|
||||
previousJSON = root["JSON3"],
|
||||
isRestored = false;
|
||||
|
||||
var JSON3 = runInContext(root, (root["JSON3"] = {
|
||||
// Public: Restores the original value of the global `JSON` object and
|
||||
// returns a reference to the `JSON3` object.
|
||||
"noConflict": function () {
|
||||
if (!isRestored) {
|
||||
isRestored = true;
|
||||
root.JSON = nativeJSON;
|
||||
root["JSON3"] = previousJSON;
|
||||
nativeJSON = previousJSON = null;
|
||||
}
|
||||
return JSON3;
|
||||
}
|
||||
}));
|
||||
|
||||
root.JSON = {
|
||||
"parse": JSON3.parse,
|
||||
"stringify": JSON3.stringify
|
||||
};
|
||||
}
|
||||
|
||||
// Export for asynchronous module loaders.
|
||||
if (isLoader) {
|
||||
define(function () {
|
||||
return JSON3;
|
||||
});
|
||||
}
|
||||
}).call(this);
|
||||
270
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/mocha.css
generated
vendored
Normal file
270
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/mocha.css
generated
vendored
Normal file
@@ -0,0 +1,270 @@
|
||||
@charset "utf-8";
|
||||
|
||||
body {
|
||||
margin:0;
|
||||
}
|
||||
|
||||
#mocha {
|
||||
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
margin: 60px 50px;
|
||||
}
|
||||
|
||||
#mocha ul,
|
||||
#mocha li {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#mocha ul {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#mocha h1,
|
||||
#mocha h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#mocha h1 {
|
||||
margin-top: 15px;
|
||||
font-size: 1em;
|
||||
font-weight: 200;
|
||||
}
|
||||
|
||||
#mocha h1 a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
#mocha h1 a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#mocha .suite .suite h1 {
|
||||
margin-top: 0;
|
||||
font-size: .8em;
|
||||
}
|
||||
|
||||
#mocha .hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha h2 {
|
||||
font-size: 12px;
|
||||
font-weight: normal;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#mocha .suite {
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
#mocha .test {
|
||||
margin-left: 15px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#mocha .test.pending:hover h2::after {
|
||||
content: '(pending)';
|
||||
font-family: arial, sans-serif;
|
||||
}
|
||||
|
||||
#mocha .test.pass.medium .duration {
|
||||
background: #c09853;
|
||||
}
|
||||
|
||||
#mocha .test.pass.slow .duration {
|
||||
background: #b94a48;
|
||||
}
|
||||
|
||||
#mocha .test.pass::before {
|
||||
content: '✓';
|
||||
font-size: 12px;
|
||||
display: block;
|
||||
float: left;
|
||||
margin-right: 5px;
|
||||
color: #00d6b2;
|
||||
}
|
||||
|
||||
#mocha .test.pass .duration {
|
||||
font-size: 9px;
|
||||
margin-left: 5px;
|
||||
padding: 2px 5px;
|
||||
color: #fff;
|
||||
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-ms-border-radius: 5px;
|
||||
-o-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#mocha .test.pass.fast .duration {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha .test.pending {
|
||||
color: #0b97c4;
|
||||
}
|
||||
|
||||
#mocha .test.pending::before {
|
||||
content: '◦';
|
||||
color: #0b97c4;
|
||||
}
|
||||
|
||||
#mocha .test.fail {
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
#mocha .test.fail pre {
|
||||
color: black;
|
||||
}
|
||||
|
||||
#mocha .test.fail::before {
|
||||
content: '✖';
|
||||
font-size: 12px;
|
||||
display: block;
|
||||
float: left;
|
||||
margin-right: 5px;
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
#mocha .test pre.error {
|
||||
color: #c00;
|
||||
max-height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* (1): approximate for browsers not supporting calc
|
||||
* (2): 42 = 2*15 + 2*10 + 2*1 (padding + margin + border)
|
||||
* ^^ seriously
|
||||
*/
|
||||
#mocha .test pre {
|
||||
display: block;
|
||||
float: left;
|
||||
clear: left;
|
||||
font: 12px/1.5 monaco, monospace;
|
||||
margin: 5px;
|
||||
padding: 15px;
|
||||
border: 1px solid #eee;
|
||||
max-width: 85%; /*(1)*/
|
||||
max-width: calc(100% - 42px); /*(2)*/
|
||||
word-wrap: break-word;
|
||||
border-bottom-color: #ddd;
|
||||
-webkit-border-radius: 3px;
|
||||
-webkit-box-shadow: 0 1px 3px #eee;
|
||||
-moz-border-radius: 3px;
|
||||
-moz-box-shadow: 0 1px 3px #eee;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#mocha .test h2 {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#mocha .test a.replay {
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
right: 0;
|
||||
text-decoration: none;
|
||||
vertical-align: middle;
|
||||
display: block;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
line-height: 15px;
|
||||
text-align: center;
|
||||
background: #eee;
|
||||
font-size: 15px;
|
||||
-moz-border-radius: 15px;
|
||||
border-radius: 15px;
|
||||
-webkit-transition: opacity 200ms;
|
||||
-moz-transition: opacity 200ms;
|
||||
transition: opacity 200ms;
|
||||
opacity: 0.3;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
#mocha .test:hover a.replay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
#mocha-report.pass .test.fail {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha-report.fail .test.pass {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha-report.pending .test.pass,
|
||||
#mocha-report.pending .test.fail {
|
||||
display: none;
|
||||
}
|
||||
#mocha-report.pending .test.pass.pending {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#mocha-error {
|
||||
color: #c00;
|
||||
font-size: 1.5em;
|
||||
font-weight: 100;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
#mocha-stats {
|
||||
position: fixed;
|
||||
top: 15px;
|
||||
right: 10px;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
color: #888;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
#mocha-stats .progress {
|
||||
float: right;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
#mocha-stats em {
|
||||
color: black;
|
||||
}
|
||||
|
||||
#mocha-stats a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
#mocha-stats a:hover {
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
#mocha-stats li {
|
||||
display: inline-block;
|
||||
margin: 0 5px;
|
||||
list-style: none;
|
||||
padding-top: 11px;
|
||||
}
|
||||
|
||||
#mocha-stats canvas {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
#mocha code .comment { color: #ddd; }
|
||||
#mocha code .init { color: #2f6fad; }
|
||||
#mocha code .string { color: #5890ad; }
|
||||
#mocha code .keyword { color: #8a6343; }
|
||||
#mocha code .number { color: #2f6fad; }
|
||||
|
||||
@media screen and (max-device-width: 480px) {
|
||||
#mocha {
|
||||
margin: 60px 0px;
|
||||
}
|
||||
|
||||
#mocha #stats {
|
||||
position: absolute;
|
||||
}
|
||||
}
|
||||
6095
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/mocha.js
generated
vendored
Normal file
6095
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/mocha.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
16
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/worker.js
generated
vendored
Normal file
16
build/node_modules/hydrolysis/node_modules/es6-promise/dist/test/worker.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
importScripts('es6-promise.js');
|
||||
new ES6Promise.Promise(function(resolve, reject) {
|
||||
self.onmessage = function (e) {
|
||||
if (e.data === 'ping') {
|
||||
resolve('pong');
|
||||
} else {
|
||||
reject(new Error('wrong message'));
|
||||
}
|
||||
};
|
||||
}).then(function (result) {
|
||||
self.postMessage(result);
|
||||
}, function (err){
|
||||
setTimeout(function () {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
18
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise.umd.js
generated
vendored
Normal file
18
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise.umd.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import Promise from './es6-promise/promise';
|
||||
import polyfill from './es6-promise/polyfill';
|
||||
|
||||
var ES6Promise = {
|
||||
'Promise': Promise,
|
||||
'polyfill': polyfill
|
||||
};
|
||||
|
||||
/* global define:true module:true window: true */
|
||||
if (typeof define === 'function' && define['amd']) {
|
||||
define(function() { return ES6Promise; });
|
||||
} else if (typeof module !== 'undefined' && module['exports']) {
|
||||
module['exports'] = ES6Promise;
|
||||
} else if (typeof this !== 'undefined') {
|
||||
this['ES6Promise'] = ES6Promise;
|
||||
}
|
||||
|
||||
polyfill();
|
||||
252
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/-internal.js
generated
vendored
Normal file
252
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/-internal.js
generated
vendored
Normal file
@@ -0,0 +1,252 @@
|
||||
import {
|
||||
objectOrFunction,
|
||||
isFunction
|
||||
} from './utils';
|
||||
|
||||
import {
|
||||
asap
|
||||
} from './asap';
|
||||
|
||||
function noop() {}
|
||||
|
||||
var PENDING = void 0;
|
||||
var FULFILLED = 1;
|
||||
var REJECTED = 2;
|
||||
|
||||
var GET_THEN_ERROR = new ErrorObject();
|
||||
|
||||
function selfFullfillment() {
|
||||
return new TypeError("You cannot resolve a promise with itself");
|
||||
}
|
||||
|
||||
function cannotReturnOwn() {
|
||||
return new TypeError('A promises callback cannot return that same promise.');
|
||||
}
|
||||
|
||||
function getThen(promise) {
|
||||
try {
|
||||
return promise.then;
|
||||
} catch(error) {
|
||||
GET_THEN_ERROR.error = error;
|
||||
return GET_THEN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function tryThen(then, value, fulfillmentHandler, rejectionHandler) {
|
||||
try {
|
||||
then.call(value, fulfillmentHandler, rejectionHandler);
|
||||
} catch(e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
function handleForeignThenable(promise, thenable, then) {
|
||||
asap(function(promise) {
|
||||
var sealed = false;
|
||||
var error = tryThen(then, thenable, function(value) {
|
||||
if (sealed) { return; }
|
||||
sealed = true;
|
||||
if (thenable !== value) {
|
||||
resolve(promise, value);
|
||||
} else {
|
||||
fulfill(promise, value);
|
||||
}
|
||||
}, function(reason) {
|
||||
if (sealed) { return; }
|
||||
sealed = true;
|
||||
|
||||
reject(promise, reason);
|
||||
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
||||
|
||||
if (!sealed && error) {
|
||||
sealed = true;
|
||||
reject(promise, error);
|
||||
}
|
||||
}, promise);
|
||||
}
|
||||
|
||||
function handleOwnThenable(promise, thenable) {
|
||||
if (thenable._state === FULFILLED) {
|
||||
fulfill(promise, thenable._result);
|
||||
} else if (thenable._state === REJECTED) {
|
||||
reject(promise, thenable._result);
|
||||
} else {
|
||||
subscribe(thenable, undefined, function(value) {
|
||||
resolve(promise, value);
|
||||
}, function(reason) {
|
||||
reject(promise, reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleMaybeThenable(promise, maybeThenable) {
|
||||
if (maybeThenable.constructor === promise.constructor) {
|
||||
handleOwnThenable(promise, maybeThenable);
|
||||
} else {
|
||||
var then = getThen(maybeThenable);
|
||||
|
||||
if (then === GET_THEN_ERROR) {
|
||||
reject(promise, GET_THEN_ERROR.error);
|
||||
} else if (then === undefined) {
|
||||
fulfill(promise, maybeThenable);
|
||||
} else if (isFunction(then)) {
|
||||
handleForeignThenable(promise, maybeThenable, then);
|
||||
} else {
|
||||
fulfill(promise, maybeThenable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolve(promise, value) {
|
||||
if (promise === value) {
|
||||
reject(promise, selfFullfillment());
|
||||
} else if (objectOrFunction(value)) {
|
||||
handleMaybeThenable(promise, value);
|
||||
} else {
|
||||
fulfill(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
function publishRejection(promise) {
|
||||
if (promise._onerror) {
|
||||
promise._onerror(promise._result);
|
||||
}
|
||||
|
||||
publish(promise);
|
||||
}
|
||||
|
||||
function fulfill(promise, value) {
|
||||
if (promise._state !== PENDING) { return; }
|
||||
|
||||
promise._result = value;
|
||||
promise._state = FULFILLED;
|
||||
|
||||
if (promise._subscribers.length !== 0) {
|
||||
asap(publish, promise);
|
||||
}
|
||||
}
|
||||
|
||||
function reject(promise, reason) {
|
||||
if (promise._state !== PENDING) { return; }
|
||||
promise._state = REJECTED;
|
||||
promise._result = reason;
|
||||
|
||||
asap(publishRejection, promise);
|
||||
}
|
||||
|
||||
function subscribe(parent, child, onFulfillment, onRejection) {
|
||||
var subscribers = parent._subscribers;
|
||||
var length = subscribers.length;
|
||||
|
||||
parent._onerror = null;
|
||||
|
||||
subscribers[length] = child;
|
||||
subscribers[length + FULFILLED] = onFulfillment;
|
||||
subscribers[length + REJECTED] = onRejection;
|
||||
|
||||
if (length === 0 && parent._state) {
|
||||
asap(publish, parent);
|
||||
}
|
||||
}
|
||||
|
||||
function publish(promise) {
|
||||
var subscribers = promise._subscribers;
|
||||
var settled = promise._state;
|
||||
|
||||
if (subscribers.length === 0) { return; }
|
||||
|
||||
var child, callback, detail = promise._result;
|
||||
|
||||
for (var i = 0; i < subscribers.length; i += 3) {
|
||||
child = subscribers[i];
|
||||
callback = subscribers[i + settled];
|
||||
|
||||
if (child) {
|
||||
invokeCallback(settled, child, callback, detail);
|
||||
} else {
|
||||
callback(detail);
|
||||
}
|
||||
}
|
||||
|
||||
promise._subscribers.length = 0;
|
||||
}
|
||||
|
||||
function ErrorObject() {
|
||||
this.error = null;
|
||||
}
|
||||
|
||||
var TRY_CATCH_ERROR = new ErrorObject();
|
||||
|
||||
function tryCatch(callback, detail) {
|
||||
try {
|
||||
return callback(detail);
|
||||
} catch(e) {
|
||||
TRY_CATCH_ERROR.error = e;
|
||||
return TRY_CATCH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function invokeCallback(settled, promise, callback, detail) {
|
||||
var hasCallback = isFunction(callback),
|
||||
value, error, succeeded, failed;
|
||||
|
||||
if (hasCallback) {
|
||||
value = tryCatch(callback, detail);
|
||||
|
||||
if (value === TRY_CATCH_ERROR) {
|
||||
failed = true;
|
||||
error = value.error;
|
||||
value = null;
|
||||
} else {
|
||||
succeeded = true;
|
||||
}
|
||||
|
||||
if (promise === value) {
|
||||
reject(promise, cannotReturnOwn());
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
value = detail;
|
||||
succeeded = true;
|
||||
}
|
||||
|
||||
if (promise._state !== PENDING) {
|
||||
// noop
|
||||
} else if (hasCallback && succeeded) {
|
||||
resolve(promise, value);
|
||||
} else if (failed) {
|
||||
reject(promise, error);
|
||||
} else if (settled === FULFILLED) {
|
||||
fulfill(promise, value);
|
||||
} else if (settled === REJECTED) {
|
||||
reject(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
function initializePromise(promise, resolver) {
|
||||
try {
|
||||
resolver(function resolvePromise(value){
|
||||
resolve(promise, value);
|
||||
}, function rejectPromise(reason) {
|
||||
reject(promise, reason);
|
||||
});
|
||||
} catch(e) {
|
||||
reject(promise, e);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
noop,
|
||||
resolve,
|
||||
reject,
|
||||
fulfill,
|
||||
subscribe,
|
||||
publish,
|
||||
publishRejection,
|
||||
initializePromise,
|
||||
invokeCallback,
|
||||
FULFILLED,
|
||||
REJECTED,
|
||||
PENDING
|
||||
};
|
||||
125
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/asap.js
generated
vendored
Normal file
125
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/asap.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
var len = 0;
|
||||
var toString = {}.toString;
|
||||
var vertxNext;
|
||||
var customSchedulerFn;
|
||||
|
||||
export var asap = function asap(callback, arg) {
|
||||
queue[len] = callback;
|
||||
queue[len + 1] = arg;
|
||||
len += 2;
|
||||
if (len === 2) {
|
||||
// If len is 2, that means that we need to schedule an async flush.
|
||||
// If additional callbacks are queued before the queue is flushed, they
|
||||
// will be processed by this flush that we are scheduling.
|
||||
if (customSchedulerFn) {
|
||||
customSchedulerFn(flush);
|
||||
} else {
|
||||
scheduleFlush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function setScheduler(scheduleFn) {
|
||||
customSchedulerFn = scheduleFn;
|
||||
}
|
||||
|
||||
export function setAsap(asapFn) {
|
||||
asap = asapFn;
|
||||
}
|
||||
|
||||
var browserWindow = (typeof window !== 'undefined') ? window : undefined;
|
||||
var browserGlobal = browserWindow || {};
|
||||
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
||||
var isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
||||
|
||||
// test for web worker but not in IE10
|
||||
var isWorker = typeof Uint8ClampedArray !== 'undefined' &&
|
||||
typeof importScripts !== 'undefined' &&
|
||||
typeof MessageChannel !== 'undefined';
|
||||
|
||||
// node
|
||||
function useNextTick() {
|
||||
var nextTick = process.nextTick;
|
||||
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
||||
// setImmediate should be used instead instead
|
||||
var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);
|
||||
if (Array.isArray(version) && version[1] === '0' && version[2] === '10') {
|
||||
nextTick = setImmediate;
|
||||
}
|
||||
return function() {
|
||||
nextTick(flush);
|
||||
};
|
||||
}
|
||||
|
||||
// vertx
|
||||
function useVertxTimer() {
|
||||
return function() {
|
||||
vertxNext(flush);
|
||||
};
|
||||
}
|
||||
|
||||
function useMutationObserver() {
|
||||
var iterations = 0;
|
||||
var observer = new BrowserMutationObserver(flush);
|
||||
var node = document.createTextNode('');
|
||||
observer.observe(node, { characterData: true });
|
||||
|
||||
return function() {
|
||||
node.data = (iterations = ++iterations % 2);
|
||||
};
|
||||
}
|
||||
|
||||
// web worker
|
||||
function useMessageChannel() {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.onmessage = flush;
|
||||
return function () {
|
||||
channel.port2.postMessage(0);
|
||||
};
|
||||
}
|
||||
|
||||
function useSetTimeout() {
|
||||
return function() {
|
||||
setTimeout(flush, 1);
|
||||
};
|
||||
}
|
||||
|
||||
var queue = new Array(1000);
|
||||
function flush() {
|
||||
for (var i = 0; i < len; i+=2) {
|
||||
var callback = queue[i];
|
||||
var arg = queue[i+1];
|
||||
|
||||
callback(arg);
|
||||
|
||||
queue[i] = undefined;
|
||||
queue[i+1] = undefined;
|
||||
}
|
||||
|
||||
len = 0;
|
||||
}
|
||||
|
||||
function attemptVertex() {
|
||||
try {
|
||||
var r = require;
|
||||
var vertx = r('vertx');
|
||||
vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
||||
return useVertxTimer();
|
||||
} catch(e) {
|
||||
return useSetTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
var scheduleFlush;
|
||||
// Decide what async method to use to triggering processing of queued callbacks:
|
||||
if (isNode) {
|
||||
scheduleFlush = useNextTick();
|
||||
} else if (BrowserMutationObserver) {
|
||||
scheduleFlush = useMutationObserver();
|
||||
} else if (isWorker) {
|
||||
scheduleFlush = useMessageChannel();
|
||||
} else if (browserWindow === undefined && typeof require === 'function') {
|
||||
scheduleFlush = attemptVertex();
|
||||
} else {
|
||||
scheduleFlush = useSetTimeout();
|
||||
}
|
||||
113
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/enumerator.js
generated
vendored
Normal file
113
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/enumerator.js
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
import {
|
||||
isArray,
|
||||
isMaybeThenable
|
||||
} from './utils';
|
||||
|
||||
import {
|
||||
noop,
|
||||
reject,
|
||||
fulfill,
|
||||
subscribe,
|
||||
FULFILLED,
|
||||
REJECTED,
|
||||
PENDING
|
||||
} from './-internal';
|
||||
|
||||
function Enumerator(Constructor, input) {
|
||||
var enumerator = this;
|
||||
|
||||
enumerator._instanceConstructor = Constructor;
|
||||
enumerator.promise = new Constructor(noop);
|
||||
|
||||
if (enumerator._validateInput(input)) {
|
||||
enumerator._input = input;
|
||||
enumerator.length = input.length;
|
||||
enumerator._remaining = input.length;
|
||||
|
||||
enumerator._init();
|
||||
|
||||
if (enumerator.length === 0) {
|
||||
fulfill(enumerator.promise, enumerator._result);
|
||||
} else {
|
||||
enumerator.length = enumerator.length || 0;
|
||||
enumerator._enumerate();
|
||||
if (enumerator._remaining === 0) {
|
||||
fulfill(enumerator.promise, enumerator._result);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reject(enumerator.promise, enumerator._validationError());
|
||||
}
|
||||
}
|
||||
|
||||
Enumerator.prototype._validateInput = function(input) {
|
||||
return isArray(input);
|
||||
};
|
||||
|
||||
Enumerator.prototype._validationError = function() {
|
||||
return new Error('Array Methods must be provided an Array');
|
||||
};
|
||||
|
||||
Enumerator.prototype._init = function() {
|
||||
this._result = new Array(this.length);
|
||||
};
|
||||
|
||||
export default Enumerator;
|
||||
|
||||
Enumerator.prototype._enumerate = function() {
|
||||
var enumerator = this;
|
||||
|
||||
var length = enumerator.length;
|
||||
var promise = enumerator.promise;
|
||||
var input = enumerator._input;
|
||||
|
||||
for (var i = 0; promise._state === PENDING && i < length; i++) {
|
||||
enumerator._eachEntry(input[i], i);
|
||||
}
|
||||
};
|
||||
|
||||
Enumerator.prototype._eachEntry = function(entry, i) {
|
||||
var enumerator = this;
|
||||
var c = enumerator._instanceConstructor;
|
||||
|
||||
if (isMaybeThenable(entry)) {
|
||||
if (entry.constructor === c && entry._state !== PENDING) {
|
||||
entry._onerror = null;
|
||||
enumerator._settledAt(entry._state, i, entry._result);
|
||||
} else {
|
||||
enumerator._willSettleAt(c.resolve(entry), i);
|
||||
}
|
||||
} else {
|
||||
enumerator._remaining--;
|
||||
enumerator._result[i] = entry;
|
||||
}
|
||||
};
|
||||
|
||||
Enumerator.prototype._settledAt = function(state, i, value) {
|
||||
var enumerator = this;
|
||||
var promise = enumerator.promise;
|
||||
|
||||
if (promise._state === PENDING) {
|
||||
enumerator._remaining--;
|
||||
|
||||
if (state === REJECTED) {
|
||||
reject(promise, value);
|
||||
} else {
|
||||
enumerator._result[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (enumerator._remaining === 0) {
|
||||
fulfill(promise, enumerator._result);
|
||||
}
|
||||
};
|
||||
|
||||
Enumerator.prototype._willSettleAt = function(promise, i) {
|
||||
var enumerator = this;
|
||||
|
||||
subscribe(promise, undefined, function(value) {
|
||||
enumerator._settledAt(FULFILLED, i, value);
|
||||
}, function(reason) {
|
||||
enumerator._settledAt(REJECTED, i, reason);
|
||||
});
|
||||
};
|
||||
26
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/polyfill.js
generated
vendored
Normal file
26
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/polyfill.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
/*global self*/
|
||||
import Promise from './promise';
|
||||
|
||||
export default function polyfill() {
|
||||
var local;
|
||||
|
||||
if (typeof global !== 'undefined') {
|
||||
local = global;
|
||||
} else if (typeof self !== 'undefined') {
|
||||
local = self;
|
||||
} else {
|
||||
try {
|
||||
local = Function('return this')();
|
||||
} catch (e) {
|
||||
throw new Error('polyfill failed because global object is unavailable in this environment');
|
||||
}
|
||||
}
|
||||
|
||||
var P = local.Promise;
|
||||
|
||||
if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) {
|
||||
return;
|
||||
}
|
||||
|
||||
local.Promise = Promise;
|
||||
}
|
||||
415
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise.js
generated
vendored
Normal file
415
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise.js
generated
vendored
Normal file
@@ -0,0 +1,415 @@
|
||||
import {
|
||||
isFunction
|
||||
} from './utils';
|
||||
|
||||
import {
|
||||
noop,
|
||||
subscribe,
|
||||
initializePromise,
|
||||
invokeCallback,
|
||||
FULFILLED,
|
||||
REJECTED
|
||||
} from './-internal';
|
||||
|
||||
import {
|
||||
asap,
|
||||
setAsap,
|
||||
setScheduler
|
||||
} from './asap';
|
||||
|
||||
import all from './promise/all';
|
||||
import race from './promise/race';
|
||||
import Resolve from './promise/resolve';
|
||||
import Reject from './promise/reject';
|
||||
|
||||
var counter = 0;
|
||||
|
||||
function needsResolver() {
|
||||
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
||||
}
|
||||
|
||||
function needsNew() {
|
||||
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
||||
}
|
||||
|
||||
export default Promise;
|
||||
/**
|
||||
Promise objects represent the eventual result of an asynchronous operation. The
|
||||
primary way of interacting with a promise is through its `then` method, which
|
||||
registers callbacks to receive either a promise's eventual value or the reason
|
||||
why the promise cannot be fulfilled.
|
||||
|
||||
Terminology
|
||||
-----------
|
||||
|
||||
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
||||
- `thenable` is an object or function that defines a `then` method.
|
||||
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
||||
- `exception` is a value that is thrown using the throw statement.
|
||||
- `reason` is a value that indicates why a promise was rejected.
|
||||
- `settled` the final resting state of a promise, fulfilled or rejected.
|
||||
|
||||
A promise can be in one of three states: pending, fulfilled, or rejected.
|
||||
|
||||
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
||||
state. Promises that are rejected have a rejection reason and are in the
|
||||
rejected state. A fulfillment value is never a thenable.
|
||||
|
||||
Promises can also be said to *resolve* a value. If this value is also a
|
||||
promise, then the original promise's settled state will match the value's
|
||||
settled state. So a promise that *resolves* a promise that rejects will
|
||||
itself reject, and a promise that *resolves* a promise that fulfills will
|
||||
itself fulfill.
|
||||
|
||||
|
||||
Basic Usage:
|
||||
------------
|
||||
|
||||
```js
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
// on success
|
||||
resolve(value);
|
||||
|
||||
// on failure
|
||||
reject(reason);
|
||||
});
|
||||
|
||||
promise.then(function(value) {
|
||||
// on fulfillment
|
||||
}, function(reason) {
|
||||
// on rejection
|
||||
});
|
||||
```
|
||||
|
||||
Advanced Usage:
|
||||
---------------
|
||||
|
||||
Promises shine when abstracting away asynchronous interactions such as
|
||||
`XMLHttpRequest`s.
|
||||
|
||||
```js
|
||||
function getJSON(url) {
|
||||
return new Promise(function(resolve, reject){
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', url);
|
||||
xhr.onreadystatechange = handler;
|
||||
xhr.responseType = 'json';
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
xhr.send();
|
||||
|
||||
function handler() {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 200) {
|
||||
resolve(this.response);
|
||||
} else {
|
||||
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
getJSON('/posts.json').then(function(json) {
|
||||
// on fulfillment
|
||||
}, function(reason) {
|
||||
// on rejection
|
||||
});
|
||||
```
|
||||
|
||||
Unlike callbacks, promises are great composable primitives.
|
||||
|
||||
```js
|
||||
Promise.all([
|
||||
getJSON('/posts'),
|
||||
getJSON('/comments')
|
||||
]).then(function(values){
|
||||
values[0] // => postsJSON
|
||||
values[1] // => commentsJSON
|
||||
|
||||
return values;
|
||||
});
|
||||
```
|
||||
|
||||
@class Promise
|
||||
@param {function} resolver
|
||||
Useful for tooling.
|
||||
@constructor
|
||||
*/
|
||||
function Promise(resolver) {
|
||||
this._id = counter++;
|
||||
this._state = undefined;
|
||||
this._result = undefined;
|
||||
this._subscribers = [];
|
||||
|
||||
if (noop !== resolver) {
|
||||
if (!isFunction(resolver)) {
|
||||
needsResolver();
|
||||
}
|
||||
|
||||
if (!(this instanceof Promise)) {
|
||||
needsNew();
|
||||
}
|
||||
|
||||
initializePromise(this, resolver);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.all = all;
|
||||
Promise.race = race;
|
||||
Promise.resolve = Resolve;
|
||||
Promise.reject = Reject;
|
||||
Promise._setScheduler = setScheduler;
|
||||
Promise._setAsap = setAsap;
|
||||
Promise._asap = asap;
|
||||
|
||||
Promise.prototype = {
|
||||
constructor: Promise,
|
||||
|
||||
/**
|
||||
The primary way of interacting with a promise is through its `then` method,
|
||||
which registers callbacks to receive either a promise's eventual value or the
|
||||
reason why the promise cannot be fulfilled.
|
||||
|
||||
```js
|
||||
findUser().then(function(user){
|
||||
// user is available
|
||||
}, function(reason){
|
||||
// user is unavailable, and you are given the reason why
|
||||
});
|
||||
```
|
||||
|
||||
Chaining
|
||||
--------
|
||||
|
||||
The return value of `then` is itself a promise. This second, 'downstream'
|
||||
promise is resolved with the return value of the first promise's fulfillment
|
||||
or rejection handler, or rejected if the handler throws an exception.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return user.name;
|
||||
}, function (reason) {
|
||||
return 'default name';
|
||||
}).then(function (userName) {
|
||||
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
||||
// will be `'default name'`
|
||||
});
|
||||
|
||||
findUser().then(function (user) {
|
||||
throw new Error('Found user, but still unhappy');
|
||||
}, function (reason) {
|
||||
throw new Error('`findUser` rejected and we're unhappy');
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}, function (reason) {
|
||||
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
||||
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
||||
});
|
||||
```
|
||||
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
throw new PedagogicalException('Upstream error');
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}, function (reason) {
|
||||
// The `PedgagocialException` is propagated all the way down to here
|
||||
});
|
||||
```
|
||||
|
||||
Assimilation
|
||||
------------
|
||||
|
||||
Sometimes the value you want to propagate to a downstream promise can only be
|
||||
retrieved asynchronously. This can be achieved by returning a promise in the
|
||||
fulfillment or rejection handler. The downstream promise will then be pending
|
||||
until the returned promise is settled. This is called *assimilation*.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return findCommentsByAuthor(user);
|
||||
}).then(function (comments) {
|
||||
// The user's comments are now available
|
||||
});
|
||||
```
|
||||
|
||||
If the assimliated promise rejects, then the downstream promise will also reject.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return findCommentsByAuthor(user);
|
||||
}).then(function (comments) {
|
||||
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
||||
}, function (reason) {
|
||||
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
||||
});
|
||||
```
|
||||
|
||||
Simple Example
|
||||
--------------
|
||||
|
||||
Synchronous Example
|
||||
|
||||
```javascript
|
||||
var result;
|
||||
|
||||
try {
|
||||
result = findResult();
|
||||
// success
|
||||
} catch(reason) {
|
||||
// failure
|
||||
}
|
||||
```
|
||||
|
||||
Errback Example
|
||||
|
||||
```js
|
||||
findResult(function(result, err){
|
||||
if (err) {
|
||||
// failure
|
||||
} else {
|
||||
// success
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Promise Example;
|
||||
|
||||
```javascript
|
||||
findResult().then(function(result){
|
||||
// success
|
||||
}, function(reason){
|
||||
// failure
|
||||
});
|
||||
```
|
||||
|
||||
Advanced Example
|
||||
--------------
|
||||
|
||||
Synchronous Example
|
||||
|
||||
```javascript
|
||||
var author, books;
|
||||
|
||||
try {
|
||||
author = findAuthor();
|
||||
books = findBooksByAuthor(author);
|
||||
// success
|
||||
} catch(reason) {
|
||||
// failure
|
||||
}
|
||||
```
|
||||
|
||||
Errback Example
|
||||
|
||||
```js
|
||||
|
||||
function foundBooks(books) {
|
||||
|
||||
}
|
||||
|
||||
function failure(reason) {
|
||||
|
||||
}
|
||||
|
||||
findAuthor(function(author, err){
|
||||
if (err) {
|
||||
failure(err);
|
||||
// failure
|
||||
} else {
|
||||
try {
|
||||
findBoooksByAuthor(author, function(books, err) {
|
||||
if (err) {
|
||||
failure(err);
|
||||
} else {
|
||||
try {
|
||||
foundBooks(books);
|
||||
} catch(reason) {
|
||||
failure(reason);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(error) {
|
||||
failure(err);
|
||||
}
|
||||
// success
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Promise Example;
|
||||
|
||||
```javascript
|
||||
findAuthor().
|
||||
then(findBooksByAuthor).
|
||||
then(function(books){
|
||||
// found books
|
||||
}).catch(function(reason){
|
||||
// something went wrong
|
||||
});
|
||||
```
|
||||
|
||||
@method then
|
||||
@param {Function} onFulfilled
|
||||
@param {Function} onRejected
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
then: function(onFulfillment, onRejection) {
|
||||
var parent = this;
|
||||
var state = parent._state;
|
||||
|
||||
if (state === FULFILLED && !onFulfillment || state === REJECTED && !onRejection) {
|
||||
return this;
|
||||
}
|
||||
|
||||
var child = new this.constructor(noop);
|
||||
var result = parent._result;
|
||||
|
||||
if (state) {
|
||||
var callback = arguments[state - 1];
|
||||
asap(function(){
|
||||
invokeCallback(state, child, callback, result);
|
||||
});
|
||||
} else {
|
||||
subscribe(parent, child, onFulfillment, onRejection);
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
/**
|
||||
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
||||
as the catch block of a try/catch statement.
|
||||
|
||||
```js
|
||||
function findAuthor(){
|
||||
throw new Error('couldn't find that author');
|
||||
}
|
||||
|
||||
// synchronous
|
||||
try {
|
||||
findAuthor();
|
||||
} catch(reason) {
|
||||
// something went wrong
|
||||
}
|
||||
|
||||
// async with promises
|
||||
findAuthor().catch(function(reason){
|
||||
// something went wrong
|
||||
});
|
||||
```
|
||||
|
||||
@method catch
|
||||
@param {Function} onRejection
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
'catch': function(onRejection) {
|
||||
return this.then(null, onRejection);
|
||||
}
|
||||
};
|
||||
52
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise/all.js
generated
vendored
Normal file
52
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise/all.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import Enumerator from '../enumerator';
|
||||
|
||||
/**
|
||||
`Promise.all` accepts an array of promises, and returns a new promise which
|
||||
is fulfilled with an array of fulfillment values for the passed promises, or
|
||||
rejected with the reason of the first passed promise to be rejected. It casts all
|
||||
elements of the passed iterable to promises as it runs this algorithm.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var promise1 = resolve(1);
|
||||
var promise2 = resolve(2);
|
||||
var promise3 = resolve(3);
|
||||
var promises = [ promise1, promise2, promise3 ];
|
||||
|
||||
Promise.all(promises).then(function(array){
|
||||
// The array here would be [ 1, 2, 3 ];
|
||||
});
|
||||
```
|
||||
|
||||
If any of the `promises` given to `all` are rejected, the first promise
|
||||
that is rejected will be given as an argument to the returned promises's
|
||||
rejection handler. For example:
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var promise1 = resolve(1);
|
||||
var promise2 = reject(new Error("2"));
|
||||
var promise3 = reject(new Error("3"));
|
||||
var promises = [ promise1, promise2, promise3 ];
|
||||
|
||||
Promise.all(promises).then(function(array){
|
||||
// Code here never runs because there are rejected promises!
|
||||
}, function(error) {
|
||||
// error.message === "2"
|
||||
});
|
||||
```
|
||||
|
||||
@method all
|
||||
@static
|
||||
@param {Array} entries array of promises
|
||||
@param {String} label optional string for labeling the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} promise that is fulfilled when all `promises` have been
|
||||
fulfilled, or rejected if any of them become rejected.
|
||||
@static
|
||||
*/
|
||||
export default function all(entries) {
|
||||
return new Enumerator(this, entries).promise;
|
||||
}
|
||||
104
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise/race.js
generated
vendored
Normal file
104
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise/race.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
import {
|
||||
isArray
|
||||
} from "../utils";
|
||||
|
||||
import {
|
||||
noop,
|
||||
resolve,
|
||||
reject,
|
||||
subscribe,
|
||||
PENDING
|
||||
} from '../-internal';
|
||||
|
||||
/**
|
||||
`Promise.race` returns a new promise which is settled in the same way as the
|
||||
first passed promise to settle.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var promise1 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 1');
|
||||
}, 200);
|
||||
});
|
||||
|
||||
var promise2 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 2');
|
||||
}, 100);
|
||||
});
|
||||
|
||||
Promise.race([promise1, promise2]).then(function(result){
|
||||
// result === 'promise 2' because it was resolved before promise1
|
||||
// was resolved.
|
||||
});
|
||||
```
|
||||
|
||||
`Promise.race` is deterministic in that only the state of the first
|
||||
settled promise matters. For example, even if other promises given to the
|
||||
`promises` array argument are resolved, but the first settled promise has
|
||||
become rejected before the other promises became fulfilled, the returned
|
||||
promise will become rejected:
|
||||
|
||||
```javascript
|
||||
var promise1 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 1');
|
||||
}, 200);
|
||||
});
|
||||
|
||||
var promise2 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
reject(new Error('promise 2'));
|
||||
}, 100);
|
||||
});
|
||||
|
||||
Promise.race([promise1, promise2]).then(function(result){
|
||||
// Code here never runs
|
||||
}, function(reason){
|
||||
// reason.message === 'promise 2' because promise 2 became rejected before
|
||||
// promise 1 became fulfilled
|
||||
});
|
||||
```
|
||||
|
||||
An example real-world use case is implementing timeouts:
|
||||
|
||||
```javascript
|
||||
Promise.race([ajax('foo.json'), timeout(5000)])
|
||||
```
|
||||
|
||||
@method race
|
||||
@static
|
||||
@param {Array} promises array of promises to observe
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise which settles in the same way as the first passed
|
||||
promise to settle.
|
||||
*/
|
||||
export default function race(entries) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
|
||||
var promise = new Constructor(noop);
|
||||
|
||||
if (!isArray(entries)) {
|
||||
reject(promise, new TypeError('You must pass an array to race.'));
|
||||
return promise;
|
||||
}
|
||||
|
||||
var length = entries.length;
|
||||
|
||||
function onFulfillment(value) {
|
||||
resolve(promise, value);
|
||||
}
|
||||
|
||||
function onRejection(reason) {
|
||||
reject(promise, reason);
|
||||
}
|
||||
|
||||
for (var i = 0; promise._state === PENDING && i < length; i++) {
|
||||
subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
46
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise/reject.js
generated
vendored
Normal file
46
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise/reject.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import {
|
||||
noop,
|
||||
reject as _reject
|
||||
} from '../-internal';
|
||||
|
||||
/**
|
||||
`Promise.reject` returns a promise rejected with the passed `reason`.
|
||||
It is shorthand for the following:
|
||||
|
||||
```javascript
|
||||
var promise = new Promise(function(resolve, reject){
|
||||
reject(new Error('WHOOPS'));
|
||||
});
|
||||
|
||||
promise.then(function(value){
|
||||
// Code here doesn't run because the promise is rejected!
|
||||
}, function(reason){
|
||||
// reason.message === 'WHOOPS'
|
||||
});
|
||||
```
|
||||
|
||||
Instead of writing the above, your code now simply becomes the following:
|
||||
|
||||
```javascript
|
||||
var promise = Promise.reject(new Error('WHOOPS'));
|
||||
|
||||
promise.then(function(value){
|
||||
// Code here doesn't run because the promise is rejected!
|
||||
}, function(reason){
|
||||
// reason.message === 'WHOOPS'
|
||||
});
|
||||
```
|
||||
|
||||
@method reject
|
||||
@static
|
||||
@param {Any} reason value that the returned promise will be rejected with.
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise rejected with the given `reason`.
|
||||
*/
|
||||
export default function reject(reason) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
var promise = new Constructor(noop);
|
||||
_reject(promise, reason);
|
||||
return promise;
|
||||
}
|
||||
48
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise/resolve.js
generated
vendored
Normal file
48
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/promise/resolve.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
noop,
|
||||
resolve as _resolve
|
||||
} from '../-internal';
|
||||
|
||||
/**
|
||||
`Promise.resolve` returns a promise that will become resolved with the
|
||||
passed `value`. It is shorthand for the following:
|
||||
|
||||
```javascript
|
||||
var promise = new Promise(function(resolve, reject){
|
||||
resolve(1);
|
||||
});
|
||||
|
||||
promise.then(function(value){
|
||||
// value === 1
|
||||
});
|
||||
```
|
||||
|
||||
Instead of writing the above, your code now simply becomes the following:
|
||||
|
||||
```javascript
|
||||
var promise = Promise.resolve(1);
|
||||
|
||||
promise.then(function(value){
|
||||
// value === 1
|
||||
});
|
||||
```
|
||||
|
||||
@method resolve
|
||||
@static
|
||||
@param {Any} value value that the returned promise will be resolved with
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise that will become fulfilled with the given
|
||||
`value`
|
||||
*/
|
||||
export default function resolve(object) {
|
||||
/*jshint validthis:true */
|
||||
var Constructor = this;
|
||||
|
||||
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
||||
return object;
|
||||
}
|
||||
|
||||
var promise = new Constructor(noop);
|
||||
_resolve(promise, object);
|
||||
return promise;
|
||||
}
|
||||
22
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/utils.js
generated
vendored
Normal file
22
build/node_modules/hydrolysis/node_modules/es6-promise/lib/es6-promise/utils.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export function objectOrFunction(x) {
|
||||
return typeof x === 'function' || (typeof x === 'object' && x !== null);
|
||||
}
|
||||
|
||||
export function isFunction(x) {
|
||||
return typeof x === 'function';
|
||||
}
|
||||
|
||||
export function isMaybeThenable(x) {
|
||||
return typeof x === 'object' && x !== null;
|
||||
}
|
||||
|
||||
var _isArray;
|
||||
if (!Array.isArray) {
|
||||
_isArray = function (x) {
|
||||
return Object.prototype.toString.call(x) === '[object Array]';
|
||||
};
|
||||
} else {
|
||||
_isArray = Array.isArray;
|
||||
}
|
||||
|
||||
export var isArray = _isArray;
|
||||
92
build/node_modules/hydrolysis/node_modules/es6-promise/package.json
generated
vendored
Normal file
92
build/node_modules/hydrolysis/node_modules/es6-promise/package.json
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"_from": "es6-promise@^2.1.0",
|
||||
"_id": "es6-promise@2.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-lu258v2wGZWCKyY92KratnSBgbw=",
|
||||
"_location": "/hydrolysis/es6-promise",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "es6-promise@^2.1.0",
|
||||
"name": "es6-promise",
|
||||
"escapedName": "es6-promise",
|
||||
"rawSpec": "^2.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/hydrolysis"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-2.3.0.tgz",
|
||||
"_shasum": "96edb9f2fdb01995822b263dd8aadab6748181bc",
|
||||
"_spec": "es6-promise@^2.1.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/hydrolysis",
|
||||
"author": {
|
||||
"name": "Yehuda Katz, Tom Dale, Stefan Penner and contributors",
|
||||
"url": "Conversion to ES6 API by Jake Archibald"
|
||||
},
|
||||
"browser": {
|
||||
"vertx": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/jakearchibald/ES6-Promises/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A lightweight library that provides tools for organizing asynchronous code",
|
||||
"devDependencies": {
|
||||
"bower": "^1.3.9",
|
||||
"brfs": "0.0.8",
|
||||
"broccoli-es3-safe-recast": "0.0.8",
|
||||
"broccoli-es6-module-transpiler": "^0.5.0",
|
||||
"broccoli-jshint": "^0.5.1",
|
||||
"broccoli-merge-trees": "^0.1.4",
|
||||
"broccoli-replace": "^0.2.0",
|
||||
"broccoli-stew": "0.0.6",
|
||||
"broccoli-uglify-js": "^0.1.3",
|
||||
"broccoli-watchify": "^0.2.0",
|
||||
"ember-cli": "0.2.3",
|
||||
"ember-publisher": "0.0.7",
|
||||
"git-repo-version": "0.0.2",
|
||||
"json3": "^3.3.2",
|
||||
"minimatch": "^2.0.1",
|
||||
"mocha": "^1.20.1",
|
||||
"promises-aplus-tests-phantom": "^2.1.0-revise",
|
||||
"release-it": "0.0.10"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "lib"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"lib"
|
||||
],
|
||||
"homepage": "https://github.com/jakearchibald/ES6-Promises#readme",
|
||||
"keywords": [
|
||||
"promises",
|
||||
"futures"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "dist/es6-promise.js",
|
||||
"name": "es6-promise",
|
||||
"namespace": "es6-promise",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jakearchibald/ES6-Promises.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ember build",
|
||||
"dry-run-release": "ember build --environment production && release-it --dry-run --non-interactive",
|
||||
"lint": "jshint lib",
|
||||
"prepublish": "ember build --environment production",
|
||||
"start": "ember s",
|
||||
"test": "ember test",
|
||||
"test:node": "ember build && mocha ./dist/test/browserify",
|
||||
"test:server": "ember test --server"
|
||||
},
|
||||
"spm": {
|
||||
"main": "dist/es6-promise.js"
|
||||
},
|
||||
"version": "2.3.0"
|
||||
}
|
||||
232
build/node_modules/hydrolysis/node_modules/espree/README.md
generated
vendored
Normal file
232
build/node_modules/hydrolysis/node_modules/espree/README.md
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
# Espree
|
||||
|
||||
Espree is an actively-maintained fork Esprima, a high performance,
|
||||
standard-compliant [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm)
|
||||
parser written in ECMAScript (also popularly known as
|
||||
[JavaScript](http://en.wikipedia.org/wiki/JavaScript)).
|
||||
|
||||
## Features
|
||||
|
||||
- Full support for ECMAScript 5.1 ([ECMA-262](http://www.ecma-international.org/publications/standards/Ecma-262.htm))
|
||||
- Implements [ESTree](https://github.com/estree/estree) (both ES5 and ES6 specs) as the AST format.
|
||||
- Optional tracking of syntax node location (index-based and line-column)
|
||||
- Heavily tested and battle-hardened by inclusion in [ESLint](http://eslint.org)
|
||||
|
||||
## Usage
|
||||
|
||||
Install:
|
||||
|
||||
```
|
||||
npm i espree --save
|
||||
```
|
||||
|
||||
And in your Node.js code:
|
||||
|
||||
```javascript
|
||||
var espree = require("espree");
|
||||
|
||||
var ast = espree.parse(code);
|
||||
```
|
||||
|
||||
There is a second argument to `parse()` that allows you to specify various options:
|
||||
|
||||
```javascript
|
||||
var espree = require("espree");
|
||||
|
||||
var ast = espree.parse(code, {
|
||||
|
||||
// attach range information to each node
|
||||
range: true,
|
||||
|
||||
// attach line/column location information to each node
|
||||
loc: true,
|
||||
|
||||
// create a top-level comments array containing all comments
|
||||
comments: true,
|
||||
|
||||
// attach comments to the closest relevant node as leadingComments and
|
||||
// trailingComments
|
||||
attachComment: true,
|
||||
|
||||
// create a top-level tokens array containing all tokens
|
||||
tokens: true,
|
||||
|
||||
// try to continue parsing if an error is encountered, store errors in a
|
||||
// top-level errors array
|
||||
tolerant: true,
|
||||
|
||||
// specify parsing features (default only has blockBindings: true)
|
||||
// setting this option replaces the default values
|
||||
ecmaFeatures: {
|
||||
|
||||
// enable parsing of arrow functions
|
||||
arrowFunctions: true,
|
||||
|
||||
// enable parsing of let/const
|
||||
blockBindings: true,
|
||||
|
||||
// enable parsing of destructured arrays and objects
|
||||
destructuring: true,
|
||||
|
||||
// enable parsing of regular expression y flag
|
||||
regexYFlag: true,
|
||||
|
||||
// enable parsing of regular expression u flag
|
||||
regexUFlag: true,
|
||||
|
||||
// enable parsing of template strings
|
||||
templateStrings: true,
|
||||
|
||||
// enable parsing of binary literals
|
||||
binaryLiterals: true,
|
||||
|
||||
// enable parsing of ES6 octal literals
|
||||
octalLiterals: true,
|
||||
|
||||
// enable parsing unicode code point escape sequences
|
||||
unicodeCodePointEscapes: true,
|
||||
|
||||
// enable parsing of default parameters
|
||||
defaultParams: true,
|
||||
|
||||
// enable parsing of rest parameters
|
||||
restParams: true,
|
||||
|
||||
// enable parsing of for-of statement
|
||||
forOf: true,
|
||||
|
||||
// enable parsing computed object literal properties
|
||||
objectLiteralComputedProperties: true,
|
||||
|
||||
// enable parsing of shorthand object literal methods
|
||||
objectLiteralShorthandMethods: true,
|
||||
|
||||
// enable parsing of shorthand object literal properties
|
||||
objectLiteralShorthandProperties: true,
|
||||
|
||||
// Allow duplicate object literal properties (except '__proto__')
|
||||
objectLiteralDuplicateProperties: true,
|
||||
|
||||
// enable parsing of generators/yield
|
||||
generators: true,
|
||||
|
||||
// enable parsing spread operator
|
||||
spread: true,
|
||||
|
||||
// enable super in functions
|
||||
superInFunctions: true,
|
||||
|
||||
// enable parsing classes
|
||||
classes: true,
|
||||
|
||||
// enable parsing of new.target
|
||||
newTarget: false,
|
||||
|
||||
// enable parsing of modules
|
||||
modules: true,
|
||||
|
||||
// enable React JSX parsing
|
||||
jsx: true,
|
||||
|
||||
// enable return in global scope
|
||||
globalReturn: true,
|
||||
|
||||
// allow experimental object rest/spread
|
||||
experimentalObjectRestSpread: true
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Plans
|
||||
|
||||
Espree starts as a fork of Esprima v1.2.2, the last stable published released of Esprima before work on ECMAScript 6 began. Espree's first version is therefore v1.2.2 and is 100% compatible with Esprima v1.2.2 as a drop-in replacement. The version number will be incremented based on [semantic versioning](http://semver.org/) as features and bug fixes are added.
|
||||
|
||||
The immediate plans are:
|
||||
|
||||
1. Move away from giant files and move towards small, modular files that are easier to manage.
|
||||
1. Move towards CommonJS for all files and use browserify to create browser bundles.
|
||||
1. Support ECMAScript version filtering, allowing users to specify which version the parser should work in (similar to Acorn's `ecmaVersion` property).
|
||||
1. Add tests to track comment attachment.
|
||||
1. Add well-thought-out features that are useful for tools developers.
|
||||
1. Add full support for ECMAScript 6.
|
||||
1. Add optional parsing of JSX.
|
||||
|
||||
## Esprima Compatibility Going Forward
|
||||
|
||||
The primary goal is to produce the exact same AST structure as Esprima and Acorn, and that takes precedence over anything else. (The AST structure being the ESTree API with JSX extensions.) Separate from that, Espree may deviate from what Esprima outputs in terms of where and how comments are attached, as well as what additional information is available on AST nodes. That is to say, Espree may add more things to the AST nodes than Esprima does but the overall AST structure produced will be the same.
|
||||
|
||||
Espree may also deviate from Esprima in the interface it exposes.
|
||||
|
||||
## Frequent and Incremental Releases
|
||||
|
||||
Espree will not do giant releases. Releases will happen periodically as changes are made and incremental releases will be made towards larger goals. For instance, we will not have one big release for ECMAScript 6 support. Instead, we will implement ECMAScript 6, piece-by-piece, hiding those pieces behind an `ecmaFeatures` property that allows you to opt-in to use those features.
|
||||
|
||||
## Contributing
|
||||
|
||||
Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing.html), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/espree/issues).
|
||||
|
||||
Espree is licensed under a permissive BSD 2-clause license.
|
||||
|
||||
## Build Commands
|
||||
|
||||
* `npm test` - run all linting and tests
|
||||
* `npm run lint` - run all linting
|
||||
* `npm run browserify` - creates a version of Espree that is usable in a browser
|
||||
|
||||
## Known Incompatibilities
|
||||
|
||||
In an effort to help those wanting to transition from other parsers to Espree, the following is a list of noteworthy incompatibilities with other parsers. These are known differences that we do not intend to change.
|
||||
|
||||
### Esprima 1.2.2
|
||||
|
||||
* None.
|
||||
|
||||
### Esprima/Harmony Branch
|
||||
|
||||
* Esprima/Harmony uses a different comment attachment algorithm that results in some comments being added in different places than Espree. The algorithm Espree uses is the same one used in Esprima 1.2.2.
|
||||
* Espree uses ESTree format for the AST nodes whereas Esprima/Harmony uses a nonstandard format.
|
||||
|
||||
### Esprima-FB
|
||||
|
||||
* All Esprima/Harmony incompatibilities.
|
||||
|
||||
## Frequently Asked Questions
|
||||
|
||||
### Why are you forking Esprima?
|
||||
|
||||
[ESLint](http://eslint.org) has been relying on Esprima as its parser from the beginning. While that was fine when the JavaScript language was evolving slowly, the pace of development has increased dramatically and Esprima has fallen behind. ESLint, like many other tools reliant on Esprima, has been stuck in using new JavaScript language features until Esprima updates, and that has caused our users frustration.
|
||||
|
||||
We decided the only way for us to move forward was to create our own parser, bringing us inline with JSHint and JSLint, and allowing us to keep implementing new features as we need them. We chose to fork Esprima instead of starting from scratch in order to move as quickly as possible with a compatible API.
|
||||
|
||||
### Have you tried working with Esprima?
|
||||
|
||||
Yes. Since the start of ESLint, we've regularly filed bugs and feature requests with Esprima. Unfortunately, we've been unable to make much progress towards getting our needs addressed.
|
||||
|
||||
We are actively working with Esprima as part of its adoption by the jQuery Foundation. We are hoping to reconcile Espree with Esprima at some point in the future, but there are some different philosophies around how the projects work that need to be worked through. We're committed to a goal of merging Espree back into Esprima, or at the very least, to have Espree track Esprima as an upstream target so there's no duplication of effort. In the meantime, we will continue to update and maintain Espree.
|
||||
|
||||
### Why don't you just use Facebook's Esprima fork?
|
||||
|
||||
`esprima-fb` is Facebook's Esprima fork that features JSX and Flow type annotations. We tried working with `esprima-fb` in our evaluation of how to support ECMAScript 6 and JSX in ESLint. Unfortunately, we were hampered by bugs that were part of Esprima (not necessarily Facebook's code). Since `esprima-fb` tracks the Esprima Harmony branch, that means we still were unable to get fixes or features we needed in a timely manner.
|
||||
|
||||
### Why don't you just use Acorn?
|
||||
|
||||
Acorn is a great JavaScript parser that produces an AST that is compatible with Esprima. Unfortunately, ESLint relies on more than just the AST to do its job. It relies on Esprima's tokens and comment attachment features to get a complete picture of the source code. We investigated switching to Acorn, but the inconsistencies between Esprima and Acorn created too much work for a project like ESLint.
|
||||
|
||||
We expect there are other tools like ESLint that rely on more than just the AST produced by Esprima, and so a drop-in replacement will help those projects as well as ESLint.
|
||||
|
||||
### What ECMAScript 6 features do you support?
|
||||
|
||||
All of them.
|
||||
|
||||
### Why use Espree instead of Esprima?
|
||||
|
||||
* Faster turnaround time on bug fixes
|
||||
* More frequent releases
|
||||
* Better communication and responsiveness to issues
|
||||
* Ongoing development
|
||||
|
||||
### Why use Espree instead of Esprima-FB?
|
||||
|
||||
* Opt-in to just the ECMAScript 6 features you want
|
||||
* JSX support is off by default, so you're not forced to use it to use ECMAScript 6
|
||||
* Stricter ECMAScript 6 support
|
||||
127
build/node_modules/hydrolysis/node_modules/espree/bin/esparse.js
generated
vendored
Executable file
127
build/node_modules/hydrolysis/node_modules/espree/bin/esparse.js
generated
vendored
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*jslint sloppy:true node:true rhino:true */
|
||||
|
||||
var fs, espree, fname, content, options, syntax;
|
||||
|
||||
if (typeof require === 'function') {
|
||||
fs = require('fs');
|
||||
espree = require('espree');
|
||||
} else if (typeof load === 'function') {
|
||||
try {
|
||||
load('espree.js');
|
||||
} catch (e) {
|
||||
load('../espree.js');
|
||||
}
|
||||
}
|
||||
|
||||
// Shims to Node.js objects when running under Rhino.
|
||||
if (typeof console === 'undefined' && typeof process === 'undefined') {
|
||||
console = { log: print };
|
||||
fs = { readFileSync: readFile };
|
||||
process = { argv: arguments, exit: quit };
|
||||
process.argv.unshift('esparse.js');
|
||||
process.argv.unshift('rhino');
|
||||
}
|
||||
|
||||
function showUsage() {
|
||||
console.log('Usage:');
|
||||
console.log(' esparse [options] file.js');
|
||||
console.log();
|
||||
console.log('Available options:');
|
||||
console.log();
|
||||
console.log(' --comment Gather all line and block comments in an array');
|
||||
console.log(' --loc Include line-column location info for each syntax node');
|
||||
console.log(' --range Include index-based range for each syntax node');
|
||||
console.log(' --raw Display the raw value of literals');
|
||||
console.log(' --tokens List all tokens in an array');
|
||||
console.log(' --tolerant Tolerate errors on a best-effort basis (experimental)');
|
||||
console.log(' -v, --version Shows program version');
|
||||
console.log();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (process.argv.length <= 2) {
|
||||
showUsage();
|
||||
}
|
||||
|
||||
options = {};
|
||||
|
||||
process.argv.splice(2).forEach(function (entry) {
|
||||
|
||||
if (entry === '-h' || entry === '--help') {
|
||||
showUsage();
|
||||
} else if (entry === '-v' || entry === '--version') {
|
||||
console.log('ECMAScript Parser (using espree version', espree.version, ')');
|
||||
console.log();
|
||||
process.exit(0);
|
||||
} else if (entry === '--comment') {
|
||||
options.comment = true;
|
||||
} else if (entry === '--loc') {
|
||||
options.loc = true;
|
||||
} else if (entry === '--range') {
|
||||
options.range = true;
|
||||
} else if (entry === '--raw') {
|
||||
options.raw = true;
|
||||
} else if (entry === '--tokens') {
|
||||
options.tokens = true;
|
||||
} else if (entry === '--tolerant') {
|
||||
options.tolerant = true;
|
||||
} else if (entry.slice(0, 2) === '--') {
|
||||
console.log('Error: unknown option ' + entry + '.');
|
||||
process.exit(1);
|
||||
} else if (typeof fname === 'string') {
|
||||
console.log('Error: more than one input file.');
|
||||
process.exit(1);
|
||||
} else {
|
||||
fname = entry;
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof fname !== 'string') {
|
||||
console.log('Error: no input file.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Special handling for regular expression literal since we need to
|
||||
// convert it to a string literal, otherwise it will be decoded
|
||||
// as object "{}" and the regular expression would be lost.
|
||||
function adjustRegexLiteral(key, value) {
|
||||
if (key === 'value' && value instanceof RegExp) {
|
||||
value = value.toString();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
try {
|
||||
content = fs.readFileSync(fname, 'utf-8');
|
||||
syntax = espree.parse(content, options);
|
||||
console.log(JSON.stringify(syntax, adjustRegexLiteral, 4));
|
||||
} catch (e) {
|
||||
console.log('Error: ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
199
build/node_modules/hydrolysis/node_modules/espree/bin/esvalidate.js
generated
vendored
Executable file
199
build/node_modules/hydrolysis/node_modules/espree/bin/esvalidate.js
generated
vendored
Executable file
@@ -0,0 +1,199 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*jslint sloppy:true plusplus:true node:true rhino:true */
|
||||
/*global phantom:true */
|
||||
|
||||
var fs, system, espree, options, fnames, count;
|
||||
|
||||
if (typeof espree === 'undefined') {
|
||||
// PhantomJS can only require() relative files
|
||||
if (typeof phantom === 'object') {
|
||||
fs = require('fs');
|
||||
system = require('system');
|
||||
espree = require('./espree');
|
||||
} else if (typeof require === 'function') {
|
||||
fs = require('fs');
|
||||
espree = require('espree');
|
||||
} else if (typeof load === 'function') {
|
||||
try {
|
||||
load('espree.js');
|
||||
} catch (e) {
|
||||
load('../espree.js');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shims to Node.js objects when running under PhantomJS 1.7+.
|
||||
if (typeof phantom === 'object') {
|
||||
fs.readFileSync = fs.read;
|
||||
process = {
|
||||
argv: [].slice.call(system.args),
|
||||
exit: phantom.exit
|
||||
};
|
||||
process.argv.unshift('phantomjs');
|
||||
}
|
||||
|
||||
// Shims to Node.js objects when running under Rhino.
|
||||
if (typeof console === 'undefined' && typeof process === 'undefined') {
|
||||
console = { log: print };
|
||||
fs = { readFileSync: readFile };
|
||||
process = { argv: arguments, exit: quit };
|
||||
process.argv.unshift('esvalidate.js');
|
||||
process.argv.unshift('rhino');
|
||||
}
|
||||
|
||||
function showUsage() {
|
||||
console.log('Usage:');
|
||||
console.log(' esvalidate [options] file.js');
|
||||
console.log();
|
||||
console.log('Available options:');
|
||||
console.log();
|
||||
console.log(' --format=type Set the report format, plain (default) or junit');
|
||||
console.log(' -v, --version Print program version');
|
||||
console.log();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (process.argv.length <= 2) {
|
||||
showUsage();
|
||||
}
|
||||
|
||||
options = {
|
||||
format: 'plain'
|
||||
};
|
||||
|
||||
fnames = [];
|
||||
|
||||
process.argv.splice(2).forEach(function (entry) {
|
||||
|
||||
if (entry === '-h' || entry === '--help') {
|
||||
showUsage();
|
||||
} else if (entry === '-v' || entry === '--version') {
|
||||
console.log('ECMAScript Validator (using espree version', espree.version, ')');
|
||||
console.log();
|
||||
process.exit(0);
|
||||
} else if (entry.slice(0, 9) === '--format=') {
|
||||
options.format = entry.slice(9);
|
||||
if (options.format !== 'plain' && options.format !== 'junit') {
|
||||
console.log('Error: unknown report format ' + options.format + '.');
|
||||
process.exit(1);
|
||||
}
|
||||
} else if (entry.slice(0, 2) === '--') {
|
||||
console.log('Error: unknown option ' + entry + '.');
|
||||
process.exit(1);
|
||||
} else {
|
||||
fnames.push(entry);
|
||||
}
|
||||
});
|
||||
|
||||
if (fnames.length === 0) {
|
||||
console.log('Error: no input file.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (options.format === 'junit') {
|
||||
console.log('<?xml version="1.0" encoding="UTF-8"?>');
|
||||
console.log('<testsuites>');
|
||||
}
|
||||
|
||||
count = 0;
|
||||
fnames.forEach(function (fname) {
|
||||
var content, timestamp, syntax, name;
|
||||
try {
|
||||
content = fs.readFileSync(fname, 'utf-8');
|
||||
|
||||
if (content[0] === '#' && content[1] === '!') {
|
||||
content = '//' + content.substr(2, content.length);
|
||||
}
|
||||
|
||||
timestamp = Date.now();
|
||||
syntax = espree.parse(content, { tolerant: true });
|
||||
|
||||
if (options.format === 'junit') {
|
||||
|
||||
name = fname;
|
||||
if (name.lastIndexOf('/') >= 0) {
|
||||
name = name.slice(name.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
console.log('<testsuite name="' + fname + '" errors="0" ' +
|
||||
' failures="' + syntax.errors.length + '" ' +
|
||||
' tests="' + syntax.errors.length + '" ' +
|
||||
' time="' + Math.round((Date.now() - timestamp) / 1000) +
|
||||
'">');
|
||||
|
||||
syntax.errors.forEach(function (error) {
|
||||
var msg = error.message;
|
||||
msg = msg.replace(/^Line\ [0-9]*\:\ /, '');
|
||||
console.log(' <testcase name="Line ' + error.lineNumber + ': ' + msg + '" ' +
|
||||
' time="0">');
|
||||
console.log(' <error type="SyntaxError" message="' + error.message + '">' +
|
||||
error.message + '(' + name + ':' + error.lineNumber + ')' +
|
||||
'</error>');
|
||||
console.log(' </testcase>');
|
||||
});
|
||||
|
||||
console.log('</testsuite>');
|
||||
|
||||
} else if (options.format === 'plain') {
|
||||
|
||||
syntax.errors.forEach(function (error) {
|
||||
var msg = error.message;
|
||||
msg = msg.replace(/^Line\ [0-9]*\:\ /, '');
|
||||
msg = fname + ':' + error.lineNumber + ': ' + msg;
|
||||
console.log(msg);
|
||||
++count;
|
||||
});
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
++count;
|
||||
if (options.format === 'junit') {
|
||||
console.log('<testsuite name="' + fname + '" errors="1" failures="0" tests="1" ' +
|
||||
' time="' + Math.round((Date.now() - timestamp) / 1000) + '">');
|
||||
console.log(' <testcase name="' + e.message + '" ' + ' time="0">');
|
||||
console.log(' <error type="ParseError" message="' + e.message + '">' +
|
||||
e.message + '(' + fname + ((e.lineNumber) ? ':' + e.lineNumber : '') +
|
||||
')</error>');
|
||||
console.log(' </testcase>');
|
||||
console.log('</testsuite>');
|
||||
} else {
|
||||
console.log('Error: ' + e.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (options.format === 'junit') {
|
||||
console.log('</testsuites>');
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (count === 0 && typeof phantom === 'object') {
|
||||
process.exit(0);
|
||||
}
|
||||
5533
build/node_modules/hydrolysis/node_modules/espree/espree.js
generated
vendored
Normal file
5533
build/node_modules/hydrolysis/node_modules/espree/espree.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
964
build/node_modules/hydrolysis/node_modules/espree/lib/ast-node-factory.js
generated
vendored
Normal file
964
build/node_modules/hydrolysis/node_modules/espree/lib/ast-node-factory.js
generated
vendored
Normal file
@@ -0,0 +1,964 @@
|
||||
/**
|
||||
* @fileoverview A factory for creating AST nodes
|
||||
* @author Fred K. Schott
|
||||
* @copyright 2014 Fred K. Schott. All rights reserved.
|
||||
* @copyright 2011-2013 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var astNodeTypes = require("./ast-node-types");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* Create an Array Expression ASTNode out of an array of elements
|
||||
* @param {ASTNode[]} elements An array of ASTNode elements
|
||||
* @returns {ASTNode} An ASTNode representing the entire array expression
|
||||
*/
|
||||
createArrayExpression: function(elements) {
|
||||
return {
|
||||
type: astNodeTypes.ArrayExpression,
|
||||
elements: elements
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an Arrow Function Expression ASTNode
|
||||
* @param {ASTNode} params The function arguments
|
||||
* @param {ASTNode} body The function body
|
||||
* @param {boolean} expression True if the arrow function is created via an expression.
|
||||
* Always false for declarations, but kept here to be in sync with
|
||||
* FunctionExpression objects.
|
||||
* @returns {ASTNode} An ASTNode representing the entire arrow function expression
|
||||
*/
|
||||
createArrowFunctionExpression: function (params, body, expression) {
|
||||
return {
|
||||
type: astNodeTypes.ArrowFunctionExpression,
|
||||
id: null,
|
||||
params: params,
|
||||
body: body,
|
||||
generator: false,
|
||||
expression: expression
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an assignment expression
|
||||
* @param {ASTNode} operator The assignment operator
|
||||
* @param {ASTNode} left The left operand
|
||||
* @param {ASTNode} right The right operand
|
||||
* @returns {ASTNode} An ASTNode representing the entire assignment expression
|
||||
*/
|
||||
createAssignmentExpression: function(operator, left, right) {
|
||||
return {
|
||||
type: astNodeTypes.AssignmentExpression,
|
||||
operator: operator,
|
||||
left: left,
|
||||
right: right
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an assignment pattern (default parameters)
|
||||
* @param {ASTNode} left The left operand
|
||||
* @param {ASTNode} right The right operand
|
||||
* @returns {ASTNode} An ASTNode representing the entire assignment pattern
|
||||
*/
|
||||
createAssignmentPattern: function(left, right) {
|
||||
return {
|
||||
type: astNodeTypes.AssignmentPattern,
|
||||
left: left,
|
||||
right: right
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a binary expression
|
||||
* @param {ASTNode} operator The assignment operator
|
||||
* @param {ASTNode} left The left operand
|
||||
* @param {ASTNode} right The right operand
|
||||
* @returns {ASTNode} An ASTNode representing the entire binary expression
|
||||
*/
|
||||
createBinaryExpression: function(operator, left, right) {
|
||||
var type = (operator === "||" || operator === "&&") ? astNodeTypes.LogicalExpression :
|
||||
astNodeTypes.BinaryExpression;
|
||||
return {
|
||||
type: type,
|
||||
operator: operator,
|
||||
left: left,
|
||||
right: right
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a block statement
|
||||
* @param {ASTNode} body The block statement body
|
||||
* @returns {ASTNode} An ASTNode representing the entire block statement
|
||||
*/
|
||||
createBlockStatement: function(body) {
|
||||
return {
|
||||
type: astNodeTypes.BlockStatement,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a break statement
|
||||
* @param {ASTNode} label The break statement label
|
||||
* @returns {ASTNode} An ASTNode representing the break statement
|
||||
*/
|
||||
createBreakStatement: function(label) {
|
||||
return {
|
||||
type: astNodeTypes.BreakStatement,
|
||||
label: label
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a call expression
|
||||
* @param {ASTNode} callee The function being called
|
||||
* @param {ASTNode[]} args An array of ASTNodes representing the function call arguments
|
||||
* @returns {ASTNode} An ASTNode representing the entire call expression
|
||||
*/
|
||||
createCallExpression: function(callee, args) {
|
||||
return {
|
||||
type: astNodeTypes.CallExpression,
|
||||
callee: callee,
|
||||
"arguments": args
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a catch clause/block
|
||||
* @param {ASTNode} param Any catch clause exeption/conditional parameter information
|
||||
* @param {ASTNode} body The catch block body
|
||||
* @returns {ASTNode} An ASTNode representing the entire catch clause
|
||||
*/
|
||||
createCatchClause: function(param, body) {
|
||||
return {
|
||||
type: astNodeTypes.CatchClause,
|
||||
param: param,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates an ASTNode representation of a class body.
|
||||
* @param {ASTNode} body The node representing the body of the class.
|
||||
* @returns {ASTNode} An ASTNode representing the class body.
|
||||
*/
|
||||
createClassBody: function(body) {
|
||||
return {
|
||||
type: astNodeTypes.ClassBody,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
createClassExpression: function(id, superClass, body) {
|
||||
return {
|
||||
type: astNodeTypes.ClassExpression,
|
||||
id: id,
|
||||
superClass: superClass,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
createClassDeclaration: function(id, superClass, body) {
|
||||
return {
|
||||
type: astNodeTypes.ClassDeclaration,
|
||||
id: id,
|
||||
superClass: superClass,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
createMethodDefinition: function(propertyType, kind, key, value, computed) {
|
||||
return {
|
||||
type: astNodeTypes.MethodDefinition,
|
||||
key: key,
|
||||
value: value,
|
||||
kind: kind,
|
||||
"static": propertyType === "static",
|
||||
computed: computed
|
||||
};
|
||||
},
|
||||
|
||||
createMetaProperty: function(meta, property) {
|
||||
return {
|
||||
type: astNodeTypes.MetaProperty,
|
||||
meta: meta,
|
||||
property: property
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a conditional expression
|
||||
* @param {ASTNode} test The conditional to evaluate
|
||||
* @param {ASTNode} consequent The code to be run if the test returns true
|
||||
* @param {ASTNode} alternate The code to be run if the test returns false
|
||||
* @returns {ASTNode} An ASTNode representing the entire conditional expression
|
||||
*/
|
||||
createConditionalExpression: function(test, consequent, alternate) {
|
||||
return {
|
||||
type: astNodeTypes.ConditionalExpression,
|
||||
test: test,
|
||||
consequent: consequent,
|
||||
alternate: alternate
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a continue statement
|
||||
* @param {?ASTNode} label The optional continue label (null if not set)
|
||||
* @returns {ASTNode} An ASTNode representing the continue statement
|
||||
*/
|
||||
createContinueStatement: function(label) {
|
||||
return {
|
||||
type: astNodeTypes.ContinueStatement,
|
||||
label: label
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a debugger statement
|
||||
* @returns {ASTNode} An ASTNode representing the debugger statement
|
||||
*/
|
||||
createDebuggerStatement: function() {
|
||||
return {
|
||||
type: astNodeTypes.DebuggerStatement
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an empty statement
|
||||
* @returns {ASTNode} An ASTNode representing an empty statement
|
||||
*/
|
||||
createEmptyStatement: function() {
|
||||
return {
|
||||
type: astNodeTypes.EmptyStatement
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an expression statement
|
||||
* @param {ASTNode} expression The expression
|
||||
* @returns {ASTNode} An ASTNode representing an expression statement
|
||||
*/
|
||||
createExpressionStatement: function(expression) {
|
||||
return {
|
||||
type: astNodeTypes.ExpressionStatement,
|
||||
expression: expression
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a while statement
|
||||
* @param {ASTNode} test The while conditional
|
||||
* @param {ASTNode} body The while loop body
|
||||
* @returns {ASTNode} An ASTNode representing a while statement
|
||||
*/
|
||||
createWhileStatement: function(test, body) {
|
||||
return {
|
||||
type: astNodeTypes.WhileStatement,
|
||||
test: test,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a do..while statement
|
||||
* @param {ASTNode} test The do..while conditional
|
||||
* @param {ASTNode} body The do..while loop body
|
||||
* @returns {ASTNode} An ASTNode representing a do..while statement
|
||||
*/
|
||||
createDoWhileStatement: function(test, body) {
|
||||
return {
|
||||
type: astNodeTypes.DoWhileStatement,
|
||||
body: body,
|
||||
test: test
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a for statement
|
||||
* @param {ASTNode} init The initialization expression
|
||||
* @param {ASTNode} test The conditional test expression
|
||||
* @param {ASTNode} update The update expression
|
||||
* @param {ASTNode} body The statement body
|
||||
* @returns {ASTNode} An ASTNode representing a for statement
|
||||
*/
|
||||
createForStatement: function(init, test, update, body) {
|
||||
return {
|
||||
type: astNodeTypes.ForStatement,
|
||||
init: init,
|
||||
test: test,
|
||||
update: update,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a for..in statement
|
||||
* @param {ASTNode} left The left-side variable for the property name
|
||||
* @param {ASTNode} right The right-side object
|
||||
* @param {ASTNode} body The statement body
|
||||
* @returns {ASTNode} An ASTNode representing a for..in statement
|
||||
*/
|
||||
createForInStatement: function(left, right, body) {
|
||||
return {
|
||||
type: astNodeTypes.ForInStatement,
|
||||
left: left,
|
||||
right: right,
|
||||
body: body,
|
||||
each: false
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a for..of statement
|
||||
* @param {ASTNode} left The left-side variable for the property value
|
||||
* @param {ASTNode} right The right-side object
|
||||
* @param {ASTNode} body The statement body
|
||||
* @returns {ASTNode} An ASTNode representing a for..of statement
|
||||
*/
|
||||
createForOfStatement: function(left, right, body) {
|
||||
return {
|
||||
type: astNodeTypes.ForOfStatement,
|
||||
left: left,
|
||||
right: right,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a function declaration
|
||||
* @param {ASTNode} id The function name
|
||||
* @param {ASTNode} params The function arguments
|
||||
* @param {ASTNode} body The function body
|
||||
* @param {boolean} generator True if the function is a generator, false if not.
|
||||
* @param {boolean} expression True if the function is created via an expression.
|
||||
* Always false for declarations, but kept here to be in sync with
|
||||
* FunctionExpression objects.
|
||||
* @returns {ASTNode} An ASTNode representing a function declaration
|
||||
*/
|
||||
createFunctionDeclaration: function (id, params, body, generator, expression) {
|
||||
return {
|
||||
type: astNodeTypes.FunctionDeclaration,
|
||||
id: id,
|
||||
params: params || [],
|
||||
body: body,
|
||||
generator: !!generator,
|
||||
expression: !!expression
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a function expression
|
||||
* @param {ASTNode} id The function name
|
||||
* @param {ASTNode} params The function arguments
|
||||
* @param {ASTNode} body The function body
|
||||
* @param {boolean} generator True if the function is a generator, false if not.
|
||||
* @param {boolean} expression True if the function is created via an expression.
|
||||
* @returns {ASTNode} An ASTNode representing a function declaration
|
||||
*/
|
||||
createFunctionExpression: function (id, params, body, generator, expression) {
|
||||
return {
|
||||
type: astNodeTypes.FunctionExpression,
|
||||
id: id,
|
||||
params: params || [],
|
||||
body: body,
|
||||
generator: !!generator,
|
||||
expression: !!expression
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an identifier
|
||||
* @param {ASTNode} name The identifier name
|
||||
* @returns {ASTNode} An ASTNode representing an identifier
|
||||
*/
|
||||
createIdentifier: function(name) {
|
||||
return {
|
||||
type: astNodeTypes.Identifier,
|
||||
name: name
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an if statement
|
||||
* @param {ASTNode} test The if conditional expression
|
||||
* @param {ASTNode} consequent The consequent if statement to run
|
||||
* @param {ASTNode} alternate the "else" alternate statement
|
||||
* @returns {ASTNode} An ASTNode representing an if statement
|
||||
*/
|
||||
createIfStatement: function(test, consequent, alternate) {
|
||||
return {
|
||||
type: astNodeTypes.IfStatement,
|
||||
test: test,
|
||||
consequent: consequent,
|
||||
alternate: alternate
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a labeled statement
|
||||
* @param {ASTNode} label The statement label
|
||||
* @param {ASTNode} body The labeled statement body
|
||||
* @returns {ASTNode} An ASTNode representing a labeled statement
|
||||
*/
|
||||
createLabeledStatement: function(label, body) {
|
||||
return {
|
||||
type: astNodeTypes.LabeledStatement,
|
||||
label: label,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode literal from the source code
|
||||
* @param {ASTNode} token The ASTNode token
|
||||
* @param {string} source The source code to get the literal from
|
||||
* @returns {ASTNode} An ASTNode representing the new literal
|
||||
*/
|
||||
createLiteralFromSource: function(token, source) {
|
||||
var node = {
|
||||
type: astNodeTypes.Literal,
|
||||
value: token.value,
|
||||
raw: source.slice(token.range[0], token.range[1])
|
||||
};
|
||||
|
||||
// regular expressions have regex properties
|
||||
if (token.regex) {
|
||||
node.regex = token.regex;
|
||||
}
|
||||
|
||||
return node;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode template element
|
||||
* @param {Object} value Data on the element value
|
||||
* @param {string} value.raw The raw template string
|
||||
* @param {string} value.cooked The processed template string
|
||||
* @param {boolean} tail True if this is the final element in a template string
|
||||
* @returns {ASTNode} An ASTNode representing the template string element
|
||||
*/
|
||||
createTemplateElement: function(value, tail) {
|
||||
return {
|
||||
type: astNodeTypes.TemplateElement,
|
||||
value: value,
|
||||
tail: tail
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode template literal
|
||||
* @param {ASTNode[]} quasis An array of the template string elements
|
||||
* @param {ASTNode[]} expressions An array of the template string expressions
|
||||
* @returns {ASTNode} An ASTNode representing the template string
|
||||
*/
|
||||
createTemplateLiteral: function(quasis, expressions) {
|
||||
return {
|
||||
type: astNodeTypes.TemplateLiteral,
|
||||
quasis: quasis,
|
||||
expressions: expressions
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a spread element
|
||||
* @param {ASTNode} argument The array being spread
|
||||
* @returns {ASTNode} An ASTNode representing a spread element
|
||||
*/
|
||||
createSpreadElement: function(argument) {
|
||||
return {
|
||||
type: astNodeTypes.SpreadElement,
|
||||
argument: argument
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an experimental rest property
|
||||
* @param {ASTNode} argument The identifier being rested
|
||||
* @returns {ASTNode} An ASTNode representing a rest element
|
||||
*/
|
||||
createExperimentalRestProperty: function(argument) {
|
||||
return {
|
||||
type: astNodeTypes.ExperimentalRestProperty,
|
||||
argument: argument
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an experimental spread property
|
||||
* @param {ASTNode} argument The identifier being spread
|
||||
* @returns {ASTNode} An ASTNode representing a spread element
|
||||
*/
|
||||
createExperimentalSpreadProperty: function(argument) {
|
||||
return {
|
||||
type: astNodeTypes.ExperimentalSpreadProperty,
|
||||
argument: argument
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode tagged template expression
|
||||
* @param {ASTNode} tag The tag expression
|
||||
* @param {ASTNode} quasi A TemplateLiteral ASTNode representing
|
||||
* the template string itself.
|
||||
* @returns {ASTNode} An ASTNode representing the tagged template
|
||||
*/
|
||||
createTaggedTemplateExpression: function(tag, quasi) {
|
||||
return {
|
||||
type: astNodeTypes.TaggedTemplateExpression,
|
||||
tag: tag,
|
||||
quasi: quasi
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a member expression
|
||||
* @param {string} accessor The member access method (bracket or period)
|
||||
* @param {ASTNode} object The object being referenced
|
||||
* @param {ASTNode} property The object-property being referenced
|
||||
* @returns {ASTNode} An ASTNode representing a member expression
|
||||
*/
|
||||
createMemberExpression: function(accessor, object, property) {
|
||||
return {
|
||||
type: astNodeTypes.MemberExpression,
|
||||
computed: accessor === "[",
|
||||
object: object,
|
||||
property: property
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a new expression
|
||||
* @param {ASTNode} callee The constructor for the new object type
|
||||
* @param {ASTNode} args The arguments passed to the constructor
|
||||
* @returns {ASTNode} An ASTNode representing a new expression
|
||||
*/
|
||||
createNewExpression: function(callee, args) {
|
||||
return {
|
||||
type: astNodeTypes.NewExpression,
|
||||
callee: callee,
|
||||
"arguments": args
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a new object expression
|
||||
* @param {ASTNode[]} properties An array of ASTNodes that represent all object
|
||||
* properties and associated values
|
||||
* @returns {ASTNode} An ASTNode representing a new object expression
|
||||
*/
|
||||
createObjectExpression: function(properties) {
|
||||
return {
|
||||
type: astNodeTypes.ObjectExpression,
|
||||
properties: properties
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a postfix expression
|
||||
* @param {string} operator The postfix operator ("++", "--", etc.)
|
||||
* @param {ASTNode} argument The operator argument
|
||||
* @returns {ASTNode} An ASTNode representing a postfix expression
|
||||
*/
|
||||
createPostfixExpression: function(operator, argument) {
|
||||
return {
|
||||
type: astNodeTypes.UpdateExpression,
|
||||
operator: operator,
|
||||
argument: argument,
|
||||
prefix: false
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an entire program
|
||||
* @param {ASTNode} body The program body
|
||||
* @param {string} sourceType Either "module" or "script".
|
||||
* @returns {ASTNode} An ASTNode representing an entire program
|
||||
*/
|
||||
createProgram: function(body, sourceType) {
|
||||
return {
|
||||
type: astNodeTypes.Program,
|
||||
body: body,
|
||||
sourceType: sourceType
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of an object property
|
||||
* @param {string} kind The type of property represented ("get", "set", etc.)
|
||||
* @param {ASTNode} key The property key
|
||||
* @param {ASTNode} value The new property value
|
||||
* @param {boolean} method True if the property is also a method (value is a function)
|
||||
* @param {boolean} shorthand True if the property is shorthand
|
||||
* @param {boolean} computed True if the property value has been computed
|
||||
* @returns {ASTNode} An ASTNode representing an object property
|
||||
*/
|
||||
createProperty: function(kind, key, value, method, shorthand, computed) {
|
||||
return {
|
||||
type: astNodeTypes.Property,
|
||||
key: key,
|
||||
value: value,
|
||||
kind: kind,
|
||||
method: method,
|
||||
shorthand: shorthand,
|
||||
computed: computed
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a rest element
|
||||
* @param {ASTNode} argument The rest argument
|
||||
* @returns {ASTNode} An ASTNode representing a rest element
|
||||
*/
|
||||
createRestElement: function (argument) {
|
||||
return {
|
||||
type: astNodeTypes.RestElement,
|
||||
argument: argument
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a return statement
|
||||
* @param {?ASTNode} argument The return argument, null if no argument is provided
|
||||
* @returns {ASTNode} An ASTNode representing a return statement
|
||||
*/
|
||||
createReturnStatement: function(argument) {
|
||||
return {
|
||||
type: astNodeTypes.ReturnStatement,
|
||||
argument: argument
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a sequence of expressions
|
||||
* @param {ASTNode[]} expressions An array containing each expression, in order
|
||||
* @returns {ASTNode} An ASTNode representing a sequence of expressions
|
||||
*/
|
||||
createSequenceExpression: function(expressions) {
|
||||
return {
|
||||
type: astNodeTypes.SequenceExpression,
|
||||
expressions: expressions
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of super
|
||||
* @returns {ASTNode} An ASTNode representing super
|
||||
*/
|
||||
createSuper: function() {
|
||||
return {
|
||||
type: astNodeTypes.Super
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a switch case statement
|
||||
* @param {ASTNode} test The case value to test against the switch value
|
||||
* @param {ASTNode} consequent The consequent case statement
|
||||
* @returns {ASTNode} An ASTNode representing a switch case
|
||||
*/
|
||||
createSwitchCase: function(test, consequent) {
|
||||
return {
|
||||
type: astNodeTypes.SwitchCase,
|
||||
test: test,
|
||||
consequent: consequent
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a switch statement
|
||||
* @param {ASTNode} discriminant An expression to test against each case value
|
||||
* @param {ASTNode[]} cases An array of switch case statements
|
||||
* @returns {ASTNode} An ASTNode representing a switch statement
|
||||
*/
|
||||
createSwitchStatement: function(discriminant, cases) {
|
||||
return {
|
||||
type: astNodeTypes.SwitchStatement,
|
||||
discriminant: discriminant,
|
||||
cases: cases
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a this statement
|
||||
* @returns {ASTNode} An ASTNode representing a this statement
|
||||
*/
|
||||
createThisExpression: function() {
|
||||
return {
|
||||
type: astNodeTypes.ThisExpression
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a throw statement
|
||||
* @param {ASTNode} argument The argument to throw
|
||||
* @returns {ASTNode} An ASTNode representing a throw statement
|
||||
*/
|
||||
createThrowStatement: function(argument) {
|
||||
return {
|
||||
type: astNodeTypes.ThrowStatement,
|
||||
argument: argument
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a try statement
|
||||
* @param {ASTNode} block The try block
|
||||
* @param {ASTNode} handler A catch handler
|
||||
* @param {?ASTNode} finalizer The final code block to run after the try/catch has run
|
||||
* @returns {ASTNode} An ASTNode representing a try statement
|
||||
*/
|
||||
createTryStatement: function(block, handler, finalizer) {
|
||||
return {
|
||||
type: astNodeTypes.TryStatement,
|
||||
block: block,
|
||||
handler: handler,
|
||||
finalizer: finalizer
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a unary expression
|
||||
* @param {string} operator The unary operator
|
||||
* @param {ASTNode} argument The unary operand
|
||||
* @returns {ASTNode} An ASTNode representing a unary expression
|
||||
*/
|
||||
createUnaryExpression: function(operator, argument) {
|
||||
if (operator === "++" || operator === "--") {
|
||||
return {
|
||||
type: astNodeTypes.UpdateExpression,
|
||||
operator: operator,
|
||||
argument: argument,
|
||||
prefix: true
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: astNodeTypes.UnaryExpression,
|
||||
operator: operator,
|
||||
argument: argument,
|
||||
prefix: true
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a variable declaration
|
||||
* @param {ASTNode[]} declarations An array of variable declarations
|
||||
* @param {string} kind The kind of variable created ("var", "let", etc.)
|
||||
* @returns {ASTNode} An ASTNode representing a variable declaration
|
||||
*/
|
||||
createVariableDeclaration: function(declarations, kind) {
|
||||
return {
|
||||
type: astNodeTypes.VariableDeclaration,
|
||||
declarations: declarations,
|
||||
kind: kind
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a variable declarator
|
||||
* @param {ASTNode} id The variable ID
|
||||
* @param {ASTNode} init The variable's initial value
|
||||
* @returns {ASTNode} An ASTNode representing a variable declarator
|
||||
*/
|
||||
createVariableDeclarator: function(id, init) {
|
||||
return {
|
||||
type: astNodeTypes.VariableDeclarator,
|
||||
id: id,
|
||||
init: init
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an ASTNode representation of a with statement
|
||||
* @param {ASTNode} object The with statement object expression
|
||||
* @param {ASTNode} body The with statement body
|
||||
* @returns {ASTNode} An ASTNode representing a with statement
|
||||
*/
|
||||
createWithStatement: function(object, body) {
|
||||
return {
|
||||
type: astNodeTypes.WithStatement,
|
||||
object: object,
|
||||
body: body
|
||||
};
|
||||
},
|
||||
|
||||
createYieldExpression: function(argument, delegate) {
|
||||
return {
|
||||
type: astNodeTypes.YieldExpression,
|
||||
argument: argument || null,
|
||||
delegate: delegate
|
||||
};
|
||||
},
|
||||
|
||||
createJSXAttribute: function(name, value) {
|
||||
return {
|
||||
type: astNodeTypes.JSXAttribute,
|
||||
name: name,
|
||||
value: value || null
|
||||
};
|
||||
},
|
||||
|
||||
createJSXSpreadAttribute: function(argument) {
|
||||
return {
|
||||
type: astNodeTypes.JSXSpreadAttribute,
|
||||
argument: argument
|
||||
};
|
||||
},
|
||||
|
||||
createJSXIdentifier: function(name) {
|
||||
return {
|
||||
type: astNodeTypes.JSXIdentifier,
|
||||
name: name
|
||||
};
|
||||
},
|
||||
|
||||
createJSXNamespacedName: function(namespace, name) {
|
||||
return {
|
||||
type: astNodeTypes.JSXNamespacedName,
|
||||
namespace: namespace,
|
||||
name: name
|
||||
};
|
||||
},
|
||||
|
||||
createJSXMemberExpression: function(object, property) {
|
||||
return {
|
||||
type: astNodeTypes.JSXMemberExpression,
|
||||
object: object,
|
||||
property: property
|
||||
};
|
||||
},
|
||||
|
||||
createJSXElement: function(openingElement, closingElement, children) {
|
||||
return {
|
||||
type: astNodeTypes.JSXElement,
|
||||
openingElement: openingElement,
|
||||
closingElement: closingElement,
|
||||
children: children
|
||||
};
|
||||
},
|
||||
|
||||
createJSXEmptyExpression: function() {
|
||||
return {
|
||||
type: astNodeTypes.JSXEmptyExpression
|
||||
};
|
||||
},
|
||||
|
||||
createJSXExpressionContainer: function(expression) {
|
||||
return {
|
||||
type: astNodeTypes.JSXExpressionContainer,
|
||||
expression: expression
|
||||
};
|
||||
},
|
||||
|
||||
createJSXOpeningElement: function(name, attributes, selfClosing) {
|
||||
return {
|
||||
type: astNodeTypes.JSXOpeningElement,
|
||||
name: name,
|
||||
selfClosing: selfClosing,
|
||||
attributes: attributes
|
||||
};
|
||||
},
|
||||
|
||||
createJSXClosingElement: function(name) {
|
||||
return {
|
||||
type: astNodeTypes.JSXClosingElement,
|
||||
name: name
|
||||
};
|
||||
},
|
||||
|
||||
createExportSpecifier: function(local, exported) {
|
||||
return {
|
||||
type: astNodeTypes.ExportSpecifier,
|
||||
exported: exported || local,
|
||||
local: local
|
||||
};
|
||||
},
|
||||
|
||||
createImportDefaultSpecifier: function(local) {
|
||||
return {
|
||||
type: astNodeTypes.ImportDefaultSpecifier,
|
||||
local: local
|
||||
};
|
||||
},
|
||||
|
||||
createImportNamespaceSpecifier: function(local) {
|
||||
return {
|
||||
type: astNodeTypes.ImportNamespaceSpecifier,
|
||||
local: local
|
||||
};
|
||||
},
|
||||
|
||||
createExportNamedDeclaration: function(declaration, specifiers, source) {
|
||||
return {
|
||||
type: astNodeTypes.ExportNamedDeclaration,
|
||||
declaration: declaration,
|
||||
specifiers: specifiers,
|
||||
source: source
|
||||
};
|
||||
},
|
||||
|
||||
createExportDefaultDeclaration: function(declaration) {
|
||||
return {
|
||||
type: astNodeTypes.ExportDefaultDeclaration,
|
||||
declaration: declaration
|
||||
};
|
||||
},
|
||||
|
||||
createExportAllDeclaration: function(source) {
|
||||
return {
|
||||
type: astNodeTypes.ExportAllDeclaration,
|
||||
source: source
|
||||
};
|
||||
},
|
||||
|
||||
createImportSpecifier: function(local, imported) {
|
||||
return {
|
||||
type: astNodeTypes.ImportSpecifier,
|
||||
local: local || imported,
|
||||
imported: imported
|
||||
};
|
||||
},
|
||||
|
||||
createImportDeclaration: function(specifiers, source) {
|
||||
return {
|
||||
type: astNodeTypes.ImportDeclaration,
|
||||
specifiers: specifiers,
|
||||
source: source
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
119
build/node_modules/hydrolysis/node_modules/espree/lib/ast-node-types.js
generated
vendored
Normal file
119
build/node_modules/hydrolysis/node_modules/espree/lib/ast-node-types.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* @fileoverview The AST node types produced by the parser.
|
||||
* @author Nicholas C. Zakas
|
||||
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
||||
* @copyright 2011-2013 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// None!
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
AssignmentExpression: "AssignmentExpression",
|
||||
AssignmentPattern: "AssignmentPattern",
|
||||
ArrayExpression: "ArrayExpression",
|
||||
ArrayPattern: "ArrayPattern",
|
||||
ArrowFunctionExpression: "ArrowFunctionExpression",
|
||||
BlockStatement: "BlockStatement",
|
||||
BinaryExpression: "BinaryExpression",
|
||||
BreakStatement: "BreakStatement",
|
||||
CallExpression: "CallExpression",
|
||||
CatchClause: "CatchClause",
|
||||
ClassBody: "ClassBody",
|
||||
ClassDeclaration: "ClassDeclaration",
|
||||
ClassExpression: "ClassExpression",
|
||||
ConditionalExpression: "ConditionalExpression",
|
||||
ContinueStatement: "ContinueStatement",
|
||||
DoWhileStatement: "DoWhileStatement",
|
||||
DebuggerStatement: "DebuggerStatement",
|
||||
EmptyStatement: "EmptyStatement",
|
||||
ExperimentalRestProperty: "ExperimentalRestProperty",
|
||||
ExperimentalSpreadProperty: "ExperimentalSpreadProperty",
|
||||
ExpressionStatement: "ExpressionStatement",
|
||||
ForStatement: "ForStatement",
|
||||
ForInStatement: "ForInStatement",
|
||||
ForOfStatement: "ForOfStatement",
|
||||
FunctionDeclaration: "FunctionDeclaration",
|
||||
FunctionExpression: "FunctionExpression",
|
||||
Identifier: "Identifier",
|
||||
IfStatement: "IfStatement",
|
||||
Literal: "Literal",
|
||||
LabeledStatement: "LabeledStatement",
|
||||
LogicalExpression: "LogicalExpression",
|
||||
MemberExpression: "MemberExpression",
|
||||
MetaProperty: "MetaProperty",
|
||||
MethodDefinition: "MethodDefinition",
|
||||
NewExpression: "NewExpression",
|
||||
ObjectExpression: "ObjectExpression",
|
||||
ObjectPattern: "ObjectPattern",
|
||||
Program: "Program",
|
||||
Property: "Property",
|
||||
RestElement: "RestElement",
|
||||
ReturnStatement: "ReturnStatement",
|
||||
SequenceExpression: "SequenceExpression",
|
||||
SpreadElement: "SpreadElement",
|
||||
Super: "Super",
|
||||
SwitchCase: "SwitchCase",
|
||||
SwitchStatement: "SwitchStatement",
|
||||
TaggedTemplateExpression: "TaggedTemplateExpression",
|
||||
TemplateElement: "TemplateElement",
|
||||
TemplateLiteral: "TemplateLiteral",
|
||||
ThisExpression: "ThisExpression",
|
||||
ThrowStatement: "ThrowStatement",
|
||||
TryStatement: "TryStatement",
|
||||
UnaryExpression: "UnaryExpression",
|
||||
UpdateExpression: "UpdateExpression",
|
||||
VariableDeclaration: "VariableDeclaration",
|
||||
VariableDeclarator: "VariableDeclarator",
|
||||
WhileStatement: "WhileStatement",
|
||||
WithStatement: "WithStatement",
|
||||
YieldExpression: "YieldExpression",
|
||||
JSXIdentifier: "JSXIdentifier",
|
||||
JSXNamespacedName: "JSXNamespacedName",
|
||||
JSXMemberExpression: "JSXMemberExpression",
|
||||
JSXEmptyExpression: "JSXEmptyExpression",
|
||||
JSXExpressionContainer: "JSXExpressionContainer",
|
||||
JSXElement: "JSXElement",
|
||||
JSXClosingElement: "JSXClosingElement",
|
||||
JSXOpeningElement: "JSXOpeningElement",
|
||||
JSXAttribute: "JSXAttribute",
|
||||
JSXSpreadAttribute: "JSXSpreadAttribute",
|
||||
JSXText: "JSXText",
|
||||
ExportDefaultDeclaration: "ExportDefaultDeclaration",
|
||||
ExportNamedDeclaration: "ExportNamedDeclaration",
|
||||
ExportAllDeclaration: "ExportAllDeclaration",
|
||||
ExportSpecifier: "ExportSpecifier",
|
||||
ImportDeclaration: "ImportDeclaration",
|
||||
ImportSpecifier: "ImportSpecifier",
|
||||
ImportDefaultSpecifier: "ImportDefaultSpecifier",
|
||||
ImportNamespaceSpecifier: "ImportNamespaceSpecifier"
|
||||
};
|
||||
183
build/node_modules/hydrolysis/node_modules/espree/lib/comment-attachment.js
generated
vendored
Normal file
183
build/node_modules/hydrolysis/node_modules/espree/lib/comment-attachment.js
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* @fileoverview Attaches comments to the AST.
|
||||
* @author Nicholas C. Zakas
|
||||
* @copyright 2015 Nicholas C. Zakas. All rights reserved.
|
||||
* @copyright 2011-2013 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var astNodeTypes = require("./ast-node-types");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Private
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var extra = {
|
||||
trailingComments: [],
|
||||
leadingComments: [],
|
||||
bottomRightStack: []
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
|
||||
reset: function() {
|
||||
extra.trailingComments = [];
|
||||
extra.leadingComments = [];
|
||||
extra.bottomRightStack = [];
|
||||
},
|
||||
|
||||
addComment: function(comment) {
|
||||
extra.trailingComments.push(comment);
|
||||
extra.leadingComments.push(comment);
|
||||
},
|
||||
|
||||
processComment: function(node) {
|
||||
var lastChild,
|
||||
trailingComments,
|
||||
i;
|
||||
|
||||
if (node.type === astNodeTypes.Program) {
|
||||
if (node.body.length > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (extra.trailingComments.length > 0) {
|
||||
|
||||
/*
|
||||
* If the first comment in trailingComments comes after the
|
||||
* current node, then we're good - all comments in the array will
|
||||
* come after the node and so it's safe to add then as official
|
||||
* trailingComments.
|
||||
*/
|
||||
if (extra.trailingComments[0].range[0] >= node.range[1]) {
|
||||
trailingComments = extra.trailingComments;
|
||||
extra.trailingComments = [];
|
||||
} else {
|
||||
|
||||
/*
|
||||
* Otherwise, if the first comment doesn't come after the
|
||||
* current node, that means we have a mix of leading and trailing
|
||||
* comments in the array and that leadingComments contains the
|
||||
* same items as trailingComments. Reset trailingComments to
|
||||
* zero items and we'll handle this by evaluating leadingComments
|
||||
* later.
|
||||
*/
|
||||
extra.trailingComments.length = 0;
|
||||
}
|
||||
} else {
|
||||
if (extra.bottomRightStack.length > 0 &&
|
||||
extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments &&
|
||||
extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments[0].range[0] >= node.range[1]) {
|
||||
trailingComments = extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;
|
||||
delete extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;
|
||||
}
|
||||
}
|
||||
|
||||
// Eating the stack.
|
||||
while (extra.bottomRightStack.length > 0 && extra.bottomRightStack[extra.bottomRightStack.length - 1].range[0] >= node.range[0]) {
|
||||
lastChild = extra.bottomRightStack.pop();
|
||||
}
|
||||
|
||||
if (lastChild) {
|
||||
if (lastChild.leadingComments) {
|
||||
if (lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {
|
||||
node.leadingComments = lastChild.leadingComments;
|
||||
delete lastChild.leadingComments;
|
||||
} else {
|
||||
// A leading comment for an anonymous class had been stolen by its first MethodDefinition,
|
||||
// so this takes back the leading comment.
|
||||
// See Also: https://github.com/eslint/espree/issues/158
|
||||
for (i = lastChild.leadingComments.length - 2; i >= 0; --i) {
|
||||
if (lastChild.leadingComments[i].range[1] <= node.range[0]) {
|
||||
node.leadingComments = lastChild.leadingComments.splice(0, i + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (extra.leadingComments.length > 0) {
|
||||
|
||||
if (extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {
|
||||
node.leadingComments = extra.leadingComments;
|
||||
extra.leadingComments = [];
|
||||
} else {
|
||||
|
||||
// https://github.com/eslint/espree/issues/2
|
||||
|
||||
/*
|
||||
* In special cases, such as return (without a value) and
|
||||
* debugger, all comments will end up as leadingComments and
|
||||
* will otherwise be eliminated. This extra step runs when the
|
||||
* bottomRightStack is empty and there are comments left
|
||||
* in leadingComments.
|
||||
*
|
||||
* This loop figures out the stopping point between the actual
|
||||
* leading and trailing comments by finding the location of the
|
||||
* first comment that comes after the given node.
|
||||
*/
|
||||
for (i = 0; i < extra.leadingComments.length; i++) {
|
||||
if (extra.leadingComments[i].range[1] > node.range[0]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Split the array based on the location of the first comment
|
||||
* that comes after the node. Keep in mind that this could
|
||||
* result in an empty array, and if so, the array must be
|
||||
* deleted.
|
||||
*/
|
||||
node.leadingComments = extra.leadingComments.slice(0, i);
|
||||
if (node.leadingComments.length === 0) {
|
||||
delete node.leadingComments;
|
||||
}
|
||||
|
||||
/*
|
||||
* Similarly, trailing comments are attached later. The variable
|
||||
* must be reset to null if there are no trailing comments.
|
||||
*/
|
||||
trailingComments = extra.leadingComments.slice(i);
|
||||
if (trailingComments.length === 0) {
|
||||
trailingComments = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (trailingComments) {
|
||||
node.trailingComments = trailingComments;
|
||||
}
|
||||
|
||||
extra.bottomRightStack.push(node);
|
||||
}
|
||||
|
||||
};
|
||||
117
build/node_modules/hydrolysis/node_modules/espree/lib/features.js
generated
vendored
Normal file
117
build/node_modules/hydrolysis/node_modules/espree/lib/features.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* @fileoverview The list of feature flags supported by the parser and their default
|
||||
* settings.
|
||||
* @author Nicholas C. Zakas
|
||||
* @copyright 2015 Fred K. Schott. All rights reserved.
|
||||
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// None!
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
|
||||
// enable parsing of arrow functions
|
||||
arrowFunctions: false,
|
||||
|
||||
// enable parsing of let and const
|
||||
blockBindings: true,
|
||||
|
||||
// enable parsing of destructured arrays and objects
|
||||
destructuring: false,
|
||||
|
||||
// enable parsing of regex u flag
|
||||
regexUFlag: false,
|
||||
|
||||
// enable parsing of regex y flag
|
||||
regexYFlag: false,
|
||||
|
||||
// enable parsing of template strings
|
||||
templateStrings: false,
|
||||
|
||||
// enable parsing binary literals
|
||||
binaryLiterals: false,
|
||||
|
||||
// enable parsing ES6 octal literals
|
||||
octalLiterals: false,
|
||||
|
||||
// enable parsing unicode code point escape sequences
|
||||
unicodeCodePointEscapes: true,
|
||||
|
||||
// enable parsing of default parameters
|
||||
defaultParams: false,
|
||||
|
||||
// enable parsing of rest parameters
|
||||
restParams: false,
|
||||
|
||||
// enable parsing of for-of statements
|
||||
forOf: false,
|
||||
|
||||
// enable parsing computed object literal properties
|
||||
objectLiteralComputedProperties: false,
|
||||
|
||||
// enable parsing of shorthand object literal methods
|
||||
objectLiteralShorthandMethods: false,
|
||||
|
||||
// enable parsing of shorthand object literal properties
|
||||
objectLiteralShorthandProperties: false,
|
||||
|
||||
// Allow duplicate object literal properties (except '__proto__')
|
||||
objectLiteralDuplicateProperties: false,
|
||||
|
||||
// enable parsing of generators/yield
|
||||
generators: false,
|
||||
|
||||
// support the spread operator
|
||||
spread: false,
|
||||
|
||||
// enable super in functions
|
||||
superInFunctions: false,
|
||||
|
||||
// enable parsing of classes
|
||||
classes: false,
|
||||
|
||||
// enable parsing of new.target
|
||||
newTarget: false,
|
||||
|
||||
// enable parsing of modules
|
||||
modules: false,
|
||||
|
||||
// React JSX parsing
|
||||
jsx: false,
|
||||
|
||||
// allow return statement in global scope
|
||||
globalReturn: false,
|
||||
|
||||
// allow experimental object rest/spread
|
||||
experimentalObjectRestSpread: false
|
||||
};
|
||||
99
build/node_modules/hydrolysis/node_modules/espree/lib/messages.js
generated
vendored
Normal file
99
build/node_modules/hydrolysis/node_modules/espree/lib/messages.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* @fileoverview Error messages returned by the parser.
|
||||
* @author Nicholas C. Zakas
|
||||
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
||||
* @copyright 2011-2013 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// None!
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// error messages should be identical to V8 where possible
|
||||
module.exports = {
|
||||
UnexpectedToken: "Unexpected token %0",
|
||||
UnexpectedNumber: "Unexpected number",
|
||||
UnexpectedString: "Unexpected string",
|
||||
UnexpectedIdentifier: "Unexpected identifier",
|
||||
UnexpectedReserved: "Unexpected reserved word",
|
||||
UnexpectedTemplate: "Unexpected quasi %0",
|
||||
UnexpectedEOS: "Unexpected end of input",
|
||||
NewlineAfterThrow: "Illegal newline after throw",
|
||||
InvalidRegExp: "Invalid regular expression",
|
||||
InvalidRegExpFlag: "Invalid regular expression flag",
|
||||
UnterminatedRegExp: "Invalid regular expression: missing /",
|
||||
InvalidLHSInAssignment: "Invalid left-hand side in assignment",
|
||||
InvalidLHSInFormalsList: "Invalid left-hand side in formals list",
|
||||
InvalidLHSInForIn: "Invalid left-hand side in for-in",
|
||||
MultipleDefaultsInSwitch: "More than one default clause in switch statement",
|
||||
NoCatchOrFinally: "Missing catch or finally after try",
|
||||
NoUnintializedConst: "Const must be initialized",
|
||||
UnknownLabel: "Undefined label '%0'",
|
||||
Redeclaration: "%0 '%1' has already been declared",
|
||||
IllegalContinue: "Illegal continue statement",
|
||||
IllegalBreak: "Illegal break statement",
|
||||
IllegalReturn: "Illegal return statement",
|
||||
IllegalYield: "Illegal yield expression",
|
||||
IllegalSpread: "Illegal spread element",
|
||||
StrictModeWith: "Strict mode code may not include a with statement",
|
||||
StrictCatchVariable: "Catch variable may not be eval or arguments in strict mode",
|
||||
StrictVarName: "Variable name may not be eval or arguments in strict mode",
|
||||
StrictParamName: "Parameter name eval or arguments is not allowed in strict mode",
|
||||
StrictParamDupe: "Strict mode function may not have duplicate parameter names",
|
||||
TemplateOctalLiteral: "Octal literals are not allowed in template strings.",
|
||||
ParameterAfterRestParameter: "Rest parameter must be last formal parameter",
|
||||
DefaultRestParameter: "Rest parameter can not have a default value",
|
||||
ElementAfterSpreadElement: "Spread must be the final element of an element list",
|
||||
ObjectPatternAsRestParameter: "Invalid rest parameter",
|
||||
ObjectPatternAsSpread: "Invalid spread argument",
|
||||
StrictFunctionName: "Function name may not be eval or arguments in strict mode",
|
||||
StrictOctalLiteral: "Octal literals are not allowed in strict mode.",
|
||||
StrictDelete: "Delete of an unqualified identifier in strict mode.",
|
||||
StrictDuplicateProperty: "Duplicate data property in object literal not allowed in strict mode",
|
||||
DuplicatePrototypeProperty: "Duplicate '__proto__' property in object literal are not allowed",
|
||||
ConstructorSpecialMethod: "Class constructor may not be an accessor",
|
||||
DuplicateConstructor: "A class may only have one constructor",
|
||||
StaticPrototype: "Classes may not have static property named prototype",
|
||||
AccessorDataProperty: "Object literal may not have data and accessor property with the same name",
|
||||
AccessorGetSet: "Object literal may not have multiple get/set accessors with the same name",
|
||||
StrictLHSAssignment: "Assignment to eval or arguments is not allowed in strict mode",
|
||||
StrictLHSPostfix: "Postfix increment/decrement may not have eval or arguments operand in strict mode",
|
||||
StrictLHSPrefix: "Prefix increment/decrement may not have eval or arguments operand in strict mode",
|
||||
StrictReservedWord: "Use of future reserved word in strict mode",
|
||||
InvalidJSXAttributeValue: "JSX value should be either an expression or a quoted JSX text",
|
||||
ExpectedJSXClosingTag: "Expected corresponding JSX closing tag for %0",
|
||||
AdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag",
|
||||
MissingFromClause: "Missing from clause",
|
||||
NoAsAfterImportNamespace: "Missing as after import *",
|
||||
InvalidModuleSpecifier: "Invalid module specifier",
|
||||
IllegalImportDeclaration: "Illegal import declaration",
|
||||
IllegalExportDeclaration: "Illegal export declaration"
|
||||
};
|
||||
55
build/node_modules/hydrolysis/node_modules/espree/lib/string-map.js
generated
vendored
Normal file
55
build/node_modules/hydrolysis/node_modules/espree/lib/string-map.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @fileoverview A simple map that helps avoid collisions on the Object prototype.
|
||||
* @author Jamund Ferguson
|
||||
* @copyright 2015 Jamund Ferguson. All rights reserved.
|
||||
* @copyright 2011-2013 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
function StringMap() {
|
||||
this.$data = {};
|
||||
}
|
||||
|
||||
StringMap.prototype.get = function (key) {
|
||||
key = "$" + key;
|
||||
return this.$data[key];
|
||||
};
|
||||
|
||||
StringMap.prototype.set = function (key, value) {
|
||||
key = "$" + key;
|
||||
this.$data[key] = value;
|
||||
return this;
|
||||
};
|
||||
|
||||
StringMap.prototype.has = function (key) {
|
||||
key = "$" + key;
|
||||
return Object.prototype.hasOwnProperty.call(this.$data, key);
|
||||
};
|
||||
|
||||
StringMap.prototype.delete = function (key) {
|
||||
key = "$" + key;
|
||||
return delete this.$data[key];
|
||||
};
|
||||
|
||||
module.exports = StringMap;
|
||||
189
build/node_modules/hydrolysis/node_modules/espree/lib/syntax.js
generated
vendored
Normal file
189
build/node_modules/hydrolysis/node_modules/espree/lib/syntax.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
90
build/node_modules/hydrolysis/node_modules/espree/lib/token-info.js
generated
vendored
Normal file
90
build/node_modules/hydrolysis/node_modules/espree/lib/token-info.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* @fileoverview Contains token information.
|
||||
* @author Nicholas C. Zakas
|
||||
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
||||
* @copyright 2013 Thaddee Tyl <thaddee.tyl@gmail.com>
|
||||
* @copyright 2011-2013 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// None!
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Private
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var Token = {
|
||||
BooleanLiteral: 1,
|
||||
EOF: 2,
|
||||
Identifier: 3,
|
||||
Keyword: 4,
|
||||
NullLiteral: 5,
|
||||
NumericLiteral: 6,
|
||||
Punctuator: 7,
|
||||
StringLiteral: 8,
|
||||
RegularExpression: 9,
|
||||
Template: 10,
|
||||
JSXIdentifier: 11,
|
||||
JSXText: 12
|
||||
};
|
||||
|
||||
var TokenName = {};
|
||||
TokenName[Token.BooleanLiteral] = "Boolean";
|
||||
TokenName[Token.EOF] = "<end>";
|
||||
TokenName[Token.Identifier] = "Identifier";
|
||||
TokenName[Token.Keyword] = "Keyword";
|
||||
TokenName[Token.NullLiteral] = "Null";
|
||||
TokenName[Token.NumericLiteral] = "Numeric";
|
||||
TokenName[Token.Punctuator] = "Punctuator";
|
||||
TokenName[Token.StringLiteral] = "String";
|
||||
TokenName[Token.RegularExpression] = "RegularExpression";
|
||||
TokenName[Token.Template] = "Template";
|
||||
TokenName[Token.JSXIdentifier] = "JSXIdentifier";
|
||||
TokenName[Token.JSXText] = "JSXText";
|
||||
|
||||
// A function following one of those tokens is an expression.
|
||||
var FnExprTokens = ["(", "{", "[", "in", "typeof", "instanceof", "new",
|
||||
"return", "case", "delete", "throw", "void",
|
||||
// assignment operators
|
||||
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
|
||||
"&=", "|=", "^=", ",",
|
||||
// binary/unary operators
|
||||
"+", "-", "*", "/", "%", "++", "--", "<<", ">>", ">>>", "&",
|
||||
"|", "^", "!", "~", "&&", "||", "?", ":", "===", "==", ">=",
|
||||
"<=", "<", ">", "!=", "!=="];
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
Token: Token,
|
||||
TokenName: TokenName,
|
||||
FnExprTokens: FnExprTokens
|
||||
};
|
||||
293
build/node_modules/hydrolysis/node_modules/espree/lib/xhtml-entities.js
generated
vendored
Normal file
293
build/node_modules/hydrolysis/node_modules/espree/lib/xhtml-entities.js
generated
vendored
Normal file
@@ -0,0 +1,293 @@
|
||||
/**
|
||||
* @fileoverview The list of XHTML entities that are valid in JSX.
|
||||
* @author Nicholas C. Zakas
|
||||
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// None!
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
quot: "\u0022",
|
||||
amp: "&",
|
||||
apos: "\u0027",
|
||||
lt: "<",
|
||||
gt: ">",
|
||||
nbsp: "\u00A0",
|
||||
iexcl: "\u00A1",
|
||||
cent: "\u00A2",
|
||||
pound: "\u00A3",
|
||||
curren: "\u00A4",
|
||||
yen: "\u00A5",
|
||||
brvbar: "\u00A6",
|
||||
sect: "\u00A7",
|
||||
uml: "\u00A8",
|
||||
copy: "\u00A9",
|
||||
ordf: "\u00AA",
|
||||
laquo: "\u00AB",
|
||||
not: "\u00AC",
|
||||
shy: "\u00AD",
|
||||
reg: "\u00AE",
|
||||
macr: "\u00AF",
|
||||
deg: "\u00B0",
|
||||
plusmn: "\u00B1",
|
||||
sup2: "\u00B2",
|
||||
sup3: "\u00B3",
|
||||
acute: "\u00B4",
|
||||
micro: "\u00B5",
|
||||
para: "\u00B6",
|
||||
middot: "\u00B7",
|
||||
cedil: "\u00B8",
|
||||
sup1: "\u00B9",
|
||||
ordm: "\u00BA",
|
||||
raquo: "\u00BB",
|
||||
frac14: "\u00BC",
|
||||
frac12: "\u00BD",
|
||||
frac34: "\u00BE",
|
||||
iquest: "\u00BF",
|
||||
Agrave: "\u00C0",
|
||||
Aacute: "\u00C1",
|
||||
Acirc: "\u00C2",
|
||||
Atilde: "\u00C3",
|
||||
Auml: "\u00C4",
|
||||
Aring: "\u00C5",
|
||||
AElig: "\u00C6",
|
||||
Ccedil: "\u00C7",
|
||||
Egrave: "\u00C8",
|
||||
Eacute: "\u00C9",
|
||||
Ecirc: "\u00CA",
|
||||
Euml: "\u00CB",
|
||||
Igrave: "\u00CC",
|
||||
Iacute: "\u00CD",
|
||||
Icirc: "\u00CE",
|
||||
Iuml: "\u00CF",
|
||||
ETH: "\u00D0",
|
||||
Ntilde: "\u00D1",
|
||||
Ograve: "\u00D2",
|
||||
Oacute: "\u00D3",
|
||||
Ocirc: "\u00D4",
|
||||
Otilde: "\u00D5",
|
||||
Ouml: "\u00D6",
|
||||
times: "\u00D7",
|
||||
Oslash: "\u00D8",
|
||||
Ugrave: "\u00D9",
|
||||
Uacute: "\u00DA",
|
||||
Ucirc: "\u00DB",
|
||||
Uuml: "\u00DC",
|
||||
Yacute: "\u00DD",
|
||||
THORN: "\u00DE",
|
||||
szlig: "\u00DF",
|
||||
agrave: "\u00E0",
|
||||
aacute: "\u00E1",
|
||||
acirc: "\u00E2",
|
||||
atilde: "\u00E3",
|
||||
auml: "\u00E4",
|
||||
aring: "\u00E5",
|
||||
aelig: "\u00E6",
|
||||
ccedil: "\u00E7",
|
||||
egrave: "\u00E8",
|
||||
eacute: "\u00E9",
|
||||
ecirc: "\u00EA",
|
||||
euml: "\u00EB",
|
||||
igrave: "\u00EC",
|
||||
iacute: "\u00ED",
|
||||
icirc: "\u00EE",
|
||||
iuml: "\u00EF",
|
||||
eth: "\u00F0",
|
||||
ntilde: "\u00F1",
|
||||
ograve: "\u00F2",
|
||||
oacute: "\u00F3",
|
||||
ocirc: "\u00F4",
|
||||
otilde: "\u00F5",
|
||||
ouml: "\u00F6",
|
||||
divide: "\u00F7",
|
||||
oslash: "\u00F8",
|
||||
ugrave: "\u00F9",
|
||||
uacute: "\u00FA",
|
||||
ucirc: "\u00FB",
|
||||
uuml: "\u00FC",
|
||||
yacute: "\u00FD",
|
||||
thorn: "\u00FE",
|
||||
yuml: "\u00FF",
|
||||
OElig: "\u0152",
|
||||
oelig: "\u0153",
|
||||
Scaron: "\u0160",
|
||||
scaron: "\u0161",
|
||||
Yuml: "\u0178",
|
||||
fnof: "\u0192",
|
||||
circ: "\u02C6",
|
||||
tilde: "\u02DC",
|
||||
Alpha: "\u0391",
|
||||
Beta: "\u0392",
|
||||
Gamma: "\u0393",
|
||||
Delta: "\u0394",
|
||||
Epsilon: "\u0395",
|
||||
Zeta: "\u0396",
|
||||
Eta: "\u0397",
|
||||
Theta: "\u0398",
|
||||
Iota: "\u0399",
|
||||
Kappa: "\u039A",
|
||||
Lambda: "\u039B",
|
||||
Mu: "\u039C",
|
||||
Nu: "\u039D",
|
||||
Xi: "\u039E",
|
||||
Omicron: "\u039F",
|
||||
Pi: "\u03A0",
|
||||
Rho: "\u03A1",
|
||||
Sigma: "\u03A3",
|
||||
Tau: "\u03A4",
|
||||
Upsilon: "\u03A5",
|
||||
Phi: "\u03A6",
|
||||
Chi: "\u03A7",
|
||||
Psi: "\u03A8",
|
||||
Omega: "\u03A9",
|
||||
alpha: "\u03B1",
|
||||
beta: "\u03B2",
|
||||
gamma: "\u03B3",
|
||||
delta: "\u03B4",
|
||||
epsilon: "\u03B5",
|
||||
zeta: "\u03B6",
|
||||
eta: "\u03B7",
|
||||
theta: "\u03B8",
|
||||
iota: "\u03B9",
|
||||
kappa: "\u03BA",
|
||||
lambda: "\u03BB",
|
||||
mu: "\u03BC",
|
||||
nu: "\u03BD",
|
||||
xi: "\u03BE",
|
||||
omicron: "\u03BF",
|
||||
pi: "\u03C0",
|
||||
rho: "\u03C1",
|
||||
sigmaf: "\u03C2",
|
||||
sigma: "\u03C3",
|
||||
tau: "\u03C4",
|
||||
upsilon: "\u03C5",
|
||||
phi: "\u03C6",
|
||||
chi: "\u03C7",
|
||||
psi: "\u03C8",
|
||||
omega: "\u03C9",
|
||||
thetasym: "\u03D1",
|
||||
upsih: "\u03D2",
|
||||
piv: "\u03D6",
|
||||
ensp: "\u2002",
|
||||
emsp: "\u2003",
|
||||
thinsp: "\u2009",
|
||||
zwnj: "\u200C",
|
||||
zwj: "\u200D",
|
||||
lrm: "\u200E",
|
||||
rlm: "\u200F",
|
||||
ndash: "\u2013",
|
||||
mdash: "\u2014",
|
||||
lsquo: "\u2018",
|
||||
rsquo: "\u2019",
|
||||
sbquo: "\u201A",
|
||||
ldquo: "\u201C",
|
||||
rdquo: "\u201D",
|
||||
bdquo: "\u201E",
|
||||
dagger: "\u2020",
|
||||
Dagger: "\u2021",
|
||||
bull: "\u2022",
|
||||
hellip: "\u2026",
|
||||
permil: "\u2030",
|
||||
prime: "\u2032",
|
||||
Prime: "\u2033",
|
||||
lsaquo: "\u2039",
|
||||
rsaquo: "\u203A",
|
||||
oline: "\u203E",
|
||||
frasl: "\u2044",
|
||||
euro: "\u20AC",
|
||||
image: "\u2111",
|
||||
weierp: "\u2118",
|
||||
real: "\u211C",
|
||||
trade: "\u2122",
|
||||
alefsym: "\u2135",
|
||||
larr: "\u2190",
|
||||
uarr: "\u2191",
|
||||
rarr: "\u2192",
|
||||
darr: "\u2193",
|
||||
harr: "\u2194",
|
||||
crarr: "\u21B5",
|
||||
lArr: "\u21D0",
|
||||
uArr: "\u21D1",
|
||||
rArr: "\u21D2",
|
||||
dArr: "\u21D3",
|
||||
hArr: "\u21D4",
|
||||
forall: "\u2200",
|
||||
part: "\u2202",
|
||||
exist: "\u2203",
|
||||
empty: "\u2205",
|
||||
nabla: "\u2207",
|
||||
isin: "\u2208",
|
||||
notin: "\u2209",
|
||||
ni: "\u220B",
|
||||
prod: "\u220F",
|
||||
sum: "\u2211",
|
||||
minus: "\u2212",
|
||||
lowast: "\u2217",
|
||||
radic: "\u221A",
|
||||
prop: "\u221D",
|
||||
infin: "\u221E",
|
||||
ang: "\u2220",
|
||||
and: "\u2227",
|
||||
or: "\u2228",
|
||||
cap: "\u2229",
|
||||
cup: "\u222A",
|
||||
"int": "\u222B",
|
||||
there4: "\u2234",
|
||||
sim: "\u223C",
|
||||
cong: "\u2245",
|
||||
asymp: "\u2248",
|
||||
ne: "\u2260",
|
||||
equiv: "\u2261",
|
||||
le: "\u2264",
|
||||
ge: "\u2265",
|
||||
sub: "\u2282",
|
||||
sup: "\u2283",
|
||||
nsub: "\u2284",
|
||||
sube: "\u2286",
|
||||
supe: "\u2287",
|
||||
oplus: "\u2295",
|
||||
otimes: "\u2297",
|
||||
perp: "\u22A5",
|
||||
sdot: "\u22C5",
|
||||
lceil: "\u2308",
|
||||
rceil: "\u2309",
|
||||
lfloor: "\u230A",
|
||||
rfloor: "\u230B",
|
||||
lang: "\u2329",
|
||||
rang: "\u232A",
|
||||
loz: "\u25CA",
|
||||
spades: "\u2660",
|
||||
clubs: "\u2663",
|
||||
hearts: "\u2665",
|
||||
diams: "\u2666"
|
||||
};
|
||||
111
build/node_modules/hydrolysis/node_modules/espree/package.json
generated
vendored
Normal file
111
build/node_modules/hydrolysis/node_modules/espree/package.json
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
{
|
||||
"_from": "espree@^2.0.1",
|
||||
"_id": "espree@2.2.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-32kbkxCIlAKuspzAZnCMVmkLhUs=",
|
||||
"_location": "/hydrolysis/espree",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "espree@^2.0.1",
|
||||
"name": "espree",
|
||||
"escapedName": "espree",
|
||||
"rawSpec": "^2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/hydrolysis"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/espree/-/espree-2.2.5.tgz",
|
||||
"_shasum": "df691b9310889402aeb29cc066708c56690b854b",
|
||||
"_spec": "espree@^2.0.1",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/hydrolysis",
|
||||
"author": {
|
||||
"name": "Nicholas C. Zakas",
|
||||
"email": "nicholas+npm@nczconsulting.com"
|
||||
},
|
||||
"bin": {
|
||||
"esparse": "./bin/esparse.js",
|
||||
"esvalidate": "./bin/esvalidate.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/eslint/espree.git"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "An actively-maintained fork of Esprima, the ECMAScript parsing infrastructure for multipurpose analysis",
|
||||
"devDependencies": {
|
||||
"browserify": "^7.0.0",
|
||||
"chai": "^1.10.0",
|
||||
"complexity-report": "~0.6.1",
|
||||
"dateformat": "^1.0.11",
|
||||
"eslint": "^0.9.2",
|
||||
"esprima": "git://github.com/jquery/esprima.git",
|
||||
"esprima-fb": "^8001.2001.0-dev-harmony-fb",
|
||||
"istanbul": "~0.2.6",
|
||||
"json-diff": "~0.3.1",
|
||||
"leche": "^1.0.1",
|
||||
"mocha": "^2.0.1",
|
||||
"npm-license": "^0.2.3",
|
||||
"optimist": "~0.6.0",
|
||||
"regenerate": "~0.5.4",
|
||||
"semver": "^4.1.1",
|
||||
"shelljs": "^0.3.0",
|
||||
"shelljs-nodecli": "^0.1.1",
|
||||
"unicode-6.3.0": "~0.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"lib",
|
||||
"test/run.js",
|
||||
"test/runner.js",
|
||||
"test/test.js",
|
||||
"test/compat.js",
|
||||
"test/reflect.js",
|
||||
"espree.js"
|
||||
],
|
||||
"homepage": "https://github.com/eslint/espree",
|
||||
"keywords": [
|
||||
"ast",
|
||||
"ecmascript",
|
||||
"javascript",
|
||||
"parser",
|
||||
"syntax"
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"type": "BSD",
|
||||
"url": "http://github.com/nzakas/espree/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "espree.js",
|
||||
"name": "espree",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/eslint/espree.git"
|
||||
},
|
||||
"scripts": {
|
||||
"analyze-complexity": "node tools/list-complexity.js",
|
||||
"analyze-coverage": "node node_modules/istanbul/lib/cli.js cover test/runner.js",
|
||||
"benchmark": "node test/benchmarks.js",
|
||||
"benchmark-quick": "node test/benchmarks.js quick",
|
||||
"browserify": "node Makefile.js browserify",
|
||||
"check-complexity": "node node_modules/complexity-report/src/cli.js --maxcc 14 --silent -l -w espree.js",
|
||||
"check-coverage": "node node_modules/istanbul/lib/cli.js check-coverage --statement 99 --branch 99 --function 99",
|
||||
"complexity": "npm run-script analyze-complexity && npm run-script check-complexity",
|
||||
"coverage": "npm run-script analyze-coverage && npm run-script check-coverage",
|
||||
"generate-regex": "node tools/generate-identifier-regex.js",
|
||||
"lint": "node Makefile.js lint",
|
||||
"major": "node Makefile.js major",
|
||||
"minor": "node Makefile.js minor",
|
||||
"patch": "node Makefile.js patch",
|
||||
"test": "npm run-script lint && node Makefile.js test && node test/run.js"
|
||||
},
|
||||
"version": "2.2.5"
|
||||
}
|
||||
255
build/node_modules/hydrolysis/node_modules/espree/test/compat.js
generated
vendored
Normal file
255
build/node_modules/hydrolysis/node_modules/espree/test/compat.js
generated
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
|
||||
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*jslint node: true */
|
||||
/*global document: true, window:true, espree: true, testReflect: true */
|
||||
|
||||
var runTests;
|
||||
|
||||
function getContext(espree, reportCase, reportFailure) {
|
||||
'use strict';
|
||||
|
||||
var Reflect, Pattern;
|
||||
|
||||
// Maps Mozilla Reflect object to our espree parser.
|
||||
Reflect = {
|
||||
parse: function (code) {
|
||||
var result;
|
||||
|
||||
reportCase(code);
|
||||
|
||||
try {
|
||||
result = espree.parse(code);
|
||||
} catch (error) {
|
||||
result = error;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// This is used by Reflect test suite to match a syntax tree.
|
||||
Pattern = function (obj) {
|
||||
var pattern;
|
||||
|
||||
// Poor man's deep object cloning.
|
||||
pattern = JSON.parse(JSON.stringify(obj));
|
||||
|
||||
// Special handling for regular expression literal since we need to
|
||||
// convert it to a string literal, otherwise it will be decoded
|
||||
// as object "{}" and the regular expression would be lost.
|
||||
if (obj.type && obj.type === 'Literal') {
|
||||
if (obj.value instanceof RegExp) {
|
||||
pattern = {
|
||||
type: obj.type,
|
||||
value: obj.value.toString()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Special handling for branch statement because SpiderMonkey
|
||||
// prefers to put the 'alternate' property before 'consequent'.
|
||||
if (obj.type && obj.type === 'IfStatement') {
|
||||
pattern = {
|
||||
type: pattern.type,
|
||||
test: pattern.test,
|
||||
consequent: pattern.consequent,
|
||||
alternate: pattern.alternate
|
||||
};
|
||||
}
|
||||
|
||||
// Special handling for do while statement because SpiderMonkey
|
||||
// prefers to put the 'test' property before 'body'.
|
||||
if (obj.type && obj.type === 'DoWhileStatement') {
|
||||
pattern = {
|
||||
type: pattern.type,
|
||||
body: pattern.body,
|
||||
test: pattern.test
|
||||
};
|
||||
}
|
||||
|
||||
// Remove special properties on Property node
|
||||
if (obj.type && obj.type === 'Property') {
|
||||
pattern = {
|
||||
type: pattern.type,
|
||||
key: pattern.key,
|
||||
value: pattern.value,
|
||||
kind: pattern.kind
|
||||
};
|
||||
}
|
||||
|
||||
function adjustRegexLiteralAndRaw(key, value) {
|
||||
if (key === 'value' && value instanceof RegExp) {
|
||||
value = value.toString();
|
||||
} else if (key === 'raw' && typeof value === "string") {
|
||||
// Ignore Espree-specific 'raw' property.
|
||||
return undefined;
|
||||
} else if (key === 'regex' && typeof value === "object") {
|
||||
// Ignore Espree-specific 'regex' property.
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
if (obj.type && (obj.type === 'Program')) {
|
||||
pattern.assert = function (tree) {
|
||||
var actual, expected;
|
||||
actual = JSON.stringify(tree, adjustRegexLiteralAndRaw, 4);
|
||||
expected = JSON.stringify(obj, null, 4);
|
||||
|
||||
if (expected !== actual) {
|
||||
reportFailure(expected, actual);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return pattern;
|
||||
};
|
||||
|
||||
return {
|
||||
Reflect: Reflect,
|
||||
Pattern: Pattern
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
// Run all tests in a browser environment.
|
||||
runTests = function () {
|
||||
'use strict';
|
||||
|
||||
var total = 0,
|
||||
failures = 0;
|
||||
|
||||
function setText(el, str) {
|
||||
if (typeof el.innerText === 'string') {
|
||||
el.innerText = str;
|
||||
} else {
|
||||
el.textContent = str;
|
||||
}
|
||||
}
|
||||
|
||||
function reportCase(code) {
|
||||
var report, e;
|
||||
report = document.getElementById('report');
|
||||
e = document.createElement('pre');
|
||||
e.setAttribute('class', 'code');
|
||||
setText(e, code);
|
||||
report.appendChild(e);
|
||||
total += 1;
|
||||
}
|
||||
|
||||
function reportFailure(expected, actual) {
|
||||
var report, e;
|
||||
|
||||
failures += 1;
|
||||
|
||||
report = document.getElementById('report');
|
||||
|
||||
e = document.createElement('p');
|
||||
setText(e, 'Expected');
|
||||
report.appendChild(e);
|
||||
|
||||
e = document.createElement('pre');
|
||||
e.setAttribute('class', 'expected');
|
||||
setText(e, expected);
|
||||
report.appendChild(e);
|
||||
|
||||
e = document.createElement('p');
|
||||
setText(e, 'Actual');
|
||||
report.appendChild(e);
|
||||
|
||||
e = document.createElement('pre');
|
||||
e.setAttribute('class', 'actual');
|
||||
setText(e, actual);
|
||||
report.appendChild(e);
|
||||
}
|
||||
|
||||
setText(document.getElementById('version'), espree.version);
|
||||
|
||||
window.setTimeout(function () {
|
||||
var tick, context = getContext(espree, reportCase, reportFailure);
|
||||
|
||||
tick = new Date();
|
||||
testReflect(context.Reflect, context.Pattern);
|
||||
tick = (new Date()) - tick;
|
||||
|
||||
if (failures > 0) {
|
||||
document.getElementById('status').className = 'alert-box alert';
|
||||
setText(document.getElementById('status'), total + ' tests. ' +
|
||||
'Failures: ' + failures + '. ' + tick + ' ms');
|
||||
} else {
|
||||
document.getElementById('status').className = 'alert-box success';
|
||||
setText(document.getElementById('status'), total + ' tests. ' +
|
||||
'No failure. ' + tick + ' ms');
|
||||
}
|
||||
}, 11);
|
||||
};
|
||||
} else {
|
||||
(function (global) {
|
||||
'use strict';
|
||||
var espree = require('../espree'),
|
||||
tick,
|
||||
total = 0,
|
||||
failures = [],
|
||||
header,
|
||||
current,
|
||||
context;
|
||||
|
||||
function reportCase(code) {
|
||||
total += 1;
|
||||
current = code;
|
||||
}
|
||||
|
||||
function reportFailure(expected, actual) {
|
||||
failures.push({
|
||||
source: current,
|
||||
expected: expected.toString(),
|
||||
actual: actual.toString()
|
||||
});
|
||||
}
|
||||
|
||||
context = getContext(espree, reportCase, reportFailure);
|
||||
|
||||
tick = new Date();
|
||||
require('./reflect').testReflect(context.Reflect, context.Pattern);
|
||||
tick = (new Date()) - tick;
|
||||
|
||||
header = total + ' tests. ' + failures.length + ' failures. ' +
|
||||
tick + ' ms';
|
||||
if (failures.length) {
|
||||
console.error(header);
|
||||
failures.forEach(function (failure) {
|
||||
console.error(failure.source + ': Expected\n ' +
|
||||
failure.expected.split('\n').join('\n ') +
|
||||
'\nto match\n ' + failure.actual);
|
||||
});
|
||||
} else {
|
||||
console.log(header);
|
||||
}
|
||||
process.exit(failures.length === 0 ? 0 : 1);
|
||||
}(this));
|
||||
}
|
||||
/* vim: set sw=4 ts=4 et tw=80 : */
|
||||
422
build/node_modules/hydrolysis/node_modules/espree/test/reflect.js
generated
vendored
Normal file
422
build/node_modules/hydrolysis/node_modules/espree/test/reflect.js
generated
vendored
Normal file
@@ -0,0 +1,422 @@
|
||||
// This is modified from Mozilla Reflect.parse test suite (the file is located
|
||||
// at js/src/tests/js1_8_5/extensions/reflect-parse.js in the source tree).
|
||||
//
|
||||
// Some notable changes:
|
||||
// * Removed unsupported features (destructuring, let, comprehensions...).
|
||||
// * Removed tests for E4X (ECMAScript for XML).
|
||||
// * Removed everything related to builder.
|
||||
// * Enclosed every 'Pattern' construct with a scope.
|
||||
// * Tweaked some expected tree to remove generator field.
|
||||
// * Removed the test for bug 632030 and bug 632024.
|
||||
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
*/
|
||||
|
||||
(function (exports) {
|
||||
|
||||
function testReflect(Reflect, Pattern) {
|
||||
|
||||
function program(elts) { return Pattern({ type: "Program", body: elts }) }
|
||||
function exprStmt(expr) { return Pattern({ type: "ExpressionStatement", expression: expr }) }
|
||||
function throwStmt(expr) { return Pattern({ type: "ThrowStatement", argument: expr }) }
|
||||
function returnStmt(expr) { return Pattern({ type: "ReturnStatement", argument: expr }) }
|
||||
function yieldExpr(expr) { return Pattern({ type: "YieldExpression", argument: expr }) }
|
||||
function lit(val) { return Pattern({ type: "Literal", value: val }) }
|
||||
var thisExpr = Pattern({ type: "ThisExpression" });
|
||||
function funDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration",
|
||||
id: id,
|
||||
params: params,
|
||||
defaults: [],
|
||||
body: body,
|
||||
rest: null,
|
||||
generator: false,
|
||||
expression: false
|
||||
}) }
|
||||
function genFunDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration",
|
||||
id: id,
|
||||
params: params,
|
||||
defaults: [],
|
||||
body: body,
|
||||
rest: null,
|
||||
generator: false,
|
||||
expression: false
|
||||
}) }
|
||||
function declarator(id, init) { return Pattern({ type: "VariableDeclarator", id: id, init: init }) }
|
||||
function varDecl(decls) { return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "var" }) }
|
||||
function letDecl(decls) { return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "let" }) }
|
||||
function constDecl(decls) { return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "const" }) }
|
||||
function ident(name) { return Pattern({ type: "Identifier", name: name }) }
|
||||
function dotExpr(obj, id) { return Pattern({ type: "MemberExpression", computed: false, object: obj, property: id }) }
|
||||
function memExpr(obj, id) { return Pattern({ type: "MemberExpression", computed: true, object: obj, property: id }) }
|
||||
function forStmt(init, test, update, body) { return Pattern({ type: "ForStatement", init: init, test: test, update: update, body: body }) }
|
||||
function forInStmt(lhs, rhs, body) { return Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: false }) }
|
||||
function forEachInStmt(lhs, rhs, body) { return Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: true }) }
|
||||
function breakStmt(lab) { return Pattern({ type: "BreakStatement", label: lab }) }
|
||||
function continueStmt(lab) { return Pattern({ type: "ContinueStatement", label: lab }) }
|
||||
function blockStmt(body) { return Pattern({ type: "BlockStatement", body: body }) }
|
||||
var emptyStmt = Pattern({ type: "EmptyStatement" });
|
||||
function ifStmt(test, cons, alt) { return Pattern({ type: "IfStatement", test: test, alternate: alt, consequent: cons }) }
|
||||
function labStmt(lab, stmt) { return Pattern({ type: "LabeledStatement", label: lab, body: stmt }) }
|
||||
function withStmt(obj, stmt) { return Pattern({ type: "WithStatement", object: obj, body: stmt }) }
|
||||
function whileStmt(test, stmt) { return Pattern({ type: "WhileStatement", test: test, body: stmt }) }
|
||||
function doStmt(stmt, test) { return Pattern({ type: "DoWhileStatement", test: test, body: stmt }) }
|
||||
function switchStmt(disc, cases) { return Pattern({ type: "SwitchStatement", discriminant: disc, cases: cases }) }
|
||||
function caseClause(test, stmts) { return Pattern({ type: "SwitchCase", test: test, consequent: stmts }) }
|
||||
function defaultClause(stmts) { return Pattern({ type: "SwitchCase", test: null, consequent: stmts }) }
|
||||
function catchClause(id, guard, body) { if (guard) { return Pattern({ type: "GuardedCatchClause", param: id, guard: guard, body: body }) } else { return Pattern({ type: "CatchClause", param: id, body: body }) } }
|
||||
function tryStmt(body, guarded, catches, fin) { return Pattern({ type: "TryStatement", block: body, guardedHandlers: guarded, handlers: catches, handler: (catches.length > 0) ? catches[0] : null, finalizer: fin }) }
|
||||
function letStmt(head, body) { return Pattern({ type: "LetStatement", head: head, body: body }) }
|
||||
function funExpr(id, args, body, gen) { return Pattern({ type: "FunctionExpression",
|
||||
id: id,
|
||||
params: args,
|
||||
defaults: [],
|
||||
body: body,
|
||||
rest: null,
|
||||
generator: false,
|
||||
expression: false
|
||||
}) }
|
||||
function genFunExpr(id, args, body) { return Pattern({ type: "FunctionExpression",
|
||||
id: id,
|
||||
params: args,
|
||||
defaults: [],
|
||||
body: body,
|
||||
rest: null,
|
||||
generator: false,
|
||||
expression: false
|
||||
}) }
|
||||
|
||||
function unExpr(op, arg) { return Pattern({ type: "UnaryExpression", operator: op, argument: arg, prefix: true }) }
|
||||
function binExpr(op, left, right) { return Pattern({ type: "BinaryExpression", operator: op, left: left, right: right }) }
|
||||
function aExpr(op, left, right) { return Pattern({ type: "AssignmentExpression", operator: op, left: left, right: right }) }
|
||||
function updExpr(op, arg, prefix) { return Pattern({ type: "UpdateExpression", operator: op, argument: arg, prefix: prefix }) }
|
||||
function logExpr(op, left, right) { return Pattern({ type: "LogicalExpression", operator: op, left: left, right: right }) }
|
||||
|
||||
function condExpr(test, cons, alt) { return Pattern({ type: "ConditionalExpression", test: test, consequent: cons, alternate: alt }) }
|
||||
function seqExpr(exprs) { return Pattern({ type: "SequenceExpression", expressions: exprs }) }
|
||||
function newExpr(callee, args) { return Pattern({ type: "NewExpression", callee: callee, arguments: args }) }
|
||||
function callExpr(callee, args) { return Pattern({ type: "CallExpression", callee: callee, arguments: args }) }
|
||||
function arrExpr(elts) { return Pattern({ type: "ArrayExpression", elements: elts }) }
|
||||
function objExpr(elts) { return Pattern({ type: "ObjectExpression", properties: elts }) }
|
||||
function objProp(key, value, kind) { return Pattern({ type: "Property", key: key, value: value, kind: kind }) }
|
||||
|
||||
function arrPatt(elts) { return Pattern({ type: "ArrayPattern", elements: elts }) }
|
||||
function objPatt(elts) { return Pattern({ type: "ObjectPattern", properties: elts }) }
|
||||
|
||||
function localSrc(src) { return "(function(){ " + src + " })" }
|
||||
function localPatt(patt) { return program([exprStmt(funExpr(null, [], blockStmt([patt])))]) }
|
||||
function blockSrc(src) { return "(function(){ { " + src + " } })" }
|
||||
function blockPatt(patt) { return program([exprStmt(funExpr(null, [], blockStmt([blockStmt([patt])])))]) }
|
||||
|
||||
function assertBlockStmt(src, patt) {
|
||||
blockPatt(patt).assert(Reflect.parse(blockSrc(src)));
|
||||
}
|
||||
|
||||
function assertBlockExpr(src, patt) {
|
||||
assertBlockStmt(src, exprStmt(patt));
|
||||
}
|
||||
|
||||
function assertBlockDecl(src, patt, builder) {
|
||||
blockPatt(patt).assert(Reflect.parse(blockSrc(src), {builder: builder}));
|
||||
}
|
||||
|
||||
function assertLocalStmt(src, patt) {
|
||||
localPatt(patt).assert(Reflect.parse(localSrc(src)));
|
||||
}
|
||||
|
||||
function assertLocalExpr(src, patt) {
|
||||
assertLocalStmt(src, exprStmt(patt));
|
||||
}
|
||||
|
||||
function assertLocalDecl(src, patt) {
|
||||
localPatt(patt).assert(Reflect.parse(localSrc(src)));
|
||||
}
|
||||
|
||||
function assertGlobalStmt(src, patt, builder) {
|
||||
program([patt]).assert(Reflect.parse(src, {builder: builder}));
|
||||
}
|
||||
|
||||
function assertGlobalExpr(src, patt, builder) {
|
||||
program([exprStmt(patt)]).assert(Reflect.parse(src, {builder: builder}));
|
||||
//assertStmt(src, exprStmt(patt));
|
||||
}
|
||||
|
||||
function assertGlobalDecl(src, patt) {
|
||||
program([patt]).assert(Reflect.parse(src));
|
||||
}
|
||||
|
||||
function assertProg(src, patt) {
|
||||
program(patt).assert(Reflect.parse(src));
|
||||
}
|
||||
|
||||
function assertStmt(src, patt) {
|
||||
assertLocalStmt(src, patt);
|
||||
assertGlobalStmt(src, patt);
|
||||
assertBlockStmt(src, patt);
|
||||
}
|
||||
|
||||
function assertExpr(src, patt) {
|
||||
assertLocalExpr(src, patt);
|
||||
assertGlobalExpr(src, patt);
|
||||
assertBlockExpr(src, patt);
|
||||
}
|
||||
|
||||
function assertDecl(src, patt) {
|
||||
assertLocalDecl(src, patt);
|
||||
assertGlobalDecl(src, patt);
|
||||
assertBlockDecl(src, patt);
|
||||
}
|
||||
|
||||
function assertError(src, errorType) {
|
||||
try {
|
||||
Reflect.parse(src);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
throw new Error("expected " + errorType.name + " for " + uneval(src));
|
||||
}
|
||||
|
||||
|
||||
// general tests
|
||||
|
||||
// NB: These are useful but for now jit-test doesn't do I/O reliably.
|
||||
|
||||
//program(_).assert(Reflect.parse(snarf('data/flapjax.txt')));
|
||||
//program(_).assert(Reflect.parse(snarf('data/jquery-1.4.2.txt')));
|
||||
//program(_).assert(Reflect.parse(snarf('data/prototype.js')));
|
||||
//program(_).assert(Reflect.parse(snarf('data/dojo.js.uncompressed.js')));
|
||||
//program(_).assert(Reflect.parse(snarf('data/mootools-1.2.4-core-nc.js')));
|
||||
|
||||
|
||||
// declarations
|
||||
|
||||
assertDecl("var x = 1, y = 2, z = 3",
|
||||
varDecl([declarator(ident("x"), lit(1)),
|
||||
declarator(ident("y"), lit(2)),
|
||||
declarator(ident("z"), lit(3))]));
|
||||
assertDecl("var x, y, z",
|
||||
varDecl([declarator(ident("x"), null),
|
||||
declarator(ident("y"), null),
|
||||
declarator(ident("z"), null)]));
|
||||
assertDecl("function foo() { }",
|
||||
funDecl(ident("foo"), [], blockStmt([])));
|
||||
assertDecl("function foo() { return 42 }",
|
||||
funDecl(ident("foo"), [], blockStmt([returnStmt(lit(42))])));
|
||||
|
||||
|
||||
// Bug 591437: rebound args have their defs turned into uses
|
||||
assertDecl("function f(a) { function a() { } }",
|
||||
funDecl(ident("f"), [ident("a")], blockStmt([funDecl(ident("a"), [], blockStmt([]))])));
|
||||
assertDecl("function f(a,b,c) { function b() { } }",
|
||||
funDecl(ident("f"), [ident("a"),ident("b"),ident("c")], blockStmt([funDecl(ident("b"), [], blockStmt([]))])));
|
||||
|
||||
// expressions
|
||||
|
||||
assertExpr("true", lit(true));
|
||||
assertExpr("false", lit(false));
|
||||
assertExpr("42", lit(42));
|
||||
assertExpr("(/asdf/)", lit(/asdf/));
|
||||
assertExpr("this", thisExpr);
|
||||
assertExpr("foo", ident("foo"));
|
||||
assertExpr("foo.bar", dotExpr(ident("foo"), ident("bar")));
|
||||
assertExpr("foo[bar]", memExpr(ident("foo"), ident("bar")));
|
||||
assertExpr("(function(){})", funExpr(null, [], blockStmt([])));
|
||||
assertExpr("(function f() {})", funExpr(ident("f"), [], blockStmt([])));
|
||||
assertExpr("(function f(x,y,z) {})", funExpr(ident("f"), [ident("x"),ident("y"),ident("z")], blockStmt([])));
|
||||
assertExpr("(++x)", updExpr("++", ident("x"), true));
|
||||
assertExpr("(x++)", updExpr("++", ident("x"), false));
|
||||
assertExpr("(+x)", unExpr("+", ident("x")));
|
||||
assertExpr("(-x)", unExpr("-", ident("x")));
|
||||
assertExpr("(!x)", unExpr("!", ident("x")));
|
||||
assertExpr("(~x)", unExpr("~", ident("x")));
|
||||
assertExpr("(delete x)", unExpr("delete", ident("x")));
|
||||
assertExpr("(typeof x)", unExpr("typeof", ident("x")));
|
||||
assertExpr("(void x)", unExpr("void", ident("x")));
|
||||
assertExpr("(x == y)", binExpr("==", ident("x"), ident("y")));
|
||||
assertExpr("(x != y)", binExpr("!=", ident("x"), ident("y")));
|
||||
assertExpr("(x === y)", binExpr("===", ident("x"), ident("y")));
|
||||
assertExpr("(x !== y)", binExpr("!==", ident("x"), ident("y")));
|
||||
assertExpr("(x < y)", binExpr("<", ident("x"), ident("y")));
|
||||
assertExpr("(x <= y)", binExpr("<=", ident("x"), ident("y")));
|
||||
assertExpr("(x > y)", binExpr(">", ident("x"), ident("y")));
|
||||
assertExpr("(x >= y)", binExpr(">=", ident("x"), ident("y")));
|
||||
assertExpr("(x << y)", binExpr("<<", ident("x"), ident("y")));
|
||||
assertExpr("(x >> y)", binExpr(">>", ident("x"), ident("y")));
|
||||
assertExpr("(x >>> y)", binExpr(">>>", ident("x"), ident("y")));
|
||||
assertExpr("(x + y)", binExpr("+", ident("x"), ident("y")));
|
||||
assertExpr("(w + x + y + z)", binExpr("+", binExpr("+", binExpr("+", ident("w"), ident("x")), ident("y")), ident("z")));
|
||||
assertExpr("(x - y)", binExpr("-", ident("x"), ident("y")));
|
||||
assertExpr("(w - x - y - z)", binExpr("-", binExpr("-", binExpr("-", ident("w"), ident("x")), ident("y")), ident("z")));
|
||||
assertExpr("(x * y)", binExpr("*", ident("x"), ident("y")));
|
||||
assertExpr("(x / y)", binExpr("/", ident("x"), ident("y")));
|
||||
assertExpr("(x % y)", binExpr("%", ident("x"), ident("y")));
|
||||
assertExpr("(x | y)", binExpr("|", ident("x"), ident("y")));
|
||||
assertExpr("(x ^ y)", binExpr("^", ident("x"), ident("y")));
|
||||
assertExpr("(x & y)", binExpr("&", ident("x"), ident("y")));
|
||||
assertExpr("(x in y)", binExpr("in", ident("x"), ident("y")));
|
||||
assertExpr("(x instanceof y)", binExpr("instanceof", ident("x"), ident("y")));
|
||||
assertExpr("(x = y)", aExpr("=", ident("x"), ident("y")));
|
||||
assertExpr("(x += y)", aExpr("+=", ident("x"), ident("y")));
|
||||
assertExpr("(x -= y)", aExpr("-=", ident("x"), ident("y")));
|
||||
assertExpr("(x *= y)", aExpr("*=", ident("x"), ident("y")));
|
||||
assertExpr("(x /= y)", aExpr("/=", ident("x"), ident("y")));
|
||||
assertExpr("(x %= y)", aExpr("%=", ident("x"), ident("y")));
|
||||
assertExpr("(x <<= y)", aExpr("<<=", ident("x"), ident("y")));
|
||||
assertExpr("(x >>= y)", aExpr(">>=", ident("x"), ident("y")));
|
||||
assertExpr("(x >>>= y)", aExpr(">>>=", ident("x"), ident("y")));
|
||||
assertExpr("(x |= y)", aExpr("|=", ident("x"), ident("y")));
|
||||
assertExpr("(x ^= y)", aExpr("^=", ident("x"), ident("y")));
|
||||
assertExpr("(x &= y)", aExpr("&=", ident("x"), ident("y")));
|
||||
assertExpr("(x || y)", logExpr("||", ident("x"), ident("y")));
|
||||
assertExpr("(x && y)", logExpr("&&", ident("x"), ident("y")));
|
||||
assertExpr("(w || x || y || z)", logExpr("||", logExpr("||", logExpr("||", ident("w"), ident("x")), ident("y")), ident("z")))
|
||||
assertExpr("(x ? y : z)", condExpr(ident("x"), ident("y"), ident("z")));
|
||||
assertExpr("(x,y)", seqExpr([ident("x"),ident("y")]))
|
||||
assertExpr("(x,y,z)", seqExpr([ident("x"),ident("y"),ident("z")]))
|
||||
assertExpr("(a,b,c,d,e,f,g)", seqExpr([ident("a"),ident("b"),ident("c"),ident("d"),ident("e"),ident("f"),ident("g")]));
|
||||
assertExpr("(new Object)", newExpr(ident("Object"), []));
|
||||
assertExpr("(new Object())", newExpr(ident("Object"), []));
|
||||
assertExpr("(new Object(42))", newExpr(ident("Object"), [lit(42)]));
|
||||
assertExpr("(new Object(1,2,3))", newExpr(ident("Object"), [lit(1),lit(2),lit(3)]));
|
||||
assertExpr("(String())", callExpr(ident("String"), []));
|
||||
assertExpr("(String(42))", callExpr(ident("String"), [lit(42)]));
|
||||
assertExpr("(String(1,2,3))", callExpr(ident("String"), [lit(1),lit(2),lit(3)]));
|
||||
assertExpr("[]", arrExpr([]));
|
||||
assertExpr("[1]", arrExpr([lit(1)]));
|
||||
assertExpr("[1,2]", arrExpr([lit(1),lit(2)]));
|
||||
assertExpr("[1,2,3]", arrExpr([lit(1),lit(2),lit(3)]));
|
||||
assertExpr("[1,,2,3]", arrExpr([lit(1),,lit(2),lit(3)]));
|
||||
assertExpr("[1,,,2,3]", arrExpr([lit(1),,,lit(2),lit(3)]));
|
||||
assertExpr("[1,,,2,,3]", arrExpr([lit(1),,,lit(2),,lit(3)]));
|
||||
assertExpr("[1,,,2,,,3]", arrExpr([lit(1),,,lit(2),,,lit(3)]));
|
||||
assertExpr("[,1,2,3]", arrExpr([,lit(1),lit(2),lit(3)]));
|
||||
assertExpr("[,,1,2,3]", arrExpr([,,lit(1),lit(2),lit(3)]));
|
||||
assertExpr("[,,,1,2,3]", arrExpr([,,,lit(1),lit(2),lit(3)]));
|
||||
assertExpr("[,,,1,2,3,]", arrExpr([,,,lit(1),lit(2),lit(3)]));
|
||||
assertExpr("[,,,1,2,3,,]", arrExpr([,,,lit(1),lit(2),lit(3),undefined]));
|
||||
assertExpr("[,,,1,2,3,,,]", arrExpr([,,,lit(1),lit(2),lit(3),undefined,undefined]));
|
||||
assertExpr("[,,,,,]", arrExpr([undefined,undefined,undefined,undefined,undefined]));
|
||||
assertExpr("({})", objExpr([]));
|
||||
assertExpr("({x:1})", objExpr([objProp(ident("x"), lit(1), "init")]));
|
||||
assertExpr("({x:1, y:2})", objExpr([objProp(ident("x"), lit(1), "init"),
|
||||
objProp(ident("y"), lit(2), "init")]));
|
||||
assertExpr("({x:1, y:2, z:3})", objExpr([objProp(ident("x"), lit(1), "init"),
|
||||
objProp(ident("y"), lit(2), "init"),
|
||||
objProp(ident("z"), lit(3), "init") ]));
|
||||
assertExpr("({x:1, 'y':2, z:3})", objExpr([objProp(ident("x"), lit(1), "init"),
|
||||
objProp(lit("y"), lit(2), "init"),
|
||||
objProp(ident("z"), lit(3), "init") ]));
|
||||
assertExpr("({'x':1, 'y':2, z:3})", objExpr([objProp(lit("x"), lit(1), "init"),
|
||||
objProp(lit("y"), lit(2), "init"),
|
||||
objProp(ident("z"), lit(3), "init") ]));
|
||||
assertExpr("({'x':1, 'y':2, 3:3})", objExpr([objProp(lit("x"), lit(1), "init"),
|
||||
objProp(lit("y"), lit(2), "init"),
|
||||
objProp(lit(3), lit(3), "init") ]));
|
||||
|
||||
// Bug 571617: eliminate constant-folding
|
||||
assertExpr("2 + 3", binExpr("+", lit(2), lit(3)));
|
||||
|
||||
// Bug 632026: constant-folding
|
||||
assertExpr("typeof(0?0:a)", unExpr("typeof", condExpr(lit(0), lit(0), ident("a"))));
|
||||
|
||||
// Bug 632056: constant-folding
|
||||
program([exprStmt(ident("f")),
|
||||
ifStmt(lit(1),
|
||||
funDecl(ident("f"), [], blockStmt([])),
|
||||
null)]).assert(Reflect.parse("f; if (1) function f(){}"));
|
||||
|
||||
// statements
|
||||
|
||||
assertStmt("throw 42", throwStmt(lit(42)));
|
||||
assertStmt("for (;;) break", forStmt(null, null, null, breakStmt(null)));
|
||||
assertStmt("for (x; y; z) break", forStmt(ident("x"), ident("y"), ident("z"), breakStmt(null)));
|
||||
assertStmt("for (var x; y; z) break", forStmt(varDecl([declarator(ident("x"), null)]), ident("y"), ident("z"), breakStmt(null)));
|
||||
assertStmt("for (var x = 42; y; z) break", forStmt(varDecl([declarator(ident("x"), lit(42))]), ident("y"), ident("z"), breakStmt(null)));
|
||||
assertStmt("for (x; ; z) break", forStmt(ident("x"), null, ident("z"), breakStmt(null)));
|
||||
assertStmt("for (var x; ; z) break", forStmt(varDecl([declarator(ident("x"), null)]), null, ident("z"), breakStmt(null)));
|
||||
assertStmt("for (var x = 42; ; z) break", forStmt(varDecl([declarator(ident("x"), lit(42))]), null, ident("z"), breakStmt(null)));
|
||||
assertStmt("for (x; y; ) break", forStmt(ident("x"), ident("y"), null, breakStmt(null)));
|
||||
assertStmt("for (var x; y; ) break", forStmt(varDecl([declarator(ident("x"), null)]), ident("y"), null, breakStmt(null)));
|
||||
assertStmt("for (var x = 42; y; ) break", forStmt(varDecl([declarator(ident("x"),lit(42))]), ident("y"), null, breakStmt(null)));
|
||||
assertStmt("for (var x in y) break", forInStmt(varDecl([declarator(ident("x"),null)]), ident("y"), breakStmt(null)));
|
||||
assertStmt("for (x in y) break", forInStmt(ident("x"), ident("y"), breakStmt(null)));
|
||||
assertStmt("{ }", blockStmt([]));
|
||||
assertStmt("{ throw 1; throw 2; throw 3; }", blockStmt([ throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))]));
|
||||
assertStmt(";", emptyStmt);
|
||||
assertStmt("if (foo) throw 42;", ifStmt(ident("foo"), throwStmt(lit(42)), null));
|
||||
assertStmt("if (foo) throw 42; else true;", ifStmt(ident("foo"), throwStmt(lit(42)), exprStmt(lit(true))));
|
||||
assertStmt("if (foo) { throw 1; throw 2; throw 3; }",
|
||||
ifStmt(ident("foo"),
|
||||
blockStmt([throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))]),
|
||||
null));
|
||||
assertStmt("if (foo) { throw 1; throw 2; throw 3; } else true;",
|
||||
ifStmt(ident("foo"),
|
||||
blockStmt([throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))]),
|
||||
exprStmt(lit(true))));
|
||||
assertStmt("foo: for(;;) break foo;", labStmt(ident("foo"), forStmt(null, null, null, breakStmt(ident("foo")))));
|
||||
assertStmt("foo: for(;;) continue foo;", labStmt(ident("foo"), forStmt(null, null, null, continueStmt(ident("foo")))));
|
||||
assertStmt("with (obj) { }", withStmt(ident("obj"), blockStmt([])));
|
||||
assertStmt("with (obj) { obj; }", withStmt(ident("obj"), blockStmt([exprStmt(ident("obj"))])));
|
||||
assertStmt("while (foo) { }", whileStmt(ident("foo"), blockStmt([])));
|
||||
assertStmt("while (foo) { foo; }", whileStmt(ident("foo"), blockStmt([exprStmt(ident("foo"))])));
|
||||
assertStmt("do { } while (foo);", doStmt(blockStmt([]), ident("foo")));
|
||||
assertStmt("do { foo; } while (foo)", doStmt(blockStmt([exprStmt(ident("foo"))]), ident("foo")));
|
||||
assertStmt("switch (foo) { case 1: 1; break; case 2: 2; break; default: 3; }",
|
||||
switchStmt(ident("foo"),
|
||||
[ caseClause(lit(1), [ exprStmt(lit(1)), breakStmt(null) ]),
|
||||
caseClause(lit(2), [ exprStmt(lit(2)), breakStmt(null) ]),
|
||||
defaultClause([ exprStmt(lit(3)) ]) ]));
|
||||
assertStmt("switch (foo) { case 1: 1; break; case 2: 2; break; default: 3; case 42: 42; }",
|
||||
switchStmt(ident("foo"),
|
||||
[ caseClause(lit(1), [ exprStmt(lit(1)), breakStmt(null) ]),
|
||||
caseClause(lit(2), [ exprStmt(lit(2)), breakStmt(null) ]),
|
||||
defaultClause([ exprStmt(lit(3)) ]),
|
||||
caseClause(lit(42), [ exprStmt(lit(42)) ]) ]));
|
||||
assertStmt("try { } catch (e) { }",
|
||||
tryStmt(blockStmt([]),
|
||||
[],
|
||||
[ catchClause(ident("e"), null, blockStmt([])) ],
|
||||
null));
|
||||
assertStmt("try { } catch (e) { } finally { }",
|
||||
tryStmt(blockStmt([]),
|
||||
[],
|
||||
[ catchClause(ident("e"), null, blockStmt([])) ],
|
||||
blockStmt([])));
|
||||
assertStmt("try { } finally { }",
|
||||
tryStmt(blockStmt([]),
|
||||
[],
|
||||
[],
|
||||
blockStmt([])));
|
||||
|
||||
// redeclarations (TOK_NAME nodes with lexdef)
|
||||
|
||||
assertStmt("function f() { function g() { } function g() { } }",
|
||||
funDecl(ident("f"), [], blockStmt([funDecl(ident("g"), [], blockStmt([])),
|
||||
funDecl(ident("g"), [], blockStmt([]))])));
|
||||
|
||||
assertStmt("function f() { function g() { } function g() { return 42 } }",
|
||||
funDecl(ident("f"), [], blockStmt([funDecl(ident("g"), [], blockStmt([])),
|
||||
funDecl(ident("g"), [], blockStmt([returnStmt(lit(42))]))])));
|
||||
|
||||
assertStmt("function f() { var x = 42; var x = 43; }",
|
||||
funDecl(ident("f"), [], blockStmt([varDecl([declarator(ident("x"),lit(42))]),
|
||||
varDecl([declarator(ident("x"),lit(43))])])));
|
||||
|
||||
// getters and setters
|
||||
|
||||
assertExpr("({ get x() { return 42 } })",
|
||||
objExpr([ objProp(ident("x"),
|
||||
funExpr(null, [], blockStmt([returnStmt(lit(42))])),
|
||||
"get" ) ]));
|
||||
assertExpr("({ set x(v) { return 42 } })",
|
||||
objExpr([ objProp(ident("x"),
|
||||
funExpr(null, [ident("v")], blockStmt([returnStmt(lit(42))])),
|
||||
"set" ) ]));
|
||||
|
||||
}
|
||||
|
||||
exports.testReflect = testReflect;
|
||||
|
||||
}(typeof exports === 'undefined' ? this : exports));
|
||||
68
build/node_modules/hydrolysis/node_modules/espree/test/run.js
generated
vendored
Normal file
68
build/node_modules/hydrolysis/node_modules/espree/test/run.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*jslint node:true */
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var child = require('child_process'),
|
||||
nodejs = '"' + process.execPath + '"',
|
||||
ret = 0,
|
||||
suites,
|
||||
index;
|
||||
|
||||
suites = [
|
||||
'runner',
|
||||
// TODO: Figure out what to do about this test...remove?
|
||||
// 'compat',
|
||||
'parselibs'
|
||||
];
|
||||
|
||||
function nextTest() {
|
||||
var suite = suites[index];
|
||||
|
||||
if (index < suites.length) {
|
||||
child.exec(nodejs + ' ./test/' + suite + '.js', function (err, stdout, stderr) {
|
||||
if (stdout) {
|
||||
process.stdout.write(suite + ': ' + stdout);
|
||||
}
|
||||
if (stderr) {
|
||||
process.stderr.write(suite + ': ' + stderr);
|
||||
}
|
||||
if (err) {
|
||||
ret = err.code;
|
||||
}
|
||||
index += 1;
|
||||
nextTest();
|
||||
});
|
||||
} else {
|
||||
process.exit(ret);
|
||||
}
|
||||
}
|
||||
|
||||
index = 0;
|
||||
nextTest();
|
||||
}());
|
||||
492
build/node_modules/hydrolysis/node_modules/espree/test/runner.js
generated
vendored
Normal file
492
build/node_modules/hydrolysis/node_modules/espree/test/runner.js
generated
vendored
Normal file
@@ -0,0 +1,492 @@
|
||||
/*
|
||||
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
|
||||
Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
|
||||
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
Copyright (C) 2011 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
Copyright (C) 2011 Arpad Borsos <arpad.borsos@googlemail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*jslint browser:true node:true */
|
||||
/*global espree:true, testFixture:true */
|
||||
|
||||
var runTests;
|
||||
|
||||
// Special handling for regular expression literal since we need to
|
||||
// convert it to a string literal, otherwise it will be decoded
|
||||
// as object "{}" and the regular expression would be lost.
|
||||
function adjustRegexLiteral(key, value) {
|
||||
'use strict';
|
||||
if (key === 'value' && value instanceof RegExp) {
|
||||
value = value.toString();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function NotMatchingError(expected, actual) {
|
||||
'use strict';
|
||||
Error.call(this, 'Expected ');
|
||||
this.expected = expected;
|
||||
this.actual = actual;
|
||||
}
|
||||
NotMatchingError.prototype = new Error();
|
||||
|
||||
function errorToObject(e) {
|
||||
'use strict';
|
||||
var msg = e.toString();
|
||||
|
||||
// Opera 9.64 produces an non-standard string in toString().
|
||||
if (msg.substr(0, 6) !== 'Error:') {
|
||||
if (typeof e.message === 'string') {
|
||||
msg = 'Error: ' + e.message;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
index: e.index,
|
||||
lineNumber: e.lineNumber,
|
||||
column: e.column,
|
||||
message: msg
|
||||
};
|
||||
}
|
||||
|
||||
function sortedObject(o) {
|
||||
if (o === null) {
|
||||
return o;
|
||||
}
|
||||
if (o instanceof Array) {
|
||||
return o.map(sortedObject);
|
||||
}
|
||||
if (typeof o !== 'object') {
|
||||
return o;
|
||||
}
|
||||
if (o instanceof RegExp) {
|
||||
return o;
|
||||
}
|
||||
var keys = Object.keys(o);
|
||||
var result = {
|
||||
range: undefined,
|
||||
loc: undefined
|
||||
};
|
||||
keys.forEach(function (key) {
|
||||
if (o.hasOwnProperty(key)){
|
||||
result[key] = sortedObject(o[key]);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function hasAttachedComment(syntax) {
|
||||
var key;
|
||||
for (key in syntax) {
|
||||
if (key === 'leadingComments' || key === 'trailingComments') {
|
||||
return true;
|
||||
}
|
||||
if (typeof syntax[key] === 'object' && syntax[key] !== null) {
|
||||
if (hasAttachedComment(syntax[key])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function testParse(espree, code, syntax) {
|
||||
'use strict';
|
||||
var expected, tree, actual, options, StringObject, i, len, err;
|
||||
|
||||
// alias, so that JSLint does not complain.
|
||||
StringObject = String;
|
||||
|
||||
options = {
|
||||
comment: (typeof syntax.comments !== 'undefined'),
|
||||
range: true,
|
||||
loc: true,
|
||||
tokens: (typeof syntax.tokens !== 'undefined'),
|
||||
raw: true,
|
||||
tolerant: (typeof syntax.errors !== 'undefined'),
|
||||
source: null
|
||||
};
|
||||
|
||||
if (options.comment) {
|
||||
options.attachComment = hasAttachedComment(syntax);
|
||||
}
|
||||
|
||||
if (typeof syntax.tokens !== 'undefined') {
|
||||
if (syntax.tokens.length > 0) {
|
||||
options.range = (typeof syntax.tokens[0].range !== 'undefined');
|
||||
options.loc = (typeof syntax.tokens[0].loc !== 'undefined');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof syntax.comments !== 'undefined') {
|
||||
if (syntax.comments.length > 0) {
|
||||
options.range = (typeof syntax.comments[0].range !== 'undefined');
|
||||
options.loc = (typeof syntax.comments[0].loc !== 'undefined');
|
||||
}
|
||||
}
|
||||
|
||||
if (options.loc) {
|
||||
options.source = syntax.loc.source;
|
||||
}
|
||||
|
||||
syntax = sortedObject(syntax);
|
||||
expected = JSON.stringify(syntax, null, 4);
|
||||
try {
|
||||
// Some variations of the options.
|
||||
tree = espree.parse(code, { tolerant: options.tolerant });
|
||||
tree = espree.parse(code, { tolerant: options.tolerant, range: true });
|
||||
tree = espree.parse(code, { tolerant: options.tolerant, loc: true });
|
||||
|
||||
tree = espree.parse(code, options);
|
||||
tree = (options.comment || options.tokens || options.tolerant) ? tree : tree.body[0];
|
||||
|
||||
if (options.tolerant) {
|
||||
for (i = 0, len = tree.errors.length; i < len; i += 1) {
|
||||
tree.errors[i] = errorToObject(tree.errors[i]);
|
||||
}
|
||||
}
|
||||
tree = sortedObject(tree);
|
||||
actual = JSON.stringify(tree, adjustRegexLiteral, 4);
|
||||
|
||||
// Only to ensure that there is no error when using string object.
|
||||
espree.parse(new StringObject(code), options);
|
||||
|
||||
} catch (e) {
|
||||
throw new NotMatchingError(expected, e.toString());
|
||||
}
|
||||
if (expected !== actual) {
|
||||
throw new NotMatchingError(expected, actual);
|
||||
}
|
||||
|
||||
function filter(key, value) {
|
||||
if (key === 'value' && value instanceof RegExp) {
|
||||
value = value.toString();
|
||||
}
|
||||
return (key === 'loc' || key === 'range') ? undefined : value;
|
||||
}
|
||||
|
||||
if (options.tolerant) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Check again without any location info.
|
||||
options.range = false;
|
||||
options.loc = false;
|
||||
syntax = sortedObject(syntax);
|
||||
expected = JSON.stringify(syntax, filter, 4);
|
||||
try {
|
||||
tree = espree.parse(code, options);
|
||||
tree = (options.comment || options.tokens) ? tree : tree.body[0];
|
||||
|
||||
if (options.tolerant) {
|
||||
for (i = 0, len = tree.errors.length; i < len; i += 1) {
|
||||
tree.errors[i] = errorToObject(tree.errors[i]);
|
||||
}
|
||||
}
|
||||
tree = sortedObject(tree);
|
||||
actual = JSON.stringify(tree, filter, 4);
|
||||
} catch (e) {
|
||||
throw new NotMatchingError(expected, e.toString());
|
||||
}
|
||||
if (expected !== actual) {
|
||||
throw new NotMatchingError(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
function testTokenize(espree, code, tokens) {
|
||||
'use strict';
|
||||
var options, expected, actual, tree;
|
||||
|
||||
options = {
|
||||
comment: true,
|
||||
tolerant: true,
|
||||
loc: true,
|
||||
range: true
|
||||
};
|
||||
|
||||
expected = JSON.stringify(tokens, null, 4);
|
||||
|
||||
try {
|
||||
tree = espree.tokenize(code, options);
|
||||
actual = JSON.stringify(tree, null, 4);
|
||||
} catch (e) {
|
||||
throw new NotMatchingError(expected, e.toString());
|
||||
}
|
||||
if (expected !== actual) {
|
||||
throw new NotMatchingError(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
function testError(espree, code, exception) {
|
||||
'use strict';
|
||||
var i, options, expected, actual, err, handleInvalidRegexFlag, tokenize;
|
||||
|
||||
// Different parsing options should give the same error.
|
||||
options = [
|
||||
{},
|
||||
{ comment: true },
|
||||
{ raw: true },
|
||||
{ raw: true, comment: true }
|
||||
];
|
||||
|
||||
// If handleInvalidRegexFlag is true, an invalid flag in a regular expression
|
||||
// will throw an exception. In some old version V8, this is not the case
|
||||
// and hence handleInvalidRegexFlag is false.
|
||||
handleInvalidRegexFlag = false;
|
||||
try {
|
||||
'test'.match(new RegExp('[a-z]', 'x'));
|
||||
} catch (e) {
|
||||
handleInvalidRegexFlag = true;
|
||||
}
|
||||
|
||||
exception.description = exception.message.replace(/Error: Line [0-9]+: /, '');
|
||||
|
||||
if (exception.tokenize) {
|
||||
tokenize = true;
|
||||
exception.tokenize = undefined;
|
||||
}
|
||||
expected = JSON.stringify(exception);
|
||||
|
||||
for (i = 0; i < options.length; i += 1) {
|
||||
|
||||
try {
|
||||
if (tokenize) {
|
||||
espree.tokenize(code, options[i])
|
||||
} else {
|
||||
espree.parse(code, options[i]);
|
||||
}
|
||||
} catch (e) {
|
||||
err = errorToObject(e);
|
||||
err.description = e.description;
|
||||
actual = JSON.stringify(err);
|
||||
}
|
||||
|
||||
if (expected !== actual) {
|
||||
|
||||
// Compensate for old V8 which does not handle invalid flag.
|
||||
if (exception.message.indexOf('Invalid regular expression') > 0) {
|
||||
if (typeof actual === 'undefined' && !handleInvalidRegexFlag) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotMatchingError(expected, actual);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function testAPI(espree, code, result) {
|
||||
'use strict';
|
||||
var expected, res, actual;
|
||||
|
||||
expected = JSON.stringify(result.result, null, 4);
|
||||
try {
|
||||
if (typeof result.property !== 'undefined') {
|
||||
res = espree[result.property];
|
||||
} else {
|
||||
res = espree[result.call].apply(espree, result.args);
|
||||
}
|
||||
actual = JSON.stringify(res, adjustRegexLiteral, 4);
|
||||
} catch (e) {
|
||||
throw new NotMatchingError(expected, e.toString());
|
||||
}
|
||||
if (expected !== actual) {
|
||||
throw new NotMatchingError(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
function runTest(espree, code, result) {
|
||||
'use strict';
|
||||
if (result.hasOwnProperty('lineNumber')) {
|
||||
testError(espree, code, result);
|
||||
} else if (result.hasOwnProperty('result')) {
|
||||
testAPI(espree, code, result);
|
||||
} else if (result instanceof Array) {
|
||||
testTokenize(espree, code, result);
|
||||
} else {
|
||||
testParse(espree, code, result);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
// Run all tests in a browser environment.
|
||||
runTests = function () {
|
||||
'use strict';
|
||||
var total = 0,
|
||||
failures = 0,
|
||||
category,
|
||||
fixture,
|
||||
source,
|
||||
tick,
|
||||
expected,
|
||||
index,
|
||||
len;
|
||||
|
||||
function setText(el, str) {
|
||||
if (typeof el.innerText === 'string') {
|
||||
el.innerText = str;
|
||||
} else {
|
||||
el.textContent = str;
|
||||
}
|
||||
}
|
||||
|
||||
function startCategory(category) {
|
||||
var report, e;
|
||||
report = document.getElementById('report');
|
||||
e = document.createElement('h4');
|
||||
setText(e, category);
|
||||
report.appendChild(e);
|
||||
}
|
||||
|
||||
function reportSuccess(code) {
|
||||
var report, e;
|
||||
report = document.getElementById('report');
|
||||
e = document.createElement('pre');
|
||||
e.setAttribute('class', 'code');
|
||||
setText(e, code);
|
||||
report.appendChild(e);
|
||||
}
|
||||
|
||||
function reportFailure(code, expected, actual) {
|
||||
var report, e;
|
||||
|
||||
report = document.getElementById('report');
|
||||
|
||||
e = document.createElement('p');
|
||||
setText(e, 'Code:');
|
||||
report.appendChild(e);
|
||||
|
||||
e = document.createElement('pre');
|
||||
e.setAttribute('class', 'code');
|
||||
setText(e, code);
|
||||
report.appendChild(e);
|
||||
|
||||
e = document.createElement('p');
|
||||
setText(e, 'Expected');
|
||||
report.appendChild(e);
|
||||
|
||||
e = document.createElement('pre');
|
||||
e.setAttribute('class', 'expected');
|
||||
setText(e, expected);
|
||||
report.appendChild(e);
|
||||
|
||||
e = document.createElement('p');
|
||||
setText(e, 'Actual');
|
||||
report.appendChild(e);
|
||||
|
||||
e = document.createElement('pre');
|
||||
e.setAttribute('class', 'actual');
|
||||
setText(e, actual);
|
||||
report.appendChild(e);
|
||||
}
|
||||
|
||||
setText(document.getElementById('version'), espree.version);
|
||||
|
||||
tick = new Date();
|
||||
for (category in testFixture) {
|
||||
if (testFixture.hasOwnProperty(category)) {
|
||||
startCategory(category);
|
||||
fixture = testFixture[category];
|
||||
for (source in fixture) {
|
||||
if (fixture.hasOwnProperty(source)) {
|
||||
expected = fixture[source];
|
||||
total += 1;
|
||||
try {
|
||||
runTest(espree, source, expected);
|
||||
reportSuccess(source, JSON.stringify(expected, null, 4));
|
||||
} catch (e) {
|
||||
failures += 1;
|
||||
reportFailure(source, e.expected, e.actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tick = (new Date()) - tick;
|
||||
|
||||
if (failures > 0) {
|
||||
document.getElementById('status').className = 'alert-box alert';
|
||||
setText(document.getElementById('status'), total + ' tests. ' +
|
||||
'Failures: ' + failures + '. ' + tick + ' ms.');
|
||||
} else {
|
||||
document.getElementById('status').className = 'alert-box success';
|
||||
setText(document.getElementById('status'), total + ' tests. ' +
|
||||
'No failure. ' + tick + ' ms.');
|
||||
}
|
||||
};
|
||||
} else {
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var espree = require('../espree'),
|
||||
diff = require('json-diff').diffString,
|
||||
total = 0,
|
||||
failures = [],
|
||||
tick = new Date(),
|
||||
expected,
|
||||
header,
|
||||
testFixture = require("./test");
|
||||
|
||||
Object.keys(testFixture).forEach(function (category) {
|
||||
Object.keys(testFixture[category]).forEach(function (source) {
|
||||
total += 1;
|
||||
expected = testFixture[category][source];
|
||||
try {
|
||||
runTest(espree, source, expected);
|
||||
} catch (e) {
|
||||
e.source = source;
|
||||
failures.push(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
tick = (new Date()) - tick;
|
||||
|
||||
header = total + ' tests. ' + failures.length + ' failures. ' +
|
||||
tick + ' ms';
|
||||
if (failures.length) {
|
||||
console.error(header);
|
||||
failures.forEach(function (failure) {
|
||||
try {
|
||||
var expectedObject = JSON.parse(failure.expected);
|
||||
var actualObject = JSON.parse(failure.actual);
|
||||
|
||||
console.error(failure.source + ': Expected\n ' +
|
||||
failure.expected.split('\n').join('\n ') +
|
||||
'\nto match\n ' + failure.actual + '\nDiff:\n' +
|
||||
diff(expectedObject, actualObject));
|
||||
} catch (ex) {
|
||||
console.error(failure.source + ': Expected\n ' +
|
||||
failure.expected.split('\n').join('\n ') +
|
||||
'\nto match\n ' + failure.actual);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(header);
|
||||
}
|
||||
process.exit(failures.length === 0 ? 0 : 1);
|
||||
}());
|
||||
}
|
||||
34
build/node_modules/hydrolysis/node_modules/espree/test/test.js
generated
vendored
Normal file
34
build/node_modules/hydrolysis/node_modules/espree/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @fileoverview Tests for parsing/tokenization.
|
||||
* @author Nicholas C. Zakas
|
||||
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var shelljs = require("shelljs"),
|
||||
fs = require("fs"),
|
||||
path = require("path");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Processing
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var files = shelljs.find("./tests/fixtures/ast");
|
||||
|
||||
files.filter(function(filename) {
|
||||
return path.extname(filename) === ".json";
|
||||
}).forEach(function(filename) {
|
||||
var basename = path.basename(filename, ".json");
|
||||
exports[basename] = JSON.parse(fs.readFileSync(filename, "utf8"), function(key, value) {
|
||||
|
||||
// JSON can't represent undefined, so we use a special value
|
||||
if (value === "espree@undefined") {
|
||||
return undefined;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
});
|
||||
70
build/node_modules/hydrolysis/package.json
generated
vendored
Normal file
70
build/node_modules/hydrolysis/package.json
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "hydrolysis@1.22.0",
|
||||
"_id": "hydrolysis@1.22.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-hNrgExeCFNLLCA13e4eZLSnnM2o=",
|
||||
"_location": "/hydrolysis",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "hydrolysis@1.22.0",
|
||||
"name": "hydrolysis",
|
||||
"escapedName": "hydrolysis",
|
||||
"rawSpec": "1.22.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.22.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/http2-push-manifest",
|
||||
"/vulcanize"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/hydrolysis/-/hydrolysis-1.22.0.tgz",
|
||||
"_shasum": "84dae013178214d2cb080d777b87992d29e7336a",
|
||||
"_spec": "hydrolysis@1.22.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/http2-push-manifest",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Polymer/hydrolysis/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"doctrine": "^0.7.0",
|
||||
"dom5": "^1.1.0",
|
||||
"es6-promise": "^2.1.0",
|
||||
"espree": "^2.0.1",
|
||||
"estraverse": "^3.1.0",
|
||||
"path-is-absolute": "^1.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Breaks polymers into monomers",
|
||||
"devDependencies": {
|
||||
"browserify": "^9.0.8",
|
||||
"chai": "^2.2.0",
|
||||
"jsdoc-to-markdown": "^1.0.3",
|
||||
"jshint": "^2.7.0",
|
||||
"mocha": "^2.2.4",
|
||||
"watch": "latest",
|
||||
"web-component-tester": "^3.3.21"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"LICENSE",
|
||||
"lib/"
|
||||
],
|
||||
"homepage": "https://github.com/Polymer/hydrolysis",
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "index.js",
|
||||
"name": "hydrolysis",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Polymer/hydrolysis.git"
|
||||
},
|
||||
"scripts": {
|
||||
"apidocs": "node_modules/jsdoc-to-markdown/bin/cli.js {index.js,lib/{analyzer,loader/*}.js} > API.md",
|
||||
"build": "browserify -d -r ./index.js:hydrolysis -o hydrolysis.js",
|
||||
"build:watch": "watch 'npm run build' ./lib",
|
||||
"release": "browserify -r ./index.js:hydrolysis -o hydrolysis.js",
|
||||
"test": "jshint index.js lib/ && npm run build && wct && mocha test/test.js"
|
||||
},
|
||||
"version": "1.22.0"
|
||||
}
|
||||
Reference in New Issue
Block a user