hydrolysis
Advanced tools
Comparing version 1.23.3 to 1.24.1-nobabel
@@ -12,3 +12,2 @@ /** | ||
'use strict'; | ||
require("babel-polyfill"); | ||
/** | ||
@@ -15,0 +14,0 @@ * Static analysis for Polymer. |
1144
lib/analyzer.js
@@ -11,42 +11,21 @@ /** | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) { | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function rejected(value) { | ||
try { | ||
step(generator.throw(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : new P(function (resolve) { | ||
resolve(result.value); | ||
}).then(fulfilled, rejected); | ||
} | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
var dom5 = require('dom5'); | ||
var url = require('url'); | ||
var docs = require('./ast-utils/docs'); | ||
var file_loader_1 = require('./loader/file-loader'); | ||
var import_parse_1 = require('./ast-utils/import-parse'); | ||
var js_parse_1 = require('./ast-utils/js-parse'); | ||
var noop_resolver_1 = require('./loader/noop-resolver'); | ||
var string_resolver_1 = require('./loader/string-resolver'); | ||
var fs_resolver_1 = require('./loader/fs-resolver'); | ||
var xhr_resolver_1 = require('./loader/xhr-resolver'); | ||
var error_swallowing_fs_resolver_1 = require('./loader/error-swallowing-fs-resolver'); | ||
const dom5 = require('dom5'); | ||
const url = require('url'); | ||
const docs = require('./ast-utils/docs'); | ||
const file_loader_1 = require('./loader/file-loader'); | ||
const import_parse_1 = require('./ast-utils/import-parse'); | ||
const js_parse_1 = require('./ast-utils/js-parse'); | ||
const noop_resolver_1 = require('./loader/noop-resolver'); | ||
const string_resolver_1 = require('./loader/string-resolver'); | ||
const fs_resolver_1 = require('./loader/fs-resolver'); | ||
const xhr_resolver_1 = require('./loader/xhr-resolver'); | ||
const error_swallowing_fs_resolver_1 = require('./loader/error-swallowing-fs-resolver'); | ||
function reduceMetadata(m1, m2) { | ||
@@ -56,3 +35,3 @@ return { | ||
features: m1.features.concat(m2.features), | ||
behaviors: m1.behaviors.concat(m2.behaviors) | ||
behaviors: m1.behaviors.concat(m2.behaviors), | ||
}; | ||
@@ -64,4 +43,3 @@ } | ||
*/ | ||
var Analyzer = function () { | ||
class Analyzer { | ||
/** | ||
@@ -72,6 +50,3 @@ * @param {boolean} attachAST If true, attach a parse5 compliant AST | ||
*/ | ||
function Analyzer(attachAST, loader) { | ||
_classCallCheck(this, Analyzer); | ||
constructor(attachAST, loader) { | ||
/** | ||
@@ -119,656 +94,458 @@ * A list of all elements the `Analyzer` has metadata for. | ||
} | ||
_createClass(Analyzer, [{ | ||
key: 'load', | ||
value: function load(href) { | ||
var _this = this; | ||
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)); | ||
}, 0); | ||
}).catch(function (err) { | ||
console.error("Error processing document at " + href); | ||
throw err; | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: '_parseHTML', | ||
/** | ||
* 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` | ||
*/ | ||
value: function _parseHTML(htmlImport, href) { | ||
var _this2 = this; | ||
if (href in this.html) { | ||
return this.html[href]; | ||
} | ||
var depsLoaded = []; | ||
var depHrefs = []; | ||
var metadataLoaded = Promise.resolve(EMPTY_METADATA); | ||
var parsed; | ||
try { | ||
parsed = import_parse_1.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); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = pseudoElements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var element = _step.value; | ||
element.contentHref = href; | ||
this.elements.push(element); | ||
this.elementsByTagName[element.is] = element; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
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); | ||
} | ||
} | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = parsed.import[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var link = _step2.value; | ||
var linkurl = dom5.getAttribute(link, 'href'); | ||
if (linkurl) { | ||
var resolvedUrl = url.resolve(baseUri, linkurl); | ||
depHrefs.push(resolvedUrl); | ||
depsLoaded.push(this._dependenciesLoadedFor(resolvedUrl, href)); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
load(href) { | ||
return this.loader.request(href).then((content) => { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
this._content[href] = content; | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
resolve(this._parseHTML(content, href)); | ||
} | ||
} | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator3 = parsed.style[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var styleElement = _step3.value; | ||
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) { | ||
_this2._content[styleHref] = content; | ||
return {}; | ||
})); | ||
} | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
} | ||
} | ||
} | ||
var depsStrLoaded = Promise.all(depsLoaded).then(function () { | ||
return depHrefs; | ||
}, 0); | ||
}).catch(function (err) { | ||
console.error("Error processing document at " + href); | ||
throw err; | ||
}); | ||
this.parsedDocuments[href] = parsed.ast; | ||
this.html[href] = { | ||
href: href, | ||
htmlLoaded: htmlLoaded, | ||
metadataLoaded: metadataLoaded, | ||
depHrefs: depHrefs, | ||
depsLoaded: depsStrLoaded | ||
}; | ||
}); | ||
} | ||
; | ||
/** | ||
* 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` | ||
*/ | ||
_parseHTML(htmlImport, href) { | ||
if (href in this.html) { | ||
return this.html[href]; | ||
} | ||
}, { | ||
key: '_processScripts', | ||
value: function _processScripts(scripts, href) { | ||
var _this3 = this; | ||
var scriptPromises = []; | ||
scripts.forEach(function (script) { | ||
scriptPromises.push(_this3._processScript(script, href)); | ||
}); | ||
return Promise.all(scriptPromises).then(function (metadataList) { | ||
// TODO(ajo) remove this cast. | ||
var list = metadataList; | ||
return list.reduce(reduceMetadata, EMPTY_METADATA); | ||
}); | ||
var depsLoaded = []; | ||
var depHrefs = []; | ||
var metadataLoaded = Promise.resolve(EMPTY_METADATA); | ||
var parsed; | ||
try { | ||
parsed = import_parse_1.importParse(htmlImport, href); | ||
} | ||
}, { | ||
key: '_processScript', | ||
value: function _processScript(script, href) { | ||
var _this4 = this; | ||
var src = dom5.getAttribute(script, 'src'); | ||
var parsedJs; | ||
if (!src) { | ||
try { | ||
parsedJs = js_parse_1.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); | ||
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); | ||
for (const element of pseudoElements) { | ||
element.contentHref = href; | ||
this.elements.push(element); | ||
this.elementsByTagName[element.is] = element; | ||
} | ||
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); | ||
} | ||
if (parsedJs.elements) { | ||
parsedJs.elements.forEach(function (element) { | ||
element.scriptElement = script; | ||
element.contentHref = href; | ||
_this4.elements.push(element); | ||
if (element.is in _this4.elementsByTagName) { | ||
console.warn('Ignoring duplicate element definition: ' + element.is); | ||
} else { | ||
_this4.elementsByTagName[element.is] = element; | ||
} | ||
}); | ||
} | ||
for (const link of parsed.import) { | ||
var linkurl = dom5.getAttribute(link, 'href'); | ||
if (linkurl) { | ||
var resolvedUrl = url.resolve(baseUri, linkurl); | ||
depHrefs.push(resolvedUrl); | ||
depsLoaded.push(this._dependenciesLoadedFor(resolvedUrl, href)); | ||
} | ||
if (parsedJs.features) { | ||
parsedJs.features.forEach(function (feature) { | ||
feature.contentHref = href; | ||
feature.scriptElement = script; | ||
}); | ||
this.features = this.features.concat(parsedJs.features); | ||
} | ||
for (const styleElement of parsed.style) { | ||
if (polymerExternalStyle(styleElement)) { | ||
var styleHref = dom5.getAttribute(styleElement, 'href'); | ||
if (href) { | ||
styleHref = url.resolve(baseUri, styleHref); | ||
depsLoaded.push(this.loader.request(styleHref).then((content) => { | ||
this._content[styleHref] = content; | ||
return {}; | ||
})); | ||
} | ||
} | ||
if (parsedJs.behaviors) { | ||
parsedJs.behaviors.forEach(function (behavior) { | ||
behavior.contentHref = href; | ||
_this4.behaviorsByName[behavior.is] = behavior; | ||
_this4.behaviorsByName[behavior.symbol] = behavior; | ||
}); | ||
this.behaviors = this.behaviors.concat(parsedJs.behaviors); | ||
} | ||
if (!Object.hasOwnProperty.call(this.parsedScripts, href)) { | ||
this.parsedScripts[href] = []; | ||
} | ||
var scriptElement; | ||
} | ||
} | ||
const depsStrLoaded = 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: depsStrLoaded | ||
}; | ||
return this.html[href]; | ||
} | ||
; | ||
_processScripts(scripts, href) { | ||
var scriptPromises = []; | ||
scripts.forEach((script) => { | ||
scriptPromises.push(this._processScript(script, href)); | ||
}); | ||
return Promise.all(scriptPromises).then(function (metadataList) { | ||
// TODO(ajo) remove this cast. | ||
var list = metadataList; | ||
return list.reduce(reduceMetadata, EMPTY_METADATA); | ||
}); | ||
} | ||
; | ||
_processScript(script, href) { | ||
const src = dom5.getAttribute(script, 'src'); | ||
var parsedJs; | ||
if (!src) { | ||
try { | ||
parsedJs = js_parse_1.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) { | ||
scriptElement = script; | ||
line = script.__locationDetail.line - 1; | ||
col = script.__locationDetail.column - 1; | ||
} | ||
this.parsedScripts[href].push({ | ||
ast: parsedJs.parsedScript, | ||
scriptElement: scriptElement | ||
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((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; | ||
} | ||
}); | ||
return Promise.resolve(parsedJs); | ||
} | ||
if (this.loader) { | ||
var resolvedSrc = url.resolve(href, src); | ||
return this.loader.request(resolvedSrc).then(function (content) { | ||
_this4._content[resolvedSrc] = content; | ||
var scriptText = dom5.constructors.text(content); | ||
dom5.append(script, scriptText); | ||
dom5.removeAttribute(script, 'src'); | ||
script.__hydrolysisInlined = src; | ||
return _this4._processScript(script, resolvedSrc); | ||
}).catch(function (err) { | ||
throw err; | ||
if (parsedJs.features) { | ||
parsedJs.features.forEach(function (feature) { | ||
feature.contentHref = href; | ||
feature.scriptElement = script; | ||
}); | ||
} else { | ||
return Promise.resolve(EMPTY_METADATA); | ||
this.features = this.features.concat(parsedJs.features); | ||
} | ||
} | ||
}, { | ||
key: '_dependenciesLoadedFor', | ||
value: function _dependenciesLoadedFor(href, root) { | ||
var _this5 = this; | ||
var found = {}; | ||
if (root !== undefined) { | ||
found[root] = true; | ||
} | ||
return this._getDependencies(href, found).then(function (deps) { | ||
var depPromises = deps.map(function (depHref) { | ||
return _this5.load(depHref).then(function (htmlMonomer) { | ||
return htmlMonomer.metadataLoaded; | ||
}); | ||
if (parsedJs.behaviors) { | ||
parsedJs.behaviors.forEach((behavior) => { | ||
behavior.contentHref = href; | ||
this.behaviorsByName[behavior.is] = behavior; | ||
this.behaviorsByName[behavior.symbol] = behavior; | ||
}); | ||
return Promise.all(depPromises); | ||
}); | ||
} | ||
}, { | ||
key: '_getDependencies', | ||
/** | ||
* 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. | ||
*/ | ||
value: function _getDependencies(href, found, transitive) { | ||
var _this6 = this; | ||
if (found === undefined) { | ||
found = {}; | ||
found[href] = true; | ||
this.behaviors = this.behaviors.concat(parsedJs.behaviors); | ||
} | ||
if (transitive === undefined) { | ||
transitive = true; | ||
if (!Object.hasOwnProperty.call(this.parsedScripts, href)) { | ||
this.parsedScripts[href] = []; | ||
} | ||
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(_this6._getDependencies(depHref, found)); | ||
} | ||
}); | ||
return Promise.all(transitiveDeps); | ||
}).then(function (transitiveDeps) { | ||
var alldeps = transitiveDeps.reduce(function (a, b) { | ||
return a.concat(b); | ||
}, []).concat(deps); | ||
return alldeps; | ||
var scriptElement; | ||
if (script.__ownerDocument && script.__ownerDocument == href) { | ||
scriptElement = script; | ||
} | ||
this.parsedScripts[href].push({ | ||
ast: parsedJs.parsedScript, | ||
scriptElement: scriptElement | ||
}); | ||
return Promise.resolve(parsedJs); | ||
} | ||
}, { | ||
key: 'elementsForFolder', | ||
/** | ||
* Returns the elements defined in the folder containing `href`. | ||
* @param {string} href path to search. | ||
*/ | ||
value: function elementsForFolder(href) { | ||
return this.elements.filter(function (element) { | ||
return matchesDocumentFolder(element, href); | ||
}); | ||
if (this.loader) { | ||
var resolvedSrc = url.resolve(href, src); | ||
return this.loader.request(resolvedSrc).then((content) => { | ||
this._content[resolvedSrc] = content; | ||
var scriptText = dom5.constructors.text(content); | ||
dom5.append(script, scriptText); | ||
dom5.removeAttribute(script, 'src'); | ||
script.__hydrolysisInlined = src; | ||
return this._processScript(script, resolvedSrc); | ||
}).catch(function (err) { throw err; }); | ||
} | ||
}, { | ||
key: 'behaviorsForFolder', | ||
/** | ||
* Returns the behaviors defined in the folder containing `href`. | ||
* @param {string} href path to search. | ||
* @return {Array.<BehaviorDescriptor>} | ||
*/ | ||
value: function behaviorsForFolder(href) { | ||
return this.behaviors.filter(function (behavior) { | ||
return matchesDocumentFolder(behavior, href); | ||
}); | ||
else { | ||
return Promise.resolve(EMPTY_METADATA); | ||
} | ||
}, { | ||
key: 'metadataTree', | ||
/** | ||
* 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} | ||
*/ | ||
value: function metadataTree(href) { | ||
var _this7 = this; | ||
return this.load(href).then(function (monomer) { | ||
var loadedHrefs = {}; | ||
loadedHrefs[href] = true; | ||
return _this7._metadataTree(monomer, loadedHrefs); | ||
}); | ||
} | ||
; | ||
_dependenciesLoadedFor(href, root) { | ||
var found = {}; | ||
if (root !== undefined) { | ||
found[root] = true; | ||
} | ||
}, { | ||
key: '_metadataTree', | ||
value: function _metadataTree(htmlMonomer, loadedHrefs) { | ||
return __awaiter(this, void 0, void 0, regeneratorRuntime.mark(function _callee() { | ||
var metadata, hrefs, depMetadata, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, href, metadataPromise; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (loadedHrefs === undefined) { | ||
loadedHrefs = {}; | ||
} | ||
_context.next = 3; | ||
return htmlMonomer.metadataLoaded; | ||
case 3: | ||
metadata = _context.sent; | ||
metadata = { | ||
elements: metadata.elements, | ||
features: metadata.features, | ||
behaviors: [], | ||
href: htmlMonomer.href | ||
}; | ||
_context.next = 7; | ||
return htmlMonomer.depsLoaded; | ||
case 7: | ||
hrefs = _context.sent; | ||
depMetadata = []; | ||
_iteratorNormalCompletion4 = true; | ||
_didIteratorError4 = false; | ||
_iteratorError4 = undefined; | ||
_context.prev = 12; | ||
_iterator4 = hrefs[Symbol.iterator](); | ||
case 14: | ||
if (_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done) { | ||
_context.next = 29; | ||
break; | ||
} | ||
href = _step4.value; | ||
metadataPromise = undefined; | ||
if (loadedHrefs[href]) { | ||
_context.next = 24; | ||
break; | ||
} | ||
loadedHrefs[href] = true; | ||
metadataPromise = this._metadataTree(this.html[href], loadedHrefs); | ||
_context.next = 22; | ||
return metadataPromise; | ||
case 22: | ||
_context.next = 25; | ||
break; | ||
case 24: | ||
metadataPromise = Promise.resolve({}); | ||
case 25: | ||
depMetadata.push(metadataPromise); | ||
case 26: | ||
_iteratorNormalCompletion4 = true; | ||
_context.next = 14; | ||
break; | ||
case 29: | ||
_context.next = 35; | ||
break; | ||
case 31: | ||
_context.prev = 31; | ||
_context.t0 = _context['catch'](12); | ||
_didIteratorError4 = true; | ||
_iteratorError4 = _context.t0; | ||
case 35: | ||
_context.prev = 35; | ||
_context.prev = 36; | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
} | ||
case 38: | ||
_context.prev = 38; | ||
if (!_didIteratorError4) { | ||
_context.next = 41; | ||
break; | ||
} | ||
throw _iteratorError4; | ||
case 41: | ||
return _context.finish(38); | ||
case 42: | ||
return _context.finish(35); | ||
case 43: | ||
return _context.abrupt('return', Promise.all(depMetadata).then(function (importMetadata) { | ||
// TODO(ajo): remove this when tsc stops having issues. | ||
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; | ||
}); | ||
})); | ||
case 44: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this, [[12, 31, 35, 43], [36,, 38, 42]]); | ||
})); | ||
} | ||
}, { | ||
key: '_inlineStyles', | ||
value: function _inlineStyles(ast, href) { | ||
var _this8 = this; | ||
var cssLinks = dom5.queryAll(ast, polymerExternalStyle); | ||
cssLinks.forEach(function (link) { | ||
var linkHref = dom5.getAttribute(link, 'href'); | ||
var uri = url.resolve(href, linkHref); | ||
var content = _this8._content[uri]; | ||
var style = dom5.constructors.element('style'); | ||
dom5.setTextContent(style, '\n' + content + '\n'); | ||
dom5.replace(link, style); | ||
return this._getDependencies(href, found).then((deps) => { | ||
var depPromises = deps.map((depHref) => { | ||
return this.load(depHref).then((htmlMonomer) => { | ||
return htmlMonomer.metadataLoaded; | ||
}); | ||
}); | ||
return cssLinks.length > 0; | ||
return Promise.all(depPromises); | ||
}); | ||
} | ||
; | ||
/** | ||
* 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. | ||
*/ | ||
_getDependencies(href, found, transitive) { | ||
if (found === undefined) { | ||
found = {}; | ||
found[href] = true; | ||
} | ||
}, { | ||
key: '_inlineScripts', | ||
value: function _inlineScripts(ast, href) { | ||
var _this9 = this; | ||
var scripts = dom5.queryAll(ast, externalScript); | ||
scripts.forEach(function (script) { | ||
var scriptHref = dom5.getAttribute(script, 'src'); | ||
var uri = url.resolve(href, scriptHref); | ||
var content = _this9._content[uri]; | ||
var inlined = dom5.constructors.element('script'); | ||
dom5.setTextContent(inlined, '\n' + content + '\n'); | ||
dom5.replace(script, inlined); | ||
}); | ||
return scripts.length > 0; | ||
if (transitive === undefined) { | ||
transitive = true; | ||
} | ||
}, { | ||
key: '_inlineImports', | ||
value: function _inlineImports(ast, href, loaded) { | ||
var _this10 = this; | ||
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); | ||
var deps = []; | ||
return this.load(href).then((htmlMonomer) => { | ||
var transitiveDeps = []; | ||
htmlMonomer.depHrefs.forEach((depHref) => { | ||
if (found[depHref]) { | ||
return; | ||
} | ||
var content = _this10.getLoadedAst(uri, loaded); | ||
dom5.replace(htmlImport, content); | ||
deps.push(depHref); | ||
found[depHref] = true; | ||
if (transitive) { | ||
transitiveDeps.push(this._getDependencies(depHref, found)); | ||
} | ||
}); | ||
return imports.length > 0; | ||
} | ||
}, { | ||
key: 'getLoadedAst', | ||
/** | ||
* 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>} | ||
*/ | ||
value: function getLoadedAst(href, loaded) { | ||
if (!loaded) { | ||
loaded = {}; | ||
return Promise.all(transitiveDeps); | ||
}).then(function (transitiveDeps) { | ||
var alldeps = transitiveDeps.reduce(function (a, b) { | ||
return a.concat(b); | ||
}, []).concat(deps); | ||
return alldeps; | ||
}); | ||
} | ||
; | ||
/** | ||
* Returns the elements defined in the folder containing `href`. | ||
* @param {string} href path to search. | ||
*/ | ||
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>} | ||
*/ | ||
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} | ||
*/ | ||
metadataTree(href) { | ||
return this.load(href).then((monomer) => { | ||
var loadedHrefs = {}; | ||
loadedHrefs[href] = true; | ||
return this._metadataTree(monomer, loadedHrefs); | ||
}); | ||
} | ||
; | ||
_metadataTree(htmlMonomer, loadedHrefs) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (loadedHrefs === undefined) { | ||
loadedHrefs = {}; | ||
} | ||
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; | ||
} | ||
}, { | ||
key: 'nodeWalkDocuments', | ||
/** | ||
* Calls `dom5.nodeWalkAll` on each document that `Anayzler` has laoded. | ||
*/ | ||
value: 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; | ||
} | ||
}, { | ||
key: 'nodeWalkAllDocuments', | ||
/** | ||
* Calls `dom5.nodeWalkAll` on each document that `Anayzler` has laoded. | ||
* | ||
* TODO: make nodeWalkAll & nodeWalkAllDocuments distict, or delete one. | ||
*/ | ||
value: function nodeWalkAllDocuments(predicate) { | ||
var results = []; | ||
for (var href in this.parsedDocuments) { | ||
var newNodes = dom5.nodeWalkAll(this.parsedDocuments[href], predicate); | ||
results = results.concat(newNodes); | ||
} | ||
return results; | ||
} | ||
}, { | ||
key: 'annotate', | ||
/** Annotates all loaded metadata with its documentation. */ | ||
value: function annotate() { | ||
var _this11 = this; | ||
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 elementHelper(descriptor) { | ||
docs.annotateElement(descriptor, behaviorsByName); | ||
let metadata = yield htmlMonomer.metadataLoaded; | ||
metadata = { | ||
elements: metadata.elements, | ||
features: metadata.features, | ||
behaviors: [], | ||
href: htmlMonomer.href | ||
}; | ||
this.elements.forEach(elementHelper); | ||
this.behaviors.forEach(elementHelper); // Same shape. | ||
this.behaviors.forEach(function (behavior) { | ||
if (behavior.is !== behavior.symbol && behavior.symbol) { | ||
_this11.behaviorsByName[behavior.symbol] = undefined; | ||
const hrefs = yield htmlMonomer.depsLoaded; | ||
var depMetadata = []; | ||
for (const href of hrefs) { | ||
let metadataPromise; | ||
if (!loadedHrefs[href]) { | ||
loadedHrefs[href] = true; | ||
metadataPromise = this._metadataTree(this.html[href], loadedHrefs); | ||
yield metadataPromise; | ||
} | ||
else { | ||
metadataPromise = Promise.resolve({}); | ||
} | ||
depMetadata.push(metadataPromise); | ||
} | ||
return Promise.all(depMetadata).then(function (importMetadata) { | ||
// TODO(ajo): remove this when tsc stops having issues. | ||
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; | ||
}); | ||
}); | ||
}); | ||
} | ||
; | ||
_inlineStyles(ast, href) { | ||
var cssLinks = dom5.queryAll(ast, polymerExternalStyle); | ||
cssLinks.forEach((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); | ||
}); | ||
return cssLinks.length > 0; | ||
} | ||
; | ||
_inlineScripts(ast, href) { | ||
var scripts = dom5.queryAll(ast, externalScript); | ||
scripts.forEach((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); | ||
}); | ||
return scripts.length > 0; | ||
} | ||
; | ||
_inlineImports(ast, href, loaded) { | ||
var imports = dom5.queryAll(ast, isHtmlImportNode); | ||
imports.forEach((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); | ||
}); | ||
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>} | ||
*/ | ||
getLoadedAst(href, loaded) { | ||
if (!loaded) { | ||
loaded = {}; | ||
} | ||
}, { | ||
key: 'clean', | ||
/** Removes redundant properties from the collected descriptors. */ | ||
value: function clean() { | ||
this.elements.forEach(docs.cleanElement); | ||
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. | ||
*/ | ||
nodeWalkDocuments(predicate) { | ||
var results = []; | ||
for (var href in this.parsedDocuments) { | ||
var newNodes = dom5.nodeWalkAll(this.parsedDocuments[href], predicate); | ||
results = results.concat(newNodes); | ||
} | ||
}]); | ||
return Analyzer; | ||
}(); | ||
return results; | ||
} | ||
; | ||
/** | ||
* Calls `dom5.nodeWalkAll` on each document that `Anayzler` has laoded. | ||
* | ||
* TODO: make nodeWalkAll & nodeWalkAllDocuments distict, or delete one. | ||
*/ | ||
nodeWalkAllDocuments(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. */ | ||
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 = (descriptor) => { | ||
docs.annotateElement(descriptor, behaviorsByName); | ||
}; | ||
this.elements.forEach(elementHelper); | ||
this.behaviors.forEach(elementHelper); // Same shape. | ||
this.behaviors.forEach((behavior) => { | ||
if (behavior.is !== behavior.symbol && behavior.symbol) { | ||
this.behaviorsByName[behavior.symbol] = undefined; | ||
} | ||
}); | ||
} | ||
; | ||
/** Removes redundant properties from the collected descriptors. */ | ||
clean() { | ||
this.elements.forEach(docs.cleanElement); | ||
} | ||
; | ||
} | ||
/** | ||
@@ -785,4 +562,2 @@ * Shorthand for transitively loading and processing all imports beginning at | ||
*/ | ||
Analyzer.analyze = function analyze(href, options) { | ||
@@ -796,14 +571,18 @@ options = options || {}; | ||
resolver = 'fs'; | ||
} else { | ||
} | ||
else { | ||
resolver = 'xhr'; | ||
} | ||
} | ||
var primaryResolver = undefined; | ||
let primaryResolver; | ||
if (resolver === 'fs') { | ||
primaryResolver = new fs_resolver_1.FSResolver(options); | ||
} else if (resolver === 'xhr') { | ||
} | ||
else if (resolver === 'xhr') { | ||
primaryResolver = new xhr_resolver_1.XHRResolver(options); | ||
} else if (resolver === 'permissive') { | ||
} | ||
else if (resolver === 'permissive') { | ||
primaryResolver = new error_swallowing_fs_resolver_1.ErrorSwallowingFSResolver(options); | ||
} else { | ||
} | ||
else { | ||
throw new Error("Resolver must be one of 'fs', 'xhr', or 'permissive'"); | ||
@@ -817,3 +596,3 @@ } | ||
var analyzer = new Analyzer(false, loader); | ||
return analyzer.metadataTree(href).then(function (root) { | ||
return analyzer.metadataTree(href).then((root) => { | ||
if (!options.noAnnotations) { | ||
@@ -867,29 +646,8 @@ analyzer.annotate(); | ||
var domModules = parsedImport['dom-module']; | ||
var _iteratorNormalCompletion5 = true; | ||
var _didIteratorError5 = false; | ||
var _iteratorError5 = undefined; | ||
try { | ||
for (var _iterator5 = domModules[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { | ||
var domModule = _step5.value; | ||
if (dom5.getAttribute(domModule, 'id') === element.is) { | ||
element.domModule = domModule; | ||
return; | ||
} | ||
for (const domModule of domModules) { | ||
if (dom5.getAttribute(domModule, 'id') === element.is) { | ||
element.domModule = domModule; | ||
return; | ||
} | ||
} catch (err) { | ||
_didIteratorError5 = true; | ||
_iteratorError5 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion5 && _iterator5.return) { | ||
_iterator5.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError5) { | ||
throw _iteratorError5; | ||
} | ||
} | ||
} | ||
} | ||
} |
@@ -11,5 +11,4 @@ /** | ||
'use strict'; | ||
var esutil = require('./esutil'); | ||
var astValue = require('./ast-value'); | ||
const esutil = require('./esutil'); | ||
const astValue = require('./ast-value'); | ||
function analyzeProperties(node) { | ||
@@ -20,3 +19,3 @@ var analyzedProps = []; | ||
} | ||
var obEx = node; | ||
const obEx = node; | ||
for (var i = 0; i < obEx.properties.length; i++) { | ||
@@ -39,3 +38,3 @@ var property = obEx.properties[i]; | ||
*/ | ||
var propDescExpr = property.value; | ||
const propDescExpr = property.value; | ||
for (var j = 0; j < propDescExpr.properties.length; j++) { | ||
@@ -59,3 +58,4 @@ var propertyArg = propDescExpr.properties[j]; | ||
prop.notify = astValue.expressionToValue(propertyArg.value); | ||
if (prop.notify === undefined) prop.notify = astValue.CANT_CONVERT; | ||
if (prop.notify === undefined) | ||
prop.notify = astValue.CANT_CONVERT; | ||
} | ||
@@ -67,3 +67,4 @@ break; | ||
prop.observerNode = propertyArg.value; | ||
if (prop.observer === undefined) prop.observer = astValue.CANT_CONVERT; | ||
if (prop.observer === undefined) | ||
prop.observer = astValue.CANT_CONVERT; | ||
} | ||
@@ -74,3 +75,4 @@ break; | ||
prop.readOnly = astValue.expressionToValue(propertyArg.value); | ||
if (prop.readOnly === undefined) prop.readOnly = astValue.CANT_CONVERT; | ||
if (prop.readOnly === undefined) | ||
prop.readOnly = astValue.CANT_CONVERT; | ||
} | ||
@@ -81,3 +83,4 @@ break; | ||
prop.reflectToAttribute = astValue.expressionToValue(propertyArg); | ||
if (prop.reflectToAttribute === undefined) prop.reflectToAttribute = astValue.CANT_CONVERT; | ||
if (prop.reflectToAttribute === undefined) | ||
prop.reflectToAttribute = astValue.CANT_CONVERT; | ||
} | ||
@@ -88,3 +91,4 @@ break; | ||
prop.default = astValue.expressionToValue(propertyArg.value); | ||
if (prop.default === undefined) prop.default = astValue.CANT_CONVERT; | ||
if (prop.default === undefined) | ||
prop.default = astValue.CANT_CONVERT; | ||
} | ||
@@ -108,2 +112,2 @@ break; | ||
exports.analyzeProperties = analyzeProperties; | ||
; | ||
; |
@@ -16,3 +16,2 @@ /** | ||
*/ | ||
function literalToValue(literal) { | ||
@@ -26,3 +25,4 @@ return literal.value; | ||
var argValue = expressionToValue(unary.argument); | ||
if (argValue === undefined) return; | ||
if (argValue === undefined) | ||
return; | ||
return unary.operator + argValue; | ||
@@ -41,6 +41,8 @@ } | ||
function functionDeclarationToValue(fn) { | ||
if (fn.body.type == "BlockStatement") return blockStatementToValue(fn.body); | ||
if (fn.body.type == "BlockStatement") | ||
return blockStatementToValue(fn.body); | ||
} | ||
function functionExpressionToValue(fn) { | ||
if (fn.body.type == "BlockStatement") return blockStatementToValue(fn.body); | ||
if (fn.body.type == "BlockStatement") | ||
return blockStatementToValue(fn.body); | ||
} | ||
@@ -52,3 +54,4 @@ /** | ||
for (var i = block.body.length - 1; i >= 0; i--) { | ||
if (block.body[i].type === "ReturnStatement") return returnStatementToValue(block.body[i]); | ||
if (block.body[i].type === "ReturnStatement") | ||
return returnStatementToValue(block.body[i]); | ||
} | ||
@@ -69,4 +72,6 @@ } | ||
var v = expressionToValue(arry.elements[i]); | ||
if (v === undefined) continue; | ||
if (i !== 0) value += ', '; | ||
if (v === undefined) | ||
continue; | ||
if (i !== 0) | ||
value += ', '; | ||
value += v; | ||
@@ -85,4 +90,6 @@ } | ||
var v = expressionToValue(obj.properties[i].value); | ||
if (v === undefined) continue; | ||
if (i !== 0) value += ', '; | ||
if (v === undefined) | ||
continue; | ||
if (i !== 0) | ||
value += ', '; | ||
value += '"' + k + '": ' + v; | ||
@@ -141,2 +148,2 @@ } | ||
exports.expressionToValue = expressionToValue; | ||
exports.CANT_CONVERT = 'UNKNOWN'; | ||
exports.CANT_CONVERT = 'UNKNOWN'; |
@@ -11,11 +11,10 @@ /** | ||
'use strict'; | ||
var docs = require('./docs'); | ||
var esutil = require('./esutil'); | ||
var jsdoc = require('./jsdoc'); | ||
var astValue = require('./ast-value'); | ||
var declaration_property_handlers_1 = require('./declaration-property-handlers'); | ||
const docs = require('./docs'); | ||
const esutil = require('./esutil'); | ||
const jsdoc = require('./jsdoc'); | ||
const astValue = require('./ast-value'); | ||
const declaration_property_handlers_1 = require('./declaration-property-handlers'); | ||
function dedupe(array, keyFunc) { | ||
var bucket = {}; | ||
array.forEach(function (el) { | ||
array.forEach((el) => { | ||
var key = keyFunc(el); | ||
@@ -28,3 +27,3 @@ if (key in bucket) { | ||
var returned = []; | ||
Object.keys(bucket).forEach(function (k) { | ||
Object.keys(bucket).forEach((k) => { | ||
returned.push(bucket[k]); | ||
@@ -46,3 +45,3 @@ }); | ||
function mergeBehavior(newBehavior) { | ||
var isBehaviorImpl = function isBehaviorImpl(b) { | ||
var isBehaviorImpl = (b) => { | ||
// filter out BehaviorImpl | ||
@@ -52,8 +51,11 @@ return b.indexOf(newBehavior.is) === -1; | ||
for (var i = 0; i < behaviors.length; i++) { | ||
if (newBehavior.is !== behaviors[i].is) continue; | ||
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 { | ||
if (newBehavior.desc.length > behaviors[i].desc.length) | ||
behaviors[i].desc = newBehavior.desc; | ||
} | ||
else { | ||
behaviors[i].desc = newBehavior.desc; | ||
@@ -66,5 +68,3 @@ } | ||
behaviors[i].events = (behaviors[i].events || []).concat(newBehavior.events || []); | ||
behaviors[i].events = dedupe(behaviors[i].events, function (e) { | ||
return e.name; | ||
}); | ||
behaviors[i].events = dedupe(behaviors[i].events, (e) => { return e.name; }); | ||
// merge properties | ||
@@ -75,3 +75,5 @@ behaviors[i].properties = (behaviors[i].properties || []).concat(newBehavior.properties || []); | ||
// merge behaviors | ||
behaviors[i].behaviors = (behaviors[i].behaviors || []).concat(newBehavior.behaviors || []).filter(isBehaviorImpl); | ||
behaviors[i].behaviors = | ||
(behaviors[i].behaviors || []).concat(newBehavior.behaviors || []) | ||
.filter(isBehaviorImpl); | ||
return behaviors[i]; | ||
@@ -91,3 +93,3 @@ } | ||
case 'VariableDeclaration': | ||
var n = node; | ||
const n = node; | ||
return n.declarations.length > 0 ? n.declarations[0].init : null; | ||
@@ -101,6 +103,8 @@ } | ||
function isSimpleBehaviorArray(expression) { | ||
if (!expression || expression.type !== 'ArrayExpression') return false; | ||
var arrayExpr = expression; | ||
if (!expression || expression.type !== 'ArrayExpression') | ||
return false; | ||
const arrayExpr = expression; | ||
for (var i = 0; i < arrayExpr.elements.length; i++) { | ||
if (arrayExpr.elements[i].type !== 'MemberExpression' && arrayExpr.elements[i].type !== 'Identifier') { | ||
if (arrayExpr.elements[i].type !== 'MemberExpression' && | ||
arrayExpr.elements[i].type !== 'Identifier') { | ||
return false; | ||
@@ -120,9 +124,11 @@ } | ||
if (expression && expression.type === 'ArrayExpression') { | ||
var arrExpr = expression; | ||
const arrExpr = expression; | ||
for (var i = 0; i < arrExpr.elements.length; i++) { | ||
if (arrExpr.elements[i].type === 'MemberExpression' || arrExpr.elements[i].type === 'Identifier') { | ||
if (arrExpr.elements[i].type === 'MemberExpression' || | ||
arrExpr.elements[i].type === 'Identifier') { | ||
chained.push(astValue.expressionToValue(arrExpr.elements[i])); | ||
} | ||
} | ||
if (chained.length > 0) currentBehavior.behaviors = chained; | ||
if (chained.length > 0) | ||
currentBehavior.behaviors = chained; | ||
} | ||
@@ -144,3 +150,5 @@ } | ||
return { desc: event }; | ||
}) | ||
}), | ||
behaviors: [], | ||
observers: [] | ||
}; | ||
@@ -150,3 +158,4 @@ propertyHandlers = declaration_property_handlers_1.declarationPropertyHandlers(currentBehavior); | ||
// Make sure that we actually parsed a behavior tag! | ||
if (!jsdoc.hasTag(currentBehavior.jsdoc, 'polymerBehavior') && symbol !== templatizer) { | ||
if (!jsdoc.hasTag(currentBehavior.jsdoc, 'polymerBehavior') && | ||
symbol !== templatizer) { | ||
currentBehavior = null; | ||
@@ -172,5 +181,8 @@ propertyHandlers = null; | ||
// 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); | ||
if (!currentBehavior.observers) | ||
currentBehavior.observers = []; | ||
if (!currentBehavior.properties) | ||
currentBehavior.properties = []; | ||
if (behaviors.indexOf(currentBehavior) === -1) | ||
behaviors.push(currentBehavior); | ||
currentBehavior = null; | ||
@@ -184,4 +196,5 @@ propertyHandlers = null; | ||
*/ | ||
enterVariableDeclaration: function enterVariableDeclaration(node, parent) { | ||
if (node.declarations.length !== 1) return; // Ambiguous. | ||
enterVariableDeclaration: function (node, parent) { | ||
if (node.declarations.length !== 1) | ||
return; // Ambiguous. | ||
_initBehavior(node, function () { | ||
@@ -194,3 +207,3 @@ return esutil.objectKeyToString(node.declarations[0].id); | ||
*/ | ||
enterAssignmentExpression: function enterAssignmentExpression(node, parent) { | ||
enterAssignmentExpression: function (node, parent) { | ||
_initBehavior(parent, function () { | ||
@@ -204,4 +217,6 @@ return esutil.objectKeyToString(node.left); | ||
*/ | ||
enterObjectExpression: function enterObjectExpression(node, parent) { | ||
if (!currentBehavior || currentBehavior.properties) return; | ||
enterObjectExpression: function (node, parent) { | ||
if (!currentBehavior || currentBehavior.properties) { | ||
return; | ||
} | ||
currentBehavior.properties = currentBehavior.properties || []; | ||
@@ -220,3 +235,4 @@ currentBehavior.observers = currentBehavior.observers || []; | ||
propertyHandlers[name](prop.value); | ||
} else { | ||
} | ||
else { | ||
currentBehavior.properties.push(esutil.toPropertyDescriptor(prop)); | ||
@@ -227,3 +243,3 @@ } | ||
currentBehavior = null; | ||
} | ||
}, | ||
}; | ||
@@ -233,2 +249,2 @@ return { visitors: visitors, behaviors: behaviors }; | ||
exports.behaviorFinder = behaviorFinder; | ||
; | ||
; |
@@ -11,5 +11,4 @@ /** | ||
'use strict'; | ||
var astValue = require('./ast-value'); | ||
var analyze_properties_1 = require('./analyze-properties'); | ||
const astValue = require('./ast-value'); | ||
const analyze_properties_1 = require('./analyze-properties'); | ||
/** | ||
@@ -25,3 +24,3 @@ * Returns an object containing functions that will annotate `declaration` with | ||
return { | ||
is: function is(node) { | ||
is: function (node) { | ||
if (node.type == 'Literal') { | ||
@@ -31,3 +30,3 @@ declaration.is = node.value.toString(); | ||
}, | ||
properties: function properties(node) { | ||
properties: function (node) { | ||
var props = analyze_properties_1.analyzeProperties(node); | ||
@@ -38,69 +37,28 @@ for (var i = 0; i < props.length; i++) { | ||
}, | ||
behaviors: function behaviors(node) { | ||
behaviors: function (node) { | ||
if (node.type != 'ArrayExpression') { | ||
return; | ||
} | ||
var arrNode = node; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = arrNode.elements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var element = _step.value; | ||
var v = astValue.expressionToValue(element); | ||
if (v === undefined) { | ||
v = astValue.CANT_CONVERT; | ||
} | ||
declaration.behaviors.push(v); | ||
const arrNode = node; | ||
for (const element of arrNode.elements) { | ||
let v = astValue.expressionToValue(element); | ||
if (v === undefined) { | ||
v = astValue.CANT_CONVERT; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
declaration.behaviors.push(v); | ||
} | ||
}, | ||
observers: function observers(node) { | ||
observers: function (node) { | ||
if (node.type != 'ArrayExpression') { | ||
return; | ||
} | ||
var arrNode = node; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = arrNode.elements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var element = _step2.value; | ||
var v = astValue.expressionToValue(element); | ||
if (v === undefined) v = astValue.CANT_CONVERT; | ||
declaration.observers.push({ | ||
javascriptNode: element, | ||
expression: v | ||
}); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
const arrNode = node; | ||
for (let element of arrNode.elements) { | ||
var v = astValue.expressionToValue(element); | ||
if (v === undefined) | ||
v = astValue.CANT_CONVERT; | ||
declaration.observers.push({ | ||
javascriptNode: element, | ||
expression: v | ||
}); | ||
} | ||
@@ -110,2 +68,2 @@ } | ||
} | ||
exports.declarationPropertyHandlers = declarationPropertyHandlers; | ||
exports.declarationPropertyHandlers = declarationPropertyHandlers; |
@@ -10,2 +10,2 @@ /** | ||
*/ | ||
'use strict'; | ||
'use strict'; |
@@ -11,9 +11,29 @@ /** | ||
'use strict'; | ||
var jsdoc = require('./jsdoc'); | ||
var dom5 = require('dom5'); | ||
const jsdoc = require('./jsdoc'); | ||
const dom5 = require('dom5'); | ||
/** Properties on element prototypes that are purely configuration. */ | ||
var ELEMENT_CONFIGURATION = ['attached', 'attributeChanged', 'beforeRegister', 'configure', 'constructor', 'created', 'detached', 'enableCustomStyleProperties', 'extends', 'hostAttributes', 'is', 'listeners', 'mixins', 'properties', 'ready', 'registered']; | ||
const ELEMENT_CONFIGURATION = [ | ||
'attached', | ||
'attributeChanged', | ||
'beforeRegister', | ||
'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']; | ||
const HANDLED_TAGS = [ | ||
'param', | ||
'return', | ||
'type', | ||
]; | ||
/** | ||
@@ -32,3 +52,4 @@ * Annotates Hydrolysis descriptors, processing any `desc` properties as JSDoc. | ||
function annotate(descriptor) { | ||
if (!descriptor || descriptor.jsdoc) return descriptor; | ||
if (!descriptor || descriptor.jsdoc) | ||
return descriptor; | ||
if (typeof descriptor.desc === 'string') { | ||
@@ -111,9 +132,10 @@ descriptor.jsdoc = jsdoc.parseJsdoc(descriptor.desc); | ||
} | ||
for (var i = from.behaviors.length - 1; i >= 0; i--) { | ||
for (let i = from.behaviors.length - 1; i >= 0; i--) { | ||
// TODO: what's up with behaviors sometimes being a literal, and sometimes | ||
// being a descriptor object? | ||
var localBehavior = from.behaviors[i]; | ||
const localBehavior = from.behaviors[i]; | ||
var definedBehavior = behaviorsByName[localBehavior] || behaviorsByName[localBehavior.symbol]; | ||
if (!definedBehavior) { | ||
console.warn("Behavior " + localBehavior + " not found when mixing " + "properties into " + to.is + "!"); | ||
console.warn("Behavior " + localBehavior + " not found when mixing " + | ||
"properties into " + to.is + "!"); | ||
return; | ||
@@ -126,6 +148,7 @@ } | ||
if (descriptor.behaviors) { | ||
for (var i = descriptor.behaviors.length - 1; i >= 0; i--) { | ||
var behavior = descriptor.behaviors[i]; | ||
for (let i = descriptor.behaviors.length - 1; i >= 0; i--) { | ||
const behavior = descriptor.behaviors[i]; | ||
if (!behaviorsByName[behavior]) { | ||
console.warn("Behavior " + behavior + " not found when mixing " + "properties into " + descriptor.is + "!"); | ||
console.warn("Behavior " + behavior + " not found when mixing " + | ||
"properties into " + descriptor.is + "!"); | ||
break; | ||
@@ -172,5 +195,7 @@ } | ||
return 1; | ||
} else if (!a.private && b.private) { | ||
} | ||
else if (!a.private && b.private) { | ||
return -1; | ||
} else { | ||
} | ||
else { | ||
return a.name.localeCompare(b.name); | ||
@@ -203,5 +228,7 @@ } | ||
// process @params | ||
descriptor.params = (descriptor.jsdoc.tags || []).filter(function (tag) { | ||
descriptor.params = (descriptor.jsdoc.tags || []) | ||
.filter(function (tag) { | ||
return tag.tag === 'param'; | ||
}).map(function (tag) { | ||
}) | ||
.map(function (tag) { | ||
return { | ||
@@ -228,3 +255,4 @@ type: tag.type || "N/A", | ||
} | ||
if (!ignoreConfiguration && ELEMENT_CONFIGURATION.indexOf(descriptor.name) !== -1) { | ||
if (!ignoreConfiguration && | ||
ELEMENT_CONFIGURATION.indexOf(descriptor.name) !== -1) { | ||
descriptor.private = true; | ||
@@ -234,3 +262,4 @@ descriptor.configuration = true; | ||
// @type JSDoc wins | ||
descriptor.type = jsdoc.getTag(descriptor.jsdoc, 'type', 'type') || descriptor.type; | ||
descriptor.type = | ||
jsdoc.getTag(descriptor.jsdoc, 'type', 'type') || descriptor.type; | ||
if (descriptor.type.match(/^function/i)) { | ||
@@ -255,3 +284,3 @@ _annotateFunctionProperty(descriptor); | ||
type: returnTag.type, | ||
desc: returnTag.description | ||
desc: returnTag.description, | ||
}; | ||
@@ -264,3 +293,4 @@ } | ||
(descriptor.jsdoc && descriptor.jsdoc.tags || []).forEach(function (tag) { | ||
if (tag.tag !== 'param') return; | ||
if (tag.tag !== 'param') | ||
return; | ||
var param = paramsByName[tag.name]; | ||
@@ -284,3 +314,3 @@ if (!param) { | ||
function featureElement(features) { | ||
var properties = features.reduce(function (result, feature) { | ||
var properties = features.reduce((result, feature) => { | ||
return result.concat(feature.properties); | ||
@@ -293,3 +323,9 @@ }, []); | ||
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.' | ||
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.', | ||
}; | ||
@@ -305,3 +341,4 @@ } | ||
function clean(descriptor) { | ||
if (!descriptor.jsdoc) return; | ||
if (!descriptor.jsdoc) | ||
return; | ||
// The doctext was written to `descriptor.desc` | ||
@@ -313,3 +350,4 @@ delete descriptor.jsdoc.description; | ||
// Drop any tags we've consumed. | ||
if (HANDLED_TAGS.indexOf(tag.tag) !== -1) return; | ||
if (HANDLED_TAGS.indexOf(tag.tag) !== -1) | ||
return; | ||
cleanTags.push(tag); | ||
@@ -320,3 +358,4 @@ }); | ||
delete descriptor.jsdoc; | ||
} else { | ||
} | ||
else { | ||
descriptor.jsdoc.tags = cleanTags; | ||
@@ -357,3 +396,3 @@ } | ||
if (pseudoTag) { | ||
var element = { | ||
let element = { | ||
is: pseudoTag, | ||
@@ -363,3 +402,3 @@ type: 'element', | ||
properties: [], | ||
desc: parsedJsdoc.description | ||
desc: parsedJsdoc.description, | ||
}; | ||
@@ -396,11 +435,15 @@ annotateElementHeader(element); | ||
} | ||
if (found.length === 0) return null; | ||
return found.filter(function (comment) { | ||
if (found.length === 0) | ||
return null; | ||
return found | ||
.filter(function (comment) { | ||
// skip @license comments | ||
if (comment && comment.indexOf('@license') === -1) { | ||
return true; | ||
} else { | ||
} | ||
else { | ||
return false; | ||
} | ||
}).map(jsdoc.unindent).join('\n'); | ||
}) | ||
.map(jsdoc.unindent).join('\n'); | ||
} | ||
@@ -410,4 +453,5 @@ function _findLastChildNamed(name, parent) { | ||
for (var i = children.length - 1; i >= 0; i--) { | ||
var child = children[i]; | ||
if (child.nodeName === name) return child; | ||
let child = children[i]; | ||
if (child.nodeName === name) | ||
return child; | ||
} | ||
@@ -419,3 +463,3 @@ return null; | ||
for (var i = 0; i < node.attrs.length; i++) { | ||
var attr = node.attrs[i]; | ||
let attr = node.attrs[i]; | ||
if (attr.name === name) { | ||
@@ -425,2 +469,2 @@ return attr.value; | ||
} | ||
} | ||
} |
@@ -11,7 +11,6 @@ /** | ||
'use strict'; | ||
var estraverse = require('estraverse'); | ||
var esutil = require('./esutil'); | ||
var declaration_property_handlers_1 = require('./declaration-property-handlers'); | ||
var docs = require('./docs'); | ||
const estraverse = require('estraverse'); | ||
const esutil = require('./esutil'); | ||
const declaration_property_handlers_1 = require('./declaration-property-handlers'); | ||
const docs = require('./docs'); | ||
function elementFinder() { | ||
@@ -44,5 +43,3 @@ /** | ||
leaveClassDeclaration: function leaveClassDeclaration(node, parent) { | ||
element.properties.map(function (property) { | ||
return docs.annotate(property); | ||
}); | ||
element.properties.map(property => docs.annotate(property)); | ||
if (element) { | ||
@@ -59,7 +56,7 @@ elements.push(element); | ||
} | ||
var left = node.left; | ||
const left = node.left; | ||
if (left && left.object && left.object.type !== 'ThisExpression') { | ||
return; | ||
} | ||
var prop = left.property; | ||
const prop = left.property; | ||
if (prop && prop.name) { | ||
@@ -86,3 +83,3 @@ var name = prop.name; | ||
}; | ||
var propDesc = docs.annotate(esutil.toPropertyDescriptor(prop)); | ||
const propDesc = docs.annotate(esutil.toPropertyDescriptor(prop)); | ||
if (prop && prop.kind === 'get' && (propDesc.name === 'behaviors' || propDesc.name === 'observers')) { | ||
@@ -92,11 +89,13 @@ var returnStatement = node.value.body.body[0]; | ||
if (propDesc.name === 'behaviors') { | ||
argument.elements.forEach(function (elementObject) { | ||
argument.elements.forEach((elementObject) => { | ||
element.behaviors.push(elementObject.name); | ||
}); | ||
} else { | ||
argument.elements.forEach(function (elementObject) { | ||
} | ||
else { | ||
argument.elements.forEach((elementObject) => { | ||
element.observers.push({ javascriptNode: elementObject, expression: elementObject.raw }); | ||
}); | ||
} | ||
} else { | ||
} | ||
else { | ||
element.properties.push(propDesc); | ||
@@ -112,3 +111,3 @@ } | ||
if (callee.type == 'Identifier') { | ||
var ident = callee; | ||
const ident = callee; | ||
if (ident.name == 'Polymer') { | ||
@@ -128,4 +127,5 @@ element = { | ||
var callee = node.callee; | ||
if (callee.type == 'Identifier') { | ||
var ident = callee; | ||
var args = node.arguments; | ||
if (callee.type == 'Identifier' && args.length === 1 && args[0].type === 'ObjectExpression') { | ||
const ident = callee; | ||
if (ident.name == 'Polymer') { | ||
@@ -168,5 +168,7 @@ if (element) { | ||
getters[descriptor.name] = descriptor; | ||
} else if (descriptor.setter) { | ||
} | ||
else if (descriptor.setter) { | ||
setters[descriptor.name] = descriptor; | ||
} else { | ||
} | ||
else { | ||
element.properties.push(esutil.toPropertyDescriptor(prop)); | ||
@@ -183,3 +185,4 @@ } | ||
definedProperties[set.name] = set; | ||
} else { | ||
} | ||
else { | ||
definedProperties[set.name].setter = true; | ||
@@ -199,2 +202,2 @@ } | ||
exports.elementFinder = elementFinder; | ||
; | ||
; |
@@ -11,7 +11,4 @@ /** | ||
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var estraverse = require("estraverse"); | ||
var escodegen = require('escodegen'); | ||
const estraverse = require("estraverse"); | ||
const escodegen = require('escodegen'); | ||
/** | ||
@@ -29,3 +26,4 @@ * Returns whether an Espree node matches a particular object path. | ||
function matchesCallExpression(expression, path) { | ||
if (!expression.property || !expression.object) return; | ||
if (!expression.property || !expression.object) | ||
return; | ||
console.assert(path.length >= 2); | ||
@@ -35,5 +33,6 @@ if (expression.property.type !== 'Identifier') { | ||
} | ||
var property = expression.property; | ||
const property = expression.property; | ||
// Unravel backwards, make sure properties match each step of the way. | ||
if (property.name !== path[path.length - 1]) return false; | ||
if (property.name !== path[path.length - 1]) | ||
return false; | ||
// We've got ourselves a final member expression. | ||
@@ -62,3 +61,3 @@ if (path.length == 2 && expression.object.type === 'Identifier') { | ||
if (key.type == 'MemberExpression') { | ||
var mEx = key; | ||
let mEx = key; | ||
return objectKeyToString(mEx.object) + '.' + objectKeyToString(mEx.property); | ||
@@ -68,6 +67,6 @@ } | ||
exports.objectKeyToString = objectKeyToString; | ||
var CLOSURE_CONSTRUCTOR_MAP = { | ||
const CLOSURE_CONSTRUCTOR_MAP = { | ||
'Boolean': 'boolean', | ||
'Number': 'number', | ||
'String': 'string' | ||
'String': 'string', | ||
}; | ||
@@ -85,11 +84,14 @@ /** | ||
return node.type.substr(0, node.type.length - 10); | ||
} else if (node.type === 'Literal') { | ||
return _typeof(node.value); | ||
} else if (node.type === 'Identifier') { | ||
var ident = node; | ||
} | ||
else if (node.type === 'Literal') { | ||
return typeof node.value; | ||
} | ||
else if (node.type === 'Identifier') { | ||
let ident = node; | ||
return CLOSURE_CONSTRUCTOR_MAP[ident.name] || ident.name; | ||
} else { | ||
} | ||
else { | ||
throw { | ||
message: 'Unknown Closure type for node: ' + node.type, | ||
location: node.loc.start | ||
location: node.loc.start, | ||
}; | ||
@@ -100,3 +102,3 @@ } | ||
function getAttachedComment(node) { | ||
var comments = getLeadingComments(node) || getLeadingComments(node['key']); | ||
const comments = getLeadingComments(node) || getLeadingComments(node['key']); | ||
if (!comments) { | ||
@@ -114,6 +116,8 @@ return; | ||
estraverse.traverse(node, { | ||
enter: function enter(node) { | ||
var comments = (node.leadingComments || []).concat(node.trailingComments || []).map(function (commentAST) { | ||
enter: (node) => { | ||
var comments = (node.leadingComments || []).concat(node.trailingComments || []) | ||
.map(function (commentAST) { | ||
return commentAST.value; | ||
}).filter(function (comment) { | ||
}) | ||
.filter(function (comment) { | ||
return comment.indexOf("@event") != -1; | ||
@@ -128,3 +132,3 @@ }); | ||
// dedup | ||
return eventComments.filter(function (el, index, array) { | ||
return eventComments.filter((el, index, array) => { | ||
return array.indexOf(el) === index; | ||
@@ -139,3 +143,4 @@ }); | ||
var comments = node.leadingComments; | ||
if (!comments || comments.length === 0) return; | ||
if (!comments || comments.length === 0) | ||
return; | ||
return comments.map(function (comment) { | ||
@@ -163,4 +168,4 @@ return comment.value; | ||
if (type === 'Function') { | ||
var value = node.value; | ||
result.params = (value.params || []).map(function (param) { | ||
const value = node.value; | ||
result.params = (value.params || []).map((param) => { | ||
// With ES6 we can have a variety of param patterns. Best to leave the | ||
@@ -173,2 +178,2 @@ // formatting to escodegen. | ||
} | ||
exports.toPropertyDescriptor = toPropertyDescriptor; | ||
exports.toPropertyDescriptor = toPropertyDescriptor; |
@@ -11,4 +11,3 @@ /** | ||
'use strict'; | ||
var esutil = require('./esutil'); | ||
const esutil = require('./esutil'); | ||
var numFeatures = 0; | ||
@@ -27,4 +26,5 @@ function featureFinder() { | ||
} | ||
var objExpr = featureNode; | ||
if (!objExpr.properties) return; | ||
const objExpr = featureNode; | ||
if (!objExpr.properties) | ||
return; | ||
feature.properties = objExpr.properties.map(esutil.toPropertyDescriptor); | ||
@@ -34,3 +34,3 @@ } | ||
enterCallExpression: function enterCallExpression(node, parent) { | ||
var isAddFeatureCall = esutil.matchesCallExpression(node.callee, ['Polymer', 'Base', '_addFeature']); | ||
const isAddFeatureCall = esutil.matchesCallExpression(node.callee, ['Polymer', 'Base', '_addFeature']); | ||
if (!isAddFeatureCall) { | ||
@@ -44,3 +44,3 @@ return; | ||
features.push(feature); | ||
} | ||
}, | ||
}; | ||
@@ -50,2 +50,2 @@ return { visitors: visitors, features: features }; | ||
exports.featureFinder = featureFinder; | ||
; | ||
; |
@@ -1,1 +0,1 @@ | ||
"use strict"; | ||
"use strict"; |
@@ -11,4 +11,3 @@ /** | ||
'use strict'; | ||
var dom5 = require('dom5'); | ||
const dom5 = require('dom5'); | ||
var p = dom5.predicates; | ||
@@ -18,5 +17,5 @@ var isHtmlImportNode = p.AND(p.hasTagName('link'), p.hasAttrValue('rel', 'import'), p.NOT(p.hasAttrValue('type', 'css'))); | ||
// inline style | ||
p.hasTagName('style'), | ||
p.hasTagName('style'), | ||
// external stylesheet | ||
p.AND(p.hasTagName('link'), p.hasAttrValue('rel', 'stylesheet')), | ||
p.AND(p.hasTagName('link'), p.hasAttrValue('rel', 'stylesheet')), | ||
// polymer specific external stylesheet | ||
@@ -28,13 +27,19 @@ p.AND(p.hasTagName('link'), p.hasAttrValue('rel', 'import'), p.hasAttrValue('type', 'css'))); | ||
registry.import.push(node); | ||
} else if (isStyleNode(node)) { | ||
} | ||
else if (isStyleNode(node)) { | ||
registry.style.push(node); | ||
} else if (isJSScriptNode(node)) { | ||
} | ||
else if (isJSScriptNode(node)) { | ||
registry.script.push(node); | ||
} else if (node.tagName === 'base') { | ||
} | ||
else if (node.tagName === 'base') { | ||
registry.base.push(node); | ||
} else if (node.tagName === 'template') { | ||
} | ||
else if (node.tagName === 'template') { | ||
registry.template.push(node); | ||
} else if (node.tagName === 'dom-module') { | ||
} | ||
else if (node.tagName === 'dom-module') { | ||
registry['dom-module'].push(node); | ||
} else if (dom5.isCommentNode(node)) { | ||
} | ||
else if (dom5.isCommentNode(node)) { | ||
registry.comment.push(node); | ||
@@ -66,3 +71,4 @@ } | ||
doc = dom5.parse(htmlString, { locationInfo: true }); | ||
} catch (err) { | ||
} | ||
catch (err) { | ||
console.log(err); | ||
@@ -102,2 +108,2 @@ return null; | ||
exports.importParse = importParse; | ||
; | ||
; |
@@ -14,48 +14,26 @@ /** | ||
'use strict'; | ||
var espree = require('espree'); | ||
var estraverse = require('estraverse'); | ||
var behavior_finder_1 = require('./behavior-finder'); | ||
var element_finder_1 = require('./element-finder'); | ||
var feature_finder_1 = require('./feature-finder'); | ||
const espree = require('espree'); | ||
const estraverse = require('estraverse'); | ||
const behavior_finder_1 = require('./behavior-finder'); | ||
const element_finder_1 = require('./element-finder'); | ||
const feature_finder_1 = require('./feature-finder'); | ||
function traverse(visitorRegistries) { | ||
function applyVisitors(name, node, parent) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = visitorRegistries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var registry = _step.value; | ||
if (name in registry) { | ||
var returnVal = registry[name](node, parent); | ||
if (returnVal) { | ||
return returnVal; | ||
} | ||
for (const registry of visitorRegistries) { | ||
if (name in registry) { | ||
let returnVal = registry[name](node, parent); | ||
if (returnVal) { | ||
return returnVal; | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
return { | ||
enter: function enter(node, parent) { | ||
enter: function (node, parent) { | ||
return applyVisitors('enter' + node.type, node, parent); | ||
}, | ||
leave: function leave(node, parent) { | ||
leave: function (node, parent) { | ||
return applyVisitors('leave' + node.type, node, parent); | ||
}, | ||
fallback: 'iteration' | ||
fallback: 'iteration', | ||
}; | ||
@@ -85,2 +63,2 @@ } | ||
exports.jsParse = jsParse; | ||
; | ||
; |
@@ -11,4 +11,3 @@ /** | ||
'use strict'; | ||
var doctrine = require('doctrine'); | ||
const doctrine = require('doctrine'); | ||
/** | ||
@@ -74,7 +73,9 @@ * doctrine configuration, | ||
function _tagsToHydroTags(tags) { | ||
if (!tags) return null; | ||
if (!tags) | ||
return null; | ||
return tags.map(function (tag) { | ||
if (tag.title in CUSTOM_TAGS) { | ||
return CUSTOM_TAGS[tag.title](tag); | ||
} else { | ||
} | ||
else { | ||
return { | ||
@@ -84,3 +85,3 @@ tag: tag.title, | ||
name: tag.name, | ||
description: tag.description | ||
description: tag.description, | ||
}; | ||
@@ -94,8 +95,12 @@ } | ||
function _removeLeadingAsterisks(description) { | ||
if (typeof description !== 'string') return description; | ||
return description.split('\n').map(function (line) { | ||
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'); | ||
}) | ||
.join('\n'); | ||
} | ||
@@ -124,10 +129,10 @@ /** | ||
function hasTag(jsdoc, tagName) { | ||
if (!jsdoc || !jsdoc.tags) return false; | ||
return jsdoc.tags.some(function (tag) { | ||
return tag.tag === tagName; | ||
}); | ||
if (!jsdoc || !jsdoc.tags) | ||
return false; | ||
return jsdoc.tags.some(function (tag) { return tag.tag === tagName; }); | ||
} | ||
exports.hasTag = hasTag; | ||
function getTag(jsdoc, tagName, key) { | ||
if (!jsdoc || !jsdoc.tags) return null; | ||
if (!jsdoc || !jsdoc.tags) | ||
return null; | ||
for (var i = 0; i < jsdoc.tags.length; i++) { | ||
@@ -143,14 +148,15 @@ var tag = jsdoc.tags[i]; | ||
function unindent(text) { | ||
if (!text) return 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. | ||
if (/^\s*$/.test(line)) | ||
return prev; // Completely ignore blank lines. | ||
var lineIndent = line.match(/^(\s*)/)[0].length; | ||
if (prev === null) return lineIndent; | ||
if (prev === null) | ||
return lineIndent; | ||
return lineIndent < prev ? lineIndent : prev; | ||
}, null); | ||
return lines.map(function (l) { | ||
return l.substr(indent); | ||
}).join('\n'); | ||
return lines.map(function (l) { return l.substr(indent); }).join('\n'); | ||
} | ||
exports.unindent = unindent; | ||
exports.unindent = unindent; |
@@ -11,36 +11,15 @@ /** | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var fs_resolver_1 = require('./fs-resolver'); | ||
var ErrorSwallowingFSResolver = function (_fs_resolver_1$FSReso) { | ||
_inherits(ErrorSwallowingFSResolver, _fs_resolver_1$FSReso); | ||
function ErrorSwallowingFSResolver(config) { | ||
_classCallCheck(this, ErrorSwallowingFSResolver); | ||
return _possibleConstructorReturn(this, Object.getPrototypeOf(ErrorSwallowingFSResolver).call(this, config)); | ||
const fs_resolver_1 = require('./fs-resolver'); | ||
class ErrorSwallowingFSResolver extends fs_resolver_1.FSResolver { | ||
constructor(config) { | ||
super(config); | ||
} | ||
_createClass(ErrorSwallowingFSResolver, [{ | ||
key: 'accept', | ||
value: function accept(uri, deferred) { | ||
var reject = deferred.reject; | ||
deferred.reject = function (arg) { | ||
deferred.resolve(""); | ||
}; | ||
return fs_resolver_1.FSResolver.prototype.accept.call(this, uri, deferred); | ||
} | ||
}]); | ||
return ErrorSwallowingFSResolver; | ||
}(fs_resolver_1.FSResolver); | ||
exports.ErrorSwallowingFSResolver = ErrorSwallowingFSResolver; | ||
accept(uri, deferred) { | ||
var reject = deferred.reject; | ||
deferred.reject = function (arg) { | ||
deferred.resolve(""); | ||
}; | ||
return fs_resolver_1.FSResolver.prototype.accept.call(this, uri, deferred); | ||
} | ||
} | ||
exports.ErrorSwallowingFSResolver = ErrorSwallowingFSResolver; |
@@ -11,16 +11,8 @@ /** | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var resolver_1 = require('./resolver'); | ||
const resolver_1 = require('./resolver'); | ||
/** | ||
* A FileLoader lets you resolve URLs with a set of potential resolvers. | ||
*/ | ||
var FileLoader = function () { | ||
function FileLoader() { | ||
_classCallCheck(this, FileLoader); | ||
class FileLoader { | ||
constructor() { | ||
this.resolvers = []; | ||
@@ -37,50 +29,41 @@ // map url -> Deferred | ||
*/ | ||
_createClass(FileLoader, [{ | ||
key: 'addResolver', | ||
value: function addResolver(resolver) { | ||
this.resolvers.push(resolver); | ||
} | ||
}, { | ||
key: 'request', | ||
/** | ||
* 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. | ||
*/ | ||
value: function request(uri) { | ||
var promise; | ||
if (!(uri in this.requests)) { | ||
var handled = false; | ||
var deferred = new resolver_1.Deferred(); | ||
this.requests[uri] = deferred; | ||
// loop backwards through resolvers until one "accepts" the request | ||
for (var i = this.resolvers.length - 1; i >= 0; i--) { | ||
var r = this.resolvers[i]; | ||
if (r.accept(uri, deferred)) { | ||
handled = true; | ||
break; | ||
} | ||
addResolver(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(uri) { | ||
var promise; | ||
if (!(uri in this.requests)) { | ||
var handled = false; | ||
var deferred = new resolver_1.Deferred(); | ||
this.requests[uri] = deferred; | ||
// loop backwards through resolvers until one "accepts" the request | ||
for (var i = this.resolvers.length - 1; i >= 0; i--) { | ||
const 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; | ||
if (!handled) { | ||
deferred.reject(new Error('no resolver found for ' + uri)); | ||
} | ||
promise = deferred.promise; | ||
} | ||
}]); | ||
return FileLoader; | ||
}(); | ||
else { | ||
promise = this.requests[uri].promise; | ||
} | ||
return promise; | ||
} | ||
} | ||
exports.FileLoader = FileLoader; | ||
; | ||
; |
@@ -11,10 +11,5 @@ /** | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var url = require('url'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const url = require('url'); | ||
function getFile(filePath, deferred, secondPath) { | ||
@@ -25,7 +20,9 @@ fs.readFile(filePath, 'utf-8', function (err, content) { | ||
getFile(secondPath, deferred); | ||
} else { | ||
} | ||
else { | ||
console.log("ERROR finding " + filePath); | ||
deferred.reject(err); | ||
} | ||
} else { | ||
} | ||
else { | ||
deferred.resolve(content); | ||
@@ -57,46 +54,37 @@ } | ||
*/ | ||
var FSResolver = function () { | ||
function FSResolver(config) { | ||
_classCallCheck(this, FSResolver); | ||
class FSResolver { | ||
constructor(config) { | ||
this.config = config || {}; | ||
} | ||
_createClass(FSResolver, [{ | ||
key: 'accept', | ||
value: function accept(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; | ||
accept(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 (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; | ||
if (root) { | ||
local = path.join(root, local); | ||
} | ||
return false; | ||
var backup; | ||
if (redirect && isSiblingOrAunt(root, local)) { | ||
backup = redirectSibling(root, local, redirect); | ||
} | ||
getFile(local, deferred, backup); | ||
return true; | ||
} | ||
}]); | ||
return FSResolver; | ||
}(); | ||
return false; | ||
} | ||
; | ||
} | ||
exports.FSResolver = FSResolver; | ||
; | ||
; |
@@ -14,11 +14,4 @@ /** | ||
*/ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var NoopResolver = function () { | ||
function NoopResolver(config) { | ||
_classCallCheck(this, NoopResolver); | ||
class NoopResolver { | ||
constructor(config) { | ||
this.config = config; | ||
@@ -32,25 +25,18 @@ } | ||
*/ | ||
_createClass(NoopResolver, [{ | ||
key: 'accept', | ||
value: function accept(uri, deferred) { | ||
var config = this.config; | ||
if (typeof config === 'string') { | ||
if (uri.search(config) == -1) { | ||
return false; | ||
} | ||
} else { | ||
if (!config.test(uri)) { | ||
return false; | ||
} | ||
accept(uri, deferred) { | ||
const config = this.config; | ||
if (typeof config === 'string') { | ||
if (uri.search(config) == -1) { | ||
return false; | ||
} | ||
deferred.resolve(''); | ||
return true; | ||
} | ||
}]); | ||
return NoopResolver; | ||
}(); | ||
exports.NoopResolver = NoopResolver; | ||
else { | ||
if (!config.test(uri)) { | ||
return false; | ||
} | ||
} | ||
deferred.resolve(''); | ||
return true; | ||
} | ||
} | ||
exports.NoopResolver = NoopResolver; |
@@ -11,14 +11,5 @@ /** | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var path = require('path'); | ||
var url = require('url'); | ||
var fs_resolver_1 = require('./fs-resolver'); | ||
const path = require('path'); | ||
const url = require('url'); | ||
const fs_resolver_1 = require('./fs-resolver'); | ||
/** | ||
@@ -34,7 +25,4 @@ * A single redirect configuration | ||
*/ | ||
var ProtocolRedirect = function () { | ||
function ProtocolRedirect(config) { | ||
_classCallCheck(this, ProtocolRedirect); | ||
class ProtocolRedirect { | ||
constructor(config) { | ||
this.protocol = config.protocol; | ||
@@ -45,21 +33,16 @@ this.hostname = config.hostname; | ||
} | ||
_createClass(ProtocolRedirect, [{ | ||
key: 'redirect', | ||
value: 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)); | ||
redirect(uri) { | ||
var parsed = url.parse(uri); | ||
if (this.protocol !== parsed.protocol) { | ||
return null; | ||
} | ||
}]); | ||
return ProtocolRedirect; | ||
}(); | ||
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)); | ||
} | ||
} | ||
; | ||
@@ -76,32 +59,19 @@ /** | ||
*/ | ||
var RedirectResolver = function (_fs_resolver_1$FSReso) { | ||
_inherits(RedirectResolver, _fs_resolver_1$FSReso); | ||
function RedirectResolver(config) { | ||
_classCallCheck(this, RedirectResolver); | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RedirectResolver).call(this, config)); | ||
_this.redirects = config.redirects || []; | ||
return _this; | ||
class RedirectResolver extends fs_resolver_1.FSResolver { | ||
constructor(config) { | ||
super(config); | ||
this.redirects = config.redirects || []; | ||
} | ||
_createClass(RedirectResolver, [{ | ||
key: 'accept', | ||
value: function accept(uri, deferred) { | ||
for (var i = 0; i < this.redirects.length; i++) { | ||
var redirected = this.redirects[i].redirect(uri); | ||
if (redirected) { | ||
return fs_resolver_1.FSResolver.prototype.accept.call(this, redirected, deferred); | ||
} | ||
accept(uri, deferred) { | ||
for (var i = 0; i < this.redirects.length; i++) { | ||
var redirected = this.redirects[i].redirect(uri); | ||
if (redirected) { | ||
return fs_resolver_1.FSResolver.prototype.accept.call(this, redirected, deferred); | ||
} | ||
return false; | ||
} | ||
}]); | ||
return RedirectResolver; | ||
}(fs_resolver_1.FSResolver); | ||
return false; | ||
} | ||
; | ||
} | ||
RedirectResolver.ProtocolRedirect = ProtocolRedirect; | ||
exports.RedirectResolver = RedirectResolver; | ||
exports.RedirectResolver = RedirectResolver; |
'use strict'; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
require("babel-polyfill"); | ||
var Deferred = function Deferred() { | ||
_classCallCheck(this, Deferred); | ||
var self = this; | ||
this.promise = new Promise(function (resolve, reject) { | ||
self.resolve = resolve; | ||
self.reject = reject; | ||
}); | ||
}; | ||
exports.Deferred = Deferred; | ||
class Deferred { | ||
constructor() { | ||
const self = this; | ||
this.promise = new Promise(function (resolve, reject) { | ||
self.resolve = resolve; | ||
self.reject = reject; | ||
}); | ||
} | ||
} | ||
exports.Deferred = Deferred; |
@@ -14,11 +14,4 @@ /** | ||
*/ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var StringResolver = function () { | ||
function StringResolver(config) { | ||
_classCallCheck(this, StringResolver); | ||
class StringResolver { | ||
constructor(config) { | ||
this.url = config.url; | ||
@@ -36,26 +29,19 @@ this.content = config.content; | ||
*/ | ||
_createClass(StringResolver, [{ | ||
key: "accept", | ||
value: function accept(uri, deferred) { | ||
var url = this.url; | ||
if (url instanceof RegExp) { | ||
if (!url.test(uri)) { | ||
return false; | ||
} | ||
} else { | ||
if (uri.indexOf(url) == -1) { | ||
return false; | ||
} | ||
accept(uri, deferred) { | ||
const url = this.url; | ||
if (url instanceof RegExp) { | ||
if (!url.test(uri)) { | ||
return false; | ||
} | ||
deferred.resolve(this.content); | ||
return true; | ||
} | ||
}]); | ||
return StringResolver; | ||
}(); | ||
else { | ||
if (uri.indexOf(url) == -1) { | ||
return false; | ||
} | ||
} | ||
deferred.resolve(this.content); | ||
return true; | ||
} | ||
} | ||
exports.StringResolver = StringResolver; | ||
; | ||
; |
@@ -11,7 +11,2 @@ /** | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function getFile(url, deferred, config) { | ||
@@ -24,3 +19,4 @@ /* global XMLHttpRequest:false */ | ||
deferred.resolve(x.response); | ||
} else { | ||
} | ||
else { | ||
deferred.reject('xhr status: ' + status); | ||
@@ -41,22 +37,12 @@ } | ||
*/ | ||
var XHRResolver = function () { | ||
function XHRResolver(config) { | ||
_classCallCheck(this, XHRResolver); | ||
class XHRResolver { | ||
constructor(config) { | ||
this.config = config; | ||
} | ||
_createClass(XHRResolver, [{ | ||
key: 'accept', | ||
value: function accept(uri, deferred) { | ||
getFile(uri, deferred, this.config); | ||
return true; | ||
} | ||
}]); | ||
return XHRResolver; | ||
}(); | ||
accept(uri, deferred) { | ||
getFile(uri, deferred, this.config); | ||
return true; | ||
} | ||
} | ||
exports.XHRResolver = XHRResolver; | ||
; | ||
; |
{ | ||
"name": "hydrolysis", | ||
"version": "1.23.3", | ||
"version": "1.24.1-nobabel", | ||
"description": "Breaks polymers into monomers", | ||
@@ -24,3 +24,3 @@ "homepage": "https://github.com/Polymer/hydrolysis", | ||
"clean": "rm -rf typings/ lib/ && find src | grep \\.js$ | xargs rm", | ||
"compile": "if [ ! -f typings/main.d.ts ]; then npm run init; fi; tsc && babel --presets es2015 -q -d lib src", | ||
"compile": "if [ ! -f typings/main.d.ts ]; then npm run init; fi; tsc", | ||
"build": "npm run compile && browserify -d -r ./index.js:hydrolysis -o hydrolysis.js", | ||
@@ -34,5 +34,2 @@ "release": "npm run compile && browserify -r ./index.js:hydrolysis -o hydrolysis.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.4.5", | ||
"babel-preset-es2015": "^6.1.18", | ||
"babelify": "^7.2.0", | ||
"browserify": "^9.0.8", | ||
@@ -43,3 +40,3 @@ "chai": "^2.2.0", | ||
"typescript": "^1.8.0", | ||
"typings": "^0.6.3", | ||
"typings": "^0.8.1", | ||
"watch": "latest", | ||
@@ -49,3 +46,2 @@ "web-component-tester": "^4.2.2" | ||
"dependencies": { | ||
"babel-polyfill": "^6.2.0", | ||
"doctrine": "^0.7.0", | ||
@@ -52,0 +48,0 @@ "dom5": "^1.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
6
8
4306623
3792
1
- Removedbabel-polyfill@^6.2.0
- Removedbabel-polyfill@6.26.0(transitive)
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.10.50.11.1(transitive)