89 lines
8.7 KiB
JavaScript
89 lines
8.7 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
||
|
|
||
|
var _ExportMap = require('../ExportMap');
|
||
|
|
||
|
var _ExportMap2 = _interopRequireDefault(_ExportMap);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
docs: {}
|
||
|
},
|
||
|
|
||
|
create: function (context) {
|
||
|
const named = new Map();
|
||
|
|
||
|
function addNamed(name, node) {
|
||
|
let nodes = named.get(name);
|
||
|
|
||
|
if (nodes == null) {
|
||
|
nodes = new Set();
|
||
|
named.set(name, nodes);
|
||
|
}
|
||
|
|
||
|
nodes.add(node);
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
'ExportDefaultDeclaration': node => addNamed('default', node),
|
||
|
|
||
|
'ExportSpecifier': function (node) {
|
||
|
addNamed(node.exported.name, node.exported);
|
||
|
},
|
||
|
|
||
|
'ExportNamedDeclaration': function (node) {
|
||
|
if (node.declaration == null) return;
|
||
|
|
||
|
if (node.declaration.id != null) {
|
||
|
addNamed(node.declaration.id.name, node.declaration.id);
|
||
|
}
|
||
|
|
||
|
if (node.declaration.declarations != null) {
|
||
|
for (let declaration of node.declaration.declarations) {
|
||
|
(0, _ExportMap.recursivePatternCapture)(declaration.id, v => addNamed(v.name, v));
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
'ExportAllDeclaration': function (node) {
|
||
|
if (node.source == null) return; // not sure if this is ever true
|
||
|
|
||
|
const remoteExports = _ExportMap2.default.get(node.source.value, context);
|
||
|
if (remoteExports == null) return;
|
||
|
|
||
|
if (remoteExports.errors.length) {
|
||
|
remoteExports.reportErrors(context, node);
|
||
|
return;
|
||
|
}
|
||
|
let any = false;
|
||
|
remoteExports.forEach((v, name) => name !== 'default' && (any = true) && // poor man's filter
|
||
|
addNamed(name, node));
|
||
|
|
||
|
if (!any) {
|
||
|
context.report(node.source, `No named exports found in module '${node.source.value}'.`);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
'Program:exit': function () {
|
||
|
for (let _ref of named) {
|
||
|
var _ref2 = _slicedToArray(_ref, 2);
|
||
|
|
||
|
let name = _ref2[0];
|
||
|
let nodes = _ref2[1];
|
||
|
|
||
|
if (nodes.size <= 1) continue;
|
||
|
|
||
|
for (let node of nodes) {
|
||
|
if (name === 'default') {
|
||
|
context.report(node, 'Multiple default exports.');
|
||
|
} else context.report(node, `Multiple exports of name '${name}'.`);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL2V4cG9ydC5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsImRvY3MiLCJjcmVhdGUiLCJjb250ZXh0IiwibmFtZWQiLCJNYXAiLCJhZGROYW1lZCIsIm5hbWUiLCJub2RlIiwibm9kZXMiLCJnZXQiLCJTZXQiLCJzZXQiLCJhZGQiLCJleHBvcnRlZCIsImRlY2xhcmF0aW9uIiwiaWQiLCJkZWNsYXJhdGlvbnMiLCJ2Iiwic291cmNlIiwicmVtb3RlRXhwb3J0cyIsInZhbHVlIiwiZXJyb3JzIiwibGVuZ3RoIiwicmVwb3J0RXJyb3JzIiwiYW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