Skip to content

Commit 182b109

Browse files
Alexander Ryzhikovljharb
authored andcommitted
Handle unresolved js import when type is exported with the same name
1 parent 4c92c47 commit 182b109

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/ExportMap.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,12 @@ ExportMap.parse = function (path, content, context) {
533533
case 'TSTypeAliasDeclaration':
534534
case 'TSInterfaceDeclaration':
535535
case 'TSAbstractClassDeclaration':
536-
case 'TSModuleDeclaration':
537-
m.namespace.set(n.declaration.id.name, captureDoc(source, docStyleParsers, n));
536+
case 'TSModuleDeclaration': {
537+
const meta = captureDoc(docStyleParsers, n);
538+
meta.exportKind = n.exportKind;
539+
m.namespace.set(n.declaration.id.name, meta);
538540
break;
541+
}
539542
case 'VariableDeclaration':
540543
n.declaration.declarations.forEach((d) =>
541544
recursivePatternCapture(d.id,

src/rules/named.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ module.exports = {
5050
`${im[key].name} not found via ${deepPath}`);
5151
} else {
5252
context.report(im[key],
53-
im[key].name + ' not found in \'' + node.source.value + '\'');
53+
`${im[key].name} not found in '${node.source.value}'`);
54+
}
55+
} else if (node.importKind === 'value') {
56+
const meta = deepLookup.path[deepLookup.path.length - 1].namespace.get(im[key].name);
57+
const wrongType = meta && meta.exportKind !== undefined && meta.exportKind !== 'value';
58+
if (wrongType) {
59+
context.report(im[key],
60+
`${im[key].name} not found in '${node.source.value}'`);
5461
}
5562
}
5663
});

tests/src/rules/named.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,22 @@ ruleTester.run('named', rule, {
216216
parser: require.resolve('babel-eslint'),
217217
errors: ["MyMissingClass not found in './flowtypes'"],
218218
}),
219+
test({
220+
code: 'import { MyType } from "./flowtypes"',
221+
parser: 'babel-eslint',
222+
errors: [{
223+
message: "MyType not found in './flowtypes'",
224+
type: 'Identifier',
225+
}],
226+
}),
227+
test({
228+
code: 'import type { MissingType } from "./flowtypes"',
229+
parser: 'babel-eslint',
230+
errors: [{
231+
message: "MissingType not found in './flowtypes'",
232+
type: 'Identifier',
233+
}],
234+
}),
219235

220236
// jsnext
221237
test({

0 commit comments

Comments
 (0)