mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
For JavaScript files, we report semantic errors for using TypeScript-only constructs
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// import a = b;
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'import ... =' can only be used in a .ts file.",
|
||||
"start": 0,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// function F<T>() { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'type parameter declarations' can only be used in a .ts file.",
|
||||
"start": 11,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// function F(): number { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'types' can only be used in a .ts file.",
|
||||
"start": 14,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// declare var v;
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'declare' can only be used in a .ts file.",
|
||||
"start": 0,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// var v: () => number;
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'types' can only be used in a .ts file.",
|
||||
"start": 7,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// Foo<number>();
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'type arguments' can only be used in a .ts file.",
|
||||
"start": 4,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// function F(public p) { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'parameter modifiers' can only be used in a .ts file.",
|
||||
"start": 11,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// function F(p?) { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'?' can only be used in a .ts file.",
|
||||
"start": 12,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// function F(a: number) { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'types' can only be used in a .ts file.",
|
||||
"start": 14,
|
||||
@@ -9,7 +9,7 @@
|
||||
////}
|
||||
|
||||
goTo.file("a.js");
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "\'public\' can only be used in a .ts file.",
|
||||
"start": 93,
|
||||
@@ -25,7 +25,7 @@ verify.getSemanticDiagnostics(`[
|
||||
////}
|
||||
|
||||
goTo.file("b.js");
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'types' can only be used in a .ts file.",
|
||||
"start": 17,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// enum E { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'enum declarations' can only be used in a .ts file.",
|
||||
"start": 5,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// export = b;
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'export=' can only be used in a .ts file.",
|
||||
"start": 0,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// class C<T> { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'type parameter declarations' can only be used in a .ts file.",
|
||||
"start": 8,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// public class C { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'public' can only be used in a .ts file.",
|
||||
"start": 0,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// class C implements D { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'implements clauses' can only be used in a .ts file.",
|
||||
"start": 8,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// interface I { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'interface declarations' can only be used in a .ts file.",
|
||||
"start": 10,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// module M { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'module declarations' can only be used in a .ts file.",
|
||||
"start": 7,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// type a = b;
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'type aliases' can only be used in a .ts file.",
|
||||
"start": 5,
|
||||
@@ -4,7 +4,7 @@
|
||||
// @Filename: a.js
|
||||
//// public function F() { }
|
||||
|
||||
verify.getSemanticDiagnostics(`[
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "'public' can only be used in a .ts file.",
|
||||
"start": 0,
|
||||
@@ -0,0 +1,40 @@
|
||||
/// <reference path="../fourslash.ts" />
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: b.js
|
||||
//// var a = "a";
|
||||
//// var b: boolean = true;
|
||||
//// function foo(): string { }
|
||||
//// var var = "c";
|
||||
|
||||
verify.getSyntacticDiagnostics(`[
|
||||
{
|
||||
"message": "Variable declaration expected.",
|
||||
"start": 67,
|
||||
"length": 3,
|
||||
"category": "error",
|
||||
"code": 1134
|
||||
},
|
||||
{
|
||||
"message": "Variable declaration expected.",
|
||||
"start": 71,
|
||||
"length": 1,
|
||||
"category": "error",
|
||||
"code": 1134
|
||||
},
|
||||
{
|
||||
"message": "Variable declaration expected.",
|
||||
"start": 73,
|
||||
"length": 3,
|
||||
"category": "error",
|
||||
"code": 1134
|
||||
},
|
||||
{
|
||||
"message": "\'types\' can only be used in a .ts file.",
|
||||
"start": 20,
|
||||
"length": 7,
|
||||
"category": "error",
|
||||
"code": 8010
|
||||
}
|
||||
]`);
|
||||
verify.getSemanticDiagnostics(`[]`);
|
||||
Reference in New Issue
Block a user