diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index cd08e592be8d2..c25ad20e990e3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2242,17 +2242,14 @@ module ts { } function parseTypeMemberSemicolon() { - // Try to parse out an explicit or implicit (ASI) semicolon for a type member. If we - // don't have one, then an appropriate error will be reported. - if (parseSemicolon()) { + // We allow type members to be separated by commas or (possibly ASI) semicolons. + // First check if it was a comma. If so, we're done with the member. + if (parseOptional(SyntaxKind.CommaToken)) { return; } - // If we don't have a semicolon, then the user may have written a comma instead - // accidently (pretty easy to do since commas are so prevalent as list separators). So - // just consume the comma and keep going. Note: we'll have already reported the error - // about the missing semicolon above. - parseOptional(SyntaxKind.CommaToken); + // Didn't have a comma. We must have a (possible ASI) semicolon. + parseSemicolon(); } function parseSignatureMember(kind: SyntaxKind): SignatureDeclaration { diff --git a/tests/baselines/reference/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.errors.txt b/tests/baselines/reference/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.errors.txt deleted file mode 100644 index 81798538bb7f4..0000000000000 --- a/tests/baselines/reference/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/conformance/internalModules/exportDeclarations/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.ts(8,27): error TS1005: ';' expected. -tests/cases/conformance/internalModules/exportDeclarations/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.ts(8,43): error TS1005: ';' expected. -tests/cases/conformance/internalModules/exportDeclarations/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.ts(9,30): error TS1005: ';' expected. - - -==== tests/cases/conformance/internalModules/exportDeclarations/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.ts (3 errors) ==== - module A { - - class Point { - constructor(public x: number, public y: number) { } - } - - export var UnitSquare : { - top: { left: Point, right: Point }, - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1005: ';' expected. - bottom: { left: Point, right: Point } - ~ -!!! error TS1005: ';' expected. - } = null; - } \ No newline at end of file diff --git a/tests/baselines/reference/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.types b/tests/baselines/reference/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.types new file mode 100644 index 0000000000000..a4284a8f4103b --- /dev/null +++ b/tests/baselines/reference/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/internalModules/exportDeclarations/ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.ts === +module A { +>A : typeof A + + class Point { +>Point : Point + + constructor(public x: number, public y: number) { } +>x : number +>y : number + } + + export var UnitSquare : { +>UnitSquare : { top: { left: Point; right: Point; }; bottom: { left: Point; right: Point; }; } + + top: { left: Point, right: Point }, +>top : { left: Point; right: Point; } +>left : Point +>Point : Point +>right : Point +>Point : Point + + bottom: { left: Point, right: Point } +>bottom : { left: Point; right: Point; } +>left : Point +>Point : Point +>right : Point +>Point : Point + + } = null; +} diff --git a/tests/baselines/reference/complicatedPrivacy.errors.txt b/tests/baselines/reference/complicatedPrivacy.errors.txt index 5aa399d1d8485..8cf5f81d906f3 100644 --- a/tests/baselines/reference/complicatedPrivacy.errors.txt +++ b/tests/baselines/reference/complicatedPrivacy.errors.txt @@ -1,9 +1,10 @@ -tests/cases/compiler/complicatedPrivacy.ts(24,38): error TS1005: ';' expected. +tests/cases/compiler/complicatedPrivacy.ts(11,24): error TS1054: A 'get' accessor cannot have parameters. +tests/cases/compiler/complicatedPrivacy.ts(35,5): error TS1170: Computed property names are not allowed in type literals. tests/cases/compiler/complicatedPrivacy.ts(35,6): error TS2304: Cannot find name 'number'. tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' has no exported member 'i6'. -==== tests/cases/compiler/complicatedPrivacy.ts (3 errors) ==== +==== tests/cases/compiler/complicatedPrivacy.ts (4 errors) ==== module m1 { export module m2 { @@ -15,6 +16,8 @@ tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' export class C2 implements m3.i3 { public get p1(arg) { + ~~ +!!! error TS1054: A 'get' accessor cannot have parameters. return new C1(); } @@ -28,8 +31,6 @@ tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' } export function f2(arg1: { x?: C1, y: number }) { - ~ -!!! error TS1005: ';' expected. } export function f3(): { @@ -41,6 +42,8 @@ tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' export function f4(arg1: { [number]: C1; // Used to be indexer, now it is a computed property + ~~~~~~~~ +!!! error TS1170: Computed property names are not allowed in type literals. ~~~~~~ !!! error TS2304: Cannot find name 'number'. }) { diff --git a/tests/baselines/reference/interfaceWithCommaSeparators.js b/tests/baselines/reference/interfaceWithCommaSeparators.js new file mode 100644 index 0000000000000..df144402d9f5d --- /dev/null +++ b/tests/baselines/reference/interfaceWithCommaSeparators.js @@ -0,0 +1,6 @@ +//// [interfaceWithCommaSeparators.ts] +var v: { bar(): void, baz } +interface Foo { bar(): void, baz } + +//// [interfaceWithCommaSeparators.js] +var v; diff --git a/tests/baselines/reference/interfaceWithCommaSeparators.types b/tests/baselines/reference/interfaceWithCommaSeparators.types new file mode 100644 index 0000000000000..8af41a4344ad0 --- /dev/null +++ b/tests/baselines/reference/interfaceWithCommaSeparators.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/interfaceWithCommaSeparators.ts === +var v: { bar(): void, baz } +>v : { bar(): void; baz: any; } +>bar : () => void +>baz : any + +interface Foo { bar(): void, baz } +>Foo : Foo +>bar : () => void +>baz : any + diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt index ef7620139895f..f12e29f511720 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt @@ -3,7 +3,6 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,16): error TS1131: Property or signature expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,25): error TS1128: Declaration or statement expected. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(6,53): error TS1005: ';' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(6,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'. Types of property 'id' are incompatible. Type 'number' is not assignable to type 'string'. @@ -12,7 +11,7 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr Type 'number' is not assignable to type 'boolean'. -==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (7 errors) ==== +==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (6 errors) ==== var id: number = 10000; var name: string = "my name"; @@ -28,8 +27,6 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr ~ !!! error TS1128: Declaration or statement expected. function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error - ~ -!!! error TS1005: ';' expected. ~~~~~~~~~~~~ !!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'. !!! error TS2322: Types of property 'id' are incompatible. diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt index b10ef656cd007..26b0224f2b037 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt @@ -1,20 +1,17 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(4,5): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'. Property 'b' is missing in type '{ name: string; id: number; }'. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(5,55): error TS1005: ';' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(5,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'. Types of property 'name' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(6,55): error TS1005: ';' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,16): error TS1131: Property or signature expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,25): error TS1128: Declaration or statement expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(8,5): error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'. Types of property 'name' are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(8,28): error TS1005: ';' expected. -==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (9 errors) ==== +==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (6 errors) ==== var id: number = 10000; var name: string = "my name"; @@ -23,15 +20,11 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr !!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'. !!! error TS2322: Property 'b' is missing in type '{ name: string; id: number; }'. function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error - ~ -!!! error TS1005: ';' expected. ~~~~~~~~~~~~ !!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'. !!! error TS2322: Types of property 'name' are incompatible. !!! error TS2322: Type 'string' is not assignable to type 'number'. function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error - ~ -!!! error TS1005: ';' expected. var person1: { name, id }; // error : Can't use shorthand in the type position ~~~~ !!! error TS1131: Property or signature expected. @@ -43,6 +36,4 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr ~~~~~~~ !!! error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'. !!! error TS2322: Types of property 'name' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. - ~ -!!! error TS1005: ';' expected. \ No newline at end of file +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt b/tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt index a774115e350da..00442f4f87d1d 100644 --- a/tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt +++ b/tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(2,16): error TS1005: ';' expected. tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,22): error TS1005: ';' expected. -==== tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts (2 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts (1 errors) ==== var x: { foo: string, - ~ -!!! error TS1005: ';' expected. bar: string } diff --git a/tests/baselines/reference/parserCommaInTypeMemberList1.errors.txt b/tests/baselines/reference/parserCommaInTypeMemberList1.errors.txt deleted file mode 100644 index 8bc22ca887ea9..0000000000000 --- a/tests/baselines/reference/parserCommaInTypeMemberList1.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList1.ts(1,23): error TS1005: ';' expected. - - -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList1.ts (1 errors) ==== - var v: { workItem: any, width: string }; - ~ -!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserCommaInTypeMemberList1.types b/tests/baselines/reference/parserCommaInTypeMemberList1.types new file mode 100644 index 0000000000000..177372c3e2772 --- /dev/null +++ b/tests/baselines/reference/parserCommaInTypeMemberList1.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList1.ts === +var v: { workItem: any, width: string }; +>v : { workItem: any; width: string; } +>workItem : any +>width : string + diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt index 8f29c985a66c3..931bd87293dc5 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt @@ -1,11 +1,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,9): error TS2304: Cannot find name '$'. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,53): error TS1005: ';' expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts (1 errors) ==== var s = $.extend< { workItem: any }, { workItem: any, width: string }>({ workItem: this._workItem }, {}); ~ !!! error TS2304: Cannot find name '$'. - ~ -!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/cases/compiler/interfaceWithCommaSeparators.ts b/tests/cases/compiler/interfaceWithCommaSeparators.ts new file mode 100644 index 0000000000000..03ae5480ef18d --- /dev/null +++ b/tests/cases/compiler/interfaceWithCommaSeparators.ts @@ -0,0 +1,2 @@ +var v: { bar(): void, baz } +interface Foo { bar(): void, baz } \ No newline at end of file