forked from babel/babel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use scope for typescript export removals. Fixes babel#10033
This also fixes enum not adding the respective declaration to the scope during the typescript visitation. Rewrites: 2080042 babel#9944 a6392bd babel#10019
- Loading branch information
1 parent
a596da2
commit f667e63
Showing
12 changed files
with
114 additions
and
121 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
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
33 changes: 1 addition & 32 deletions
33
packages/babel-plugin-transform-typescript/test/fixtures/declarations/erased/output.mjs
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 |
---|---|---|
@@ -1,32 +1 @@ | ||
export class C2 {} | ||
export { E }; // only E | ||
|
||
// everything removed | ||
export { E as E2, C2 as C3 }; // only E and C2 | ||
|
||
var BB; | ||
|
||
(function (BB) { | ||
BB[BB["K"] = 0] = "K"; | ||
})(BB || (BB = {})); | ||
|
||
(function (BB) { | ||
BB["L"] = "LL"; | ||
})(BB || (BB = {})); | ||
|
||
export { BB }; // only BB | ||
|
||
// everything removed | ||
export { BB as BB1 }; // as-is | ||
|
||
var BB2; | ||
|
||
(function (BB2) {})(BB2 || (BB2 = {})); | ||
|
||
function foo() {} | ||
|
||
export { BB2 as BB3, foo }; // only BB2 and foo | ||
// export an interface before declaration | ||
|
||
// everything removed | ||
export { C2 as C4 }; // only C4 | ||
; // Otherwise-empty file |
11 changes: 11 additions & 0 deletions
11
packages/babel-plugin-transform-typescript/test/fixtures/exports/declare-namespace/input.mjs
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,11 @@ | ||
export class N { | ||
f1(value: N.I) { | ||
value.f2(); | ||
} | ||
} | ||
export declare namespace N { | ||
export interface I { | ||
f2(); | ||
} | ||
} | ||
export default N; |
7 changes: 7 additions & 0 deletions
7
...ages/babel-plugin-transform-typescript/test/fixtures/exports/declare-namespace/output.mjs
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,7 @@ | ||
export class N { | ||
f1(value) { | ||
value.f2(); | ||
} | ||
|
||
} | ||
export default N; |
48 changes: 48 additions & 0 deletions
48
packages/babel-plugin-transform-typescript/test/fixtures/exports/declared-types/input.mjs
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,48 @@ | ||
declare const x: number; | ||
declare function f(): void; | ||
declare class C {} | ||
declare enum E {} | ||
declare module "m" {} | ||
declare module M {} | ||
declare namespace N {} | ||
export interface I {} | ||
export type T = number; | ||
export class C2 {} | ||
|
||
export { x, f, E, C }; // Not-even E | ||
export { M, N, I as I1, T as T1 }; // everything removed | ||
export { | ||
x as x2, | ||
f as f2, | ||
C as CC2, | ||
E as E2, | ||
M as M2, | ||
N as N2, | ||
I as I2, | ||
T as T2, | ||
C2 as C3 | ||
}; // only C2->C3 | ||
|
||
interface II2 {} | ||
type AA = {}; | ||
enum BB { | ||
K | ||
} | ||
enum BB { | ||
L = "LL" | ||
} | ||
export { II2, AA, BB }; // only BB | ||
export { II2 as II3, AA as AA2 }; // everything removed | ||
export { BB as BB1 }; // BB->BB1 | ||
|
||
interface II3 {} | ||
type AA2 = {}; | ||
enum BB2 {} | ||
function foo() {} | ||
export { II3 as default, AA2 as A, BB2 as BB3, foo }; // only BB2->BB3 and foo | ||
|
||
// export an interface before declaration | ||
export default Bar; | ||
export { Bar } // everything removed | ||
export { Bar as Bar2, C2 as C4 } // only C2->C4 | ||
interface Bar {} |
30 changes: 30 additions & 0 deletions
30
packages/babel-plugin-transform-typescript/test/fixtures/exports/declared-types/output.mjs
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,30 @@ | ||
export class C2 {} | ||
// everything removed | ||
export { C2 as C3 }; // only C2->C3 | ||
|
||
var BB; | ||
|
||
(function (BB) { | ||
BB[BB["K"] = 0] = "K"; | ||
})(BB || (BB = {})); | ||
|
||
(function (BB) { | ||
BB["L"] = "LL"; | ||
})(BB || (BB = {})); | ||
|
||
export { BB }; // only BB | ||
|
||
// everything removed | ||
export { BB as BB1 }; // BB->BB1 | ||
|
||
var BB2; | ||
|
||
(function (BB2) {})(BB2 || (BB2 = {})); | ||
|
||
function foo() {} | ||
|
||
export { BB2 as BB3, foo }; // only BB2->BB3 and foo | ||
// export an interface before declaration | ||
|
||
// everything removed | ||
export { C2 as C4 }; // only C2->C4 |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-typescript/test/fixtures/exports/interface/input.mjs
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
; // Otherwise-empty file | ||
export interface I {} | ||
export default interface A {} |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-typescript/test/fixtures/exports/interface/output.mjs
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 @@ | ||
; // Otherwise-empty file |
2 changes: 2 additions & 0 deletions
2
packages/babel-plugin-transform-typescript/test/fixtures/exports/simple/input.mjs
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,2 @@ | ||
export class N {} | ||
export default N; |
2 changes: 2 additions & 0 deletions
2
packages/babel-plugin-transform-typescript/test/fixtures/exports/simple/output.mjs
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,2 @@ | ||
export class N {} | ||
export default N; |