Skip to content

Commit 59dd3b2

Browse files
authored
Merge pull request #1477 from asger-semmle/ts-debug-failure-in-tsconfig
Approved by xiemaisi
2 parents 832abc7 + 52f31dc commit 59dd3b2

File tree

1 file changed

+3
-26
lines changed
  • javascript/extractor/lib/typescript/src

1 file changed

+3
-26
lines changed

javascript/extractor/lib/typescript/src/main.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ import * as ast_extractor from "./ast_extractor";
4040
import { Project } from "./common";
4141
import { 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-
4943
interface 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-
168146
function extractFile(filename: string): string {
169147
let ast = getAstForFile(filename);
170148

@@ -231,7 +209,7 @@ function getAstForFile(filename: string): ts.SourceFile {
231209
}
232210

233211
function 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

267245
function 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

Comments
 (0)