From de108f0f6763c43f28dd2d559f1646895c897a0b Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 28 Aug 2020 16:44:39 +0200 Subject: [PATCH] Improve coverage --- src/ast/nodes/IfStatement.ts | 14 ++++++++++---- src/ast/scopes/BlockScope.ts | 2 +- src/ast/scopes/Scope.ts | 2 +- src/ast/scopes/TrackingScope.ts | 6 ++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ast/nodes/IfStatement.ts b/src/ast/nodes/IfStatement.ts index 2fb3510d33d..b828353f53a 100644 --- a/src/ast/nodes/IfStatement.ts +++ b/src/ast/nodes/IfStatement.ts @@ -70,12 +70,18 @@ export default class IfStatement extends StatementBase implements DeoptimizableE parseNode(esTreeNode: GenericEsTreeNode) { this.consequentScope = new TrackingScope(this.scope); - this.consequent = new (this.context.nodeConstructors[esTreeNode.consequent.type] || - this.context.nodeConstructors.UnknownNode)(esTreeNode.consequent, this, this.consequentScope); + this.consequent = new this.context.nodeConstructors[esTreeNode.consequent.type]( + esTreeNode.consequent, + this, + this.consequentScope + ); if (esTreeNode.alternate) { this.alternateScope = new TrackingScope(this.scope); - this.alternate = new (this.context.nodeConstructors[esTreeNode.alternate.type] || - this.context.nodeConstructors.UnknownNode)(esTreeNode.alternate, this, this.alternateScope); + this.alternate = new this.context.nodeConstructors[esTreeNode.alternate.type]( + esTreeNode.alternate, + this, + this.alternateScope + ); } super.parseNode(esTreeNode); } diff --git a/src/ast/scopes/BlockScope.ts b/src/ast/scopes/BlockScope.ts index 45bda1fe7f1..b72bcc3a19e 100644 --- a/src/ast/scopes/BlockScope.ts +++ b/src/ast/scopes/BlockScope.ts @@ -9,7 +9,7 @@ export default class BlockScope extends ChildScope { addDeclaration( identifier: Identifier, context: AstContext, - init: ExpressionEntity | null = null, + init: ExpressionEntity | null, isHoisted: boolean ): LocalVariable { if (isHoisted) { diff --git a/src/ast/scopes/Scope.ts b/src/ast/scopes/Scope.ts index e38a5b068bc..32a46d31719 100644 --- a/src/ast/scopes/Scope.ts +++ b/src/ast/scopes/Scope.ts @@ -13,7 +13,7 @@ export default class Scope { addDeclaration( identifier: Identifier, context: AstContext, - init: ExpressionEntity | null = null, + init: ExpressionEntity | null, _isHoisted: boolean ) { const name = identifier.name; diff --git a/src/ast/scopes/TrackingScope.ts b/src/ast/scopes/TrackingScope.ts index 46c65dad892..41bf1dd98eb 100644 --- a/src/ast/scopes/TrackingScope.ts +++ b/src/ast/scopes/TrackingScope.ts @@ -10,12 +10,10 @@ export default class TrackingScope extends BlockScope { addDeclaration( identifier: Identifier, context: AstContext, - init: ExpressionEntity | null = null, + init: ExpressionEntity | null, isHoisted: boolean ): LocalVariable { - if (isHoisted) { - this.hoistedDeclarations.push(identifier); - } + this.hoistedDeclarations.push(identifier); return this.parent.addDeclaration(identifier, context, init, isHoisted); } }