Skip to content

Commit 7e39622

Browse files
author
Yui T
committed
Basic implementation for finding all references
1 parent e9122b4 commit 7e39622

7 files changed

+32
-17
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ module ts {
110110
getAliasedSymbol: resolveImport,
111111
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
112112
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
113-
hasEarlyErrors: hasEarlyErrors
113+
hasEarlyErrors: hasEarlyErrors,
114+
resolveEntityNameForShortHandPropertyAssignment: resolveEntityNameForShortHandPropertyAssignment,
114115
};
115116

116117
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
@@ -537,6 +538,10 @@ module ts {
537538
return symbol.flags & meaning ? symbol : resolveImport(symbol);
538539
}
539540

541+
function resolveEntityNameForShortHandPropertyAssignment(location: Node): Symbol {
542+
return resolveEntityName(location, <Identifier>location, SymbolFlags.Value);
543+
}
544+
540545
function isExternalModuleNameRelative(moduleName: string): boolean {
541546
// TypeScript 1.0 spec (April 2014): 11.2.1
542547
// An external module name is "relative" if the first term is "." or "..".

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ module ts {
733733
getEnumMemberValue(node: EnumMember): number;
734734
isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean;
735735
getAliasedSymbol(symbol: Symbol): Symbol;
736+
resolveEntityNameForShortHandPropertyAssignment(location: Node): Symbol;
736737
}
737738

738739
export interface SymbolDisplayBuilder {

src/services/services.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4227,6 +4227,9 @@ module ts {
42274227
forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => {
42284228
result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol));
42294229
});
4230+
if (location.kind === SyntaxKind.Identifier && location.parent.kind === SyntaxKind.ShortHandPropertyAssignment) {
4231+
result.push(typeInfoResolver.resolveEntityNameForShortHandPropertyAssignment(location));
4232+
}
42304233
}
42314234

42324235
// If this is a union property, add all the symbols from all its source symbols in all unioned types.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
tests/cases/compiler/incompleteObjectLiteral1.ts(1,14): error TS1005: ':' expected.
1+
tests/cases/compiler/incompleteObjectLiteral1.ts(1,14): error TS1005: ',' expected.
22
tests/cases/compiler/incompleteObjectLiteral1.ts(1,16): error TS1128: Declaration or statement expected.
3+
tests/cases/compiler/incompleteObjectLiteral1.ts(1,12): error TS2304: Cannot find name 'aa'.
34

45

5-
==== tests/cases/compiler/incompleteObjectLiteral1.ts (2 errors) ====
6+
==== tests/cases/compiler/incompleteObjectLiteral1.ts (3 errors) ====
67
var tt = { aa; }
78
~
8-
!!! error TS1005: ':' expected.
9+
!!! error TS1005: ',' expected.
910
~
1011
!!! error TS1128: Declaration or statement expected.
12+
~~
13+
!!! error TS2304: Cannot find name 'aa'.
1114
var x = tt;

tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(12,6): error TS1112: A class member cannot be declared optional.
22
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(20,6): error TS1112: A class member cannot be declared optional.
3-
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1005: ':' expected.
4-
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,7): error TS1109: Expression expected.
3+
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1159: A object member cannot be declared optional.
54

65

7-
==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (4 errors) ====
6+
==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (3 errors) ====
87
// Basic uses of optional properties
98

109
var a: {
@@ -33,8 +32,6 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith
3332

3433
var b = {
3534
x?: 1 // error
36-
~
37-
!!! error TS1005: ':' expected.
38-
~
39-
!!! error TS1109: Expression expected.
35+
36+
!!! error TS1159: A object member cannot be declared optional.
4037
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,14): error TS1005: ':' expected.
1+
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,14): error TS1005: ',' expected.
22
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,16): error TS1128: Declaration or statement expected.
3+
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,12): error TS2304: Cannot find name 'aa'.
34

45

5-
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts (2 errors) ====
6+
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts (3 errors) ====
67
var tt = { aa; } // After this point, no useful parsing occurs in the entire file
78
~
8-
!!! error TS1005: ':' expected.
9+
!!! error TS1005: ',' expected.
910
~
1011
!!! error TS1128: Declaration or statement expected.
12+
~~
13+
!!! error TS2304: Cannot find name 'aa'.
1114

1215
if (true) {
1316
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,1): error TS1005: ':' expected.
1+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,1): error TS1005: ',' expected.
22
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,7): error TS1005: ':' expected.
3+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(1,11): error TS2304: Cannot find name 'a'.
34

45

5-
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts (2 errors) ====
6+
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts (3 errors) ====
67
var v = { a
8+
~
9+
!!! error TS2304: Cannot find name 'a'.
710
return;
811
~~~~~~
9-
!!! error TS1005: ':' expected.
12+
!!! error TS1005: ',' expected.
1013
~
1114
!!! error TS1005: ':' expected.

0 commit comments

Comments
 (0)