From 02ebfa5d115104653eeff83a1f58ab14ed1c9420 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 21 Mar 2016 11:54:10 -0700 Subject: [PATCH] Added environment variable to force experimental transformations. --- Jakefile.js | 11 +++-------- src/compiler/program.ts | 5 +++++ src/compiler/sys.ts | 12 ++++++++++-- src/compiler/tsc.ts | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index fdde2ea9dbd..e9e5fc31912 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -241,7 +241,6 @@ function concatenateFiles(destinationFile, sourceFiles) { } var useDebugMode = true; -var useTransforms = process.env.USE_TRANSFORMS || false; var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node"); var compilerFilename = "tsc.js"; var LKGCompiler = path.join(LKGDirectory, compilerFilename); @@ -309,8 +308,8 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts options += " --stripInternal" } - if (useBuiltCompiler && useTransforms) { - options += " --experimentalTransforms" + if (useBuiltCompiler && Boolean(process.env.USE_TRANSFORMS)) { + console.warn("\u001b[93mwarning: Found 'USE_TRANSFORMS' environment variable. Experimental transforms will be enabled by default.\u001b[0m"); } var cmd = host + " " + compilerPath + " " + options + " "; @@ -430,10 +429,6 @@ task("setDebugMode", function() { useDebugMode = true; }); -task("setTransforms", function() { - useTransforms = true; -}); - task("configure-nightly", [configureNightlyJs], function() { var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + programTs; console.log(cmd); @@ -519,7 +514,7 @@ compileFile(servicesFileInBrowserTest, servicesSources,[builtLocalDirectory, cop var i = content.lastIndexOf("\n"); fs.writeFileSync(servicesFileInBrowserTest, content.substring(0, i) + "\r\n//# sourceURL=../built/local/typeScriptServices.js" + content.substring(i)); }); - + var serverFile = path.join(builtLocalDirectory, "tsserver.js"); compileFile(serverFile, serverSources,[builtLocalDirectory, copyright].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 7ec3c7a0f47..29e44ca11f5 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -994,6 +994,11 @@ namespace ts { const start = new Date().getTime(); + // TODO(rbuckton): remove USE_TRANSFORMS condition when we switch to transforms permenantly. + if (Boolean(sys.getEnvironmentVariable("USE_TRANSFORMS"))) { + options.experimentalTransforms = true; + } + const fileEmitter = options.experimentalTransforms ? printFiles : emitFiles; const emitResult = fileEmitter( emitResolver, diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index c1920884b22..fce9408caf0 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -8,7 +8,6 @@ namespace ts { args: string[]; newLine: string; useCaseSensitiveFileNames: boolean; - /*@internal*/ developmentMode?: boolean; write(s: string): void; readFile(path: string, encoding?: string): string; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; @@ -23,6 +22,7 @@ namespace ts { readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; + /*@internal*/ getEnvironmentVariable(name: string): string; /*@internal*/ tryEnableSourceMapsForHost?(): void; } @@ -213,6 +213,9 @@ namespace ts { getCurrentDirectory() { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getEnvironmentVariable(name: string) { + return new ActiveXObject("WScript.Shell").ExpandEnvironmentStrings(`%${name}%`); + }, readDirectory, exit(exitCode?: number): void { try { @@ -523,7 +526,6 @@ namespace ts { args: process.argv.slice(2), newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, - developmentMode: /^development$/i.test(String(process.env.NODE_ENV)), write(s: string): void { process.stdout.write(s); }, @@ -581,6 +583,9 @@ namespace ts { getCurrentDirectory() { return process.cwd(); }, + getEnvironmentVariable(name: string) { + return process.env[name] || ""; + }, readDirectory, getMemoryUsage() { if (global.gc) { @@ -627,6 +632,9 @@ namespace ts { createDirectory: ChakraHost.createDirectory, getExecutingFilePath: () => ChakraHost.executingFile, getCurrentDirectory: () => ChakraHost.currentDirectory, + getEnvironmentVariable(name: string) { + return ""; + }, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, }; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index bf16b274d9b..789db5a1faf 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -781,7 +781,7 @@ namespace ts { } } -if (ts.sys.developmentMode && ts.sys.tryEnableSourceMapsForHost) { +if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) { ts.sys.tryEnableSourceMapsForHost(); }