Skip to content

Allow commas as a separator between object/interface type members. #1971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we print the type with a comma too?

>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;
}
11 changes: 7 additions & 4 deletions tests/baselines/reference/complicatedPrivacy.errors.txt
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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();
}

Expand All @@ -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(): {
Expand All @@ -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'.
}) {
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/interfaceWithCommaSeparators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [interfaceWithCommaSeparators.ts]
var v: { bar(): void, baz }
interface Foo { bar(): void, baz }

//// [interfaceWithCommaSeparators.js]
var v;
11 changes: 11 additions & 0 deletions tests/baselines/reference/interfaceWithCommaSeparators.types
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand All @@ -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";

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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.
Expand All @@ -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.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down

This file was deleted.

6 changes: 6 additions & 0 deletions tests/baselines/reference/parserCommaInTypeMemberList1.types
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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.

2 changes: 2 additions & 0 deletions tests/cases/compiler/interfaceWithCommaSeparators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var v: { bar(): void, baz }
interface Foo { bar(): void, baz }