From 0de8f9eeb2b1b90bfc3a38c6ab5f1eac0f7acec8 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Tue, 23 Feb 2016 13:30:24 -0800 Subject: [PATCH] Using removeComments from commandLineParser. This is more robust as it removes both single and multiline comments --- src/compiler/commandLineParser.ts | 2 +- src/services/jsTyping.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 6d6392ff848..11b9576c87a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -477,7 +477,7 @@ namespace ts { * * This method replace comment content by whitespace rather than completely remove them to keep positions in json parsing error reporting accurate. */ - function removeComments(jsonText: string): string { + export function removeComments(jsonText: string): string { let output = ""; const scanner = createScanner(ScriptTarget.ES5, /* skipTrivia */ false, LanguageVariant.Standard, jsonText); let token: SyntaxKind; diff --git a/src/services/jsTyping.ts b/src/services/jsTyping.ts index d561734661b..251995a2991 100644 --- a/src/services/jsTyping.ts +++ b/src/services/jsTyping.ts @@ -21,8 +21,7 @@ namespace ts.JsTyping { function tryParseJson(jsonPath: string, host: TypingResolutionHost): any { if (host.fileExists(jsonPath)) { try { - // Strip out single-line comments - const contents = host.readFile(jsonPath).replace(/^\s*\/\/(.*)$/gm, ""); + const contents = removeComments(host.readFile(jsonPath)); return JSON.parse(contents); } catch (e) { }