Skip to content

Commit 8bebc9b

Browse files
bradzacherfacebook-github-bot
authored andcommitted
fix handling of imports
Summary: All imports are treated as "type" definitions regardless of whether or not they have a "type" kind. You can import classes and enums as values and use them in type locations. Additionally namespace imports can be used in a type location (eg `React.MixedElement`). Because we don't have cross-file information, we cannot statically determine if an imported thing is a "type referencible" thing, so we have to just treat all imports as possible types. This diff marks all import bindings as type definitions. Reviewed By: evanyeung Differential Revision: D33574248 fbshipit-source-id: b6dc10dc2afb8ad01e0dbfbe40d0dab25b0ec297
1 parent 678b569 commit 8bebc9b

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

tools/hermes-parser/js/hermes-eslint/__tests__/HermesScopeManager-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ describe('Imports', () => {
16001600
{
16011601
name: 'RefType',
16021602
type: DefinitionType.ImportBinding,
1603-
referenceCount: 0,
1603+
referenceCount: 1,
16041604
},
16051605
{
16061606
name: 'foo',
@@ -1717,7 +1717,7 @@ describe('Imports', () => {
17171717
{
17181718
name: 'RefType',
17191719
type: DefinitionType.ImportBinding,
1720-
referenceCount: 0,
1720+
referenceCount: 1,
17211721
},
17221722
{
17231723
name: 'foo',
@@ -1835,7 +1835,7 @@ describe('Imports', () => {
18351835
{
18361836
name: 'RefType',
18371837
type: DefinitionType.ImportBinding,
1838-
referenceCount: 0,
1838+
referenceCount: 1,
18391839
},
18401840
{
18411841
name: 'foo',

tools/hermes-parser/js/hermes-eslint/src/scope-manager/definition/ImportBindingDefinition.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,31 @@ class ImportBindingDefinition extends DefinitionBase<
4343
decl.importKind === 'type' ||
4444
decl.importKind === 'typeof'
4545
) {
46-
this.isTypeDefinition = true;
4746
this.isVariableDefinition = false;
4847
} else {
49-
this.isTypeDefinition = false;
5048
this.isVariableDefinition = true;
5149
}
5250
break;
5351

5452
case 'ImportDefaultSpecifier':
5553
if (decl.importKind === 'type' || decl.importKind === 'typeof') {
56-
this.isTypeDefinition = true;
5754
this.isVariableDefinition = false;
5855
} else {
59-
this.isTypeDefinition = false;
6056
this.isVariableDefinition = true;
6157
}
6258
break;
6359

6460
case 'ImportNamespaceSpecifier':
65-
// not possible for a namespace import to be a type in flow
66-
this.isTypeDefinition = false;
6761
this.isVariableDefinition = true;
6862
break;
6963
}
7064
}
7165

72-
+isTypeDefinition: boolean;
66+
// all imports are treated as "type" definitions regardless of whether or
67+
// not they have a "type" kind. You can import classes and enums as values
68+
// and use them in type locations. Additionally namespace imports can be
69+
// used in a type location (eg React.MixedElement).
70+
+isTypeDefinition: boolean = true;
7371
+isVariableDefinition: boolean;
7472
}
7573

0 commit comments

Comments
 (0)