Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept duplicated import/variable in different module #13527

Merged
merged 3 commits into from Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/babel-traverse/src/scope/index.ts
Expand Up @@ -202,6 +202,9 @@ const collectorVisitor: Visitor<CollectVisitorState> = {
// delegate block scope handling to the `BlockScoped` method
if (path.isBlockScoped()) return;

// import handing to the `ImportDeclaration` method
colinaaa marked this conversation as resolved.
Show resolved Hide resolved
if (path.isImportDeclaration()) return;

// this will be hit again once we traverse into it after this iteration
if (path.isExportDeclaration()) return;

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