@@ -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
0 commit comments