diff --git a/src/parser/statement.js b/src/parser/statement.js index 26bc4e5525..3d61f047e9 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -848,7 +848,7 @@ pp.parseExport = function (node) { if (needsSemi) this.semicolon(); this.checkExport(node, true, true); return this.finishNode(node, "ExportDefaultDeclaration"); - } else if (this.state.type.keyword || this.shouldParseExportDeclaration()) { + } else if (this.shouldParseExportDeclaration()) { node.specifiers = []; node.source = null; node.declaration = this.parseExportDeclaration(node); @@ -861,8 +861,22 @@ pp.parseExport = function (node) { return this.finishNode(node, "ExportNamedDeclaration"); }; +pp.shouldParseExportDeclaration = function () { + return this.state.type.keyword || this.isContextual("async"); +}; + +pp.isDeclaration = function (node): boolean { + return node.type === "VariableDeclaration" + || node.type === "FunctionDeclaration" + || node.type === "ClassDeclaration"; +}; + pp.parseExportDeclaration = function () { - return this.parseStatement(true); + const statement = this.parseStatement(true); + if (!this.isDeclaration(statement)) { + this.unexpected(statement.start); + } + return statement; }; pp.isExportDefaultSpecifier = function () { @@ -901,10 +915,6 @@ pp.parseExportFrom = function (node, expect?) { this.semicolon(); }; -pp.shouldParseExportDeclaration = function () { - return this.isContextual("async"); -}; - pp.checkExport = function (node, checkNames, isDefault) { if (checkNames) { // Check for duplicate exports