-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
generators/typescript/codegen/src/ast/__test__/TypeLiteral.test.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,10 @@ | ||
import { ts } from "../.."; | ||
|
||
describe("TypeLiteral", () => { | ||
describe("numberToString", () => { | ||
it("Should generate a simple number", () => { | ||
const literal = ts.TypeLiteral.number(7); | ||
expect(literal.toStringFormatted()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
generators/typescript/codegen/src/ast/__test__/__snapshots__/TypeLiteral.test.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,5 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`TypeLiteral > numberToString > Should generate a simple number`] = ` | ||
"7 | ||
`; |
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,3 +1,18 @@ | ||
import { AbstractAstNode } from "@fern-api/generator-commons"; | ||
import { Writer } from "./Writer"; | ||
import * as prettier from "prettier"; | ||
|
||
export abstract class AstNode extends AbstractAstNode {} | ||
export abstract class AstNode extends AbstractAstNode { | ||
/** | ||
* Writes the node to a string. | ||
*/ | ||
public toString(): string { | ||
const writer = new Writer(); | ||
this.write(writer); | ||
return writer.toString(); | ||
} | ||
|
||
public toStringFormatted(): string { | ||
return prettier.format(this.toString(), { parser: "typescript", tabWidth: 4, printWidth: 120 }); | ||
} | ||
} |
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,4 +1,5 @@ | ||
export * from "./core"; | ||
export { CodeBlock } from "./CodeBlock"; | ||
export { Type } from "./Type"; | ||
export { TypeLiteral } from "./TypeLiteral"; | ||
export { Variable } from "./Variable"; |
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