diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 739c2ea460f..9fc4248c519 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -492,15 +492,15 @@ module ts { implements_clauses_can_only_be_used_in_TypeScript: { code: 8005, category: DiagnosticCategory.Error, key: "'implements clauses' can only be used in TypeScript." }, interface_declarations_can_only_be_used_in_TypeScript: { code: 8006, category: DiagnosticCategory.Error, key: "'interface declarations' can only be used in TypeScript." }, module_declarations_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'module declarations' can only be used in TypeScript." }, - type_aliases_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in TypeScript." }, - _0_can_only_be_used_in_TypeScript: { code: 8008, category: DiagnosticCategory.Error, key: "'{0}' can only be used in TypeScript." }, - types_can_only_be_used_in_TypeScript: { code: 8009, category: DiagnosticCategory.Error, key: "'types' can only be used in TypeScript." }, - type_arguments_can_only_be_used_in_TypeScript: { code: 8010, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in TypeScript." }, - parameter_modifiers_can_only_be_used_in_TypeScript: { code: 8011, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in TypeScript." }, - can_only_be_used_in_TypeScript: { code: 8012, category: DiagnosticCategory.Error, key: "'?' can only be used in TypeScript." }, - property_declarations_can_only_be_used_in_TypeScript: { code: 8013, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in TypeScript." }, - enum_declarations_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in TypeScript." }, - type_assertion_expressions_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in TypeScript." }, + type_aliases_can_only_be_used_in_TypeScript: { code: 8008, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in TypeScript." }, + _0_can_only_be_used_in_TypeScript: { code: 8009, category: DiagnosticCategory.Error, key: "'{0}' can only be used in TypeScript." }, + types_can_only_be_used_in_TypeScript: { code: 8010, category: DiagnosticCategory.Error, key: "'types' can only be used in TypeScript." }, + type_arguments_can_only_be_used_in_TypeScript: { code: 8011, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in TypeScript." }, + parameter_modifiers_can_only_be_used_in_TypeScript: { code: 8012, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in TypeScript." }, + can_only_be_used_in_TypeScript: { code: 8013, category: DiagnosticCategory.Error, key: "'?' can only be used in TypeScript." }, + property_declarations_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in TypeScript." }, + enum_declarations_can_only_be_used_in_TypeScript: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in TypeScript." }, + type_assertion_expressions_can_only_be_used_in_TypeScript: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in TypeScript." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 552f1b04606..379a95bc405 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1964,39 +1964,39 @@ }, "'type aliases' can only be used in TypeScript.": { "category": "Error", - "code": 8007 + "code": 8008 }, "'{0}' can only be used in TypeScript.": { "category": "Error", - "code": 8008 + "code": 8009 }, "'types' can only be used in TypeScript.": { "category": "Error", - "code": 8009 + "code": 8010 }, "'type arguments' can only be used in TypeScript.": { "category": "Error", - "code": 8010 + "code": 8011 }, "'parameter modifiers' can only be used in TypeScript.": { "category": "Error", - "code": 8011 + "code": 8012 }, "'?' can only be used in TypeScript.": { "category": "Error", - "code": 8012 + "code": 8013 }, "'property declarations' can only be used in TypeScript.": { "category": "Error", - "code": 8013 + "code": 8014 }, "'enum declarations' can only be used in TypeScript.": { "category": "Error", - "code": 8014 + "code": 8015 }, "'type assertion expressions' can only be used in TypeScript.": { "category": "Error", - "code": 8014 + "code": 8016 }, "'yield' expressions are not currently supported.": { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 44927a7a49a..9d55fcc58b9 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -797,9 +797,6 @@ module FourSlash { var diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName); var realized = ts.realizeDiagnostics(diagnostics, "\r\n"); var actual = JSON.stringify(realized, null, " "); - if (actual !== expected) { - ts.sys.writeFile("c:\\temp\\out.txt", actual); - } assert.equal(actual, expected); } diff --git a/src/services/services.ts b/src/services/services.ts index 8715a171c8b..a64358dd9fc 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2384,7 +2384,8 @@ module ts { let targetSourceFile = getValidSourceFile(fileName); // For JavaScript files, we don't want to report the normal typescript semantic errors. - // Instead, we just report errors for using TypeScript + // Instead, we just report errors for using TypeScript-only constructs from within a + // JavaScript file. if (isJavaScript(fileName)) { return getJavaScriptSemanticDiagnostics(targetSourceFile); } @@ -2505,7 +2506,8 @@ module ts { diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_TypeScript)); return; case SyntaxKind.TypeAssertionExpression: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_assertion_expressions_can_only_be_used_in_TypeScript)); + let typeAssertionExpression = node; + diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_TypeScript)); return; } diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts new file mode 100644 index 00000000000..d5bf9e142d7 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F() { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'type parameter declarations' can only be used in TypeScript.", + "start": 11, + "length": 1, + "category": "error", + "code": 8004 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts new file mode 100644 index 00000000000..060dfa4c01a --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F(): number { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'types' can only be used in TypeScript.", + "start": 14, + "length": 6, + "category": "error", + "code": 8010 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts new file mode 100644 index 00000000000..4a73b44725d --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// declare var v; + +verify.getSemanticDiagnostics(`[ + { + "message": "'declare' can only be used in TypeScript.", + "start": 0, + "length": 7, + "category": "error", + "code": 8009 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts new file mode 100644 index 00000000000..2717e23aba9 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// var v: () => number; + +verify.getSemanticDiagnostics(`[ + { + "message": "'types' can only be used in TypeScript.", + "start": 7, + "length": 12, + "category": "error", + "code": 8010 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts new file mode 100644 index 00000000000..c67659379fc --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// Foo(); + +verify.getSemanticDiagnostics(`[ + { + "message": "'type arguments' can only be used in TypeScript.", + "start": 4, + "length": 6, + "category": "error", + "code": 8011 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts new file mode 100644 index 00000000000..756e17d9a34 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F(public p) { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'parameter modifiers' can only be used in TypeScript.", + "start": 11, + "length": 6, + "category": "error", + "code": 8012 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts new file mode 100644 index 00000000000..1ce8f3a767d --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F(p?) { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'?' can only be used in TypeScript.", + "start": 12, + "length": 1, + "category": "error", + "code": 8013 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts new file mode 100644 index 00000000000..fad657f9b50 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F(a: number) { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'types' can only be used in TypeScript.", + "start": 14, + "length": 6, + "category": "error", + "code": 8010 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts new file mode 100644 index 00000000000..6c2578d6e85 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// class C { v } + +verify.getSemanticDiagnostics(`[ + { + "message": "'property declarations' can only be used in TypeScript.", + "start": 10, + "length": 1, + "category": "error", + "code": 8014 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts new file mode 100644 index 00000000000..6dc83c38327 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// enum E { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'enum declarations' can only be used in TypeScript.", + "start": 5, + "length": 1, + "category": "error", + "code": 8015 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts new file mode 100644 index 00000000000..cf5f16b827a --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// var v = undefined; + +verify.getSemanticDiagnostics(`[ + { + "message": "'type assertion expressions' can only be used in TypeScript.", + "start": 9, + "length": 6, + "category": "error", + "code": 8016 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts index 27635cb34b7..8505798e230 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts @@ -10,6 +10,6 @@ verify.getSemanticDiagnostics(`[ "start": 0, "length": 6, "category": "error", - "code": 8008 + "code": 8009 } ]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts new file mode 100644 index 00000000000..09cd23ffbf6 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// interface I { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'interface declarations' can only be used in TypeScript.", + "start": 10, + "length": 1, + "category": "error", + "code": 8006 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts new file mode 100644 index 00000000000..77c0b1f4e0d --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// module M { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'module declarations' can only be used in TypeScript.", + "start": 7, + "length": 1, + "category": "error", + "code": 8007 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts new file mode 100644 index 00000000000..c0a27621539 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// type a = b; + +verify.getSemanticDiagnostics(`[ + { + "message": "'type aliases' can only be used in TypeScript.", + "start": 0, + "length": 11, + "category": "error", + "code": 8008 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts new file mode 100644 index 00000000000..6b7eed188fe --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// public function F() { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'public' can only be used in TypeScript.", + "start": 0, + "length": 6, + "category": "error", + "code": 8009 + } +]`); \ No newline at end of file