Skip to content

Commit 18883f9

Browse files
committed
Using removeComments from commandLineParser. This is more robust as it removes both single and multiline comments
1 parent 20511f8 commit 18883f9

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ namespace ts {
503503
*
504504
* This method replace comment content by whitespace rather than completely remove them to keep positions in json parsing error reporting accurate.
505505
*/
506-
function removeComments(jsonText: string): string {
506+
export function removeComments(jsonText: string): string {
507507
let output = "";
508508
const scanner = createScanner(ScriptTarget.ES5, /* skipTrivia */ false, LanguageVariant.Standard, jsonText);
509509
let token: SyntaxKind;

src/services/jsTyping.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ namespace ts.JsTyping {
2121
function tryParseJson(jsonPath: string, host: TypingResolutionHost): any {
2222
if (host.fileExists(jsonPath)) {
2323
try {
24-
// Strip out single-line comments
25-
const contents = host.readFile(jsonPath).replace(/^\s*\/\/(.*)$/gm, "");
24+
const contents = removeComments(host.readFile(jsonPath));
2625
return JSON.parse(contents);
2726
}
2827
catch (e) { }

0 commit comments

Comments
 (0)