Don't create a missing node for "foo[]".

We want to remove 'missing' nodes, and we also want to improve increment reuse (which missing nodes
interfere with).
This commit is contained in:
Cyrus Najmabadi 2014-12-01 14:14:39 -08:00
parent 3a6dba5878
commit eee6491521
3 changed files with 19 additions and 16 deletions

View File

@ -5246,11 +5246,13 @@ module ts {
function checkIndexedAccess(node: ElementAccessExpression): Type {
// Obtain base constraint such that we can bail out if the constraint is an unknown type
var objectType = getApparentType(checkExpression(node.expression));
var indexType = checkExpression(node.argumentExpression);
var indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType;
if (objectType === unknownType) return unknownType;
if (objectType === unknownType) {
return unknownType;
}
if (isConstEnumObjectType(objectType) && node.argumentExpression.kind !== SyntaxKind.StringLiteral) {
if (isConstEnumObjectType(objectType) && node.argumentExpression && node.argumentExpression.kind !== SyntaxKind.StringLiteral) {
error(node.argumentExpression, Diagnostics.Index_expression_arguments_in_const_enums_must_be_of_type_string);
}
@ -5264,12 +5266,14 @@ module ts {
// - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any.
// See if we can index as a property.
if (node.argumentExpression.kind === SyntaxKind.StringLiteral || node.argumentExpression.kind === SyntaxKind.NumericLiteral) {
var name = (<LiteralExpression>node.argumentExpression).text;
var prop = getPropertyOfType(objectType, name);
if (prop) {
getNodeLinks(node).resolvedSymbol = prop;
return getTypeOfSymbol(prop);
if (node.argumentExpression) {
if (node.argumentExpression.kind === SyntaxKind.StringLiteral || node.argumentExpression.kind === SyntaxKind.NumericLiteral) {
var name = (<LiteralExpression>node.argumentExpression).text;
var prop = getPropertyOfType(objectType, name);
if (prop) {
getNodeLinks(node).resolvedSymbol = prop;
return getTypeOfSymbol(prop);
}
}
}
@ -6225,7 +6229,8 @@ module ts {
case SyntaxKind.ElementAccessExpression:
var index = (<ElementAccessExpression>n).argumentExpression;
var symbol = findSymbol((<ElementAccessExpression>n).expression);
if (symbol && index.kind === SyntaxKind.StringLiteral) {
if (symbol && index && index.kind === SyntaxKind.StringLiteral) {
var name = (<LiteralExpression>index).text;
var prop = getPropertyOfType(getTypeOfSymbol(symbol), name);
return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0;
@ -8196,7 +8201,8 @@ module ts {
}
else {
if (e.kind === SyntaxKind.ElementAccessExpression) {
if ((<ElementAccessExpression>e).argumentExpression.kind !== SyntaxKind.StringLiteral) {
if ((<ElementAccessExpression>e).argumentExpression === undefined ||
(<ElementAccessExpression>e).argumentExpression.kind !== SyntaxKind.StringLiteral) {
return undefined;
}
var enumType = getTypeOfNode((<ElementAccessExpression>e).expression);

View File

@ -2943,9 +2943,6 @@ module ts {
literal.text = internIdentifier(literal.text);
}
}
else {
indexedAccess.argumentExpression = <Expression>createMissingNode();
}
parseExpected(SyntaxKind.CloseBracketToken);
expression = finishNode(indexedAccess);
@ -4769,7 +4766,7 @@ module ts {
}
function checkElementAccessExpression(node: ElementAccessExpression) {
if (node.argumentExpression.kind === SyntaxKind.Missing) {
if (!node.argumentExpression) {
if (node.parent.kind === SyntaxKind.NewExpression && (<NewExpression>node.parent).expression === node) {
var start = skipTrivia(sourceText, node.expression.end);
var end = node.end;

View File

@ -563,7 +563,7 @@ module ts {
export interface ElementAccessExpression extends MemberExpression {
expression: LeftHandSideExpression;
argumentExpression: Expression;
argumentExpression?: Expression;
}
export interface CallExpression extends LeftHandSideExpression {