Skip to content

Commit

Permalink
feat: Upgrade to code-block-writer 10.0.0.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `CodeBlockWriter#indentBlock` is now `indent`. `withHangingIndentation` is now `hangingIndent`. `withHangingIndentationUnlessBlock` is now `hangingIndentUnlessBlock`.
  • Loading branch information
dsherret committed Sep 2, 2019
1 parent 6efa96d commit 5708865
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 27 deletions.
14 changes: 7 additions & 7 deletions lib/ts-morph.d.ts
Expand Up @@ -12200,12 +12200,12 @@ export declare class CodeBlockWriter {
* Writes the text within the provided action with hanging indentation.
* @param action - Action to perform with hanging indentation.
*/
withHangingIndentation(action: () => void): this;
hangingIndent(action: () => void): this;
/**
* Writes the text within the provided action with hanging indentation unless writing a block.
* @param action - Action to perform with hanging indentation unless a block is written.
*/
withHangingIndentationUnlessBlock(action: () => void): this;
hangingIndentUnlessBlock(action: () => void): this;
/**
* Sets the current indentation level.
* @param indentationLevel - Indentation level to be at.
Expand Down Expand Up @@ -12245,11 +12245,15 @@ export declare class CodeBlockWriter {
* @param block - Write using the writer within this block.
*/
inlineBlock(block?: () => void): this;
/**
* Indents the code one level for the current line.
*/
indent(times?: number): this;
/**
* Indents a block of code.
* @param block - Block to indent.
*/
indentBlock(block: () => void): this;
indent(block: () => void): this;
/**
* Conditionally writes a line of text.
* @param condition - Condition to evaluate.
Expand Down Expand Up @@ -12284,10 +12288,6 @@ export declare class CodeBlockWriter {
* Writes a blank line.
*/
blankLine(): this;
/**
* Indents the code one level for the current line.
*/
indent(times?: number): this;
/**
* Writes a newline if the condition is true.
* @param condition - Condition to evaluate.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -70,7 +70,7 @@
},
"dependencies": {
"@dsherret/to-absolute-glob": "^2.0.2",
"code-block-writer": "9.4.1",
"code-block-writer": "^10.0.0",
"fs-extra": "^8.1.0",
"glob-parent": "^5.0.0",
"globby": "^10.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ast/base/helpers/getBodyText.ts
Expand Up @@ -8,7 +8,7 @@ import { printTextFromStringOrWriter } from "../../../../utils";
export function getBodyText(writer: CodeBlockWriter, textOrWriterFunction: string | WriterFunction) {
writer.newLineIfLastNot();
if (typeof textOrWriterFunction !== "string" || textOrWriterFunction.length > 0) {
writer.indentBlock(() => {
writer.indent(() => {
printTextFromStringOrWriter(writer, textOrWriterFunction);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/structurePrinters/Writers.ts
Expand Up @@ -27,7 +27,7 @@ export class Writers {
const keyNames = Object.keys(obj);
writer.write("{");
if (keyNames.length > 0) {
writer.indentBlock(() => {
writer.indent(() => {
writeObject();
});
}
Expand Down Expand Up @@ -57,7 +57,7 @@ export class Writers {
return (writer: CodeBlockWriter) => {
writer.write("{");
if (anyPropertyHasValue(structure)) {
writer.indentBlock(() => {
writer.indent(() => {
structurePrinterFactory.forTypeElementMemberedNode().printText(writer, structure);
});
}
Expand Down Expand Up @@ -91,7 +91,7 @@ export class Writers {
static returnStatement(value: WriterFunctionOrValue): WriterFunction {
return (writer: CodeBlockWriter) => {
writer.write("return ");
writer.withHangingIndentationUnlessBlock(() => {
writer.hangingIndentUnlessBlock(() => {
writeValue(writer, value);
writer.write(";");
});
Expand Down
Expand Up @@ -11,7 +11,7 @@ export class InitializerExpressionableNodeStructurePrinter extends Printer<Initi

const initializerText = this.getText(writer, initializer);
if (!StringUtils.isNullOrWhitespace(initializerText)) {
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.spaceIfLastNot();
writer.write(`= ${initializerText}`);
});
Expand Down
Expand Up @@ -17,7 +17,7 @@ export class ReturnTypedNodeStructurePrinter extends Printer<ReturnTypedNodeStru

const returnTypeText = this.getText(writer, returnType);
if (!StringUtils.isNullOrWhitespace(returnTypeText)) {
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.write(`: ${returnTypeText}`);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/structurePrinters/base/TypedNodeStructurePrinter.ts
Expand Up @@ -17,7 +17,7 @@ export class TypedNodeStructurePrinter extends Printer<TypedNodeStructure> {

const typeText = this.getText(writer, type);
if (!StringUtils.isNullOrWhitespace(typeText)) {
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.write(`${this.separator} ${typeText}`);
});
}
Expand Down
Expand Up @@ -43,7 +43,7 @@ export class ClassDeclarationStructurePrinter extends NodePrinter<OptionalKind<C
this.factory.forTypeParameterDeclaration().printTextsWithBrackets(writer, structure.typeParameters);
writer.space();

writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
if (structure.extends != null) {
const extendsText = this.getText(writer, structure.extends);
if (!StringUtils.isNullOrWhitespace(extendsText))
Expand Down
2 changes: 1 addition & 1 deletion src/structurePrinters/enum/EnumMemberStructurePrinter.ts
Expand Up @@ -28,7 +28,7 @@ export class EnumMemberStructurePrinter extends NodePrinter<OptionalKind<EnumMem
writer.write(structure.name);
if (typeof structure.value === "string") {
const { value } = structure;
writer.withHangingIndentation(() => writer.write(` = `).quote(value));
writer.hangingIndent(() => writer.write(` = `).quote(value));
}
else if (typeof structure.value === "number")
writer.write(` = ${structure.value}`);
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { NodePrinter } from "../../NodePrinter";

export class PropertyAssignmentStructurePrinter extends NodePrinter<OptionalKind<PropertyAssignmentStructure>> {
protected printTextInternal(writer: CodeBlockWriter, structure: OptionalKind<PropertyAssignmentStructure>) {
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.write(`${structure.name}: `);
printTextFromStringOrWriter(writer, structure.initializer);
});
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { NodePrinter } from "../../NodePrinter";

export class SpreadAssignmentStructurePrinter extends NodePrinter<OptionalKind<SpreadAssignmentStructure>> {
protected printTextInternal(writer: CodeBlockWriter, structure: OptionalKind<SpreadAssignmentStructure>) {
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.write("...");
printTextFromStringOrWriter(writer, structure.expression);
});
Expand Down
Expand Up @@ -17,7 +17,7 @@ export class ParameterDeclarationStructurePrinter extends NodePrinter<OptionalKi
printTexts(writer: CodeBlockWriter, structures: ReadonlyArray<OptionalKind<ParameterDeclarationStructure>> | undefined) {
if (structures == null || structures.length === 0)
return;
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
this.multipleWriter.printText(writer, structures);
});
}
Expand Down
Expand Up @@ -25,7 +25,7 @@ export class InterfaceDeclarationStructurePrinter extends NodePrinter<OptionalKi
: this.getText(writer, structure.extends);

if (!StringUtils.isNullOrWhitespace(extendsText))
writer.withHangingIndentation(() => writer.write(`extends ${extendsText} `));
writer.hangingIndent(() => writer.write(`extends ${extendsText} `));
}

writer.inlineBlock(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/structurePrinters/jsx/JsxElementStructurePrinter.ts
Expand Up @@ -4,7 +4,7 @@ import { NodePrinter } from "../NodePrinter";

export class JsxElementStructurePrinter extends NodePrinter<OptionalKind<JsxElementStructure>> {
protected printTextInternal(writer: CodeBlockWriter, structure: OptionalKind<JsxElementStructure>) {
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.write(`<${structure.name}`);
if (structure.attributes)
this.printAttributes(writer, structure.attributes);
Expand All @@ -29,7 +29,7 @@ export class JsxElementStructurePrinter extends NodePrinter<OptionalKind<JsxElem
return;

writer.newLine();
writer.indentBlock(() => {
writer.indent(() => {
for (const child of children) {
this.factory.forJsxChildDecider().printText(writer, child);
writer.newLine();
Expand Down
Expand Up @@ -4,7 +4,7 @@ import { NodePrinter } from "../NodePrinter";

export class JsxSelfClosingElementStructurePrinter extends NodePrinter<OptionalKind<JsxSelfClosingElementStructure>> {
protected printTextInternal(writer: CodeBlockWriter, structure: OptionalKind<JsxSelfClosingElementStructure>) {
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.write(`<${structure.name}`);
if (structure.attributes)
this.printAttributes(writer, structure.attributes);
Expand Down
Expand Up @@ -4,7 +4,7 @@ import { NodePrinter } from "../NodePrinter";

export class JsxSpreadAttributeStructurePrinter extends NodePrinter<JsxSpreadAttributeStructure> {
protected printTextInternal(writer: CodeBlockWriter, structure: JsxSpreadAttributeStructure) {
writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.write("...");
writer.write(structure.expression);
});
Expand Down
Expand Up @@ -14,7 +14,7 @@ export class VariableStatementStructurePrinter extends NodePrinter<OptionalKind<
protected printTextInternal(writer: CodeBlockWriter, structure: OptionalKind<VariableStatementStructure>) {
this.factory.forJSDoc().printDocs(writer, structure.docs);

writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
this.factory.forModifierableNode().printText(writer, structure);
writer.write(`${structure.declarationKind || VariableDeclarationKind.Let} `);
this.factory.forVariableDeclaration().printTexts(writer, structure.declarations);
Expand Down
Expand Up @@ -25,7 +25,7 @@ export class TypeParameterDeclarationStructurePrinter extends NodePrinter<Option
return;
}

writer.withHangingIndentation(() => {
writer.hangingIndent(() => {
writer.write(structure.name);
if (structure.constraint != null) {
const constraintText = this.getText(writer, structure.constraint);
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Expand Up @@ -443,6 +443,10 @@ code-block-writer@9.4.1:
version "9.4.1"
resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-9.4.1.tgz#1448fca79dfc7a3649000f4c85be6bc770604c4c"

code-block-writer@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-10.0.0.tgz#d98a94b7ffb3ae9f9c02b531a3f5184ac7c0dbe3"

code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
Expand Down

0 comments on commit 5708865

Please sign in to comment.