diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 213661fdd60..a87b1f8cc28 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -124,7 +124,7 @@ module ts { Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: DiagnosticCategory.Error, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, - A_object_member_cannot_be_declared_optional: { code: 1160, category: DiagnosticCategory.Error, key: "A object member cannot be declared optional." }, + An_object_member_cannot_be_declared_optional: { code: 1160, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index cd2e209e3eb..7c966f7c954 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -488,7 +488,7 @@ "code": 1161 }, - "A object member cannot be declared optional.": { + "An object member cannot be declared optional.": { "category": "Error", "code": 1160 }, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 76d87199581..6a73a8a15a8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2733,6 +2733,7 @@ module ts { function parsePropertyAssignment(): Declaration { var nodePos = scanner.getStartPos(); + var tokenIsIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); var node: Declaration; @@ -2752,12 +2753,12 @@ module ts { // Disallow optional property assignment if (token === SyntaxKind.QuestionToken) { var questionStart = scanner.getTokenPos(); - grammarErrorAtPos(questionStart, scanner.getStartPos() - questionStart, Diagnostics.A_object_member_cannot_be_declared_optional); + grammarErrorAtPos(questionStart, scanner.getStartPos() - questionStart, Diagnostics.An_object_member_cannot_be_declared_optional); nextToken(); } // Parse to check if it is short-hand property assignment or normal property assignment - if (token !== SyntaxKind.ColonToken && nameToken === SyntaxKind.Identifier) { + if ((token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken) && tokenIsIdentifier) { node = createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos); node.name = propertyName; } diff --git a/tests/baselines/reference/incompleteObjectLiteral1.errors.txt b/tests/baselines/reference/incompleteObjectLiteral1.errors.txt index c37f308960a..2e363de591e 100644 --- a/tests/baselines/reference/incompleteObjectLiteral1.errors.txt +++ b/tests/baselines/reference/incompleteObjectLiteral1.errors.txt @@ -1,14 +1,11 @@ -tests/cases/compiler/incompleteObjectLiteral1.ts(1,14): error TS1005: ',' expected. +tests/cases/compiler/incompleteObjectLiteral1.ts(1,14): error TS1005: ':' expected. tests/cases/compiler/incompleteObjectLiteral1.ts(1,16): error TS1128: Declaration or statement expected. -tests/cases/compiler/incompleteObjectLiteral1.ts(1,12): error TS2304: Cannot find name 'aa'. -==== tests/cases/compiler/incompleteObjectLiteral1.ts (3 errors) ==== +==== tests/cases/compiler/incompleteObjectLiteral1.ts (2 errors) ==== var tt = { aa; } ~ -!!! error TS1005: ',' expected. +!!! error TS1005: ':' expected. ~ !!! error TS1128: Declaration or statement expected. - ~~ -!!! error TS2304: Cannot find name 'aa'. var x = tt; \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt index 3c5f4e97d80..33672c3d54c 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt @@ -7,18 +7,17 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(9,8): error TS1005: ':' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(10,10): error TS1005: ':' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(12,1): error TS1005: ':' expected. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,6): error TS1005: ',' expected. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,6): error TS1005: ',' expected. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,6): error TS1005: '=' expected. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(18,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,6): error TS1005: ':' expected. +tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,6): error TS1005: ':' expected. +tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,6): error TS1005: ':' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(20,17): error TS1005: ':' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,5): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,7): error TS2304: Cannot find name 'b'. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,5): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,5): error TS2300: Duplicate identifier 'a'. -==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (18 errors) ==== +==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (17 errors) ==== // errors var y = { "stringLiteral", @@ -55,22 +54,20 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr var x = { a.b, ~ -!!! error TS1005: ',' expected. +!!! error TS1005: ':' expected. ~ !!! error TS2300: Duplicate identifier 'a'. - ~ -!!! error TS2304: Cannot find name 'b'. a["ss"], ~ -!!! error TS1005: ',' expected. +!!! error TS1005: ':' expected. ~ !!! error TS2300: Duplicate identifier 'a'. a[1], ~ -!!! error TS1005: '=' expected. +!!! error TS1005: ':' expected. + ~ +!!! error TS2300: Duplicate identifier 'a'. }; - ~ -!!! error TS1128: Declaration or statement expected. var v = { class }; // error ~ diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesErrorWithModule.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesErrorWithModule.errors.txt index f5fd8ed53f2..15bac99436f 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesErrorWithModule.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesErrorWithModule.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorWithModule.ts(10,10): error TS1005: ',' expected. +tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorWithModule.ts(10,10): error TS1005: ':' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorWithModule.ts(14,3): error TS2339: Property 'y' does not exist on type 'typeof m'. @@ -14,7 +14,7 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr export var y = { m.x // error ~ -!!! error TS1005: ',' expected. +!!! error TS1005: ':' expected. }; } diff --git a/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt b/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt index e73e8adc930..14afcebd213 100644 --- a/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt +++ b/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(12,6): error TS1112: A class member cannot be declared optional. tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(20,6): error TS1112: A class member cannot be declared optional. -tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1160: A object member cannot be declared optional. +tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1160: An object member cannot be declared optional. ==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (3 errors) ==== @@ -33,5 +33,5 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith var b = { x?: 1 // error -!!! error TS1160: A object member cannot be declared optional. +!!! error TS1160: An object member cannot be declared optional. } \ No newline at end of file diff --git a/tests/baselines/reference/parser512097.errors.txt b/tests/baselines/reference/parser512097.errors.txt index 181060db95d..3963d969c34 100644 --- a/tests/baselines/reference/parser512097.errors.txt +++ b/tests/baselines/reference/parser512097.errors.txt @@ -1,16 +1,13 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,14): error TS1005: ',' expected. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,14): error TS1005: ':' expected. tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,16): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,12): error TS2304: Cannot find name 'aa'. -==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts (2 errors) ==== var tt = { aa; } // After this point, no useful parsing occurs in the entire file ~ -!!! error TS1005: ',' expected. +!!! error TS1005: ':' expected. ~ !!! error TS1128: Declaration or statement expected. - ~~ -!!! error TS2304: Cannot find name 'aa'. if (true) { } \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ObjectLiteral2.errors.txt b/tests/baselines/reference/parserErrorRecovery_ObjectLiteral2.errors.txt index 1c526f0c9ec..55667d42de5 100644 --- a/tests/baselines/reference/parserErrorRecovery_ObjectLiteral2.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ObjectLiteral2.errors.txt @@ -1,14 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,1): error TS1005: ',' expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,1): error TS1005: ':' expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,7): error TS1005: ':' expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(1,11): error TS2304: Cannot find name 'a'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts (2 errors) ==== var v = { a - ~ -!!! error TS2304: Cannot find name 'a'. return; ~~~~~~ -!!! error TS1005: ',' expected. +!!! error TS1005: ':' expected. ~ !!! error TS1005: ':' expected. \ No newline at end of file