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:
Colin Wang 2021-07-07 01:18:12 +08:00 committed by GitHub
parent fce35af691
commit a5a63e3033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 0 deletions

View File

@ -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);
},

View File

@ -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 {}
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["syntax-flow"]
}

View File

@ -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 {}
}

View File

@ -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;
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["syntax-typescript"],
"sourceType": "module"
}

View File

@ -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;
}