MCPcopy Index your code
hub / github.com/nodejs/node / removeExtensionAndIndexPostFix

Function removeExtensionAndIndexPostFix

test/fixtures/snapshot/typescript.js:122620–122644  ·  view source on GitHub ↗
(fileName, ending, options, host)

Source from the content-addressed store, hash-verified

122618 });
122619 }
122620 function removeExtensionAndIndexPostFix(fileName, ending, options, host) {
122621 if (ts.fileExtensionIsOneOf(fileName, [".json" /* Extension.Json */, ".mjs" /* Extension.Mjs */, ".cjs" /* Extension.Cjs */]))
122622 return fileName;
122623 var noExtension = ts.removeFileExtension(fileName);
122624 if (fileName === noExtension)
122625 return fileName;
122626 if (ts.fileExtensionIsOneOf(fileName, [".d.mts" /* Extension.Dmts */, ".mts" /* Extension.Mts */, ".d.cts" /* Extension.Dcts */, ".cts" /* Extension.Cts */]))
122627 return noExtension + getJSExtensionForFile(fileName, options);
122628 switch (ending) {
122629 case 0 /* Ending.Minimal */:
122630 var withoutIndex = ts.removeSuffix(noExtension, "/index");
122631 if (host && withoutIndex !== noExtension && tryGetAnyFileFromPath(host, withoutIndex)) {
122632 // Can't remove index if there's a file by the same name as the directory.
122633 // Probably more callers should pass `host` so we can determine this?
122634 return noExtension;
122635 }
122636 return withoutIndex;
122637 case 1 /* Ending.Index */:
122638 return noExtension;
122639 case 2 /* Ending.JsExtension */:
122640 return noExtension + getJSExtensionForFile(fileName, options);
122641 default:
122642 return ts.Debug.assertNever(ending);
122643 }
122644 }
122645 function getJSExtensionForFile(fileName, options) {
122646 var _a;
122647 return (_a = tryGetJSExtensionForFile(fileName, options)) !== null && _a !== void 0 ? _a : ts.Debug.fail("Extension ".concat(ts.extensionFromPath(fileName), " is unsupported:: FileName:: ").concat(fileName));

Callers 4

getLocalModuleSpecifierFunction · 0.85

Calls 2

getJSExtensionForFileFunction · 0.85
tryGetAnyFileFromPathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…