MCPcopy Create free account
hub / github.com/compilets/compilets / getNamespaceFromNode

Function getNamespaceFromNode

src/parser-utils.ts:105–120  ·  view source on GitHub ↗
(sourceRootDir: string, node?: ts.Node)

Source from the content-addressed store, hash-verified

103 * Calculate the node's namespace according to the file it is defined.
104 */
105export function getNamespaceFromNode(sourceRootDir: string, node?: ts.Node): string | undefined {
106 if (!node)
107 return;
108 const sourceFile = node.getSourceFile();
109 if (sourceFile.isDeclarationFile) {
110 const {fileName} = sourceFile;
111 if (fileName.includes('/node_modules/@types/node/') ||
112 fileName.endsWith('/node_modules/typescript/lib/lib.dom.d.ts'))
113 return 'compilets::nodejs';
114 if (fileName.match(/node_modules\/typescript\/lib\/lib\.es.*\.d\.ts$/))
115 return 'compilets';
116 throw new Error(`Can not get namespace for declaration file "${fileName}"`);
117 }
118 const fileName = path.relative(sourceRootDir, sourceFile.fileName);
119 return getNamespaceFromFileName(fileName);
120}
121
122/**
123 * Return the computed namespace from relative fileName.

Callers 1

Calls 2

getNamespaceFromFileNameFunction · 0.85
includesMethod · 0.80

Tested by

no test coverage detected