-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Resolve module as first step Known issue, this doesn’t work with all type references * Deal with module * Add a namespace in the example and fix generation
- Loading branch information
1 parent
7e9cd82
commit 3255083
Showing
7 changed files
with
363 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import ts from "typescript"; | ||
import { resolveModules } from "./resolveModules"; | ||
|
||
describe("resolveModules", () => { | ||
it("should prefix interface", () => { | ||
const sourceText = `export namespace Metropolis { | ||
export interface Superman { | ||
name: string; | ||
hasPower: boolean; | ||
} | ||
}`; | ||
|
||
expect(print(resolveModules(sourceText))).toMatchInlineSnapshot(` | ||
"export interface MetropolisSuperman { | ||
name: string; | ||
hasPower: boolean; | ||
} | ||
" | ||
`); | ||
}); | ||
|
||
it("should prefix type", () => { | ||
const sourceText = `export namespace Metropolis { | ||
export type Name = "superman" | "clark kent" | "kal-l"; | ||
}`; | ||
|
||
expect(print(resolveModules(sourceText))).toMatchInlineSnapshot(` | ||
"export type MetropolisName = \\"superman\\" | \\"clark kent\\" | \\"kal-l\\"; | ||
" | ||
`); | ||
}); | ||
|
||
it("should prefix enum", () => { | ||
const sourceText = `export namespace Metropolis { | ||
export enum Superhero { | ||
Superman = "superman", | ||
ClarkKent = "clark_kent", | ||
}; | ||
}`; | ||
|
||
expect(print(resolveModules(sourceText))).toMatchInlineSnapshot(` | ||
"export enum MetropolisSuperhero { | ||
Superman = \\"superman\\", | ||
ClarkKent = \\"clark_kent\\" | ||
} | ||
; | ||
" | ||
`); | ||
}); | ||
|
||
it("should prefix every type references", () => { | ||
const sourceText = ` | ||
export type Weakness = "krytonite" | "lois" | ||
export namespace Metropolis { | ||
export type Name = string; | ||
export type BadassSuperman = Omit<Superman, "underKryptonite">; | ||
export interface Superman { | ||
fullName: Name; | ||
name: { first: Name; last: Name }; | ||
hasPower: boolean; | ||
weakness: Weakness; | ||
} | ||
export type SupermanBis = { | ||
fullName: Name; | ||
name: { first: Name; last: Name }; | ||
hasPower: boolean; | ||
weakness: Weakness; | ||
} | ||
}`; | ||
|
||
expect(print(resolveModules(sourceText))).toMatchInlineSnapshot(` | ||
"export type Weakness = \\"krytonite\\" | \\"lois\\"; | ||
export type MetropolisName = string; | ||
export type MetropolisBadassSuperman = Omit<MetropolisSuperman, \\"underKryptonite\\">; | ||
export interface MetropolisSuperman { | ||
fullName: MetropolisName; | ||
name: { | ||
first: MetropolisName; | ||
last: MetropolisName; | ||
}; | ||
hasPower: boolean; | ||
weakness: Weakness; | ||
} | ||
export type MetropolisSupermanBis = { | ||
fullName: MetropolisName; | ||
name: { | ||
first: MetropolisName; | ||
last: MetropolisName; | ||
}; | ||
hasPower: boolean; | ||
weakness: Weakness; | ||
}; | ||
" | ||
`); | ||
}); | ||
}); | ||
|
||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); | ||
const print = (sourceFile: ts.SourceFile) => printer.printFile(sourceFile); |
Oops, something went wrong.