Content-Length: 295533 | pFad | http://github.com/microsoft/TypeScript/commit/2d7e2b2009a1699ee03365357873a49b4df67d6c

F6 Intercept SyntaxError exception in evaluator to diagnose errors in ou… · microsoft/TypeScript@2d7e2b2 · GitHub
Skip to content

Commit 2d7e2b2

Browse files
committed
Intercept SyntaxError exception in evaluator to diagnose errors in output
1 parent e87b89c commit 2d7e2b2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/harness/evaluatorImpl.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,17 @@ namespace evaluator {
168168
const base = vpath.dirname(file);
169169
const localRequire = (id: string) => this.import(id, base);
170170
const evaluateText = `(function (module, exports, require, __dirname, __filename, ${globalNames.join(", ")}) { ${text} })`;
171-
// eslint-disable-next-line no-eval
172-
const evaluateThunk = (void 0, eval)(evaluateText) as (module: any, exports: any, require: (id: string) => any, dirname: string, filename: string, ...globalArgs: any[]) => void;
173-
evaluateThunk.call(this.globals, module, module.exports, localRequire, vpath.dirname(file), file, ...globalArgs);
171+
try {
172+
// eslint-disable-next-line no-eval
173+
const evaluateThunk = (void 0, eval)(evaluateText) as (module: any, exports: any, require: (id: string) => any, dirname: string, filename: string, ...globalArgs: any[]) => void;
174+
evaluateThunk.call(this.globals, module, module.exports, localRequire, vpath.dirname(file), file, ...globalArgs);
175+
}
176+
catch (e) {
177+
if (e instanceof SyntaxError) {
178+
throw new Error(`Evaluation failed: ${e.message}\nSource text:\n\n${evaluateText.split(/\r?\n/g).map(s => ` ${s}`).join("\n")}`);
179+
}
180+
throw e;
181+
}
174182
}
175183
}
176184

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/microsoft/TypeScript/commit/2d7e2b2009a1699ee03365357873a49b4df67d6c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy