no-named-as-default.js
4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'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 (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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1uYW1lZC1hcy1kZWZhdWx0LmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJjcmVhdGUiLCJjb250ZXh0IiwiY2hlY2tEZWZhdWx0IiwibmFtZUtleSIsImRlZmF1bHRTcGVjaWZpZXIiLCJuYW1lIiwiZGVjbGFyYXRpb24iLCJpbXBvcnRzIiwiRXhwb3J0cyIsImdldCIsInNvdXJjZSIsInZhbHV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