1namespace ts { 2 describe("unittests:: jsonParserRecovery", () => { 3 function parsesToValidSourceFileWithErrors(name: string, text: string) { 4 it(name, () => { 5 const file = parseJsonText(name, text); 6 assert(file.parseDiagnostics.length, "Should have parse errors"); 7 Harness.Baseline.runBaseline( 8 `jsonParserRecovery/${name.replace(/[^a-z0-9_-]/ig, "_")}.errors.txt`, 9 Harness.Compiler.getErrorBaseline([{ 10 content: text, 11 unitName: name 12 }], file.parseDiagnostics)); 13 14 // Will throw if parse tree does not cover full input text 15 file.getChildren(); 16 }); 17 } 18 19 parsesToValidSourceFileWithErrors("trailing identifier", "{} blah"); 20 parsesToValidSourceFileWithErrors("TypeScript code", "interface Foo {} blah"); 21 parsesToValidSourceFileWithErrors("Two comma-separated objects", "{}, {}"); 22 parsesToValidSourceFileWithErrors("Two objects", "{} {}"); 23 parsesToValidSourceFileWithErrors("JSX", ` 24 interface Test {} 25 26 const Header = () => ( 27 <div> 28 <h1>Header</h1> 29 <style jsx> 30 {\` 31 h1 { 32 color: red; 33 } 34 \`} 35 </style> 36 </div> 37 )`); 38 }); 39} 40