@@ -988,20 +988,16 @@ class Parser extends Tapable {
988988 this . hooks . export . call ( statement ) ;
989989 }
990990 if ( statement . declaration ) {
991- if ( / E x p r e s s i o n $ / . test ( statement . declaration . type ) ) {
992- throw new Error ( "Doesn't occur?" ) ;
993- } else {
994- if ( ! this . hooks . exportDeclaration . call ( statement , statement . declaration ) ) {
995- const originalDefinitions = this . scope . definitions ;
996- const tracker = new TrackingSet ( this . scope . definitions ) ;
997- this . scope . definitions = tracker ;
998- this . prewalkStatement ( statement . declaration ) ;
999- const newDefs = Array . from ( tracker . getAddedItems ( ) ) ;
1000- this . scope . definitions = originalDefinitions ;
1001- for ( let index = newDefs . length - 1 ; index >= 0 ; index -- ) {
1002- const def = newDefs [ index ] ;
1003- this . hooks . exportSpecifier . call ( statement , def , def , index ) ;
1004- }
991+ if ( ! this . hooks . exportDeclaration . call ( statement , statement . declaration ) ) {
992+ const originalDefinitions = this . scope . definitions ;
993+ const tracker = new TrackingSet ( this . scope . definitions ) ;
994+ this . scope . definitions = tracker ;
995+ this . prewalkStatement ( statement . declaration ) ;
996+ const newDefs = Array . from ( tracker . getAddedItems ( ) ) ;
997+ this . scope . definitions = originalDefinitions ;
998+ for ( let index = newDefs . length - 1 ; index >= 0 ; index -- ) {
999+ const def = newDefs [ index ] ;
1000+ this . hooks . exportSpecifier . call ( statement , def , def , index ) ;
10051001 }
10061002 }
10071003 }
@@ -1030,7 +1026,7 @@ class Parser extends Tapable {
10301026 }
10311027
10321028 prewalkExportDefaultDeclaration ( statement ) {
1033- if ( / D e c l a r a t i o n $ / . test ( statement . declaration . type ) ) {
1029+ if ( statement . declaration . id ) {
10341030 const originalDefinitions = this . scope . definitions ;
10351031 const tracker = new TrackingSet ( this . scope . definitions ) ;
10361032 this . scope . definitions = tracker ;
@@ -1046,12 +1042,21 @@ class Parser extends Tapable {
10461042
10471043 walkExportDefaultDeclaration ( statement ) {
10481044 this . hooks . export . call ( statement ) ;
1049- if ( / D e c l a r a t i o n $ / . test ( statement . declaration . type ) ) {
1045+ if ( statement . declaration . id ) {
10501046 if ( ! this . hooks . exportDeclaration . call ( statement , statement . declaration ) ) {
10511047 this . walkStatement ( statement . declaration ) ;
10521048 }
10531049 } else {
1054- this . walkExpression ( statement . declaration ) ;
1050+ // Acorn parses `export default function() {}` as `FunctionDeclaration` and
1051+ // `export default class {}` as `ClassDeclaration`, both with `id = null`.
1052+ // These nodes must be treated as expressions.
1053+ if ( statement . declaration . type === "FunctionDeclaration" ) {
1054+ this . walkFunctionDeclaration ( statement . declaration ) ;
1055+ } else if ( statement . declaration . type === "ClassDeclaration" ) {
1056+ this . walkClassDeclaration ( statement . declaration ) ;
1057+ } else {
1058+ this . walkExpression ( statement . declaration ) ;
1059+ }
10551060 if ( ! this . hooks . exportExpression . call ( statement , statement . declaration ) ) {
10561061 this . hooks . exportSpecifier . call ( statement , statement . declaration , "default" ) ;
10571062 }
0 commit comments