How to use the @ts-morph/common.KeyValueCache 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 / scripts / generation / createNodeTypeGuards.ts View on Github external
function getMethodInfos() {
        const methodInfos = new KeyValueCache();

        for (const node of inspector.getWrappedNodes()) {
            // todo: what is going on here? Why does this need to be filled
            getMethodInfoForNode(node); // fill this
            const nodeBase = node.getBase();
            if (nodeBase != null)
                fillBase(node, nodeBase);
            fillMixinable(node, node);
        }

        const allowedBaseNames = ["Node", "Expression", "BooleanLiteral"];
        for (const kindToWrapperMapping of kindToWrapperMappings.filter(v => allowedBaseNames.indexOf(v.wrapperName) >= 0)) {
            for (const syntaxKindName of kindToWrapperMapping.syntaxKindNames) {
                methodInfos.set(syntaxKindName, {
                    name: syntaxKindName,
                    wrapperName: kindToWrapperMapping.wrapperName,
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,
                        newName
                    });
                }
            }
        }
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / class / ClassDeclaration.ts View on Github external
function getAccessors() {
        type GetOrSetArray = (GetAccessorDeclaration | SetAccessorDeclaration)[];
        const result = new KeyValueCache();

        for (const accessor of [...classDec.getGetAccessors(), ...classDec.getSetAccessors()]) {
            if (accessor.isStatic() === isStatic && accessor.getScope() === Scope.Public)
                result.getOrCreate(accessor.getName(), () => []).push(accessor);
        }

        return result.getValuesAsArray();
    }
}
github dsherret / ts-morph / packages / ts-morph / src / factories / DirectoryCache.ts View on Github external
*getAllByDepth() {
        const dirLevels = new KeyValueCache();
        let depth = 0;
        this.getOrphans().forEach(addToDirLevels);
        depth = Math.min(...Array.from(dirLevels.getKeys()));

        while (dirLevels.getSize() > 0) {
            for (const dir of dirLevels.get(depth) || []) {
                yield dir;
                dir.getDirectories().forEach(addToDirLevels);
            }
            dirLevels.removeByKey(depth);
            depth++;
        }

        function addToDirLevels(dir: Directory) {
            const dirDepth = dir._getDepth();