-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5450 from sarod/allow-comments-tsconfig
Allow comments in tsconfig.json
- Loading branch information
Showing
3 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/// <reference path="..\..\..\src\harness\harness.ts" /> | ||
/// <reference path="..\..\..\src\compiler\commandLineParser.ts" /> | ||
|
||
namespace ts { | ||
describe('parseConfigFileTextToJson', () => { | ||
function assertParseResult(jsonText: string, expectedConfigObject: { config?: any; error?: Diagnostic }) { | ||
let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); | ||
assert.equal(JSON.stringify(parsed), JSON.stringify(expectedConfigObject)); | ||
} | ||
|
||
function assertParseError(jsonText: string) { | ||
let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); | ||
assert.isTrue(undefined === parsed.config); | ||
assert.isTrue(undefined !== parsed.error); | ||
} | ||
|
||
it("returns empty config for file with only whitespaces", () => { | ||
assertParseResult("", { config : {} }); | ||
assertParseResult(" ", { config : {} }); | ||
}); | ||
|
||
it("returns empty config for file with comments only", () => { | ||
assertParseResult("// Comment", { config: {} }); | ||
assertParseResult("/* Comment*/", { config: {} }); | ||
}); | ||
|
||
it("returns empty config when config is empty object", () => { | ||
assertParseResult("{}", { config: {} }); | ||
}); | ||
|
||
it("returns config object without comments", () => { | ||
assertParseResult( | ||
`{ // Excluded files | ||
"exclude": [ | ||
// Exclude d.ts | ||
"file.d.ts" | ||
] | ||
}`, { config: { exclude: ["file.d.ts"] } }); | ||
|
||
assertParseResult( | ||
`{ | ||
/* Excluded | ||
Files | ||
*/ | ||
"exclude": [ | ||
/* multiline comments can be in the middle of a line */"file.d.ts" | ||
] | ||
}`, { config: { exclude: ["file.d.ts"] } }); | ||
}); | ||
|
||
it("keeps string content untouched", () => { | ||
assertParseResult( | ||
`{ | ||
"exclude": [ | ||
"xx//file.d.ts" | ||
] | ||
}`, { config: { exclude: ["xx//file.d.ts"] } }); | ||
assertParseResult( | ||
`{ | ||
"exclude": [ | ||
"xx/*file.d.ts*/" | ||
] | ||
}`, { config: { exclude: ["xx/*file.d.ts*/"] } }); | ||
}); | ||
|
||
it("handles escaped characters in strings correctly", () => { | ||
assertParseResult( | ||
`{ | ||
"exclude": [ | ||
"xx\\"//files" | ||
] | ||
}`, { config: { exclude: ["xx\"//files"] } }); | ||
|
||
assertParseResult( | ||
`{ | ||
"exclude": [ | ||
"xx\\\\" // end of line comment | ||
] | ||
}`, { config: { exclude: ["xx\\"] } }); | ||
}); | ||
|
||
it("returns object with error when json is invalid", () => { | ||
assertParseError("invalid"); | ||
}); | ||
}); | ||
} |