-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add snippet test of name override (#27)
- Loading branch information
1 parent
c16dbff
commit bd1df67
Showing
2 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@typescript.Name { value = "N12TypescriptGeneratedInterface" } | ||
module n12.pkl.typescript.tests.moduleNameOverride | ||
|
||
import "../../src/typescript.pkl" | ||
|
||
@typescript.Name { value = "MyCustomClassName" } | ||
class CustomClassImpl { | ||
name: String | ||
} | ||
|
||
@typescript.Name { value = "classTypeProperty" } | ||
x: CustomClassImpl | ||
|
||
@typescript.Name { value = "ThisTypeAlias" } | ||
typealias AliasName = "x"|"y"|CustomClassImpl | ||
|
||
@typescript.Name { value = "typeAliasProperty" } | ||
y: AliasName |
31 changes: 31 additions & 0 deletions
31
codegen/snippet-tests/output/n12_pkl_typescript_tests_module_name_override.pkl.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,31 @@ | ||
// This file was generated by `pkl-typescript` from Pkl module `n12.pkl.typescript.tests.moduleNameOverride`. | ||
// DO NOT EDIT. | ||
import * as pklTypescript from "@pkl-community/pkl-typescript" | ||
|
||
// Ref: Module root. | ||
export interface N12TypescriptGeneratedInterface { | ||
classTypeProperty: MyCustomClassName | ||
|
||
typeAliasProperty: ThisTypeAlias | ||
} | ||
|
||
// Ref: Pkl class `n12.pkl.typescript.tests.moduleNameOverride.CustomClassImpl`. | ||
export interface MyCustomClassName { | ||
name: string | ||
} | ||
|
||
type ThisTypeAlias = "x" | "y" | MyCustomClassName | ||
|
||
// LoadFromPath loads the pkl module at the given path and evaluates it into a N12TypescriptGeneratedInterface | ||
export const loadFromPath = async (path: string): Promise<N12TypescriptGeneratedInterface> => { | ||
const evaluator = await pklTypescript.newEvaluator(pklTypescript.PreconfiguredOptions); | ||
try { | ||
const result = await load(evaluator, pklTypescript.FileSource(path)); | ||
return result | ||
} finally { | ||
evaluator.close() | ||
} | ||
}; | ||
|
||
export const load = (evaluator: pklTypescript.Evaluator, source: pklTypescript.ModuleSource): Promise<N12TypescriptGeneratedInterface> => | ||
evaluator.evaluateModule(source) as Promise<N12TypescriptGeneratedInterface>; |