Skip to content

Commit

Permalink
Add snippet test of name override (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongwartz authored Mar 17, 2024
1 parent c16dbff commit bd1df67
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
18 changes: 18 additions & 0 deletions codegen/snippet-tests/input/12-moduleNameOverride.pkl
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
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>;

0 comments on commit bd1df67

Please sign in to comment.