Allow property declarations in .js files

This commit is contained in:
Andy Hanson
2016-06-15 09:42:52 -07:00
parent 38c89af6b2
commit dd0411a2f3
3 changed files with 40 additions and 12 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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
}
]`);