@@ -89,7 +89,6 @@ export default class ExportTransform extends Transform implements TransformInter
89
89
if ( defaultDeclarationValue !== null ) {
90
90
this . exported = { ...this . exported , ...defaultDeclarationValue } ;
91
91
}
92
- console . log ( this . exported ) ;
93
92
break ;
94
93
case EXPORT_ALL_DECLARATION :
95
94
// TODO(KB): This case `export * from "./import"` is not currently supported.
@@ -160,8 +159,9 @@ export default class ExportTransform extends Transform implements TransformInter
160
159
const namedClassMatch = new RegExp ( `window.${ key } =(\\w+);` ) . exec ( code ) ;
161
160
if ( namedClassMatch && namedClassMatch . length > 0 ) {
162
161
// Remove the declaration on window scope, i.e. `window.Exported=a;`
163
- // Replace it with an export statement `export {a as Exported};`
164
- code = code . replace ( namedClassMatch [ 0 ] , `export {${ namedClassMatch [ 1 ] } as ${ key } };` ) ;
162
+ code = code . replace ( namedClassMatch [ 0 ] , '' ) ;
163
+ // Store a new export constant to output at the end. `a as Exported`
164
+ exportedConstants . push ( `${ namedClassMatch [ 1 ] } as ${ key } ` ) ;
165
165
}
166
166
break ;
167
167
case ExportClosureMapping . NAMED_DEFAULT_FUNCTION :
@@ -170,7 +170,7 @@ export default class ExportTransform extends Transform implements TransformInter
170
170
case ExportClosureMapping . NAMED_DEFAULT_CLASS :
171
171
const namedDefaultClassMatch = new RegExp ( `window.${ key } =(\\w+);` ) . exec ( code ) ;
172
172
if ( namedDefaultClassMatch && namedDefaultClassMatch . length > 0 ) {
173
- // Remove the declaration on window scope, i.e. `window.Exported =a;`
173
+ // Remove the declaration on window scope, i.e. `window.ExportedTwo =a;`
174
174
// Replace it with an export statement `export default a;`
175
175
code = code . replace (
176
176
namedDefaultClassMatch [ 0 ] ,
@@ -179,8 +179,11 @@ export default class ExportTransform extends Transform implements TransformInter
179
179
}
180
180
break ;
181
181
case ExportClosureMapping . NAMED_CONSTANT :
182
- exportedConstants . push ( key ) ;
182
+ // Remove the declaration on the window scope, i.e. `window.ExportedThree=value`
183
+ // Replace it with a const declaration, i.e `const ExportedThree=value`
183
184
code = code . replace ( `window.${ key } =` , `const ${ key } =` ) ;
185
+ // Store a new export constant to output at the end, i.e `ExportedThree`
186
+ exportedConstants . push ( key ) ;
184
187
break ;
185
188
default :
186
189
this . context . warn (
@@ -191,9 +194,11 @@ export default class ExportTransform extends Transform implements TransformInter
191
194
} ) ;
192
195
193
196
if ( exportedConstants . length > 0 ) {
197
+ // Remove the newline at the end since we are going to append exports.
194
198
if ( code . endsWith ( '\n' ) ) {
195
199
code = code . substr ( 0 , code . lastIndexOf ( '\n' ) ) ;
196
200
}
201
+ // Append the exports that were gathered, i.e `export {a as Exported, ExportedThree};`
197
202
code += `export {${ exportedConstants . join ( ',' ) } };` ;
198
203
}
199
204
}
0 commit comments