From 6ba68a5ae6094748d378550039a215666d1fbd0a 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 --- CHANGELOG.md | 9 +++++++++ src/ast/nodes/IfStatement.ts | 14 ++++---------- test/function/samples/unknown-statement/_config.js | 3 +++ test/function/samples/unknown-statement/main.js | 4 ++++ 4 files changed, 20 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/CHANGELOG.md b/CHANGELOG.md index 7bbcf57b5aa..72099eac8aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # rollup changelog +## 2.26.11 +*2020-09-08* + +### Bug Fixes +* Do not fail for unknown nodes as if statement branches (#3769) + +### Pull Requests +* [#3769](https://github.com/rollup/rollup/pull/3769): Handle debugger statements as if-statement branches (@lukastaegert) + ## 2.26.10 *2020-09-04* diff --git a/src/ast/nodes/IfStatement.ts b/src/ast/nodes/IfStatement.ts index b828353f53a..2fb3510d33d 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.alternate.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;