@@ -40,12 +40,6 @@ import * as ast_extractor from "./ast_extractor";
4040import { Project } from "./common" ;
4141import { TypeTable } from "./type_table" ;
4242
43- // Modify the TypeScript `System` object to ensure BOMs are being
44- // stripped off.
45- ts . sys . readFile = ( path : string , encoding ?: string ) => {
46- return getSourceCode ( path ) ;
47- } ;
48-
4943interface ParseCommand {
5044 command : "parse" ;
5145 filename : string ;
@@ -149,22 +143,6 @@ function stringifyAST(obj: any) {
149143 } ) ;
150144}
151145
152- /**
153- * Reads the contents of a file as UTF8 and strips off a leading BOM.
154- *
155- * This must match how the source is read in the Java part of the extractor,
156- * as source offsets will not otherwise match.
157- */
158- function getSourceCode ( filename : string ) : string {
159- let code = fs . readFileSync ( filename , "utf-8" ) ;
160-
161- if ( code . charCodeAt ( 0 ) === 0xfeff ) {
162- code = code . substring ( 1 ) ;
163- }
164-
165- return code ;
166- }
167-
168146function extractFile ( filename : string ) : string {
169147 let ast = getAstForFile ( filename ) ;
170148
@@ -231,7 +209,7 @@ function getAstForFile(filename: string): ts.SourceFile {
231209}
232210
233211function parseSingleFile ( filename : string ) : { ast : ts . SourceFile , code : string } {
234- let code = getSourceCode ( filename ) ;
212+ let code = ts . sys . readFile ( filename ) ;
235213
236214 // create a compiler host that only allows access to `filename`
237215 let compilerHost : ts . CompilerHost = {
@@ -266,15 +244,14 @@ function parseSingleFile(filename: string): {ast: ts.SourceFile, code: string} {
266244
267245function handleOpenProjectCommand ( command : OpenProjectCommand ) {
268246 let tsConfigFilename = String ( command . tsConfig ) ;
269- let tsConfigText = fs . readFileSync ( tsConfigFilename , "utf8" ) ;
270- let tsConfig = ts . parseConfigFileTextToJson ( tsConfigFilename , tsConfigText ) ;
247+ let tsConfig = ts . readConfigFile ( tsConfigFilename , ts . sys . readFile )
271248 let basePath = pathlib . dirname ( tsConfigFilename ) ;
272249
273250 let parseConfigHost : ts . ParseConfigHost = {
274251 useCaseSensitiveFileNames : true ,
275252 readDirectory : ts . sys . readDirectory ,
276253 fileExists : ( path : string ) => fs . existsSync ( path ) ,
277- readFile : getSourceCode ,
254+ readFile : ts . sys . readFile ,
278255 } ;
279256 let config = ts . parseJsonConfigFileContent ( tsConfig , parseConfigHost , basePath ) ;
280257 let project = new Project ( tsConfigFilename , config , state . typeTable ) ;
0 commit comments