GoScrobble/web/node_modules/eslint-plugin-import/lib/rules/no-named-as-default.js

43 lines
4.8 KiB
JavaScript
Raw Normal View History

2022-04-25 02:47:15 +00:00
'use strict';var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
var _importDeclaration = require('../importDeclaration');var _importDeclaration2 = _interopRequireDefault(_importDeclaration);
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
module.exports = {
meta: {
type: 'problem',
docs: {
url: (0, _docsUrl2['default'])('no-named-as-default') },
schema: [] },
create: function () {function create(context) {
function checkDefault(nameKey, defaultSpecifier) {
// #566: default is a valid specifier
if (defaultSpecifier[nameKey].name === 'default') return;
var declaration = (0, _importDeclaration2['default'])(context);
var imports = _ExportMap2['default'].get(declaration.source.value, context);
if (imports == null) return;
if (imports.errors.length) {
imports.reportErrors(context, declaration);
return;
}
if (imports.has('default') &&
imports.has(defaultSpecifier[nameKey].name)) {
context.report(defaultSpecifier,
'Using exported name \'' + defaultSpecifier[nameKey].name +
'\' as identifier for default export.');
}
}
return {
'ImportDefaultSpecifier': checkDefault.bind(null, 'local'),
'ExportDefaultSpecifier': checkDefault.bind(null, 'exported') };
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1uYW1lZC1hcy1kZWZhdWx0LmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJjcmVhdGUiLCJjb250ZXh0IiwiY2hlY2tEZWZhdWx0IiwibmFtZUtleSIsImRlZmF1bHRTcGVjaWZpZXIiLCJuYW1lIiwiZGVjbGFyYXRpb24iLCJpbXBvcnRzIiwiRXhwb3J0cyIsImdldCIsInNvdXJjZSIsInZhbHVlIi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