From 3f980bead0bac4865fd64d14e37c158e118dc0af Mon Sep 17 00:00:00 2001 From: DLehenbauer Date: Fri, 10 Mar 2017 07:10:58 -0800 Subject: [PATCH] Remove vestiges of WScript support (Issue #14414) --- Jakefile.js | 8 +- src/compiler/diagnosticMessages.json | 4 - src/compiler/program.ts | 7 +- src/compiler/sys.ts | 156 --------------------------- src/harness/harness.ts | 100 ++--------------- src/tsconfig-base.json | 4 +- 6 files changed, 13 insertions(+), 266 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 595875dfc32..9f075f7c056 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -333,7 +333,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts options += " --lib " + opts.lib } else { - options += " --lib es5,scripthost" + options += " --lib es5" } options += " --noUnusedLocals --noUnusedParameters"; @@ -587,13 +587,13 @@ var cancellationTokenFile = path.join(builtLocalDirectory, "cancellationToken.js compileFile(cancellationTokenFile, cancellationTokenSources, [builtLocalDirectory].concat(cancellationTokenSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: true, lib: "es6" }); var typingsInstallerFile = path.join(builtLocalDirectory, "typingsInstaller.js"); -compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6,scripthost" }); +compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6" }); var watchGuardFile = path.join(builtLocalDirectory, "watchGuard.js"); compileFile(watchGuardFile, watchGuardSources, [builtLocalDirectory].concat(watchGuardSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6" }); var serverFile = path.join(builtLocalDirectory, "tsserver.js"); -compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true, lib: "es6,scripthost" }); +compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true, lib: "es6" }); var tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js"); var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts"); compileFile( @@ -717,7 +717,7 @@ compileFile( /*prereqs*/[builtLocalDirectory, tscFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources), /*prefixes*/[], /*useBuiltCompiler:*/ true, - /*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"], lib: "es6,scripthost" }); + /*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"], lib: "es6" }); var internalTests = "internal/"; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 318f06ceeaa..919158645a4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2413,10 +2413,6 @@ "category": "Error", "code": 5012 }, - "Unsupported file encoding.": { - "category": "Error", - "code": 5013 - }, "Failed to parse file '{0}': {1}.": { "category": "Error", "code": 5014 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index abb8b0b2f09..e117761a3a3 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -87,9 +87,6 @@ namespace ts { return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } - // returned by CScript sys environment - const unsupportedFileEncodingErrorCode = -2147024809; - function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile { let text: string; try { @@ -100,9 +97,7 @@ namespace ts { } catch (e) { if (onError) { - onError(e.number === unsupportedFileEncodingErrorCode - ? createCompilerDiagnostic(Diagnostics.Unsupported_file_encoding).messageText - : e.message); + onError(e.message); } text = ""; } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 2a15df80102..3f585900654 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -74,13 +74,6 @@ namespace ts { return parseInt(version.substring(1, dot)); } - declare class Enumerator { - public atEnd(): boolean; - public moveNext(): boolean; - public item(): any; - constructor(o: any); - } - declare var ChakraHost: { args: string[]; currentDirectory: string; @@ -104,152 +97,6 @@ namespace ts { }; export let sys: System = (function() { - - function getWScriptSystem(): System { - - const fso = new ActiveXObject("Scripting.FileSystemObject"); - const shell = new ActiveXObject("WScript.Shell"); - - const fileStream = new ActiveXObject("ADODB.Stream"); - fileStream.Type = 2 /*text*/; - - const binaryStream = new ActiveXObject("ADODB.Stream"); - binaryStream.Type = 1 /*binary*/; - - const args: string[] = []; - for (let i = 0; i < WScript.Arguments.length; i++) { - args[i] = WScript.Arguments.Item(i); - } - - function readFile(fileName: string, encoding?: string): string { - if (!fso.FileExists(fileName)) { - return undefined; - } - fileStream.Open(); - try { - if (encoding) { - fileStream.Charset = encoding; - fileStream.LoadFromFile(fileName); - } - else { - // Load file and read the first two bytes into a string with no interpretation - fileStream.Charset = "x-ansi"; - fileStream.LoadFromFile(fileName); - const bom = fileStream.ReadText(2) || ""; - // Position must be at 0 before encoding can be changed - fileStream.Position = 0; - // [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8 - fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8"; - } - // ReadText method always strips byte order mark from resulting string - return fileStream.ReadText(); - } - catch (e) { - throw e; - } - finally { - fileStream.Close(); - } - } - - function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void { - fileStream.Open(); - binaryStream.Open(); - try { - // Write characters in UTF-8 encoding - fileStream.Charset = "utf-8"; - fileStream.WriteText(data); - // If we don't want the BOM, then skip it by setting the starting location to 3 (size of BOM). - // If not, start from position 0, as the BOM will be added automatically when charset==utf8. - if (writeByteOrderMark) { - fileStream.Position = 0; - } - else { - fileStream.Position = 3; - } - fileStream.CopyTo(binaryStream); - binaryStream.SaveToFile(fileName, 2 /*overwrite*/); - } - finally { - binaryStream.Close(); - fileStream.Close(); - } - } - - function getNames(collection: any): string[] { - const result: string[] = []; - for (const e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { - result.push(e.item().Name); - } - return result.sort(); - } - - function getDirectories(path: string): string[] { - const folder = fso.GetFolder(path); - return getNames(folder.subfolders); - } - - function getAccessibleFileSystemEntries(path: string): FileSystemEntries { - try { - const folder = fso.GetFolder(path || "."); - const files = getNames(folder.files); - const directories = getNames(folder.subfolders); - return { files, directories }; - } - catch (e) { - return { files: [], directories: [] }; - } - } - - function readDirectory(path: string, extensions?: string[], excludes?: string[], includes?: string[]): string[] { - return matchFiles(path, extensions, excludes, includes, /*useCaseSensitiveFileNames*/ false, shell.CurrentDirectory, getAccessibleFileSystemEntries); - } - - const wscriptSystem: System = { - args, - newLine: "\r\n", - useCaseSensitiveFileNames: false, - write(s: string): void { - WScript.StdOut.Write(s); - }, - readFile, - writeFile, - resolvePath(path: string): string { - return fso.GetAbsolutePathName(path); - }, - fileExists(path: string): boolean { - return fso.FileExists(path); - }, - directoryExists(path: string) { - return fso.FolderExists(path); - }, - createDirectory(directoryName: string) { - if (!wscriptSystem.directoryExists(directoryName)) { - fso.CreateFolder(directoryName); - } - }, - getExecutingFilePath() { - return WScript.ScriptFullName; - }, - getCurrentDirectory() { - return shell.CurrentDirectory; - }, - getDirectories, - getEnvironmentVariable(name: string) { - return new ActiveXObject("WScript.Shell").ExpandEnvironmentStrings(`%${name}%`); - }, - readDirectory, - exit(exitCode?: number): void { - try { - WScript.Quit(exitCode); - } - catch (e) { - } - } - }; - return wscriptSystem; - } - function getNodeSystem(): System { const _fs = require("fs"); const _path = require("path"); @@ -646,9 +493,6 @@ namespace ts { if (typeof ChakraHost !== "undefined") { sys = getChakraSystem(); } - else if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") { - sys = getWScriptSystem(); - } else if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") { // process and process.nextTick checks if current environment is node-like // process.browser check excludes webpack and browserify diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 23e8106864a..57041a1f2e3 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -34,12 +34,6 @@ var _chai: typeof chai = require("chai"); var assert: typeof _chai.assert = _chai.assert; declare var __dirname: string; // Node-specific var global: NodeJS.Global = Function("return this").call(undefined); -declare namespace NodeJS { - export interface Global { - WScript: typeof WScript; - ActiveXObject: typeof ActiveXObject; - } -} declare var window: {}; declare var XMLHttpRequest: { @@ -60,14 +54,10 @@ namespace Utils { export const enum ExecutionEnvironment { Node, Browser, - CScript } export function getExecutionEnvironment() { - if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") { - return ExecutionEnvironment.CScript; - } - else if (typeof window !== "undefined") { + if (typeof window !== "undefined") { return ExecutionEnvironment.Browser; } else { @@ -93,7 +83,6 @@ namespace Utils { export function evalFile(fileContents: string, fileName: string, nodeContext?: any) { const environment = getExecutionEnvironment(); switch (environment) { - case ExecutionEnvironment.CScript: case ExecutionEnvironment.Browser: eval(fileContents); break; @@ -516,83 +505,6 @@ namespace Harness { export const virtualFileSystemRoot = "/"; namespace IOImpl { - declare class Enumerator { - public atEnd(): boolean; - public moveNext(): boolean; - public item(): any; - constructor(o: any); - } - - export namespace CScript { - let fso: any; - if (global.ActiveXObject) { - fso = new global.ActiveXObject("Scripting.FileSystemObject"); - } - else { - fso = {}; - } - - export const args = () => ts.sys.args; - export const getExecutingFilePath = () => ts.sys.getExecutingFilePath(); - export const exit = (exitCode: number) => ts.sys.exit(exitCode); - export const resolvePath = (path: string) => ts.sys.resolvePath(path); - export const getCurrentDirectory = () => ts.sys.getCurrentDirectory(); - export const newLine = () => harnessNewLine; - export const useCaseSensitiveFileNames = () => ts.sys.useCaseSensitiveFileNames; - - export const readFile: typeof IO.readFile = path => ts.sys.readFile(path); - export const writeFile: typeof IO.writeFile = (path, content) => ts.sys.writeFile(path, content); - export const directoryName: typeof IO.directoryName = fso.GetParentFolderName; - export const getDirectories: typeof IO.getDirectories = dir => ts.sys.getDirectories(dir); - export const directoryExists: typeof IO.directoryExists = fso.FolderExists; - export const fileExists: typeof IO.fileExists = fso.FileExists; - export const log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine; - export const getEnvironmentVariable: typeof IO.getEnvironmentVariable = name => ts.sys.getEnvironmentVariable(name); - export const readDirectory: typeof IO.readDirectory = (path, extension, exclude, include) => ts.sys.readDirectory(path, extension, exclude, include); - - export function createDirectory(path: string) { - if (directoryExists(path)) { - fso.CreateFolder(path); - } - } - - export function deleteFile(path: string) { - if (fileExists(path)) { - fso.DeleteFile(path, true); // true: delete read-only files - } - } - - export let listFiles: typeof IO.listFiles = (path, spec?, options?) => { - options = options || <{ recursive?: boolean; }>{}; - function filesInFolder(folder: any, root: string): string[] { - let paths: string[] = []; - let fc: any; - - if (options.recursive) { - fc = new Enumerator(folder.subfolders); - - for (; !fc.atEnd(); fc.moveNext()) { - paths = paths.concat(filesInFolder(fc.item(), root + "\\" + fc.item().Name)); - } - } - - fc = new Enumerator(folder.files); - - for (; !fc.atEnd(); fc.moveNext()) { - if (!spec || fc.item().Name.match(spec)) { - paths.push(root + "\\" + fc.item().Name); - } - } - - return paths; - } - - const folder: any = fso.GetFolder(path); - - return filesInFolder(folder, path); - }; - } - export namespace Node { declare const require: any; let fs: any, pathModule: any; @@ -840,16 +752,16 @@ namespace Harness { } } - switch (Utils.getExecutionEnvironment()) { - case Utils.ExecutionEnvironment.CScript: - IO = IOImpl.CScript; - break; + const environment = Utils.getExecutionEnvironment(); + switch (environment) { case Utils.ExecutionEnvironment.Node: IO = IOImpl.Node; break; case Utils.ExecutionEnvironment.Browser: IO = IOImpl.Network; break; + default: + throw new Error(`Unknown value '${environment}' for ExecutionEnvironment'.`); } } @@ -873,7 +785,7 @@ namespace Harness { /** Aggregate various writes into a single array of lines. Useful for passing to the * TypeScript compiler to fill with source code or errors. */ - export class WriterAggregator implements ITextWriter { + export class WriterAggregator { public lines: string[] = []; public currentLine = undefined; diff --git a/src/tsconfig-base.json b/src/tsconfig-base.json index 078fdcc91e7..caf8e880fad 100644 --- a/src/tsconfig-base.json +++ b/src/tsconfig-base.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "lib": ["es5", "scripthost"], + "lib": ["es5"], "noEmitOnError": true, "noImplicitAny": true, "noImplicitThis": true, @@ -13,4 +13,4 @@ "target": "es5", "types": [] } -} \ No newline at end of file +}