@@ -89,24 +89,33 @@ function assignmentHelper(visitor, path, childName) {
8989 return ! scope || scope . find_owner ( name ) . parent === null ;
9090 }
9191
92- // Wrap assignments to exported identifiers with `module.runSetters`.
92+ let modifiedExports = [ ] ;
93+
94+ // Identify which exports if any are modified by the assignment.
9395 for ( let i = 0 ; i < nameCount ; ++ i ) {
9496 let name = assignedNames [ i ] ;
9597 if (
96- visitor . exportedLocalNames [ name ] === true &&
98+ visitor . exportedLocalNames [ name ] &&
9799 inModuleScope ( name )
98100 ) {
99- wrap ( visitor , path , name ) ;
100- break ;
101+ modifiedExports . push ( ...visitor . exportedLocalNames [ name ] ) ;
101102 }
102103 }
104+
105+ // Wrap assignments to exported identifiers with `module.runSetters`.
106+ if ( modifiedExports . length > 0 ) {
107+ wrap ( visitor , path , modifiedExports ) ;
108+ }
103109}
104110
105- function wrap ( visitor , path , name ) {
111+ function wrap ( visitor , path , names ) {
106112 const value = path . getValue ( ) ;
107113
108114 if ( visitor . magicString !== null ) {
109- let end = name ? `,"${ name } ")` : ')' ;
115+ let end = ')' ;
116+ if ( names ) {
117+ end = `,[${ names . map ( n => `"${ n } "` ) . join ( ',' ) } ])` ;
118+ }
110119
111120 visitor . magicString . prependRight (
112121 value . start ,
@@ -115,10 +124,14 @@ function wrap(visitor, path, name) {
115124 }
116125
117126 if ( visitor . modifyAST ) {
118- let args = name ? [ value , {
119- type : "StringLiteral" ,
120- value : name
121- } ] : [ value ] ;
127+ let args = [ value ] ;
128+ if ( names ) {
129+ let array = {
130+ type : "ArrayExpression" ,
131+ elements : names . map ( n => ( { type : "StringLiteral" , value : n } ) )
132+ } ;
133+ args . push ( array ) ;
134+ }
122135
123136 path . replace ( {
124137 type : "CallExpression" ,
0 commit comments