mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Allow property declarations in .js files
This commit is contained in:
@@ -2921,10 +2921,6 @@
|
||||
"category": "Error",
|
||||
"code": 8012
|
||||
},
|
||||
"'property declarations' can only be used in a .ts file.": {
|
||||
"category": "Error",
|
||||
"code": 8014
|
||||
},
|
||||
"'enum declarations' can only be used in a .ts file.": {
|
||||
"category": "Error",
|
||||
"code": 8015
|
||||
|
||||
@@ -1601,8 +1601,19 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.property_declarations_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
const propertyDeclaration = <PropertyDeclaration>node;
|
||||
if (propertyDeclaration.modifiers) {
|
||||
for (const modifier of propertyDeclaration.modifiers) {
|
||||
if (modifier.kind !== SyntaxKind.StaticKeyword) {
|
||||
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (checkTypeAnnotation((<PropertyDeclaration>node).type)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
|
||||
@@ -2,14 +2,35 @@
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// class C { v }
|
||||
////class C {
|
||||
//// x; // Regular property declaration allowed
|
||||
//// static y; // static allowed
|
||||
//// public z; // public not allowed
|
||||
////}
|
||||
|
||||
goTo.file("a.js");
|
||||
verify.getSemanticDiagnostics(`[
|
||||
{
|
||||
"message": "'property declarations' can only be used in a .ts file.",
|
||||
"start": 10,
|
||||
"length": 1,
|
||||
"message": "\'public\' can only be used in a .ts file.",
|
||||
"start": 93,
|
||||
"length": 6,
|
||||
"category": "error",
|
||||
"code": 8014
|
||||
"code": 8009
|
||||
}
|
||||
]`);
|
||||
]`);
|
||||
|
||||
// @Filename: b.js
|
||||
////class C {
|
||||
//// x: number; // Types not allowed
|
||||
////}
|
||||
|
||||
goTo.file("b.js");
|
||||
verify.getSemanticDiagnostics(`[
|
||||
{
|
||||
"message": "'types' can only be used in a .ts file.",
|
||||
"start": 17,
|
||||
"length": 6,
|
||||
"category": "error",
|
||||
"code": 8010
|
||||
}
|
||||
]`);
|
||||
|
||||
Reference in New Issue
Block a user