MCPcopy Index your code
hub / github.com/alibaba/lowcode-engine / parseTS

Function parseTS

modules/material-parser/src/parse/ts/index.ts:479–609  ·  view source on GitHub ↗
(filePath: string, args: IParseArgs)

Source from the content-addressed store, hash-verified

477const defaultTsConfigPath = path.resolve(__dirname, './tsconfig.json');
478
479export default function parseTS(filePath: string, args: IParseArgs): ComponentDoc[] {
480 if (!filePath) return [];
481
482 let basePath = args.moduleDir || args.workDir || path.dirname(filePath);
483 let tsConfigPath = findConfig('tsconfig.json', { cwd: basePath }); // path.resolve(basePath, 'tsconfig.json')
484 if (
485 !tsConfigPath ||
486 !existsSync(tsConfigPath) ||
487 (args.accesser === 'online' && tsConfigPath === 'tsconfig.json')
488 ) {
489 tsConfigPath = defaultTsConfigPath;
490 } else {
491 basePath = path.dirname(tsConfigPath);
492 }
493
494 log('ts config path is', tsConfigPath);
495 const { config, error } = ts.readConfigFile(tsConfigPath, (filename) =>
496 readFileSync(filename, 'utf8'));
497
498 if (error !== undefined) {
499 const errorText = `Cannot load custom tsconfig.json from provided path: ${tsConfigPath}, with error code: ${error.code}, message: ${error.messageText}`;
500 throw new Error(errorText);
501 }
502
503 const { options, errors } = ts.parseJsonConfigFileContent(
504 config,
505 ts.sys,
506 basePath,
507 {},
508 tsConfigPath,
509 );
510
511 if (errors && errors.length) {
512 throw errors[0];
513 }
514 log('ts config is', options);
515 // const filePaths = Array.isArray(filePathOrPaths) ? filePathOrPaths : [filePathOrPaths];
516 generateDTS(args);
517 const program = ts.createProgram([filePath], options);
518
519 const parser = new MyParser(program, {});
520
521 const checker = program.getTypeChecker();
522
523 const result = [filePath]
524 .map((fPath) => program.getSourceFile(fPath))
525 .filter((sourceFile) => typeof sourceFile !== 'undefined')
526 .reduce((docs: any[], sourceFile) => {
527 const moduleSymbol = checker.getSymbolAtLocation(sourceFile as ts.Node);
528
529 if (!moduleSymbol) {
530 return docs;
531 }
532
533 const exportSymbols = checker.getExportsOfModule(moduleSymbol);
534
535 for (let index = 0; index < exportSymbols.length; index++) {
536 const sym: SymbolWithMeta = exportSymbols[index];

Callers 1

index.tsFile · 0.85

Calls 10

transformItemFunction · 0.90
generateDTSFunction · 0.85
getComponentNameFunction · 0.85
pushMethod · 0.80
applyMethod · 0.80
reduceMethod · 0.65
filterMethod · 0.65
mapMethod · 0.65
getNameMethod · 0.65
findMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…