You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unable to resolve the fullQualifiedName of a identifier in a function block
"ts-morph": "^19.0.0",
Hi I have this use-case where I want to get the full qualified type of each function call happening inside a function, for some reason when the tsconfig.json has paths its not able to resolve the full qualified name properly even when I have a custom resolveModuleNames
the project invocation for ts-morph looks like this:
tsProject = new Project({
tsConfigFilePath: config.typescriptTSConfig ?? undefined,
compilerOptions: {
...compilerOptions,
},
resolutionHost: (moduleResolutionHost, getCompilerOptions) => {
return {
resolveModuleNames: (moduleNames, containingFile) => {
return moduleNames.map(moduleName => {
let matchedPathKey: string | undefined = undefined;
for (const pathKey in pathMapping) {
const regex = new RegExp('^' + pathKey.replace('*', '(.*)'));
if (regex.test(moduleName)) {
matchedPathKey = pathKey;
break;
}
}
if (matchedPathKey === undefined) {
logger.appendLine(`Could not find a path mapping for ${moduleName} ${containingFile}`);
return undefined;
}
// Replace '*' with the captured substring from moduleName
const possiblePaths = pathMapping[matchedPathKey].map(path =>
path.replace('*', moduleName.replace(
new RegExp('^' + (matchedPathKey as string).replace('*', '(.*)')), '$1')
)
);
// Try to resolve the module path
for (const possiblePath of possiblePaths) {
let fullPath = undefined;
if (baseUrl !== undefined) {
fullPath = path.join(baseUrl, possiblePath);
} else {
fullPath = possiblePath;
}
const absolutePath = ts.resolveModuleName(
fullPath,
containingFile,
getCompilerOptions(),
moduleResolutionHost,
).resolvedModule;
if (absolutePath) {
logger.appendLine(`Resolved ${moduleName} to ${absolutePath.resolvedFileName}`);
return absolutePath;
}
}
// Fallback to default resolution
logger.appendLine(`Falling back to default Could not resolve ${moduleName} ${containingFile} to any of the following paths:` + possiblePaths.join(', '));
return ts.resolveModuleName(moduleName, containingFile, compilerOptions, moduleResolutionHost).resolvedModule;
});
}
};
},
});
And an example file is:
import { trimFormattedPhoneNumber, trimPhone } from "~/utils";
export function testing() {
trimFormattedPhoneNumber("1234567890");
}
here when I am at the node trimFormattedPhoneNumber inside the function testing I do symbol.getFullyQualifiedName but it just gives me back trimFormattedPhoneNumber missing out the whole import where its originally from?
I would have expected it to resolve the module and give me utils.trimFormattedPhoneNumber (notice the utils at the start)
Happy to provide more context as well. Thanks a lot!
The text was updated successfully, but these errors were encountered:
Unable to resolve the fullQualifiedName of a identifier in a function block
Hi I have this use-case where I want to get the full qualified type of each function call happening inside a function, for some reason when the tsconfig.json has paths its not able to resolve the full qualified name properly even when I have a custom resolveModuleNames
tsconfig looks like this:
the project invocation for ts-morph looks like this:
And an example file is:
here when I am at the node
trimFormattedPhoneNumber
inside the functiontesting
I dosymbol.getFullyQualifiedName
but it just gives me backtrimFormattedPhoneNumber
missing out the whole import where its originally from?I would have expected it to resolve the module and give me
utils.trimFormattedPhoneNumber
(notice the utils at the start)Happy to provide more context as well. Thanks a lot!
The text was updated successfully, but these errors were encountered: