Files

180 lines
22 KiB
JavaScript
Raw Permalink Normal View History

'use strict';Object.defineProperty(exports, "__esModule", { value: true });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 ExportMap = function () {
function ExportMap(path) {_classCallCheck(this, ExportMap);
this.path = path;
this.namespace = new Map();
// todo: restructure to key on path, value is resolver + map of names
this.reexports = new Map();
/**
* star-exports
* @type {Set<() => ExportMap>}
*/
this.dependencies = new Set();
/**
* dependencies of this module that are not explicitly re-exported
* @type {Map<string, () => ExportMap>}
*/
this.imports = new Map();
this.errors = [];
/**
* type {'ambiguous' | 'Module' | 'Script'}
*/
this.parseGoal = 'ambiguous';
}_createClass(ExportMap, [{ key: 'has',
/**
* Note that this does not check explicitly re-exported names for existence
* in the base namespace, but it will expand all `export * from '...'` exports
* if not found in the explicit namespace.
* @param {string} name
* @return {boolean} true if `name` is exported by this module.
*/value: function () {function has(
name) {
if (this.namespace.has(name)) {return true;}
if (this.reexports.has(name)) {return true;}
// default exports must be explicitly re-exported (#328)
if (name !== 'default') {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try {
for (var _iterator = this.dependencies[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var dep = _step.value;
var innerMap = dep();
// todo: report as unresolved?
if (!innerMap) {continue;}
if (innerMap.has(name)) {return true;}
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}}
}
return false;
}return has;}()
/**
* ensure that imported name fully resolves.
* @param {string} name
* @return {{ found: boolean, path: ExportMap[] }}
*/ }, { key: 'hasDeep', value: function () {function hasDeep(
name) {
if (this.namespace.has(name)) {return { found: true, path: [this] };}
if (this.reexports.has(name)) {
var reexports = this.reexports.get(name);
var imported = reexports.getImport();
// if import is ignored, return explicit 'null'
if (imported == null) {return { found: true, path: [this] };}
// safeguard against cycles, only if name matches
if (imported.path === this.path && reexports.local === name) {
return { found: false, path: [this] };
}
var deep = imported.hasDeep(reexports.local);
deep.path.unshift(this);
return deep;
}
// default exports must be explicitly re-exported (#328)
if (name !== 'default') {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try {
for (var _iterator2 = this.dependencies[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var dep = _step2.value;
var innerMap = dep();
if (innerMap == null) {return { found: true, path: [this] };}
// todo: report as unresolved?
if (!innerMap) {continue;}
// safeguard against cycles
if (innerMap.path === this.path) {continue;}
var innerValue = innerMap.hasDeep(name);
if (innerValue.found) {
innerValue.path.unshift(this);
return innerValue;
}
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}}
}
return { found: false, path: [this] };
}return hasDeep;}() }, { key: 'get', value: function () {function get(
name) {
if (this.namespace.has(name)) {return this.namespace.get(name);}
if (this.reexports.has(name)) {
var reexports = this.reexports.get(name);
var imported = reexports.getImport();
// if import is ignored, return explicit 'null'
if (imported == null) {return null;}
// safeguard against cycles, only if name matches
if (imported.path === this.path && reexports.local === name) {return undefined;}
return imported.get(reexports.local);
}
// default exports must be explicitly re-exported (#328)
if (name !== 'default') {var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try {
for (var _iterator3 = this.dependencies[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var dep = _step3.value;
var innerMap = dep();
// todo: report as unresolved?
if (!innerMap) {continue;}
// safeguard against cycles
if (innerMap.path === this.path) {continue;}
var innerValue = innerMap.get(name);
if (innerValue !== undefined) {return innerValue;}
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}}
}
return undefined;
}return get;}() }, { key: 'forEach', value: function () {function forEach(
callback, thisArg) {var _this = this;
this.namespace.forEach(function (v, n) {callback.call(thisArg, v, n, _this);});
this.reexports.forEach(function (reexports, name) {
var reexported = reexports.getImport();
// can't look up meta for ignored re-exports (#348)
callback.call(thisArg, reexported && reexported.get(reexports.local), name, _this);
});
this.dependencies.forEach(function (dep) {
var d = dep();
// CJS / ignored dependencies won't exist (#717)
if (d == null) {return;}
d.forEach(function (v, n) {
if (n !== 'default') {
callback.call(thisArg, v, n, _this);
}
});
});
}return forEach;}()
// todo: keys, values, entries?
}, { key: 'reportErrors', value: function () {function reportErrors(
context, declaration) {
var msg = this.errors.
map(function (e) {return String(e.message) + ' (' + String(e.lineNumber) + ':' + String(e.column) + ')';}).
join(', ');
context.report({
node: declaration.source,
message: 'Parse errors in imported module \'' + String(declaration.source.value) + '\': ' + String(msg) });
}return reportErrors;}() }, { key: 'hasDefault', get: function () {function get() {return this.get('default') != null;}return get;}() // stronger than this.has
}, { key: 'size', get: function () {function get() {var size = this.namespace.size + this.reexports.size;this.dependencies.forEach(function (dep) {var d = dep(); // CJS / ignored dependencies won't exist (#717)
if (d == null) {return;}size += d.size;});return size;}return get;}() }]);return ExportMap;}();exports['default'] = ExportMap;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9leHBvcnRNYXAvaW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