Allow special element access assignments to create declarations (#33537)

* Start enabling element access special assignment

* Treat element access assignment as special assignment in JS

* Make declarations for bindable element access expressions

* Fix navigationBar crash

* Add multi-level test for JS

* Propagate element access expressions to more code paths

* Fix property access on `this`

* Add quick info test

* Uhhh I guess this is fine

* Fix module["exports"] and property access chained off element access

* Add test for this property assignment

* Add test for and fix prototype property assignment

* Fix teeeest???

* Update APIs

* Fix element access declarations on `this`

* Fix go-to-definition

* Add declaration emit to tests

* Reconcile with late-bound symbol element access assignment

* Fix baselines

* Add JS declaration back to tests

* Fix JS declaration emit of non-late-bound string literal property names

* Revert accidental auto-format

* Use `isAccessExpression`

* Add underscore escaping member to test

* Fix and test navBar changes
This commit is contained in:
Andrew Branch
2019-09-30 15:08:44 -05:00
committed by GitHub
parent 053388d6d2
commit f89de95955
31 changed files with 1078 additions and 129 deletions

View File

@@ -135,12 +135,13 @@ namespace ts.NavigationBar {
function endNestedNodes(depth: number): void {
for (let i = 0; i < depth; i++) endNode();
}
function startNestedNodes(targetNode: Node, entityName: EntityNameExpression) {
const names: Identifier[] = [];
while (!isIdentifier(entityName)) {
const name = entityName.name;
function startNestedNodes(targetNode: Node, entityName: BindableStaticNameExpression) {
const names: PropertyNameLiteral[] = [];
while (!isPropertyNameLiteral(entityName)) {
const name = getNameOrArgument(entityName);
const nameText = getElementOrPropertyAccessName(entityName);
entityName = entityName.expression;
if (name.escapedText === "prototype") continue;
if (nameText === "prototype") continue;
names.push(name);
}
names.push(entityName);
@@ -333,7 +334,7 @@ namespace ts.NavigationBar {
assignmentTarget;
let depth = 0;
let className: Identifier;
let className: PropertyNameLiteral;
// If we see a prototype assignment, start tracking the target as a class
// This is only done for simple classes not nested assignments.
if (isIdentifier(prototypeAccess.expression)) {
@@ -384,16 +385,16 @@ namespace ts.NavigationBar {
}
case AssignmentDeclarationKind.Property: {
const binaryExpression = (node as BinaryExpression);
const assignmentTarget = binaryExpression.left as PropertyAccessExpression;
const assignmentTarget = binaryExpression.left as PropertyAccessExpression | BindableElementAccessExpression;
const targetFunction = assignmentTarget.expression;
if (isIdentifier(targetFunction) && assignmentTarget.name.escapedText !== "prototype" &&
if (isIdentifier(targetFunction) && getElementOrPropertyAccessName(assignmentTarget) !== "prototype" &&
trackedEs5Classes && trackedEs5Classes.has(targetFunction.text)) {
if (isFunctionExpression(binaryExpression.right) || isArrowFunction(binaryExpression.right)) {
addNodeWithRecursiveChild(node, binaryExpression.right, targetFunction);
}
else {
else if (isBindableStaticAccessExpression(assignmentTarget)) {
startNode(binaryExpression, targetFunction);
addNodeWithRecursiveChild(binaryExpression.left, binaryExpression.right, assignmentTarget.name);
addNodeWithRecursiveChild(binaryExpression.left, binaryExpression.right, getNameOrArgument(assignmentTarget));
endNode();
}
return;