From 094ef31c01f7f65a3f44d608a87671fa90eff199 Mon Sep 17 00:00:00 2001 From: James DiGioia Date: Sun, 22 Jul 2018 18:50:29 -0400 Subject: [PATCH] Wrap callback in try/finally This ensures we clean up always if the callback throws. --- packages/babel-parser/src/parser/expression.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index b04e26bac3..47a34a18ea 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -2131,10 +2131,11 @@ export default class ExpressionParser extends LValParser { maxTopicIndex: null, }; - const callbackResult = callback(); - - this.state.topicContext = outerContextTopicState; - return callbackResult; + try { + return callback(); + } finally { + this.state.topicContext = outerContextTopicState; + } } // Disable topic references from outer contexts within syntax constructs @@ -2153,10 +2154,11 @@ export default class ExpressionParser extends LValParser { maxTopicIndex: null, }; - const callbackResult = callback(); - - this.state.topicContext = outerContextTopicState; - return callbackResult; + try { + return callback(); + } finally { + this.state.topicContext = outerContextTopicState; + } } // Register the use of a primary topic reference (`#`) within the current