Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Compile export default from #7309

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 33 additions & 10 deletions packages/babylon/src/parser/statement.js
Expand Up @@ -1310,21 +1310,44 @@ export default class StatementParser extends ExpressionParser {
this.parseExportStar(node);
if (node.type === "ExportAllDeclaration") return node;
} else if (this.isExportDefaultSpecifier()) {
this.expectPlugin("exportDefaultFrom");
const specifier = this.startNode();
specifier.exported = this.parseIdentifier(true);
let isDefaultfrom = false;
if (specifier.exported.name === "default" && this.isContextual("from")) {
isDefaultfrom = true;
const lookaheadState = this.lookahead();
if (
lookaheadState.value === "=" ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I have another token? e.g. export default from + 2;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah Sorry, didn't consider that.. Will update the PR

lookaheadState.type === tt.semi ||
lookaheadState.type === tt.eof ||
lookaheadState.type === tt.braceR ||
lineBreak.test(
this.input.slice(lookaheadState.lastTokEnd, lookaheadState.start),
)
) {
node.declaration = this.parseMaybeAssign();
this.checkExport(node, true, true);
return this.finishNode(node, "ExportDefaultDeclaration");
}
}
this.expectPlugin("exportDefaultFrom");
const specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
node.specifiers = specifiers;
if (this.match(tt.comma) && this.lookahead().type === tt.star) {
this.expect(tt.comma);
const specifier = this.startNode();
this.expect(tt.star);
this.expectContextual("as");
specifier.exported = this.parseIdentifier();
specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
} else {
this.parseExportSpecifiersMaybe(node);
if (!isDefaultfrom) {
if (this.match(tt.comma) && this.lookahead().type === tt.star) {
this.expect(tt.comma);
const specifier = this.startNode();
this.expect(tt.star);
this.expectContextual("as");
specifier.exported = this.parseIdentifier();
specifiers.push(
this.finishNode(specifier, "ExportNamespaceSpecifier"),
);
} else {
this.parseExportSpecifiersMaybe(node);
}
}

this.parseExportFrom(node, true);
} else if (this.eat(tt._default)) {
// export default ...
Expand Down
@@ -1,3 +1,3 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)"
"throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:15)"
}
@@ -1,4 +1,4 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)",
"throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:9)",
"plugins": []
}