diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 46e90e825507..06999c46f24b 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -2129,7 +2129,10 @@ export default class ExpressionParser extends LValParser { // But there is no chance to pop the context if the keyword is consumed // as an identifier such as a property name. const context = this.state.context; - if (context[context.length - 1].token === "function") { + if ( + (name === "class" || name === "function") && + context[context.length - 1].token === "function" + ) { context.pop(); } } else {