Merge pull request #9189 from Microsoft/js_property_declaration
Allow property declarations in .js files
This commit is contained in:
commit
a1e0504ed4
5 changed files with 40 additions and 24 deletions
|
@ -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;
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
|
||||
tests/cases/compiler/a.js(1,11): error TS8014: 'property declarations' can only be used in a .ts file.
|
||||
|
||||
|
||||
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
|
||||
==== tests/cases/compiler/a.js (1 errors) ====
|
||||
class C { v }
|
||||
~
|
||||
!!! error TS8014: 'property declarations' can only be used in a .ts file.
|
|
@ -1,3 +0,0 @@
|
|||
// @allowJs: true
|
||||
// @filename: a.js
|
||||
class C { v }
|
|
@ -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
|
||||
}
|
||||
]`);
|
||||
|
|
Loading…
Reference in a new issue