diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index ef4410b3e33..110e59c46e1 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -798,8 +798,17 @@ module FourSlash { return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; } + public getSyntacticDiagnostics(expected: string) { + var diagnostics = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName); + this.testDiagnostics(expected, diagnostics); + } + public getSemanticDiagnostics(expected: string) { var diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName); + this.testDiagnostics(expected, diagnostics); + } + + private testDiagnostics(expected: string, diagnostics: ts.Diagnostic[]) { var realized = ts.realizeDiagnostics(diagnostics, "\r\n"); var actual = JSON.stringify(realized, null, " "); assert.equal(actual, expected); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 9c6fd814d9f..21c65c699ab 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -448,6 +448,10 @@ module FourSlashInterface { FourSlash.currentTestState.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation); } + public getSyntacticDiagnostics(expected: string) { + FourSlash.currentTestState.getSyntacticDiagnostics(expected); + } + public getSemanticDiagnostics(expected: string) { FourSlash.currentTestState.getSemanticDiagnostics(expected); } diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics22.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics22.ts new file mode 100644 index 00000000000..16c5380189e --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics22.ts @@ -0,0 +1,7 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.js +//// function foo(...a) {} + +verify.getSemanticDiagnostics(`[]`); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts new file mode 100644 index 00000000000..372ae8d6e2e --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts @@ -0,0 +1,19 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.js +//// /** +//// * @type {number} +//// * @type {string} +//// */ +//// var v; + +verify.getSyntacticDiagnostics(`[ + { + "message": "\'type\' tag already specified.", + "start": 26, + "length": 4, + "category": "error", + "code": 1219 + } +]`); \ No newline at end of file