MCPcopy
hub / github.com/TypeStrong/ts-node / evalAndExitOnTsError

Function evalAndExitOnTsError

src/bin.ts:769–797  ·  view source on GitHub ↗

* Evaluate an [eval] or [stdin] script

(
  replService: ReplService,
  module: Module,
  code: string,
  isPrinted: boolean,
  filenameAndDirname: 'eval' | 'stdin'
)

Source from the content-addressed store, hash-verified

767 * Evaluate an [eval] or [stdin] script
768 */
769function evalAndExitOnTsError(
770 replService: ReplService,
771 module: Module,
772 code: string,
773 isPrinted: boolean,
774 filenameAndDirname: 'eval' | 'stdin'
775) {
776 let result: any;
777 setupContext(global, module, filenameAndDirname);
778
779 try {
780 result = replService.evalCode(code);
781 } catch (error) {
782 if (error instanceof TSError) {
783 console.error(error);
784 process.exit(1);
785 }
786
787 throw error;
788 }
789
790 if (isPrinted) {
791 console.log(
792 typeof result === 'string'
793 ? result
794 : inspect(result, { colors: process.stdout.isTTY })
795 );
796 }
797}
798
799if (require.main === module) {
800 main();

Callers 1

phase4Function · 0.85

Calls 2

setupContextFunction · 0.90
evalCodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…