@@ -73,7 +73,7 @@ class WorkerPlugin {
73
73
/**
74
74
* @param {JavascriptParser } parser the parser
75
75
* @param {Expression } expr expression
76
- * @returns {[ BasicEvaluatedExpression, [number, number]] } parsed
76
+ * @returns {BasicEvaluatedExpression } parsed
77
77
*/
78
78
const parseModuleUrl = ( parser , expr ) => {
79
79
if (
@@ -95,8 +95,7 @@ class WorkerPlugin {
95
95
) {
96
96
return ;
97
97
}
98
- const arg1Value = parser . evaluateExpression ( arg1 ) ;
99
- return [ arg1Value , [ arg1 . range [ 0 ] , arg2 . range [ 1 ] ] ] ;
98
+ return parser . evaluateExpression ( arg1 ) ;
100
99
} ;
101
100
102
101
/**
@@ -140,111 +139,119 @@ class WorkerPlugin {
140
139
if ( expr . arguments . length === 0 || expr . arguments . length > 2 )
141
140
return ;
142
141
const [ arg1 , arg2 ] = expr . arguments ;
143
- if ( arg1 . type === "SpreadElement" ) return ;
144
- if ( arg2 && arg2 . type === "SpreadElement" ) return ;
145
- const parsedUrl = parseModuleUrl ( parser , arg1 ) ;
146
- if ( ! parsedUrl ) return ;
147
- const [ url , range ] = parsedUrl ;
148
- if ( url . isString ( ) ) {
149
- const options = arg2 && parseObjectLiteral ( parser , arg2 ) ;
150
- const {
151
- options : importOptions ,
152
- errors : commentErrors
153
- } = parser . parseCommentOptions ( expr . range ) ;
142
+ /** @type {[number, number] } */
143
+ const range = [ arg1 . range [ 0 ] , ( arg2 || arg1 ) . range [ 1 ] ] ;
144
+ const url = parseModuleUrl ( parser , arg1 ) ;
145
+ if ( ! url || ! url . isString ( ) ) return ;
146
+ let options ;
147
+ if ( arg2 ) {
148
+ options = parseObjectLiteral ( parser , arg2 ) ;
149
+ if ( ! options ) return ;
150
+ // Remove `type: "module"` if present.
151
+ delete options . type ;
152
+ // If the `options` is now an empty object,
153
+ // remove it from the final bundle.
154
+ if ( Object . keys ( options ) . length === 0 ) {
155
+ options = undefined ;
156
+ }
157
+ }
158
+ const {
159
+ options : importOptions ,
160
+ errors : commentErrors
161
+ } = parser . parseCommentOptions ( expr . range ) ;
154
162
155
- if ( commentErrors ) {
156
- for ( const e of commentErrors ) {
157
- const { comment } = e ;
158
- parser . state . module . addWarning (
159
- new CommentCompilationWarning (
160
- `Compilation error while processing magic comment(-s): /*${ comment . value } */: ${ e . message } ` ,
161
- comment . loc
162
- )
163
- ) ;
164
- }
163
+ if ( commentErrors ) {
164
+ for ( const e of commentErrors ) {
165
+ const { comment } = e ;
166
+ parser . state . module . addWarning (
167
+ new CommentCompilationWarning (
168
+ `Compilation error while processing magic comment(-s): /*${ comment . value } */: ${ e . message } ` ,
169
+ comment . loc
170
+ )
171
+ ) ;
165
172
}
173
+ }
166
174
167
- /** @type {EntryOptions } */
168
- let entryOptions = { } ;
175
+ /** @type {EntryOptions } */
176
+ let entryOptions = { } ;
169
177
170
- if ( importOptions ) {
171
- if ( importOptions . webpackIgnore !== undefined ) {
172
- if ( typeof importOptions . webpackIgnore !== "boolean" ) {
173
- parser . state . module . addWarning (
174
- new UnsupportedFeatureWarning (
175
- `\`webpackIgnore\` expected a boolean, but received: ${ importOptions . webpackIgnore } .` ,
176
- expr . loc
177
- )
178
- ) ;
179
- } else {
180
- if ( importOptions . webpackIgnore ) {
181
- return false ;
182
- }
183
- }
184
- }
185
- if ( importOptions . webpackEntryOptions !== undefined ) {
186
- if (
187
- typeof importOptions . webpackEntryOptions !== "object" ||
188
- importOptions . webpackEntryOptions === null
189
- ) {
190
- parser . state . module . addWarning (
191
- new UnsupportedFeatureWarning (
192
- `\`webpackEntryOptions\` expected a object, but received: ${ importOptions . webpackEntryOptions } .` ,
193
- expr . loc
194
- )
195
- ) ;
196
- } else {
197
- Object . assign (
198
- entryOptions ,
199
- importOptions . webpackEntryOptions
200
- ) ;
178
+ if ( importOptions ) {
179
+ if ( importOptions . webpackIgnore !== undefined ) {
180
+ if ( typeof importOptions . webpackIgnore !== "boolean" ) {
181
+ parser . state . module . addWarning (
182
+ new UnsupportedFeatureWarning (
183
+ `\`webpackIgnore\` expected a boolean, but received: ${ importOptions . webpackIgnore } .` ,
184
+ expr . loc
185
+ )
186
+ ) ;
187
+ } else {
188
+ if ( importOptions . webpackIgnore ) {
189
+ return false ;
201
190
}
202
191
}
203
- if ( importOptions . webpackChunkName !== undefined ) {
204
- if ( typeof importOptions . webpackChunkName !== "string" ) {
205
- parser . state . module . addWarning (
206
- new UnsupportedFeatureWarning (
207
- `\`webpackChunkName\` expected a string, but received: ${ importOptions . webpackChunkName } .` ,
208
- expr . loc
209
- )
210
- ) ;
211
- } else {
212
- entryOptions . name = importOptions . webpackChunkName ;
213
- }
192
+ }
193
+ if ( importOptions . webpackEntryOptions !== undefined ) {
194
+ if (
195
+ typeof importOptions . webpackEntryOptions !== "object" ||
196
+ importOptions . webpackEntryOptions === null
197
+ ) {
198
+ parser . state . module . addWarning (
199
+ new UnsupportedFeatureWarning (
200
+ `\`webpackEntryOptions\` expected a object, but received: ${ importOptions . webpackEntryOptions } .` ,
201
+ expr . loc
202
+ )
203
+ ) ;
204
+ } else {
205
+ Object . assign (
206
+ entryOptions ,
207
+ importOptions . webpackEntryOptions
208
+ ) ;
214
209
}
215
210
}
216
-
217
- if (
218
- ! Object . prototype . hasOwnProperty . call ( entryOptions , "name" ) &&
219
- options &&
220
- options . name
221
- ) {
222
- entryOptions . name = options . name ;
211
+ if ( importOptions . webpackChunkName !== undefined ) {
212
+ if ( typeof importOptions . webpackChunkName !== "string" ) {
213
+ parser . state . module . addWarning (
214
+ new UnsupportedFeatureWarning (
215
+ `\`webpackChunkName\` expected a string, but received: ${ importOptions . webpackChunkName } .` ,
216
+ expr . loc
217
+ )
218
+ ) ;
219
+ } else {
220
+ entryOptions . name = importOptions . webpackChunkName ;
221
+ }
223
222
}
223
+ }
224
224
225
- if ( ! entryOptions . runtime ) {
226
- entryOptions . runtime = `${ cachedContextify (
227
- parser . state . module . identifier ( )
228
- ) } |${ formatLocation ( expr . loc ) } `;
229
- }
225
+ if (
226
+ ! Object . prototype . hasOwnProperty . call ( entryOptions , "name" ) &&
227
+ options &&
228
+ options . name
229
+ ) {
230
+ entryOptions . name = options . name ;
231
+ }
230
232
231
- const block = new AsyncDependenciesBlock ( {
232
- name : entryOptions . name ,
233
- entryOptions : {
234
- chunkLoading : this . _chunkLoading ,
235
- wasmLoading : this . _wasmLoading ,
236
- ...entryOptions
237
- }
238
- } ) ;
239
- block . loc = expr . loc ;
240
- const dep = new WorkerDependency ( url . string , range ) ;
241
- dep . loc = expr . loc ;
242
- block . addDependency ( dep ) ;
243
- parser . state . module . addBlock ( block ) ;
244
- parser . walkExpression ( expr . callee ) ;
245
- if ( arg2 ) parser . walkExpression ( arg2 ) ;
246
- return true ;
233
+ if ( ! entryOptions . runtime ) {
234
+ entryOptions . runtime = `${ cachedContextify (
235
+ parser . state . module . identifier ( )
236
+ ) } |${ formatLocation ( expr . loc ) } `;
247
237
}
238
+
239
+ const block = new AsyncDependenciesBlock ( {
240
+ name : entryOptions . name ,
241
+ entryOptions : {
242
+ chunkLoading : this . _chunkLoading ,
243
+ wasmLoading : this . _wasmLoading ,
244
+ ...entryOptions
245
+ }
246
+ } ) ;
247
+ block . loc = expr . loc ;
248
+ const dep = new WorkerDependency ( url . string , range , options ) ;
249
+ dep . loc = expr . loc ;
250
+ block . addDependency ( dep ) ;
251
+ parser . state . module . addBlock ( block ) ;
252
+ parser . walkExpression ( expr . callee ) ;
253
+ if ( arg2 ) parser . walkExpression ( arg2 ) ;
254
+ return true ;
248
255
} ;
249
256
const processItem = item => {
250
257
if ( item . endsWith ( "()" ) ) {
0 commit comments