Skip to content

Commit 3f980be

Browse files
committed
Remove vestiges of WScript support (Issue microsoft#14414)
1 parent 940d165 commit 3f980be

File tree

6 files changed

+13
-266
lines changed

6 files changed

+13
-266
lines changed

Jakefile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
333333
options += " --lib " + opts.lib
334334
}
335335
else {
336-
options += " --lib es5,scripthost"
336+
options += " --lib es5"
337337
}
338338
options += " --noUnusedLocals --noUnusedParameters";
339339

@@ -587,13 +587,13 @@ var cancellationTokenFile = path.join(builtLocalDirectory, "cancellationToken.js
587587
compileFile(cancellationTokenFile, cancellationTokenSources, [builtLocalDirectory].concat(cancellationTokenSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: true, lib: "es6" });
588588

589589
var typingsInstallerFile = path.join(builtLocalDirectory, "typingsInstaller.js");
590-
compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6,scripthost" });
590+
compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6" });
591591

592592
var watchGuardFile = path.join(builtLocalDirectory, "watchGuard.js");
593593
compileFile(watchGuardFile, watchGuardSources, [builtLocalDirectory].concat(watchGuardSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6" });
594594

595595
var serverFile = path.join(builtLocalDirectory, "tsserver.js");
596-
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true, lib: "es6,scripthost" });
596+
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true, lib: "es6" });
597597
var tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
598598
var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
599599
compileFile(
@@ -717,7 +717,7 @@ compileFile(
717717
/*prereqs*/[builtLocalDirectory, tscFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
718718
/*prefixes*/[],
719719
/*useBuiltCompiler:*/ true,
720-
/*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"], lib: "es6,scripthost" });
720+
/*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"], lib: "es6" });
721721

722722
var internalTests = "internal/";
723723

src/compiler/diagnosticMessages.json

-4
Original file line numberDiff line numberDiff line change
@@ -2413,10 +2413,6 @@
24132413
"category": "Error",
24142414
"code": 5012
24152415
},
2416-
"Unsupported file encoding.": {
2417-
"category": "Error",
2418-
"code": 5013
2419-
},
24202416
"Failed to parse file '{0}': {1}.": {
24212417
"category": "Error",
24222418
"code": 5014

src/compiler/program.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ namespace ts {
8787
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
8888
}
8989

90-
// returned by CScript sys environment
91-
const unsupportedFileEncodingErrorCode = -2147024809;
92-
9390
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
9491
let text: string;
9592
try {
@@ -100,9 +97,7 @@ namespace ts {
10097
}
10198
catch (e) {
10299
if (onError) {
103-
onError(e.number === unsupportedFileEncodingErrorCode
104-
? createCompilerDiagnostic(Diagnostics.Unsupported_file_encoding).messageText
105-
: e.message);
100+
onError(e.message);
106101
}
107102
text = "";
108103
}

src/compiler/sys.ts

-156
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ namespace ts {
7474
return parseInt(version.substring(1, dot));
7575
}
7676

77-
declare class Enumerator {
78-
public atEnd(): boolean;
79-
public moveNext(): boolean;
80-
public item(): any;
81-
constructor(o: any);
82-
}
83-
8477
declare var ChakraHost: {
8578
args: string[];
8679
currentDirectory: string;
@@ -104,152 +97,6 @@ namespace ts {
10497
};
10598

10699
export let sys: System = (function() {
107-
108-
function getWScriptSystem(): System {
109-
110-
const fso = new ActiveXObject("Scripting.FileSystemObject");
111-
const shell = new ActiveXObject("WScript.Shell");
112-
113-
const fileStream = new ActiveXObject("ADODB.Stream");
114-
fileStream.Type = 2 /*text*/;
115-
116-
const binaryStream = new ActiveXObject("ADODB.Stream");
117-
binaryStream.Type = 1 /*binary*/;
118-
119-
const args: string[] = [];
120-
for (let i = 0; i < WScript.Arguments.length; i++) {
121-
args[i] = WScript.Arguments.Item(i);
122-
}
123-
124-
function readFile(fileName: string, encoding?: string): string {
125-
if (!fso.FileExists(fileName)) {
126-
return undefined;
127-
}
128-
fileStream.Open();
129-
try {
130-
if (encoding) {
131-
fileStream.Charset = encoding;
132-
fileStream.LoadFromFile(fileName);
133-
}
134-
else {
135-
// Load file and read the first two bytes into a string with no interpretation
136-
fileStream.Charset = "x-ansi";
137-
fileStream.LoadFromFile(fileName);
138-
const bom = fileStream.ReadText(2) || "";
139-
// Position must be at 0 before encoding can be changed
140-
fileStream.Position = 0;
141-
// [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8
142-
fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
143-
}
144-
// ReadText method always strips byte order mark from resulting string
145-
return fileStream.ReadText();
146-
}
147-
catch (e) {
148-
throw e;
149-
}
150-
finally {
151-
fileStream.Close();
152-
}
153-
}
154-
155-
function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
156-
fileStream.Open();
157-
binaryStream.Open();
158-
try {
159-
// Write characters in UTF-8 encoding
160-
fileStream.Charset = "utf-8";
161-
fileStream.WriteText(data);
162-
// If we don't want the BOM, then skip it by setting the starting location to 3 (size of BOM).
163-
// If not, start from position 0, as the BOM will be added automatically when charset==utf8.
164-
if (writeByteOrderMark) {
165-
fileStream.Position = 0;
166-
}
167-
else {
168-
fileStream.Position = 3;
169-
}
170-
fileStream.CopyTo(binaryStream);
171-
binaryStream.SaveToFile(fileName, 2 /*overwrite*/);
172-
}
173-
finally {
174-
binaryStream.Close();
175-
fileStream.Close();
176-
}
177-
}
178-
179-
function getNames(collection: any): string[] {
180-
const result: string[] = [];
181-
for (const e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
182-
result.push(e.item().Name);
183-
}
184-
return result.sort();
185-
}
186-
187-
function getDirectories(path: string): string[] {
188-
const folder = fso.GetFolder(path);
189-
return getNames(folder.subfolders);
190-
}
191-
192-
function getAccessibleFileSystemEntries(path: string): FileSystemEntries {
193-
try {
194-
const folder = fso.GetFolder(path || ".");
195-
const files = getNames(folder.files);
196-
const directories = getNames(folder.subfolders);
197-
return { files, directories };
198-
}
199-
catch (e) {
200-
return { files: [], directories: [] };
201-
}
202-
}
203-
204-
function readDirectory(path: string, extensions?: string[], excludes?: string[], includes?: string[]): string[] {
205-
return matchFiles(path, extensions, excludes, includes, /*useCaseSensitiveFileNames*/ false, shell.CurrentDirectory, getAccessibleFileSystemEntries);
206-
}
207-
208-
const wscriptSystem: System = {
209-
args,
210-
newLine: "\r\n",
211-
useCaseSensitiveFileNames: false,
212-
write(s: string): void {
213-
WScript.StdOut.Write(s);
214-
},
215-
readFile,
216-
writeFile,
217-
resolvePath(path: string): string {
218-
return fso.GetAbsolutePathName(path);
219-
},
220-
fileExists(path: string): boolean {
221-
return fso.FileExists(path);
222-
},
223-
directoryExists(path: string) {
224-
return fso.FolderExists(path);
225-
},
226-
createDirectory(directoryName: string) {
227-
if (!wscriptSystem.directoryExists(directoryName)) {
228-
fso.CreateFolder(directoryName);
229-
}
230-
},
231-
getExecutingFilePath() {
232-
return WScript.ScriptFullName;
233-
},
234-
getCurrentDirectory() {
235-
return shell.CurrentDirectory;
236-
},
237-
getDirectories,
238-
getEnvironmentVariable(name: string) {
239-
return new ActiveXObject("WScript.Shell").ExpandEnvironmentStrings(`%${name}%`);
240-
},
241-
readDirectory,
242-
exit(exitCode?: number): void {
243-
try {
244-
WScript.Quit(exitCode);
245-
}
246-
catch (e) {
247-
}
248-
}
249-
};
250-
return wscriptSystem;
251-
}
252-
253100
function getNodeSystem(): System {
254101
const _fs = require("fs");
255102
const _path = require("path");
@@ -646,9 +493,6 @@ namespace ts {
646493
if (typeof ChakraHost !== "undefined") {
647494
sys = getChakraSystem();
648495
}
649-
else if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
650-
sys = getWScriptSystem();
651-
}
652496
else if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
653497
// process and process.nextTick checks if current environment is node-like
654498
// process.browser check excludes webpack and browserify

src/harness/harness.ts

+6-94
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ var _chai: typeof chai = require("chai");
3434
var assert: typeof _chai.assert = _chai.assert;
3535
declare var __dirname: string; // Node-specific
3636
var global: NodeJS.Global = <any>Function("return this").call(undefined);
37-
declare namespace NodeJS {
38-
export interface Global {
39-
WScript: typeof WScript;
40-
ActiveXObject: typeof ActiveXObject;
41-
}
42-
}
4337

4438
declare var window: {};
4539
declare var XMLHttpRequest: {
@@ -60,14 +54,10 @@ namespace Utils {
6054
export const enum ExecutionEnvironment {
6155
Node,
6256
Browser,
63-
CScript
6457
}
6558

6659
export function getExecutionEnvironment() {
67-
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
68-
return ExecutionEnvironment.CScript;
69-
}
70-
else if (typeof window !== "undefined") {
60+
if (typeof window !== "undefined") {
7161
return ExecutionEnvironment.Browser;
7262
}
7363
else {
@@ -93,7 +83,6 @@ namespace Utils {
9383
export function evalFile(fileContents: string, fileName: string, nodeContext?: any) {
9484
const environment = getExecutionEnvironment();
9585
switch (environment) {
96-
case ExecutionEnvironment.CScript:
9786
case ExecutionEnvironment.Browser:
9887
eval(fileContents);
9988
break;
@@ -516,83 +505,6 @@ namespace Harness {
516505
export const virtualFileSystemRoot = "/";
517506

518507
namespace IOImpl {
519-
declare class Enumerator {
520-
public atEnd(): boolean;
521-
public moveNext(): boolean;
522-
public item(): any;
523-
constructor(o: any);
524-
}
525-
526-
export namespace CScript {
527-
let fso: any;
528-
if (global.ActiveXObject) {
529-
fso = new global.ActiveXObject("Scripting.FileSystemObject");
530-
}
531-
else {
532-
fso = {};
533-
}
534-
535-
export const args = () => ts.sys.args;
536-
export const getExecutingFilePath = () => ts.sys.getExecutingFilePath();
537-
export const exit = (exitCode: number) => ts.sys.exit(exitCode);
538-
export const resolvePath = (path: string) => ts.sys.resolvePath(path);
539-
export const getCurrentDirectory = () => ts.sys.getCurrentDirectory();
540-
export const newLine = () => harnessNewLine;
541-
export const useCaseSensitiveFileNames = () => ts.sys.useCaseSensitiveFileNames;
542-
543-
export const readFile: typeof IO.readFile = path => ts.sys.readFile(path);
544-
export const writeFile: typeof IO.writeFile = (path, content) => ts.sys.writeFile(path, content);
545-
export const directoryName: typeof IO.directoryName = fso.GetParentFolderName;
546-
export const getDirectories: typeof IO.getDirectories = dir => ts.sys.getDirectories(dir);
547-
export const directoryExists: typeof IO.directoryExists = fso.FolderExists;
548-
export const fileExists: typeof IO.fileExists = fso.FileExists;
549-
export const log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine;
550-
export const getEnvironmentVariable: typeof IO.getEnvironmentVariable = name => ts.sys.getEnvironmentVariable(name);
551-
export const readDirectory: typeof IO.readDirectory = (path, extension, exclude, include) => ts.sys.readDirectory(path, extension, exclude, include);
552-
553-
export function createDirectory(path: string) {
554-
if (directoryExists(path)) {
555-
fso.CreateFolder(path);
556-
}
557-
}
558-
559-
export function deleteFile(path: string) {
560-
if (fileExists(path)) {
561-
fso.DeleteFile(path, true); // true: delete read-only files
562-
}
563-
}
564-
565-
export let listFiles: typeof IO.listFiles = (path, spec?, options?) => {
566-
options = options || <{ recursive?: boolean; }>{};
567-
function filesInFolder(folder: any, root: string): string[] {
568-
let paths: string[] = [];
569-
let fc: any;
570-
571-
if (options.recursive) {
572-
fc = new Enumerator(folder.subfolders);
573-
574-
for (; !fc.atEnd(); fc.moveNext()) {
575-
paths = paths.concat(filesInFolder(fc.item(), root + "\\" + fc.item().Name));
576-
}
577-
}
578-
579-
fc = new Enumerator(folder.files);
580-
581-
for (; !fc.atEnd(); fc.moveNext()) {
582-
if (!spec || fc.item().Name.match(spec)) {
583-
paths.push(root + "\\" + fc.item().Name);
584-
}
585-
}
586-
587-
return paths;
588-
}
589-
590-
const folder: any = fso.GetFolder(path);
591-
592-
return filesInFolder(folder, path);
593-
};
594-
}
595-
596508
export namespace Node {
597509
declare const require: any;
598510
let fs: any, pathModule: any;
@@ -840,16 +752,16 @@ namespace Harness {
840752
}
841753
}
842754

843-
switch (Utils.getExecutionEnvironment()) {
844-
case Utils.ExecutionEnvironment.CScript:
845-
IO = IOImpl.CScript;
846-
break;
755+
const environment = Utils.getExecutionEnvironment();
756+
switch (environment) {
847757
case Utils.ExecutionEnvironment.Node:
848758
IO = IOImpl.Node;
849759
break;
850760
case Utils.ExecutionEnvironment.Browser:
851761
IO = IOImpl.Network;
852762
break;
763+
default:
764+
throw new Error(`Unknown value '${environment}' for ExecutionEnvironment'.`);
853765
}
854766
}
855767

@@ -873,7 +785,7 @@ namespace Harness {
873785
/** Aggregate various writes into a single array of lines. Useful for passing to the
874786
* TypeScript compiler to fill with source code or errors.
875787
*/
876-
export class WriterAggregator implements ITextWriter {
788+
export class WriterAggregator {
877789
public lines: string[] = [];
878790
public currentLine = <string>undefined;
879791

0 commit comments

Comments
 (0)