Skip to content

Commit

Permalink
Throw error when exporting non-declaration
Browse files Browse the repository at this point in the history
fixes babel#238
  • Loading branch information
kaicataldo committed Nov 28, 2016
1 parent 9b6bb3c commit ae84a65
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 () {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ae84a65

Please sign in to comment.