@@ -159,7 +159,7 @@ describe('transformWithOxc', () => {
159
159
} )
160
160
161
161
describe ( 'renderChunk' , ( ) => {
162
- test ( 'should inject helper for worker iife from esm' , async ( ) => {
162
+ test ( 'should inject helper for iife without exports from esm' , async ( ) => {
163
163
const renderChunk = await createBuildOxcPluginRenderChunk ( 'es2015' )
164
164
const result = await renderChunk (
165
165
`(function() {
@@ -191,7 +191,7 @@ describe('renderChunk', () => {
191
191
` )
192
192
} )
193
193
194
- test ( 'should inject helper for worker iife from cjs' , async ( ) => {
194
+ test ( 'should inject helper for iife without exports from cjs' , async ( ) => {
195
195
const renderChunk = await createBuildOxcPluginRenderChunk ( 'es2015' )
196
196
const result = await renderChunk (
197
197
`(function() {
@@ -220,4 +220,114 @@ describe('renderChunk', () => {
220
220
"
221
221
` )
222
222
} )
223
+
224
+ test ( 'should inject helper for iife with exports' , async ( ) => {
225
+ const renderChunk = await createBuildOxcPluginRenderChunk ( 'es2015' )
226
+ const result = await renderChunk (
227
+ `var lib = (function(exports) {
228
+
229
+
230
+ //#region entry.js
231
+ (async () => {
232
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
233
+ console.log("foo");
234
+ })();
235
+ const foo = "foo";
236
+
237
+ //#endregion
238
+ exports.foo = foo;
239
+ return exports;
240
+ })({});` ,
241
+ 'iife' ,
242
+ )
243
+ expect ( result ) . toMatchInlineSnapshot ( `
244
+ "var lib = function(exports) {var babelHelpers=function(exports){function t(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function n(e){return function(){var n=this,r=arguments;return new Promise(function(i,a){var o=e.apply(n,r);function s(e){t(o,i,a,s,c,\`next\`,e)}function c(e){t(o,i,a,s,c,\`throw\`,e)}s(void 0)})}}return exports.asyncToGenerator=n,exports}({});
245
+
246
+ //#region entry.js
247
+ babelHelpers.asyncToGenerator(function* () {
248
+ yield new Promise((resolve) => setTimeout(resolve, 1e3));
249
+ console.log("foo");
250
+ })();
251
+ const foo = "foo";
252
+ //#endregion
253
+ exports.foo = foo;
254
+ return exports;
255
+ }({});
256
+ "
257
+ ` )
258
+ } )
259
+
260
+ test ( 'should inject helper for umd without exports' , async ( ) => {
261
+ const renderChunk = await createBuildOxcPluginRenderChunk ( 'es2015' )
262
+ const result = await renderChunk (
263
+ `(function(factory) {
264
+
265
+ typeof define === 'function' && define.amd ? define([], factory) :
266
+ factory();
267
+ })(function() {
268
+
269
+ //#region entry.js
270
+ (async () => {
271
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
272
+ console.log("foo");
273
+ })();
274
+
275
+ //#endregion
276
+ });` ,
277
+ 'umd' ,
278
+ )
279
+ expect ( result ) . toMatchInlineSnapshot ( `
280
+ "(function(factory) {
281
+ typeof define === "function" && define.amd ? define([], factory) : factory();
282
+ })(function() {var babelHelpers=function(exports){function t(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function n(e){return function(){var n=this,r=arguments;return new Promise(function(i,a){var o=e.apply(n,r);function s(e){t(o,i,a,s,c,\`next\`,e)}function c(e){t(o,i,a,s,c,\`throw\`,e)}s(void 0)})}}return exports.asyncToGenerator=n,exports}({});
283
+
284
+ //#region entry.js
285
+ babelHelpers.asyncToGenerator(function* () {
286
+ yield new Promise((resolve) => setTimeout(resolve, 1e3));
287
+ console.log("foo");
288
+ })();
289
+ //#endregion
290
+ });
291
+ "
292
+ ` )
293
+ } )
294
+
295
+ test ( 'should inject helper for umd with exports' , async ( ) => {
296
+ const renderChunk = await createBuildOxcPluginRenderChunk ( 'es2015' )
297
+ const result = await renderChunk (
298
+ `(function(global, factory) {
299
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
300
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
301
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.lib = {})));
302
+ })(this, function(exports) {
303
+
304
+ //#region entry.js
305
+ (async () => {
306
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
307
+ console.log("foo");
308
+ })();
309
+ const foo = "foo";
310
+
311
+ //#endregion
312
+ exports.foo = foo;
313
+ });` ,
314
+ 'umd' ,
315
+ )
316
+ expect ( result ) . toMatchInlineSnapshot ( `
317
+ "(function(global, factory) {
318
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.lib = {}));
319
+ })(this, function(exports) {var babelHelpers=function(exports){function t(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function n(e){return function(){var n=this,r=arguments;return new Promise(function(i,a){var o=e.apply(n,r);function s(e){t(o,i,a,s,c,\`next\`,e)}function c(e){t(o,i,a,s,c,\`throw\`,e)}s(void 0)})}}return exports.asyncToGenerator=n,exports}({});
320
+
321
+ //#region entry.js
322
+ babelHelpers.asyncToGenerator(function* () {
323
+ yield new Promise((resolve) => setTimeout(resolve, 1e3));
324
+ console.log("foo");
325
+ })();
326
+ const foo = "foo";
327
+ //#endregion
328
+ exports.foo = foo;
329
+ });
330
+ "
331
+ ` )
332
+ } )
223
333
} )
0 commit comments