From 9795fa6631650b93320bbc64b1bb3902fd758093 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 30 Apr 2020 09:52:09 -0700 Subject: [PATCH 1/3] Improve assert message in binder Looking at the code, I don't think the assert can ever fire, but it clearly does, or did in the past. This will make it easier for people to create a repro. --- src/compiler/binder.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 3ea8df0a83998..72516cc0739a9 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2977,15 +2977,15 @@ namespace ts { // util.property = function ... bindExportsPropertyAssignment(node as BindableStaticPropertyAssignmentExpression); } + else if (hasDynamicName(node)) { + bindAnonymousDeclaration(node, SymbolFlags.Property | SymbolFlags.Assignment, InternalSymbolName.Computed); + const sym = bindPotentiallyMissingNamespaces(parentSymbol, node.left.expression, isTopLevelNamespaceAssignment(node.left), /*isPrototype*/ false, /*containerIsClass*/ false); + addLateBoundAssignmentDeclarationToSymbol(node, sym); + } else { - if (hasDynamicName(node)) { - bindAnonymousDeclaration(node, SymbolFlags.Property | SymbolFlags.Assignment, InternalSymbolName.Computed); - const sym = bindPotentiallyMissingNamespaces(parentSymbol, node.left.expression, isTopLevelNamespaceAssignment(node.left), /*isPrototype*/ false, /*containerIsClass*/ false); - addLateBoundAssignmentDeclarationToSymbol(node, sym); - } - else { - bindStaticPropertyAssignment(cast(node.left, isBindableStaticAccessExpression)); - } + if (!isBindableStaticAccessExpression(node.left)) + return Debug.fail(`Invalid cast. The supplied value ${getTextOfNode(node.left)} was not a BindableStaticAccessExpression.`); + bindStaticPropertyAssignment(node.left as BindableStaticAccessExpression); } } From d815effa9bea8bcf9a3de6694456cbfd9f3736b1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 30 Apr 2020 10:28:49 -0700 Subject: [PATCH 2/3] fix lint --- src/compiler/binder.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 72516cc0739a9..8a79a57b46400 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2983,8 +2983,9 @@ namespace ts { addLateBoundAssignmentDeclarationToSymbol(node, sym); } else { - if (!isBindableStaticAccessExpression(node.left)) + if (!isBindableStaticAccessExpression(node.left)) { return Debug.fail(`Invalid cast. The supplied value ${getTextOfNode(node.left)} was not a BindableStaticAccessExpression.`); + } bindStaticPropertyAssignment(node.left as BindableStaticAccessExpression); } } From add6bbcfce5f2b317bcb8cbb82852012f4e6acff Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 30 Apr 2020 14:28:23 -0700 Subject: [PATCH 3/3] Use BindableStaticNameExpression not BindableStaticAccessExpression This type does allow identifiers, but those are ruled out earlier, so I added an assert for that case. --- src/compiler/binder.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8a79a57b46400..cf9260cf6b7ed 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2983,10 +2983,7 @@ namespace ts { addLateBoundAssignmentDeclarationToSymbol(node, sym); } else { - if (!isBindableStaticAccessExpression(node.left)) { - return Debug.fail(`Invalid cast. The supplied value ${getTextOfNode(node.left)} was not a BindableStaticAccessExpression.`); - } - bindStaticPropertyAssignment(node.left as BindableStaticAccessExpression); + bindStaticPropertyAssignment(cast(node.left, isBindableStaticNameExpression)); } } @@ -2994,7 +2991,8 @@ namespace ts { * For nodes like `x.y = z`, declare a member 'y' on 'x' if x is a function (or IIFE) or class or {}, or not declared. * Also works for expression statements preceded by JSDoc, like / ** @type number * / x.y; */ - function bindStaticPropertyAssignment(node: BindableStaticAccessExpression) { + function bindStaticPropertyAssignment(node: BindableStaticNameExpression) { + Debug.assert(!isIdentifier(node)); node.expression.parent = node; bindPropertyAssignment(node.expression, node, /*isPrototypeProperty*/ false, /*containerIsClass*/ false); }