Merge pull request #3515 from Microsoft/classMemberWithMissingIdentifier
Parse class member with a missing identifier in the presence of a modifier
This commit is contained in:
commit
27cccddfea
|
@ -4207,7 +4207,7 @@ module ts {
|
|||
return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers);
|
||||
}
|
||||
|
||||
if (decorators) {
|
||||
if (decorators || modifiers) {
|
||||
// treat this as a property declaration with a missing name.
|
||||
let name = <Identifier>createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
|
||||
return parsePropertyDeclaration(fullStart, decorators, modifiers, name, /*questionToken*/ undefined);
|
||||
|
@ -4729,7 +4729,7 @@ module ts {
|
|||
case SyntaxKind.ImportKeyword:
|
||||
return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers);
|
||||
default:
|
||||
if (decorators) {
|
||||
if (decorators || modifiers) {
|
||||
// We reached this point because we encountered an AtToken and assumed a declaration would
|
||||
// follow. For recovery and error reporting purposes, return an incomplete declaration.
|
||||
let node = <ModuleElement>createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
tests/cases/compiler/classMemberWithMissingIdentifier.ts(2,11): error TS1146: Declaration expected.
|
||||
tests/cases/compiler/classMemberWithMissingIdentifier.ts(2,12): error TS1005: '=' expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/classMemberWithMissingIdentifier.ts (2 errors) ====
|
||||
class C {
|
||||
public {};
|
||||
|
||||
!!! error TS1146: Declaration expected.
|
||||
~
|
||||
!!! error TS1005: '=' expected.
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
//// [classMemberWithMissingIdentifier.ts]
|
||||
class C {
|
||||
public {};
|
||||
}
|
||||
|
||||
//// [classMemberWithMissingIdentifier.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
this. = {};
|
||||
}
|
||||
return C;
|
||||
})();
|
|
@ -0,0 +1,30 @@
|
|||
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,11): error TS1146: Declaration expected.
|
||||
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,12): error TS1005: '=' expected.
|
||||
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,14): error TS2304: Cannot find name 'name'.
|
||||
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,18): error TS1005: ']' expected.
|
||||
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,19): error TS2304: Cannot find name 'string'.
|
||||
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,25): error TS1005: ',' expected.
|
||||
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,26): error TS1136: Property assignment expected.
|
||||
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,27): error TS2304: Cannot find name 'VariableDeclaration'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/classMemberWithMissingIdentifier2.ts (8 errors) ====
|
||||
class C {
|
||||
public {[name:string]:VariableDeclaration};
|
||||
|
||||
!!! error TS1146: Declaration expected.
|
||||
~
|
||||
!!! error TS1005: '=' expected.
|
||||
~~~~
|
||||
!!! error TS2304: Cannot find name 'name'.
|
||||
~
|
||||
!!! error TS1005: ']' expected.
|
||||
~~~~~~
|
||||
!!! error TS2304: Cannot find name 'string'.
|
||||
~
|
||||
!!! error TS1005: ',' expected.
|
||||
~
|
||||
!!! error TS1136: Property assignment expected.
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'VariableDeclaration'.
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
//// [classMemberWithMissingIdentifier2.ts]
|
||||
class C {
|
||||
public {[name:string]:VariableDeclaration};
|
||||
}
|
||||
|
||||
//// [classMemberWithMissingIdentifier2.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
this. = (_a = {}, _a[name] = string, _a.VariableDeclaration = VariableDeclaration, _a);
|
||||
var _a;
|
||||
}
|
||||
return C;
|
||||
})();
|
3
tests/cases/compiler/classMemberWithMissingIdentifier.ts
Normal file
3
tests/cases/compiler/classMemberWithMissingIdentifier.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
class C {
|
||||
public {};
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class C {
|
||||
public {[name:string]:VariableDeclaration};
|
||||
}
|
Loading…
Reference in a new issue