MCPcopy
hub / github.com/patriksimek/vm2 / getTypeScriptCompiler

Function getTypeScriptCompiler

lib/compiler.js:39–56  ·  view source on GitHub ↗

* Returns the cached TypeScript compiler or loads it * if it is not found in the cache. * * @private * @param {Object} [options] - Optional compiler options. * @return {compileCallback} The TypeScript compiler. * @throws {VMError} If the TypeScript module can't be found.

(options)

Source from the content-addressed store, hash-verified

37 * @throws {VMError} If the TypeScript module can't be found.
38 */
39function getTypeScriptCompiler(options) {
40 try {
41 // The warning generated by webpack can be disabled by setting:
42 // ignoreWarnings[].message = /Can't resolve 'typescript'/
43
44 const typescript = require('typescript');
45 return (code, filename) => {
46 return typescript.transpileModule(code, {
47 fileName: filename,
48 compilerOptions: Object.assign({
49 module: typescript.ModuleKind.CommonJS,
50 }, options)
51 }).outputText;
52 };
53 } catch (e) {
54 throw new VMError('TypeScript compiler is not installed.');
55 }
56}
57
58/**
59 * Remove the shebang from source code.

Callers 1

lookupCompilerFunction · 0.85

Calls 1

requireFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…