How to use the @ts-morph/common.errors.throwIfWhitespaceOrNotString 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 / name / RenameableNode.ts View on Github external
function renameNode(node: Node) {
                errors.throwIfWhitespaceOrNotString(newName, nameof(newName));

                if (node.getText() === newName)
                    return;

                const renameLocations = languageService.findRenameLocations(node, options);
                const renameLocationsBySourceFile = new KeyValueCache();

                for (const renameLocation of renameLocations) {
                    const locations = renameLocationsBySourceFile.getOrCreate(renameLocation.getSourceFile(), () => []);
                    locations.push(renameLocation);
                }

                for (const [sourceFile, locations] of renameLocationsBySourceFile.getEntries()) {
                    replaceSourceFileTextForRename({
                        sourceFile,
                        renameLocations: locations,
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / base / initializer / InitializerExpressionableNode.ts View on Github external
setInitializer(textOrWriterFunction: string | WriterFunction) {
            const text = getTextFromStringOrWriter(this._getWriterWithQueuedChildIndentation(), textOrWriterFunction);
            errors.throwIfWhitespaceOrNotString(text, nameof(textOrWriterFunction));

            if (this.hasInitializer())
                this.removeInitializer();

            const semiColonToken = this.getLastChildIfKind(SyntaxKind.SemicolonToken);

            insertIntoParentTextRange({
                insertPos: semiColonToken != null ? semiColonToken.getPos() : this.getEnd(),
                parent: this,
                newText: ` = ${text}`
            });
            return this;
        }
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / base / name / NameableNode.ts View on Github external
set(structure: Partial) {
            callBaseSet(Base.prototype, this, structure);

            if (structure.name != null) {
                errors.throwIfWhitespaceOrNotString(structure.name, nameof.full(structure.name));
                const nameNode = this.getNameNode();
                if (nameNode == null)
                    addNameNode(this, structure.name);
                else
                    nameNode.replaceWithText(structure.name);
            }
            else if (structure.hasOwnProperty(nameof(structure.name))) {
                this.removeName();
            }

            return this;
        }
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / interface / IndexSignatureDeclaration.ts View on Github external
setKeyType(type: string) {
        errors.throwIfWhitespaceOrNotString(type, nameof(type));
        const keyTypeNode = this.getKeyTypeNode();
        if (keyTypeNode.getText() === type)
            return this;

        keyTypeNode.replaceWithText(type, this._getWriterWithQueuedChildIndentation());

        return this;
    }
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / interface / IndexSignatureDeclaration.ts View on Github external
setKeyName(name: string) {
        errors.throwIfWhitespaceOrNotString(name, nameof(name));
        if (this.getKeyName() === name)
            return;

        this.getKeyNameNode().replaceWithText(name, this._getWriterWithQueuedChildIndentation());
    }