From b8bcc700faab2fbc30b939078f4938b503ae1bfd Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 18 Nov 2014 16:15:04 -0800 Subject: [PATCH] Improve error messages --- src/compiler/parser.ts | 3 ++- .../incompleteObjectLiteral1.errors.txt | 9 +++----- ...tiesErrorFromNotUsingIdentifier.errors.txt | 23 ++++++++----------- ...rthandPropertiesErrorWithModule.errors.txt | 4 ++-- .../reference/parser512097.errors.txt | 9 +++----- ...serErrorRecovery_ObjectLiteral2.errors.txt | 9 +++----- 6 files changed, 23 insertions(+), 34 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 924f6e8393..9b2485a424 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 isTokenIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); var node: Declaration; @@ -2757,7 +2758,7 @@ module ts { } // 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) && isTokenIdentifier) { 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 c37f308960..2e363de591 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 3c5f4e97d8..33672c3d54 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 f5fd8ed53f..15bac99436 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/parser512097.errors.txt b/tests/baselines/reference/parser512097.errors.txt index 181060db95..3963d969c3 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 1c526f0c9e..55667d42de 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