From d0bbfcaaef37fea6e672e90d43c7c95a48229944 Mon Sep 17 00:00:00 2001 From: Eddie Antonio Santos Date: Wed, 14 Aug 2019 10:00:45 -0600 Subject: [PATCH] Explicilty specify what kind of a file we want. --- developer/js/model-compiler.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/developer/js/model-compiler.ts b/developer/js/model-compiler.ts index cf4b9128fa..3d6e547531 100644 --- a/developer/js/model-compiler.ts +++ b/developer/js/model-compiler.ts @@ -1,7 +1,7 @@ /// + import * as TypeScript from 'typescript'; import * as fs from 'fs'; -import * as assert from 'assert'; import LexicalModelCompiler from "./"; @@ -20,17 +20,20 @@ const enum SysExits { */ function loadFromFilename(filename: string): LexicalModelSource { let sourceCode = fs.readFileSync(filename, 'utf8'); - // Compile the module to JavaScript code. - sourceCode = '/// \n' + sourceCode; - let compilation = TypeScript.transpileModule(sourceCode, { - compilerOptions: { module: TypeScript.ModuleKind.CommonJS } - }) + // Compile the module to JavaScript code. + // NOTE: transpile module does a very simple TS to JS compilation. + // It DOES NOT check for types! + let compilationOutput = TypeScript.transpile(sourceCode, { + // Our runtime should support ES6 with Node/CommonJS modules. + target: TypeScript.ScriptTarget.ES2015, + module: TypeScript.ModuleKind.CommonJS, + }); // Turn the module into a function in which we can inject a global. - let moduleCode = '(function(exports){' + compilation.outputText + '})'; + let moduleCode = '(function(exports){' + compilationOutput + '})'; - // Run the module; its exports will be placed on the given object. + // Run the module; its exports will be assigned to `moduleExports`. let moduleExports = {}; let module = eval(moduleCode); module(moduleExports); @@ -49,6 +52,5 @@ if (process.argv.length < 3) { } let o = loadFromFilename(process.argv[2]); -// @ts-ignore let code = (new LexicalModelCompiler).generateLexicalModelCode('', o, '.'); console.log(code); \ No newline at end of file