mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 02:15:12 -06:00
Using removeComments from commandLineParser. This is more robust as it removes both single and multiline comments
This commit is contained in:
parent
5cdb97cbfd
commit
0de8f9eeb2
@ -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;
|
||||
|
||||
@ -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) { }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user