From f9e2d0a3ffdde94ababf09f57e8d4915e8816087 Mon Sep 17 00:00:00 2001 From: Benjamin Terrier Date: Mon, 21 Oct 2019 13:48:49 +0200 Subject: [PATCH] Remove the need to provide an output name for IIFE bundles --- src/finalisers/iife.ts | 11 ++--------- test/misc/write-bundle.js | 12 +----------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/finalisers/iife.ts b/src/finalisers/iife.ts index 755748e169b..4fd27c0743c 100644 --- a/src/finalisers/iife.ts +++ b/src/finalisers/iife.ts @@ -47,13 +47,6 @@ export default function iife( const deps = external.map(dep => dep.globalName || 'null'); const args = external.map(m => m.name); - if (hasExports && !name) { - error({ - code: 'INVALID_OPTION', - message: `You must supply "output.name" for IIFE bundles.` - }); - } - if (namedExportsMode && hasExports) { if (extend) { deps.unshift(`${thisProp(name as string)}${_}=${_}${thisProp(name as string)}${_}||${_}{}`); @@ -68,9 +61,9 @@ export default function iife( let wrapperIntro = `(function${_}(${args.join(`,${_}`)})${_}{${n}${useStrict}`; - if (hasExports && (!extend || !namedExportsMode)) { + if (hasExports && (!extend || !namedExportsMode) && name) { wrapperIntro = - (useVariableAssignment ? `${varOrConst} ${name}` : thisProp(name as string)) + + (useVariableAssignment ? `${varOrConst} ${name}` : thisProp(name)) + `${_}=${_}${wrapperIntro}`; } diff --git a/test/misc/write-bundle.js b/test/misc/write-bundle.js index decb030012e..8caacb5f679 100644 --- a/test/misc/write-bundle.js +++ b/test/misc/write-bundle.js @@ -25,7 +25,7 @@ describe('bundle.write()', () => { }); }); - it('expects output.name for IIFE and UMD bundles', () => { + it('expects output.name for UMD bundles', () => { let bundle; return rollup @@ -48,16 +48,6 @@ describe('bundle.write()', () => { assert.throws(() => { throw err; }, /You must supply "output\.name" for UMD bundles/); - }) - .then(() => { - return bundle.generate({ - format: 'iife' - }); - }) - .catch(err => { - assert.throws(() => { - throw err; - }, /You must supply "output\.name" for IIFE bundles/); }); });