51 lines
4.6 KiB
JavaScript
51 lines
4.6 KiB
JavaScript
'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')
|
|
}
|
|
},
|
|
|
|
create: function (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')
|
|
};
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1uYW1lZC1hcy1kZWZhdWx0LmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJjcmVhdGUiLCJjb250ZXh0IiwiY2hlY2t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