How to use the @ts-morph/common.ArrayUtils.isNullOrEmpty function in @ts-morph/common

To help you get started, we’ve selected a few @ts-morph/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / base / JSDocableNode.ts View on Github external
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
            });
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / base / ParameteredNode.ts View on Github external
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(),
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / doc / JSDoc.ts View on Github external
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 {
github dsherret / ts-morph / packages / ts-morph / src / structurePrinters / class / ClassDeclarationStructurePrinter.ts View on Github external
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);
            }
        });
    }
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / base / TypeParameteredNode.ts View on Github external
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()}>`
                });
            }
github dsherret / ts-morph / packages / ts-morph / src / structurePrinters / class / ClassDeclarationStructurePrinter.ts View on Github external
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);
        }
    }
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / base / DecoratableNode.ts View on Github external
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
            });