@@ -152,28 +152,34 @@ function cjs(
152
152
153
153
const internal_globals = get_internal_globals ( globals , helpers ) ;
154
154
155
- const user_requires = imports . map ( node => ( {
156
- type : 'VariableDeclaration' ,
157
- kind : 'const' ,
158
- declarations : [ {
159
- type : 'VariableDeclarator' ,
160
- id : node . specifiers [ 0 ] . type === 'ImportNamespaceSpecifier'
161
- ? { type : 'Identifier' , name : node . specifiers [ 0 ] . local . name }
162
- : {
163
- type : 'ObjectPattern' ,
164
- properties : node . specifiers . map ( s => ( {
165
- type : 'Property' ,
166
- method : false ,
167
- shorthand : false ,
168
- computed : false ,
169
- key : s . type === 'ImportSpecifier' ? s . imported : { type : 'Identifier' , name : 'default' } ,
170
- value : s . local ,
171
- kind : 'init'
172
- } ) )
173
- } ,
174
- init : x `require("${ edit_source ( node . source . value , sveltePath ) } ")`
175
- } ]
176
- } ) ) ;
155
+ const user_requires = imports . map ( node => {
156
+ const init = x `require("${ edit_source ( node . source . value , sveltePath ) } ")` ;
157
+ if ( node . specifiers . length === 0 ) {
158
+ return b `${ init } ;` ;
159
+ }
160
+ return {
161
+ type : 'VariableDeclaration' ,
162
+ kind : 'const' ,
163
+ declarations : [ {
164
+ type : 'VariableDeclarator' ,
165
+ id : node . specifiers [ 0 ] . type === 'ImportNamespaceSpecifier'
166
+ ? { type : 'Identifier' , name : node . specifiers [ 0 ] . local . name }
167
+ : {
168
+ type : 'ObjectPattern' ,
169
+ properties : node . specifiers . map ( s => ( {
170
+ type : 'Property' ,
171
+ method : false ,
172
+ shorthand : false ,
173
+ computed : false ,
174
+ key : s . type === 'ImportSpecifier' ? s . imported : { type : 'Identifier' , name : 'default' } ,
175
+ value : s . local ,
176
+ kind : 'init'
177
+ } ) )
178
+ } ,
179
+ init
180
+ } ]
181
+ } ;
182
+ } ) ;
177
183
178
184
const exports = module_exports . map ( x => b `exports.${ { type : 'Identifier' , name : x . as } } = ${ { type : 'Identifier' , name : x . name } } ;` ) ;
179
185
0 commit comments