From 0091cda605a432526c6d2edf157097b7f822a4af Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 8 Sep 2020 06:50:13 +0200 Subject: [PATCH] Handle debugger statements as if-statement branches --- src/ast/nodes/IfStatement.ts | 14 ++++---------- test/function/samples/unknown-statement/_config.js | 3 +++ test/function/samples/unknown-statement/main.js | 4 ++++ 3 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 test/function/samples/unknown-statement/_config.js create mode 100644 test/function/samples/unknown-statement/main.js diff --git a/src/ast/nodes/IfStatement.ts b/src/ast/nodes/IfStatement.ts index b828353f53a..1ac7c763320 100644 --- a/src/ast/nodes/IfStatement.ts +++ b/src/ast/nodes/IfStatement.ts @@ -70,18 +70,12 @@ 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]( - esTreeNode.consequent, - this, - this.consequentScope - ); + this.consequent = new (this.context.nodeConstructors[esTreeNode.consequent.type] || + this.context.nodeConstructors.UnknownNode)(esTreeNode.consequent, this, this.consequentScope); if (esTreeNode.alternate) { this.alternateScope = new TrackingScope(this.scope); - this.alternate = new this.context.nodeConstructors[esTreeNode.alternate.type]( - esTreeNode.alternate, - this, - this.alternateScope - ); + this.alternate = new (this.context.nodeConstructors[esTreeNode.consequent.type] || + this.context.nodeConstructors.UnknownNode)(esTreeNode.alternate, this, this.alternateScope); } super.parseNode(esTreeNode); } diff --git a/test/function/samples/unknown-statement/_config.js b/test/function/samples/unknown-statement/_config.js new file mode 100644 index 00000000000..b52eca19457 --- /dev/null +++ b/test/function/samples/unknown-statement/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'handles unknown statements' +}; diff --git a/test/function/samples/unknown-statement/main.js b/test/function/samples/unknown-statement/main.js new file mode 100644 index 00000000000..2ef5c938b85 --- /dev/null +++ b/test/function/samples/unknown-statement/main.js @@ -0,0 +1,4 @@ +debugger; + +if (true) debugger; +else debugger;