fix: accept duplicated import/variable in different module (#13527)
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
This commit is contained in:
parent
fce35af691
commit
a5a63e3033
@ -202,6 +202,9 @@ const collectorVisitor: Visitor<CollectVisitorState> = {
|
||||
// delegate block scope handling to the `BlockScoped` method
|
||||
if (path.isBlockScoped()) return;
|
||||
|
||||
// delegate import handing to the `ImportDeclaration` method
|
||||
if (path.isImportDeclaration()) return;
|
||||
|
||||
// this will be hit again once we traverse into it after this iteration
|
||||
if (path.isExportDeclaration()) return;
|
||||
|
||||
@ -211,6 +214,13 @@ const collectorVisitor: Visitor<CollectVisitorState> = {
|
||||
parent.registerDeclaration(path);
|
||||
},
|
||||
|
||||
ImportDeclaration(path) {
|
||||
// import may only appear in the top level or inside a module/namespace (for TS/flow)
|
||||
const parent = path.scope.getBlockParent();
|
||||
|
||||
parent.registerDeclaration(path);
|
||||
},
|
||||
|
||||
ReferencedIdentifier(path, state) {
|
||||
state.references.push(path);
|
||||
},
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
// @flow
|
||||
|
||||
type T = string;
|
||||
declare module 'test' {
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
declare var a: number;
|
||||
declare function foo(a: JSONSchema7): string;
|
||||
declare export function concatPath(dirA: string, dirB: T): string;
|
||||
declare export class A {}
|
||||
}
|
||||
|
||||
declare module 'test/submodule' {
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
declare var a: number;
|
||||
declare function foo(a: JSONSchema7): string;
|
||||
declare export function concatPath(dirA: string, dirB: string): string;
|
||||
declare export class A {}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["syntax-flow"]
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
// @flow
|
||||
type T = string;
|
||||
declare module 'test' {
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
declare var a: number;
|
||||
declare function foo(a: JSONSchema7): string;
|
||||
declare export function concatPath(dirA: string, dirB: T): string;
|
||||
declare export class A {}
|
||||
}
|
||||
declare module 'test/submodule' {
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
declare var a: number;
|
||||
declare function foo(a: JSONSchema7): string;
|
||||
declare export function concatPath(dirA: string, dirB: string): string;
|
||||
declare export class A {}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
type T = number;
|
||||
declare module 'test' {
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
import { bar } from "baz";
|
||||
export { fooBar } from "baz";
|
||||
let foo: JSONSchema7;
|
||||
// can reference type outsider module
|
||||
let baz: T;
|
||||
}
|
||||
|
||||
declare module 'test/submodule' {
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
import { bar } from "baz";
|
||||
export { fooBar } from "baz";
|
||||
let foo: JSONSchema7;
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["syntax-typescript"],
|
||||
"sourceType": "module"
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
type T = number;
|
||||
declare module 'test' {
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
import { bar } from "baz";
|
||||
export { fooBar } from "baz";
|
||||
let foo: JSONSchema7; // can reference type outsider module
|
||||
|
||||
let baz: T;
|
||||
}
|
||||
declare module 'test/submodule' {
|
||||
import type { JSONSchema7 } from 'json-schema';
|
||||
import { bar } from "baz";
|
||||
export { fooBar } from "baz";
|
||||
let foo: JSONSchema7;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user