This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rome_js_analyze): noRedeclaration declaration merging (#4288)
- Loading branch information
Showing
11 changed files
with
593 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid-declaration-merging.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Type and value merging | ||
export type Order = -1 | 0 | 1; | ||
|
||
interface Order { | ||
f(): void; | ||
} | ||
|
||
class Order { | ||
prop: number; | ||
} | ||
|
||
enum Order { | ||
Lower = -1, | ||
Equal = 0, | ||
Upper = 1, | ||
} |
97 changes: 97 additions & 0 deletions
97
...s/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid-declaration-merging.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
source: crates/rome_js_analyze/tests/spec_tests.rs | ||
assertion_line: 91 | ||
expression: invalid-declaration-merging.ts | ||
--- | ||
# Input | ||
```js | ||
// Type and value merging | ||
export type Order = -1 | 0 | 1; | ||
|
||
interface Order { | ||
f(): void; | ||
} | ||
|
||
class Order { | ||
prop: number; | ||
} | ||
|
||
enum Order { | ||
Lower = -1, | ||
Equal = 0, | ||
Upper = 1, | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
invalid-declaration-merging.ts:4:11 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Shouldn't redeclare 'Order'. Consider to delete it or rename it | ||
2 │ export type Order = -1 | 0 | 1; | ||
3 │ | ||
> 4 │ interface Order { | ||
│ ^^^^^ | ||
5 │ f(): void; | ||
6 │ } | ||
i 'Order' is defined here. | ||
1 │ // Type and value merging | ||
> 2 │ export type Order = -1 | 0 | 1; | ||
│ ^^^^^ | ||
3 │ | ||
4 │ interface Order { | ||
``` | ||
|
||
``` | ||
invalid-declaration-merging.ts:8:7 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Shouldn't redeclare 'Order'. Consider to delete it or rename it | ||
6 │ } | ||
7 │ | ||
> 8 │ class Order { | ||
│ ^^^^^ | ||
9 │ prop: number; | ||
10 │ } | ||
i 'Order' is defined here. | ||
1 │ // Type and value merging | ||
> 2 │ export type Order = -1 | 0 | 1; | ||
│ ^^^^^ | ||
3 │ | ||
4 │ interface Order { | ||
``` | ||
|
||
``` | ||
invalid-declaration-merging.ts:12:6 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Shouldn't redeclare 'Order'. Consider to delete it or rename it | ||
10 │ } | ||
11 │ | ||
> 12 │ enum Order { | ||
│ ^^^^^ | ||
13 │ Lower = -1, | ||
14 │ Equal = 0, | ||
i 'Order' is defined here. | ||
1 │ // Type and value merging | ||
> 2 │ export type Order = -1 | 0 | 1; | ||
│ ^^^^^ | ||
3 │ | ||
4 │ interface Order { | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-declaration-merging.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Type and value merging | ||
export type Order = -1 | 0 | 1; | ||
export const Order = { | ||
LOWER: -1, | ||
EQUAL: 0, | ||
UPPER: 1, | ||
} as const; | ||
|
||
export type Direction = "Up" | "Down"; | ||
export namespace Direction { | ||
export const Up = "Up"; | ||
export type Up = "Up"; | ||
export const Down = "Down"; | ||
export type Down = "Down"; | ||
} | ||
|
||
export type Person = { | ||
readonly name: string; | ||
}; | ||
export function Person(name: string): Person { | ||
return { name }; | ||
} | ||
|
||
interface Organization { | ||
readonly name: string; | ||
} | ||
export function Organization(name: string): Organization { | ||
return { name }; | ||
} | ||
|
||
// Interface merging | ||
export interface Splitted { | ||
f(): void; | ||
} | ||
export interface Splitted { | ||
g(): void; | ||
} | ||
|
||
// interface, class, and namespace merging | ||
export interface MoralPerson { | ||
phantom(): void; | ||
} | ||
export class MoralPerson { | ||
name: string; | ||
constructor(name: string) { | ||
this.name = name; | ||
} | ||
} | ||
export namespace MoralPerson { | ||
export function from(name: string) { | ||
return new MoralPerson(name); | ||
} | ||
} | ||
|
||
// function and namespace merging | ||
export function mod(): void {} | ||
export namespace MoralPerson { | ||
export function f(): void {} | ||
} | ||
|
||
// enum and namespace merging | ||
export enum Orientation { | ||
North, | ||
East, | ||
South, | ||
West, | ||
} | ||
export namespace Orientation { | ||
export function f(): void {} | ||
} | ||
|
||
// namespace merging | ||
export namespace X { | ||
export function f(): void {} | ||
} | ||
export namespace X { | ||
export function g(): void {} | ||
} | ||
|
||
// enum merging | ||
export enum Orientation2 { | ||
North = 0, | ||
South = 1, | ||
} | ||
export enum Orientation2 { | ||
East = 2, | ||
West = 3, | ||
} |
Oops, something went wrong.