Address code review

This commit is contained in:
Yui T 2014-11-13 12:02:13 -08:00
parent 1888f736e1
commit a8ebdf0cbd
16 changed files with 60 additions and 58 deletions

View File

@ -350,7 +350,7 @@ module ts {
break;
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShortHandPropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.EnumMember:

View File

@ -94,6 +94,7 @@ module ts {
getReturnTypeOfSignature: getReturnTypeOfSignature,
getSymbolsInScope: getSymbolsInScope,
getSymbolInfo: getSymbolInfo,
getValueSymbolInfo: getValueSymbolInfo,
getTypeOfNode: getTypeOfNode,
typeToString: typeToString,
getSymbolDisplayBuilder: getSymbolDisplayBuilder,
@ -111,7 +112,6 @@ module ts {
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
hasEarlyErrors: hasEarlyErrors,
resolveEntityNameForShortHandPropertyAssignment: resolveEntityNameForShortHandPropertyAssignment,
};
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
@ -538,10 +538,6 @@ module ts {
return symbol.flags & meaning ? symbol : resolveImport(symbol);
}
function resolveEntityNameForShortHandPropertyAssignment(location: Node): Symbol {
return resolveEntityName(location, <Identifier>location, SymbolFlags.Value);
}
function isExternalModuleNameRelative(moduleName: string): boolean {
// TypeScript 1.0 spec (April 2014): 11.2.1
// An external module name is "relative" if the first term is "." or "..".
@ -1672,8 +1668,8 @@ module ts {
}
// If it is a short-hand property assignment; Use the type of the identifier
if (declaration.kind === SyntaxKind.ShortHandPropertyAssignment) {
var type = checkIdentifier(<Identifier>(declaration.name));
if (declaration.kind === SyntaxKind.ShorthandPropertyAssignment) {
var type = checkIdentifier(<Identifier>declaration.name);
return type
}
@ -4986,6 +4982,7 @@ module ts {
type = checkExpression(memberDecl.initializer, contextualMapper);
}
else {
Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment);
type = checkExpression(memberDecl.name, contextualMapper);
}
var prop = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name);
@ -8647,6 +8644,11 @@ module ts {
return undefined;
}
function getValueSymbolInfo(node: Node): Symbol {
// Get symbol information as value
return resolveEntityName(node, <Identifier>node, SymbolFlags.Value);
}
function getTypeOfNode(node: Node): Type {
if (isInsideWithStatementBody(node)) {
// We cannot answer semantic questions within a with block, do not proceed any further

View File

@ -122,7 +122,7 @@ module ts {
let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." },
Invalid_template_literal_expected: { code: 1158, category: DiagnosticCategory.Error, key: "Invalid template literal; expected '}'" },
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." },
A_object_member_cannot_be_declared_optional: { code: 1159, category: DiagnosticCategory.Error, key: "A object member cannot be declared optional." },
A_object_member_cannot_be_declared_optional: { code: 1160, category: DiagnosticCategory.Error, key: "A 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." },

View File

@ -482,7 +482,7 @@
"A object member cannot be declared optional.": {
"category": "Error",
"code": 1159
"code": 1160
},
"Duplicate identifier '{0}'.": {

View File

@ -934,7 +934,7 @@ module ts {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShortHandPropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.Method:
case SyntaxKind.FunctionDeclaration:
@ -2287,7 +2287,7 @@ module ts {
return emitObjectLiteral(<ObjectLiteral>node);
case SyntaxKind.PropertyAssignment:
return emitPropertyAssignment(<PropertyDeclaration>node);
case SyntaxKind.ShortHandPropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
return emitShortHandPropertyAssignment(<ShortHandPropertyDeclaration>node);
case SyntaxKind.PropertyAccess:
return emitPropertyAccess(<PropertyAccess>node);

View File

@ -198,7 +198,7 @@ module ts {
child((<ParameterDeclaration>node).initializer);
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShortHandPropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
return child((<PropertyDeclaration>node).name) ||
child((<PropertyDeclaration>node).type) ||
child((<PropertyDeclaration>node).initializer);
@ -574,7 +574,7 @@ module ts {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShortHandPropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.Method:
case SyntaxKind.FunctionDeclaration:
@ -2669,11 +2669,11 @@ module ts {
return finishNode(node);
}
function parsePropertyAssignment(): PropertyDeclaration {
function parsePropertyAssignment(): Declaration {
var nodePos = scanner.getStartPos();
var nameToken = token;
var propertyName = parsePropertyName();
var node: PropertyDeclaration;
var node: Declaration;
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment, nodePos);
node.name = propertyName;
@ -2684,25 +2684,25 @@ module ts {
// var x = 1;
// var y = { x() { } }
// otherwise this will bring y.x into the scope of x which is incorrect
node.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
(<PropertyDeclaration>node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
return finishNode(node);
}
if (token === SyntaxKind.QuestionToken) {
var questionStart = scanner.getTokenPos();
errorAtPos(questionStart, scanner.getStartPos() - questionStart, Diagnostics.A_object_member_cannot_be_declared_optional);
grammarErrorAtPos(questionStart, scanner.getStartPos() - questionStart, Diagnostics.A_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) {
node = <ShortHandPropertyDeclaration>createNode(SyntaxKind.ShortHandPropertyAssignment, nodePos);
node = <ShortHandPropertyDeclaration>createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos);
node.name = propertyName;
}
else {
node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment, nodePos);
node.name = propertyName;
parseExpected(SyntaxKind.ColonToken);
node.initializer = parseAssignmentExpression(false);
(<PropertyDeclaration>node).initializer = parseAssignmentExpression(false);
}
return finishNode(node);
}
@ -2752,7 +2752,7 @@ module ts {
if (p.kind === SyntaxKind.PropertyAssignment) {
currentKind = Property;
}
else if (p.kind === SyntaxKind.ShortHandPropertyAssignment) {
else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) {
currentKind = Property;
}
else if (p.kind === SyntaxKind.GetAccessor) {

View File

@ -165,7 +165,7 @@ module ts {
ArrayLiteral,
ObjectLiteral,
PropertyAssignment,
ShortHandPropertyAssignment,
ShorthandPropertyAssignment,
PropertyAccess,
IndexedAccess,
CallExpression,
@ -330,7 +330,7 @@ module ts {
initializer?: Expression;
}
export interface ShortHandPropertyDeclaration extends PropertyDeclaration {
export interface ShortHandPropertyDeclaration extends Declaration {
name: Identifier;
}
@ -715,6 +715,7 @@ module ts {
getReturnTypeOfSignature(signature: Signature): Type;
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
getSymbolInfo(node: Node): Symbol;
getValueSymbolInfo(node: Node): Symbol;
getTypeOfNode(node: Node): Type;
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
@ -733,7 +734,6 @@ module ts {
getEnumMemberValue(node: EnumMember): number;
isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean;
getAliasedSymbol(symbol: Symbol): Symbol;
resolveEntityNameForShortHandPropertyAssignment(location: Node): Symbol;
}
export interface SymbolDisplayBuilder {

View File

@ -1969,7 +1969,7 @@ module ts {
/** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */
function isNameOfPropertyAssignment(node: Node): boolean {
return (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) &&
(node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShortHandPropertyAssignment) && (<PropertyDeclaration>node.parent).name === node;
(node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (<PropertyDeclaration>node.parent).name === node;
}
function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean {
@ -2648,7 +2648,7 @@ module ts {
var existingMemberNames: Map<boolean> = {};
forEach(existingMembers, m => {
if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShortHandPropertyAssignment) {
if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) {
// Ignore omitted expressions for missing members in the object literal
return;
}
@ -4062,9 +4062,9 @@ module ts {
result.push(getReferenceEntryFromNode(referenceLocation));
}
// TODO (yuisu): Comment
else if (referenceSymbol && referenceSymbol.declarations[0].kind === SyntaxKind.ShortHandPropertyAssignment) {
else if (referenceSymbol && referenceSymbol.declarations[0].kind === SyntaxKind.ShorthandPropertyAssignment) {
var referenceSymbolDeclName = referenceSymbol.declarations[0].name;
if (searchSymbols.indexOf(typeInfoResolver.resolveEntityNameForShortHandPropertyAssignment(referenceSymbolDeclName)) >= 0 &&
if (searchSymbols.indexOf(typeInfoResolver.getValueSymbolInfo(referenceSymbolDeclName)) >= 0 &&
!(<SymbolLinks>referenceSymbol).target) {
result.push(getReferenceEntryFromNode(referenceSymbolDeclName));
}
@ -4237,8 +4237,8 @@ module ts {
});
// Add the symbol in the case of short-hand property assignment
if (location.kind === SyntaxKind.Identifier && location.parent.kind === SyntaxKind.ShortHandPropertyAssignment) {
result.push(typeInfoResolver.resolveEntityNameForShortHandPropertyAssignment(location));
if (location.kind === SyntaxKind.Identifier && location.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
result.push(typeInfoResolver.getValueSymbolInfo(location));
}
}
@ -4582,7 +4582,7 @@ module ts {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShortHandPropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.Method:
case SyntaxKind.Constructor:

View File

@ -26,7 +26,7 @@ var x1 = {
a: a
};
var x2 = {
a: a
a: a,
};
var x3 = {
a: 0,

View File

@ -1,4 +1,4 @@
=== tests/cases/compiler/objectLiteralShorthandProperties.ts ===
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties.ts ===
var a, b, c;
>a : any
>b : any

View File

@ -1,23 +1,23 @@
tests/cases/compiler/objectLiteralShorthandProperties2.ts(3,20): error TS1005: ':' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(4,7): error TS1005: ':' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(5,10): error TS1005: '(' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(6,10): error TS1005: '(' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(7,9): error TS1005: ':' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(8,10): error TS1005: ':' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(9,8): error TS1005: ':' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(10,10): error TS1005: ':' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(12,1): error TS1005: ':' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(15,6): error TS1005: ',' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(16,6): error TS1005: ',' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(17,6): error TS1005: '=' expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(18,1): error TS1128: Declaration or statement expected.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(15,5): error TS2300: Duplicate identifier 'a'.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(15,7): error TS2304: Cannot find name 'b'.
tests/cases/compiler/objectLiteralShorthandProperties2.ts(16,5): error TS2300: Duplicate identifier 'a'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(3,20): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(4,7): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(5,10): error TS1005: '(' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(6,10): error TS1005: '(' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(7,9): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(8,10): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(9,8): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(10,10): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(12,1): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(15,6): error TS1005: ',' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(16,6): error TS1005: ',' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(17,6): error TS1005: '=' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(18,1): error TS1128: Declaration or statement expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(15,5): error TS2300: Duplicate identifier 'a'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(15,7): error TS2304: Cannot find name 'b'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts(16,5): error TS2300: Duplicate identifier 'a'.
==== tests/cases/compiler/objectLiteralShorthandProperties2.ts (17 errors) ====
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties2.ts (17 errors) ====
// errors
var y = {
"stringLiteral",

View File

@ -25,6 +25,6 @@ var m;
var z = m.x;
var y = {
a: m.x,
m.x: m.x
x: m.x
};
})(m || (m = {}));

View File

@ -1,4 +1,4 @@
=== tests/cases/compiler/objectLiteralShorthandProperties3.ts ===
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties3.ts ===
// module export
module m {

View File

@ -1,7 +1,7 @@
tests/cases/compiler/objectLiteralShorthandProperties4.ts(3,5): error TS2304: Cannot find name 'undefinedVariable'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties4.ts(3,5): error TS2304: Cannot find name 'undefinedVariable'.
==== tests/cases/compiler/objectLiteralShorthandProperties4.ts (1 errors) ====
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties4.ts (1 errors) ====
var x = {
x, // OK
undefinedVariable // Error

View File

@ -57,6 +57,6 @@ var m;
var z = m.x;
var y = {
a: m.x,
m.x
x: m.x
};
})(m || (m = {}));

View File

@ -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 TS1159: A object 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 (3 errors) ====
@ -33,5 +33,5 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith
var b = {
x?: 1 // error
!!! error TS1159: A object member cannot be declared optional.
!!! error TS1160: A object member cannot be declared optional.
}