-
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: #605 - Add insertMember-like methods to
TypeElementMemberedNode
.
- Loading branch information
Showing
7 changed files
with
254 additions
and
7 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
60 changes: 60 additions & 0 deletions
60
src/structurePrinters/interface/TypeElementMemberStructurePrinter.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,60 @@ | ||
import { CodeBlockWriter } from "../../codeBlockWriter"; | ||
import * as errors from "../../errors"; | ||
import { StructurePrinterFactory } from "../../factories"; | ||
import { TypeElementMemberStructures, StructureKind } from "../../structures"; | ||
import { WriterFunction } from "../../types"; | ||
import { isLastNonWhitespaceCharCloseBrace } from "../helpers"; | ||
import { Printer } from "../Printer"; | ||
|
||
export type TypeElementStructuresArrayItem = string | WriterFunction | TypeElementMemberStructures; | ||
|
||
export class TypeElementMemberStructurePrinter extends Printer<TypeElementStructuresArrayItem> { | ||
constructor(private readonly factory: StructurePrinterFactory) { | ||
super(); | ||
} | ||
|
||
printTexts(writer: CodeBlockWriter, members: ReadonlyArray<TypeElementStructuresArrayItem> | string | WriterFunction | undefined) { | ||
if (members == null) | ||
return; | ||
|
||
if (typeof members === "string" || members instanceof Function) | ||
this.printText(writer, members); | ||
else { | ||
for (const member of members) { | ||
if (isLastNonWhitespaceCharCloseBrace(writer)) | ||
writer.blankLineIfLastNot(); | ||
else if (!writer.isAtStartOfFirstLineOfBlock()) | ||
writer.newLineIfLastNot(); | ||
|
||
this.printText(writer, member); | ||
} | ||
} | ||
} | ||
|
||
printText(writer: CodeBlockWriter, members: TypeElementStructuresArrayItem) { | ||
if (typeof members === "string" || members instanceof Function || members == null) { | ||
this.printTextOrWriterFunc(writer, members); | ||
return; | ||
} | ||
|
||
switch (members.kind) { | ||
case StructureKind.PropertySignature: | ||
this.factory.forPropertySignature().printText(writer, members); | ||
break; | ||
case StructureKind.MethodSignature: | ||
this.factory.forMethodSignature().printText(writer, members); | ||
break; | ||
case StructureKind.CallSignature: | ||
this.factory.forCallSignatureDeclaration().printText(writer, members); | ||
break; | ||
case StructureKind.IndexSignature: | ||
this.factory.forIndexSignatureDeclaration().printText(writer, members); | ||
break; | ||
case StructureKind.ConstructSignature: | ||
this.factory.forConstructSignatureDeclaration().printText(writer, members); | ||
break; | ||
default: | ||
errors.throwNotImplementedForNeverValueError(members); | ||
} | ||
} | ||
} |
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
106 changes: 104 additions & 2 deletions
106
src/tests/compiler/ast/base/typeElementMemberedNodeTests.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