Set up structure of prototype assignments

No actual binding happens yet though
This commit is contained in:
Nathan Shively-Sanders 2018-02-20 16:03:54 -08:00
parent 116a8a8cff
commit 01f2ee3d1f
6 changed files with 19 additions and 2 deletions

View File

@ -2042,6 +2042,8 @@ namespace ts {
case SpecialPropertyAssignmentKind.PrototypeProperty:
bindPrototypePropertyAssignment((node as BinaryExpression).left as PropertyAccessEntityNameExpression, node);
break;
case SpecialPropertyAssignmentKind.Prototype:
bindPrototypeAssignment(node as BinaryExpression);
case SpecialPropertyAssignmentKind.ThisProperty:
bindThisPropertyAssignment(node as BinaryExpression);
break;
@ -2361,8 +2363,13 @@ namespace ts {
}
}
/** For `x.prototype = { p, ... }`, declare members p,... if `x` is function/class/{}, or not declared. */
function bindPrototypeAssignment(node: BinaryExpression) {
return node;
}
/**
* For 'x.prototype.y = z', declare a 'member' y on x if x is a function or class, or not declared.
* For `x.prototype.y = z`, declare a member `y` on `x` if `x` is a function or class, or not declared.
* Note that jsdoc preceding an ExpressionStatement like `x.prototype.y;` is also treated as a declaration.
*/
function bindPrototypePropertyAssignment(lhs: PropertyAccessEntityNameExpression, parent: Node) {

View File

@ -14254,6 +14254,7 @@ namespace ts {
case SpecialPropertyAssignmentKind.ModuleExports:
case SpecialPropertyAssignmentKind.PrototypeProperty:
case SpecialPropertyAssignmentKind.ThisProperty:
case SpecialPropertyAssignmentKind.Prototype:
return false;
default:
Debug.assertNever(kind);

View File

@ -3964,7 +3964,9 @@ namespace ts {
/// this.name = expr
ThisProperty,
// F.name = expr
Property
Property,
// F.prototype = { ... }
Prototype,
}
export interface JsFileExtensionInfo {

View File

@ -1590,6 +1590,10 @@ namespace ts {
return SpecialPropertyAssignmentKind.Property;
}
}
else if (lhs.name.escapedText === "prototype" && expr.right.kind === SyntaxKind.ObjectLiteralExpression) {
// F.prototype = { ... }
return SpecialPropertyAssignmentKind.Prototype;
}
else if (lhs.expression.kind === SyntaxKind.ThisKeyword) {
return SpecialPropertyAssignmentKind.ThisProperty;
}

View File

@ -275,6 +275,7 @@ namespace ts.NavigationBar {
case SpecialPropertyAssignmentKind.ExportsProperty:
case SpecialPropertyAssignmentKind.ModuleExports:
case SpecialPropertyAssignmentKind.PrototypeProperty:
case SpecialPropertyAssignmentKind.Prototype:
addNodeWithRecursiveChild(node, (node as BinaryExpression).right);
break;
case SpecialPropertyAssignmentKind.ThisProperty:

View File

@ -370,6 +370,8 @@ namespace ts {
case SpecialPropertyAssignmentKind.Property:
// static method / property
return isFunctionExpression(right) ? ScriptElementKind.memberFunctionElement : ScriptElementKind.memberVariableElement;
case SpecialPropertyAssignmentKind.Prototype:
return ScriptElementKind.localClassElement;
default: {
assertTypeIsNever(kind);
return ScriptElementKind.unknown;