Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
insertJsDocs(index: number, structures: ReadonlyArray | string | WriterFunction>) {
if (ArrayUtils.isNullOrEmpty(structures))
return [];
const writer = this._getWriterWithQueuedIndentation();
const structurePrinter = this._context.structurePrinterFactory.forJSDoc();
structurePrinter.printDocs(writer, structures);
writer.write(""); // final indentation
const code = writer.toString();
const nodes = this.getJsDocs();
index = verifyAndGetIndex(index, nodes.length);
const insertPos = index === nodes.length ? this.getStart() : nodes[index].getStart();
insertIntoParentTextRange({
insertPos,
parent: this,
newText: code
});
insertParameters(index: number, structures: ReadonlyArray>) {
if (ArrayUtils.isNullOrEmpty(structures))
return [];
const parameters = this.getParameters();
const syntaxList = this.getFirstChildByKindOrThrow(SyntaxKind.OpenParenToken).getNextSiblingIfKindOrThrow(SyntaxKind.SyntaxList);
index = verifyAndGetIndex(index, parameters.length);
const writer = this._getWriterWithQueuedChildIndentation();
const structurePrinter = this._context.structurePrinterFactory.forParameterDeclaration();
structurePrinter.printTexts(writer, structures);
insertIntoCommaSeparatedNodes({
parent: syntaxList,
currentNodes: parameters,
insertIndex: index,
newText: writer.toString(),
insertTags(index: number, structures: ReadonlyArray>) {
if (ArrayUtils.isNullOrEmpty(structures))
return [];
const writer = this._getWriterWithQueuedIndentation();
const tags = this.getTags();
index = verifyAndGetIndex(index, tags.length);
if (tags.length === 0 && !this.isMultiLine()) {
const structurePrinter = this._context.structurePrinterFactory.forJSDoc();
this.replaceWithText(writer => {
structurePrinter.printText(writer, {
description: this.getDescription(),
tags: structures as OptionalKind[]
});
});
}
else {
writer.inlineBlock(() => {
this.factory.forPropertyDeclaration().printTexts(writer, structure.properties);
this.printCtors(writer, structure, isAmbient);
this.printGetAndSet(writer, structure, isAmbient);
if (!ArrayUtils.isNullOrEmpty(structure.methods)) {
this.conditionalSeparator(writer, isAmbient);
this.factory.forMethodDeclaration({ isAmbient }).printTexts(writer, structure.methods);
}
});
}
insertTypeParameters(index: number, structures: ReadonlyArray | string>) {
if (ArrayUtils.isNullOrEmpty(structures))
return [];
const typeParameters = this.getTypeParameters();
const writer = this._getWriterWithQueuedChildIndentation();
const structurePrinter = this._context.structurePrinterFactory.forTypeParameterDeclaration();
index = verifyAndGetIndex(index, typeParameters.length);
structurePrinter.printTexts(writer, structures);
if (typeParameters.length === 0) {
insertIntoParentTextRange({
insertPos: getInsertPos(this),
parent: this,
newText: `<${writer.toString()}>`
});
}
private printCtors(writer: CodeBlockWriter, structure: OptionalKind, isAmbient: boolean) {
if (ArrayUtils.isNullOrEmpty(structure.ctors))
return;
for (const ctor of structure.ctors) {
this.conditionalSeparator(writer, isAmbient);
this.factory.forConstructorDeclaration({ isAmbient }).printText(writer, ctor);
}
}
insertDecorators(index: number, structures: ReadonlyArray>) {
if (ArrayUtils.isNullOrEmpty(structures))
return [];
const decoratorLines = getDecoratorLines(this, structures);
const decorators = this.getDecorators();
index = verifyAndGetIndex(index, decorators.length);
const formattingKind = getDecoratorFormattingKind(this, decorators);
const previousDecorator = decorators[index - 1];
const decoratorCode = getNewInsertCode({
structures,
newCodes: decoratorLines,
parent: this,
indentationText: this.getIndentationText(),
getSeparator: () => formattingKind,
previousFormattingKind: previousDecorator == null ? FormattingKind.None : formattingKind,
nextFormattingKind: previousDecorator == null ? formattingKind : FormattingKind.None
});