-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Ability to set a type with a writer.
- Loading branch information
Showing
17 changed files
with
81 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { CodeBlockWriter } from "../../codeBlockWriter"; | ||
import { TypedNodeStructure, QuestionTokenableNodeStructure } from "../../structures"; | ||
import { StructurePrinterFactory } from "../../factories"; | ||
import { StringUtils } from "../../utils"; | ||
import { FactoryStructurePrinter } from "../FactoryStructurePrinter"; | ||
|
||
export class TypedNodeStructurePrinter extends FactoryStructurePrinter<TypedNodeStructure> { | ||
constructor(factory: StructurePrinterFactory, private readonly separator: string, private readonly alwaysWrite = false) { | ||
super(factory); | ||
} | ||
|
||
printText(writer: CodeBlockWriter, structure: TypedNodeStructure) { | ||
let { type } = structure; | ||
if (type == null && this.alwaysWrite === false) | ||
return; | ||
|
||
type = type || "any"; | ||
|
||
// todo: hacky, will need to change this in the future... | ||
const initializerText = typeof type === "string" ? type : getTextForWriterFunc(type); | ||
if (!StringUtils.isNullOrWhitespace(initializerText)) | ||
writer.write(`${this.separator} ${initializerText}`); | ||
|
||
function getTextForWriterFunc(writerFunc: (writer: CodeBlockWriter) => void) { | ||
const newWriter = new CodeBlockWriter(writer.getOptions()); | ||
writerFunc(newWriter); | ||
return newWriter.toString(); | ||
} | ||
} | ||
} |
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 @@ | ||
export * from "./InitializerExpressionableNodeStructurePrinter"; | ||
export * from "./ModifierableNodeStructurePrinter"; | ||
export * from "./TypedNodeStructurePrinter"; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export interface TypedNodeStructure { | ||
type?: string; | ||
import { CodeBlockWriter } from "../../codeBlockWriter"; | ||
|
||
export interface TypedNodeStructure { | ||
type?: string | ((writer: CodeBlockWriter) => void); | ||
} |
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,7 +1,8 @@ | ||
import { NamedNodeStructure, TypedNodeStructure, TypeParameteredNodeStructure, JSDocableNodeStructure, AmbientableNodeStructure, ExportableNodeStructure } from "../base"; | ||
import { CodeBlockWriter } from "../../codeBlockWriter"; | ||
import { NamedNodeStructure, TypedNodeStructure, TypeParameteredNodeStructure, JSDocableNodeStructure, AmbientableNodeStructure, ExportableNodeStructure } from "../base"; | ||
|
||
export interface TypeAliasDeclarationStructure | ||
extends NamedNodeStructure, TypedNodeStructure, TypeParameteredNodeStructure, JSDocableNodeStructure, AmbientableNodeStructure, ExportableNodeStructure | ||
{ | ||
type: string; // make required (from base) | ||
type: string | ((writer: CodeBlockWriter) => void); // make required (from base) | ||
} |
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