S
S
Svyatoslav Khusamov2019-10-15 17:57:21
JavaScript
Svyatoslav Khusamov, 2019-10-15 17:57:21

How to display file path with error when calling eval(CODE)?

import {transpile} from 'typescript';
eval(transpile(<ТЕКСТ ФАЙЛА>, undefined, fileName));

Hello!
This is how I execute user scripts in TypeScripte. There may be compilation errors in the files, for this I pass the fileName parameter. But there can also be errors during code execution in eval.
They are displayed like this:
eval at ... <anonymous>:56:15
Two questions:
1) How can I replace the path to the file in TypeScript?
2) And how to replace 56:15 with the coordinates of the error not in the JS file, but in the source file in TypeScript?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Svyatoslav Khusamov, 2019-10-15
@khusamov

In general, I have so far solved this problem like this.
I compile the text, save it in os.tmpdir (), then immediately do an import. As a result, compilation errors are intelligible and runtime errors are also almost intelligible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question