Bug 1320993 - Fix exporting default class expression

This commit is contained in:
janekptacijarabaci 2018-04-14 08:40:37 +02:00 • committed by Roy Tam
commit db68ce927e
2 changed files with 37 additions and 35 deletions

View file

@ -1164,6 +1164,13 @@ ModuleBuilder::processExport(frontend::ParseNode* pn)
bool isDefault = pn->getKind() == PNK_EXPORT_DEFAULT; bool isDefault = pn->getKind() == PNK_EXPORT_DEFAULT;
ParseNode* kid = isDefault ? pn->pn_left : pn->pn_kid; ParseNode* kid = isDefault ? pn->pn_left : pn->pn_kid;
if (isDefault && pn->pn_right) {
// This is an export default containing an expression.
RootedAtom localName(cx_, cx_->names().starDefaultStar);
RootedAtom exportName(cx_, cx_->names().default_);
return appendExportEntry(exportName, localName);
}
switch (kid->getKind()) { switch (kid->getKind()) {
case PNK_EXPORT_SPEC_LIST: case PNK_EXPORT_SPEC_LIST:
MOZ_ASSERT(!isDefault); MOZ_ASSERT(!isDefault);
@ -1204,7 +1211,7 @@ ModuleBuilder::processExport(frontend::ParseNode* pn)
case PNK_FUNCTION: { case PNK_FUNCTION: {
RootedFunction func(cx_, kid->pn_funbox->function()); RootedFunction func(cx_, kid->pn_funbox->function());
if (!func->isArrow()) { MOZ_ASSERT(!func->isArrow());
RootedAtom localName(cx_, func->explicitName()); RootedAtom localName(cx_, func->explicitName());
RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get()); RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get());
MOZ_ASSERT_IF(isDefault, localName); MOZ_ASSERT_IF(isDefault, localName);
@ -1212,18 +1219,11 @@ ModuleBuilder::processExport(frontend::ParseNode* pn)
return false; return false;
break; break;
} }
}
MOZ_FALLTHROUGH; // Arrow functions are handled below.
default: default:
MOZ_ASSERT(isDefault); MOZ_CRASH("Unexpected parse node");
RootedAtom localName(cx_, cx_->names().starDefaultStar);
RootedAtom exportName(cx_, cx_->names().default_);
if (!appendExportEntry(exportName, localName))
return false;
break;
} }
return true; return true;
} }

View file

@ -0,0 +1,2 @@
parseModule("export default (class {})");
parseModule("export default (class A {})");