diff --git a/CHANGELOG.md b/CHANGELOG.md index ab04a6d..49ed70c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,29 @@ # rollup changelog +## 0.23.1 + +* Reinstate missing fix from ([#392](https://github.com/rollup/rollup/pull/392)) + +## 0.23.0 + +* Add `bundleTransform` plugin hook and option ([#387](https://github.com/rollup/rollup/pull/387)) +* Correctly store names in sourcemaps, regardless of transformers +* Add `--environment` option to CLI ([#388](https://github.com/rollup/rollup/pull/388)) +* Handle destructuring in exports ([#374](https://github.com/rollup/rollup/issues/374)) +* Fix UMD global exports bug introduced in 0.22.1 ([#392](https://github.com/rollup/rollup/pull/392)) + +## 0.22.2 + +* Prevent lost `var` keywords ([#390](https://github.com/rollup/rollup/issues/390)) + +## 0.22.1 + +* Update expected option keys ([#379](https://github.com/rollup/rollup/issues/379)) +* Handle transformers that return stringified sourcemaps ([#377](https://github.com/rollup/rollup/issues/377)) +* Automatically create missing namespaces if `moduleName` contains dots ([#378](https://github.com/rollup/rollup/issues/378)) +* Ignore external dependency warnings coming from config file ([#333](https://github.com/rollup/rollup/issues/333)) +* Update to latest magic-string for performance boost + ## 0.22.0 * Duplicate warnings are squelched ([#362](https://github.com/rollup/rollup/issues/362)) diff --git a/bin/help.md b/bin/help.md index 5ec5719..7713f67 100644 --- a/bin/help.md +++ b/bin/help.md @@ -20,14 +20,27 @@ Basic options: -m, --sourcemap Generate sourcemap (`-m inline` for inline map) --no-strict Don't emit a `"use strict";` in the generated modules. --no-indent Don't indent result +--environment Settings passed to config file (see example) +--intro Content to insert at top of bundle (inside wrapper) +--outro Content to insert at end of bundle (inside wrapper) +--banner Content to insert at top of bundle (outside wrapper) +--footer Content to insert at end of bundle (outside wrapper) Examples: +# use settings in config file rollup -c +# in config file, process.env.INCLUDE_DEPS === 'true' +# and process.env.BUILD === 'production' +rollup -c --environment INCLUDE_DEPS,BUILD:production + +# create CommonJS bundle.js from src/main.js rollup --format=cjs --output=bundle.js -- src/main.js -rollup -f iife --globals jquery:jQuery,angular:ng \ +# create self-executing IIFE using `window.jQuery` +# and `window._` as external globals +rollup -f iife --globals jquery:jQuery,lodash:_ \ -i src/app.js -o build/app.js -m build/app.js.map Notes: diff --git a/bin/runRollup.js b/bin/runRollup.js index bff21a1..74b1135 100644 --- a/bin/runRollup.js +++ b/bin/runRollup.js @@ -20,6 +20,17 @@ module.exports = function ( command ) { command.input = command._[0]; } + if ( command.environment ) { + command.environment.split( ',' ).forEach( function ( pair ) { + var index = pair.indexOf( ':' ); + if ( ~index ) { + process.env[ pair.slice( 0, index ) ] = pair.slice( index + 1 ); + } else { + process.env[ pair ] = true; + } + }); + } + var config = command.config === true ? 'rollup.config.js' : command.config; if ( config ) { @@ -27,7 +38,10 @@ module.exports = function ( command ) { rollup.rollup({ entry: config, - onwarn: log + onwarn: function ( message ) { + if ( /Treating .+ as external dependency/.test( message ) ) return; + log( message ); + } }).then( function ( bundle ) { var code = bundle.generate({ format: 'cjs' @@ -60,12 +74,16 @@ module.exports = function ( command ) { }; var equivalents = { - input: 'entry', - output: 'dest', - name: 'moduleName', + banner: 'banner', + footer: 'footer', format: 'format', globals: 'globals', id: 'moduleId', + input: 'entry', + intro: 'intro', + name: 'moduleName', + output: 'dest', + outro: 'outro', sourcemap: 'sourceMap' }; diff --git a/package.json b/package.json index db12e6c..81893b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.22.0", + "version": "0.23.1", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "jsnext:main": "src/rollup.js", @@ -48,7 +48,7 @@ "eslint": "^1.7.1", "estree-walker": "^0.2.0", "istanbul": "^0.4.0", - "magic-string": "^0.10.0", + "magic-string": "^0.10.1", "mocha": "^2.3.3", "remap-istanbul": "^0.4.0", "rollup": "^0.20.2", @@ -57,7 +57,8 @@ "rollup-plugin-replace": "^1.0.1", "sander": "^0.4.0", "source-map": "^0.5.3", - "sourcemap-codec": "^1.2.1" + "sourcemap-codec": "^1.2.1", + "uglify-js": "^2.6.1" }, "dependencies": { "chalk": "^1.1.1", diff --git a/src/Bundle.js b/src/Bundle.js index 658caf8..71cdd87 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -11,7 +11,9 @@ import getExportMode from './utils/getExportMode.js'; import getIndentString from './utils/getIndentString.js'; import { unixizePath } from './utils/normalizePlatform.js'; import transform from './utils/transform.js'; +import transformBundle from './utils/transformBundle.js'; import collapseSourcemaps from './utils/collapseSourcemaps.js'; +import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; import callIfFunction from './utils/callIfFunction.js'; import { isRelative, resolve } from './utils/path.js'; @@ -46,6 +48,10 @@ export default class Bundle { .map( plugin => plugin.transform ) .filter( Boolean ); + this.bundleTransformers = this.plugins + .map( plugin => plugin.transformBundle ) + .filter( Boolean ); + this.moduleById = blank(); this.modules = []; @@ -242,20 +248,23 @@ export default class Bundle { if ( banner ) magicString.prepend( banner + '\n' ); if ( footer ) magicString.append( '\n' + footer ); - const code = magicString.toString(); + let code = magicString.toString(); let map = null; + let bundleSourcemapChain = []; + + code = transformBundle( code, this.bundleTransformers, bundleSourcemapChain ) + .replace( new RegExp( `\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'g' ), '' ); if ( options.sourceMap ) { let file = options.sourceMapFile || options.dest; if ( file ) file = resolve( typeof process !== 'undefined' ? process.cwd() : '', file ); - map = magicString.generateMap({ - includeContent: true, - file - // TODO - }); + map = magicString.generateMap({ file, includeContent: true }); - if ( this.transformers.length ) map = collapseSourcemaps( map, usedModules ); + if ( this.transformers.length || this.bundleTransformers.length ) { + map = collapseSourcemaps( map, usedModules, bundleSourcemapChain ); + } + map.sources = map.sources.map( unixizePath ); } diff --git a/src/Module.js b/src/Module.js index e1965ab..be6117f 100644 --- a/src/Module.js +++ b/src/Module.js @@ -10,6 +10,7 @@ import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; import { SyntheticDefaultDeclaration, SyntheticNamespaceDeclaration } from './Declaration.js'; import { isFalsy, isTruthy } from './ast/conditions.js'; import { emptyBlockStatement } from './ast/create.js'; +import extractNames from './ast/extractNames.js'; export default class Module { constructor ({ id, code, originalCode, ast, sourceMapChain, bundle }) { @@ -97,6 +98,7 @@ export default class Module { } // export { foo, bar, baz } + // export var { foo, bar } = ... // export var foo = 42; // export var a = 1, b = 2, c = 3; // export function foo () {} @@ -114,17 +116,18 @@ export default class Module { else { let declaration = node.declaration; - let name; - if ( declaration.type === 'VariableDeclaration' ) { - // export var foo = 42 - name = declaration.declarations[0].id.name; - } else { + declaration.declarations.forEach( decl => { + extractNames( decl.id ).forEach( localName => { + this.exports[ localName ] = { localName }; + }); + }); + } + else { // export function foo () {} - name = declaration.id.name; + const localName = declaration.id.name; + this.exports[ localName ] = { localName }; } - - this.exports[ name ] = { localName: name }; } } } @@ -497,10 +500,14 @@ export default class Module { // modify exports as necessary if ( statement.isExportDeclaration ) { // remove `export` from `export var foo = 42` + // TODO: can we do something simpler here? + // we just want to remove `export`, right? if ( statement.node.type === 'ExportNamedDeclaration' && statement.node.declaration.type === 'VariableDeclaration' ) { - const name = statement.node.declaration.declarations[0].id.name; + const name = extractNames( statement.node.declaration.declarations[ 0 ].id )[ 0 ]; const declaration = this.declarations[ name ]; + if ( !declaration ) throw new Error( `Missing declaration for ${name}!` ); + const end = declaration.isExported && declaration.isReassigned ? statement.node.declaration.declarations[0].start : statement.node.declaration.start; diff --git a/src/ast/Scope.js b/src/ast/Scope.js index 508bf31..0dc48ec 100644 --- a/src/ast/Scope.js +++ b/src/ast/Scope.js @@ -1,38 +1,6 @@ import { blank, keys } from '../utils/object.js'; import Declaration from '../Declaration.js'; - -const extractors = { - Identifier ( names, param ) { - names.push( param.name ); - }, - - ObjectPattern ( names, param ) { - param.properties.forEach( prop => { - extractors[ prop.key.type ]( names, prop.key ); - }); - }, - - ArrayPattern ( names, param ) { - param.elements.forEach( element => { - if ( element ) extractors[ element.type ]( names, element ); - }); - }, - - RestElement ( names, param ) { - extractors[ param.argument.type ]( names, param.argument ); - }, - - AssignmentPattern ( names, param ) { - return extractors[ param.left.type ]( names, param.left ); - } -}; - -function extractNames ( param ) { - let names = []; - - extractors[ param.type ]( names, param ); - return names; -} +import extractNames from './extractNames.js'; export default class Scope { constructor ( options ) { diff --git a/src/ast/extractNames.js b/src/ast/extractNames.js new file mode 100644 index 0000000..5702d23 --- /dev/null +++ b/src/ast/extractNames.js @@ -0,0 +1,31 @@ +export default function extractNames ( param ) { + const names = []; + extractors[ param.type ]( names, param ); + return names; +} + +const extractors = { + Identifier ( names, param ) { + names.push( param.name ); + }, + + ObjectPattern ( names, param ) { + param.properties.forEach( prop => { + extractors[ prop.value.type ]( names, prop.value ); + }); + }, + + ArrayPattern ( names, param ) { + param.elements.forEach( element => { + if ( element ) extractors[ element.type ]( names, element ); + }); + }, + + RestElement ( names, param ) { + extractors[ param.argument.type ]( names, param.argument ); + }, + + AssignmentPattern ( names, param ) { + extractors[ param.left.type ]( names, param.left ); + } +}; diff --git a/src/ast/isReference.js b/src/ast/isReference.js index 7e0c8db..98d8df5 100644 --- a/src/ast/isReference.js +++ b/src/ast/isReference.js @@ -4,6 +4,11 @@ export default function isReference ( node, parent ) { } if ( node.type === 'Identifier' ) { + // the only time we could have an identifier node without a parent is + // if it's the entire body of a function without a block statement – + // i.e. an arrow function expression like `a => a` + if ( !parent ) return true; + // TODO is this right? if ( parent.type === 'MemberExpression' ) return parent.computed || node === parent.object; diff --git a/src/finalisers/iife.js b/src/finalisers/iife.js index 7c1c5d0..6e11ef5 100644 --- a/src/finalisers/iife.js +++ b/src/finalisers/iife.js @@ -2,6 +2,7 @@ import { blank } from '../utils/object.js'; import { getName } from '../utils/map-helpers.js'; import getInteropBlock from './shared/getInteropBlock.js'; import getExportBlock from './shared/getExportBlock.js'; +import getGlobalNameMaker from './shared/getGlobalNameMaker.js'; function setupNamespace ( keypath ) { let parts = keypath.split( '.' ); // TODO support e.g. `foo['something-hyphenated']`? @@ -16,13 +17,12 @@ function setupNamespace ( keypath ) { } export default function iife ( bundle, magicString, { exportMode, indentString }, options ) { - const globalNames = options.globals || blank(); + const globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn ); + const name = options.moduleName; const isNamespaced = name && ~name.indexOf( '.' ); - let dependencies = bundle.externalModules.map( module => { - return globalNames[ module.id ] || module.name; - }); + let dependencies = bundle.externalModules.map( globalNameMaker ); let args = bundle.externalModules.map( getName ); diff --git a/src/finalisers/shared/getGlobalNameMaker.js b/src/finalisers/shared/getGlobalNameMaker.js new file mode 100644 index 0000000..676b416 --- /dev/null +++ b/src/finalisers/shared/getGlobalNameMaker.js @@ -0,0 +1,11 @@ +export default function getGlobalNameMaker ( globals, onwarn ) { + const fn = typeof globals === 'function' ? globals : id => globals[ id ]; + + return function ( module ) { + const name = fn( module.id ); + if ( name ) return name; + + onwarn( `No name was provided for external module '${module.id}' in options.globals – guessing '${module.name}'` ); + return module.name; + }; +} diff --git a/src/finalisers/umd.js b/src/finalisers/umd.js index fd296e7..3e8e813 100644 --- a/src/finalisers/umd.js +++ b/src/finalisers/umd.js @@ -2,6 +2,7 @@ import { blank } from '../utils/object.js'; import { getName, quoteId, req } from '../utils/map-helpers.js'; import getInteropBlock from './shared/getInteropBlock.js'; import getExportBlock from './shared/getExportBlock.js'; +import getGlobalNameMaker from './shared/getGlobalNameMaker.js'; function setupNamespace ( name ) { const parts = name.split( '.' ); @@ -19,13 +20,11 @@ export default function umd ( bundle, magicString, { exportMode, indentString }, throw new Error( 'You must supply options.moduleName for UMD bundles' ); } - const globalNames = options.globals || blank(); + const globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn ); let amdDeps = bundle.externalModules.map( quoteId ); let cjsDeps = bundle.externalModules.map( req ); - let globalDeps = bundle.externalModules.map( module => { - return 'global.' + (globalNames[ module.id ] || module.name); - }); + let globalDeps = bundle.externalModules.map( module => `global.${globalNameMaker( module )}` ); let args = bundle.externalModules.map( getName ); @@ -50,7 +49,7 @@ export default function umd ( bundle, magicString, { exportMode, indentString }, `(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? ${cjsExport}factory(${cjsDeps.join( ', ' )}) : typeof define === 'function' && define.amd ? define(${amdParams}factory) : - ${defaultExport}factory(${globalDeps}); + (${defaultExport}factory(${globalDeps})); }(this, function (${args}) {${useStrict} `.replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() ); diff --git a/src/utils/collapseSourcemaps.js b/src/utils/collapseSourcemaps.js index 8e583cf..9399f11 100644 --- a/src/utils/collapseSourcemaps.js +++ b/src/utils/collapseSourcemaps.js @@ -1,72 +1,108 @@ import { encode, decode } from 'sourcemap-codec'; -function traceSegment ( loc, mappings ) { - const line = loc[0]; - const column = loc[1]; +function Source ( map, sources ) { + if ( !map ) throw new Error( 'Cannot generate a sourcemap if non-sourcemap-generating transformers are used' ); - const segments = mappings[ line ]; + this.sources = sources; + this.names = map.names; + this.mappings = decode( map.mappings ); +} - if ( !segments ) return null; +Source.prototype = { // TODO bring into line with others post-https://github.com/rollup/rollup/pull/386 + traceMappings () { + let names = []; + + const mappings = this.mappings.map( line => { + let tracedLine = []; + + line.forEach( segment => { + const source = this.sources[ segment[1] ]; + const traced = source.traceSegment( segment[2], segment[3], this.names[ segment[4] ] ); + + if ( traced ) { + let nameIndex = null; + segment = [ + segment[0], + traced.index, + traced.line, + traced.column + ]; + + if ( traced.name ) { + nameIndex = names.indexOf( traced.name ); + if ( nameIndex === -1 ) { + nameIndex = names.length; + names.push( traced.name ); + } + + segment[4] = nameIndex; + } + + tracedLine.push( segment ); + } + }); + + return tracedLine; + }); - for ( let i = 0; i < segments.length; i += 1 ) { - const segment = segments[i]; + return { names, mappings }; + }, - if ( segment[0] > column ) return null; + traceSegment ( line, column, name ) { + const segments = this.mappings[ line ]; - if ( segment[0] === column ) { - if ( segment[1] !== 0 ) { - throw new Error( 'Bad sourcemap' ); - } - - return [ segment[2], segment[3] ]; - } - } + if ( !segments ) return null; - return null; -} + for ( let i = 0; i < segments.length; i += 1 ) { + const segment = segments[i]; -export default function collapseSourcemaps ( map, modules ) { - const chains = modules.map( module => { - return module.sourceMapChain.map( map => { - if ( !map ) throw new Error( 'Cannot generate a sourcemap if non-sourcemap-generating transformers are used' ); - return decode( map.mappings ); - }); - }); + if ( segment[0] > column ) return null; - const decodedMappings = decode( map.mappings ); + if ( segment[0] === column ) { + const source = this.sources[ segment[1] ]; - const tracedMappings = decodedMappings.map( line => { - let tracedLine = []; + if ( !source ) throw new Error( 'Bad sourcemap' ); - line.forEach( segment => { - const sourceIndex = segment[1]; - const sourceCodeLine = segment[2]; - const sourceCodeColumn = segment[3]; + if ( source.isOriginal ) { + return { + index: source.index, + line: segment[2], + column: segment[3], + name: this.names[ segment[4] ] || name + }; + } - const chain = chains[ sourceIndex ]; + return source.traceSegment( segment[2], segment[3], name ); + } + } - let i = chain.length; - let traced = [ sourceCodeLine, sourceCodeColumn ]; + return null; + } +}; - while ( i-- && traced ) { - traced = traceSegment( traced, chain[i] ); - } +export default function collapseSourcemaps ( map, modules, bundleSourcemapChain ) { + const sources = modules.map( ( module, i ) => { + let source = { isOriginal: true, index: i }; - if ( traced ) { - tracedLine.push([ - segment[0], - segment[1], - traced[0], - traced[1] - // TODO name? - ]); - } + module.sourceMapChain.forEach( map => { + source = new Source( map, [ source ]); }); - return tracedLine; + return source; }); + let source = new Source( map, sources ); + + bundleSourcemapChain.forEach( map => { + source = new Source( map, [ source ] ); + }); + + const { names, mappings } = source.traceMappings(); + + // we re-use the `map` object because it has convenient toString/toURL methods map.sourcesContent = modules.map( module => module.originalCode ); - map.mappings = encode( tracedMappings ); + map.mappings = encode( mappings ); + map.names = names; + return map; } diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js new file mode 100644 index 0000000..f82bfb6 --- /dev/null +++ b/src/utils/transformBundle.js @@ -0,0 +1,19 @@ +export default function transformBundle ( code, transformers, sourceMapChain ) { + return transformers.reduce( ( code, transformer ) => { + let result = transformer( code ); + + if ( result == null ) return code; + + if ( typeof result === 'string' ) { + result = { + code: result, + map: null + }; + } + + const map = typeof result.map === 'string' ? JSON.parse( result.map ) : map; + sourceMapChain.push( map ); + + return result.code; + }, code ); +} diff --git a/test/cli/banner-intro-outro-footer/_config.js b/test/cli/banner-intro-outro-footer/_config.js new file mode 100644 index 0000000..2e30a3c --- /dev/null +++ b/test/cli/banner-intro-outro-footer/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'adds banner/intro/outro/footer', + command: 'rollup -i main.js -f iife --banner "// banner" --intro "// intro" --outro "// outro" --footer "// footer"' +}; diff --git a/test/cli/banner-intro-outro-footer/_expected.js b/test/cli/banner-intro-outro-footer/_expected.js new file mode 100644 index 0000000..ee1aeb3 --- /dev/null +++ b/test/cli/banner-intro-outro-footer/_expected.js @@ -0,0 +1,9 @@ +// banner +(function () { 'use strict'; + + // intro + console.log( 42 ); + // outro + +})(); +// footer diff --git a/test/cli/banner-intro-outro-footer/main.js b/test/cli/banner-intro-outro-footer/main.js new file mode 100644 index 0000000..5c72ff3 --- /dev/null +++ b/test/cli/banner-intro-outro-footer/main.js @@ -0,0 +1 @@ +console.log( 42 ); diff --git a/test/cli/config-env/_config.js b/test/cli/config-env/_config.js new file mode 100644 index 0000000..5b5f493 --- /dev/null +++ b/test/cli/config-env/_config.js @@ -0,0 +1,5 @@ +module.exports = { + description: 'passes environment variables to config file', + command: 'rollup --config --environment PRODUCTION,FOO:bar', + execute: true +}; diff --git a/test/cli/config-env/main.js b/test/cli/config-env/main.js new file mode 100644 index 0000000..b18f7a9 --- /dev/null +++ b/test/cli/config-env/main.js @@ -0,0 +1,2 @@ +assert.equal( '__ENVIRONMENT__', 'production' ); +assert.equal( '__FOO__', 'bar' ); diff --git a/test/cli/config-env/rollup.config.js b/test/cli/config-env/rollup.config.js new file mode 100644 index 0000000..7d4fb0b --- /dev/null +++ b/test/cli/config-env/rollup.config.js @@ -0,0 +1,12 @@ +var replace = require( 'rollup-plugin-replace' ); + +module.exports = { + entry: 'main.js', + format: 'cjs', + plugins: [ + replace({ + __ENVIRONMENT__: process.env.PRODUCTION ? 'production' : 'development', + __FOO__: process.env.FOO + }) + ] +}; diff --git a/test/cli/indent-none/_expected.js b/test/cli/indent-none/_expected.js index 79e7659..414587c 100644 --- a/test/cli/indent-none/_expected.js +++ b/test/cli/indent-none/_expected.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; assert.equal( 1 + 1, 2 ); diff --git a/test/cli/module-name/_expected.js b/test/cli/module-name/_expected.js index b5aa08a..4a351ac 100644 --- a/test/cli/module-name/_expected.js +++ b/test/cli/module-name/_expected.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var main = 42; diff --git a/test/form/banner-and-footer-plugin/_expected/umd.js b/test/form/banner-and-footer-plugin/_expected/umd.js index f650793..3e3bef0 100644 --- a/test/form/banner-and-footer-plugin/_expected/umd.js +++ b/test/form/banner-and-footer-plugin/_expected/umd.js @@ -3,11 +3,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; console.log( 1 + 1 ); })); /* first footer */ -/* second footer */ +/* second footer */ \ No newline at end of file diff --git a/test/form/banner-and-footer/_expected/umd.js b/test/form/banner-and-footer/_expected/umd.js index 74dd673..356ff47 100644 --- a/test/form/banner-and-footer/_expected/umd.js +++ b/test/form/banner-and-footer/_expected/umd.js @@ -2,10 +2,10 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; console.log( 'hello world' ); })); -/* this is a footer */ +/* this is a footer */ \ No newline at end of file diff --git a/test/form/block-comments/_expected/umd.js b/test/form/block-comments/_expected/umd.js index e61b314..c00edfa 100644 --- a/test/form/block-comments/_expected/umd.js +++ b/test/form/block-comments/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function foo () { @@ -20,4 +20,4 @@ alert( foo() ); -})); +})); \ No newline at end of file diff --git a/test/form/dedupes-external-imports/_expected/umd.js b/test/form/dedupes-external-imports/_expected/umd.js index 5be874c..70bc301 100644 --- a/test/form/dedupes-external-imports/_expected/umd.js +++ b/test/form/dedupes-external-imports/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : - factory((global.myBundle = {}),global.external); + (factory((global.myBundle = {}),global.external)); }(this, function (exports,external) { 'use strict'; class Foo extends external.Component { @@ -33,4 +33,4 @@ exports.bar = bar; exports.baz = baz; -})); +})); \ No newline at end of file diff --git a/test/form/exclude-unnecessary-modifications/_expected/umd.js b/test/form/exclude-unnecessary-modifications/_expected/umd.js index 1c2bb78..d5cd1bd 100644 --- a/test/form/exclude-unnecessary-modifications/_expected/umd.js +++ b/test/form/exclude-unnecessary-modifications/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var foo = {}; @@ -29,4 +29,4 @@ console.log( foo ); -})); +})); \ No newline at end of file diff --git a/test/form/export-all-from-internal/_expected/umd.js b/test/form/export-all-from-internal/_expected/umd.js index 50c5cc4..74613b4 100644 --- a/test/form/export-all-from-internal/_expected/umd.js +++ b/test/form/export-all-from-internal/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : - factory((global.exposedInternals = {})); + (factory((global.exposedInternals = {}))); }(this, function (exports) { 'use strict'; const a = 1; @@ -10,4 +10,4 @@ exports.a = a; exports.b = b; -})); +})); \ No newline at end of file diff --git a/test/form/export-default-2/_expected/umd.js b/test/form/export-default-2/_expected/umd.js index f4cd282..69c5a70 100644 --- a/test/form/export-default-2/_expected/umd.js +++ b/test/form/export-default-2/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var bar = 1; return bar; -})); +})); \ No newline at end of file diff --git a/test/form/export-default-3/_expected/umd.js b/test/form/export-default-3/_expected/umd.js index f4cd282..69c5a70 100644 --- a/test/form/export-default-3/_expected/umd.js +++ b/test/form/export-default-3/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var bar = 1; return bar; -})); +})); \ No newline at end of file diff --git a/test/form/export-default/_expected/umd.js b/test/form/export-default/_expected/umd.js index b5aa08a..16d2890 100644 --- a/test/form/export-default/_expected/umd.js +++ b/test/form/export-default/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var main = 42; return main; -})); +})); \ No newline at end of file diff --git a/test/form/export-multiple-vars/_expected/umd.js b/test/form/export-multiple-vars/_expected/umd.js index 15b3b4b..663cb1e 100644 --- a/test/form/export-multiple-vars/_expected/umd.js +++ b/test/form/export-multiple-vars/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var a = 1; @@ -14,4 +14,4 @@ assert.equal( e, 5 ); assert.equal( i, 9 ); -})); +})); \ No newline at end of file diff --git a/test/form/exports-at-end-if-possible/_expected/umd.js b/test/form/exports-at-end-if-possible/_expected/umd.js index f30f365..20d0d2a 100644 --- a/test/form/exports-at-end-if-possible/_expected/umd.js +++ b/test/form/exports-at-end-if-possible/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : - factory((global.myBundle = {})); + (factory((global.myBundle = {}))); }(this, function (exports) { 'use strict'; var FOO = 'foo'; @@ -12,4 +12,4 @@ exports.FOO = FOO; -})); +})); \ No newline at end of file diff --git a/test/form/external-imports-custom-names-function/_config.js b/test/form/external-imports-custom-names-function/_config.js new file mode 100644 index 0000000..cbc42c4 --- /dev/null +++ b/test/form/external-imports-custom-names-function/_config.js @@ -0,0 +1,8 @@ +module.exports = { + description: 'allows globals to be specified as a function', + options: { + globals: function ( id ) { + return id.replace( /-/g, '_' ); + } + } +}; diff --git a/test/form/external-imports-custom-names-function/_expected/amd.js b/test/form/external-imports-custom-names-function/_expected/amd.js new file mode 100644 index 0000000..ac48d1f --- /dev/null +++ b/test/form/external-imports-custom-names-function/_expected/amd.js @@ -0,0 +1,5 @@ +define(['a-b-c'], function (aBC) { 'use strict'; + + aBC.foo(); + +}); \ No newline at end of file diff --git a/test/form/external-imports-custom-names-function/_expected/cjs.js b/test/form/external-imports-custom-names-function/_expected/cjs.js new file mode 100644 index 0000000..58efa9a --- /dev/null +++ b/test/form/external-imports-custom-names-function/_expected/cjs.js @@ -0,0 +1,5 @@ +'use strict'; + +var aBC = require('a-b-c'); + +aBC.foo(); \ No newline at end of file diff --git a/test/form/external-imports-custom-names-function/_expected/es6.js b/test/form/external-imports-custom-names-function/_expected/es6.js new file mode 100644 index 0000000..cc482cc --- /dev/null +++ b/test/form/external-imports-custom-names-function/_expected/es6.js @@ -0,0 +1,3 @@ +import { foo } from 'a-b-c'; + +foo(); \ No newline at end of file diff --git a/test/form/external-imports-custom-names-function/_expected/iife.js b/test/form/external-imports-custom-names-function/_expected/iife.js new file mode 100644 index 0000000..d8d719b --- /dev/null +++ b/test/form/external-imports-custom-names-function/_expected/iife.js @@ -0,0 +1,5 @@ +(function (aBC) { 'use strict'; + + aBC.foo(); + +})(a_b_c); \ No newline at end of file diff --git a/test/form/external-imports-custom-names-function/_expected/umd.js b/test/form/external-imports-custom-names-function/_expected/umd.js new file mode 100644 index 0000000..1018b8a --- /dev/null +++ b/test/form/external-imports-custom-names-function/_expected/umd.js @@ -0,0 +1,9 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('a-b-c')) : + typeof define === 'function' && define.amd ? define(['a-b-c'], factory) : + (factory(global.a_b_c)); +}(this, function (aBC) { 'use strict'; + + aBC.foo(); + +})); \ No newline at end of file diff --git a/test/form/external-imports-custom-names-function/main.js b/test/form/external-imports-custom-names-function/main.js new file mode 100644 index 0000000..3746e06 --- /dev/null +++ b/test/form/external-imports-custom-names-function/main.js @@ -0,0 +1,2 @@ +import { foo } from 'a-b-c'; +foo(); diff --git a/test/form/external-imports-custom-names/_expected/umd.js b/test/form/external-imports-custom-names/_expected/umd.js index 8912390..07642a1 100644 --- a/test/form/external-imports-custom-names/_expected/umd.js +++ b/test/form/external-imports-custom-names/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) : typeof define === 'function' && define.amd ? define(['jquery'], factory) : - factory(global.jQuery); + (factory(global.jQuery)); }(this, function ($) { 'use strict'; $ = 'default' in $ ? $['default'] : $; @@ -10,4 +10,4 @@ $( 'body' ).html( '

hello world!

' ); }); -})); +})); \ No newline at end of file diff --git a/test/form/external-imports/_expected/umd.js b/test/form/external-imports/_expected/umd.js index e48dd29..3feb767 100644 --- a/test/form/external-imports/_expected/umd.js +++ b/test/form/external-imports/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('factory'), require('baz'), require('shipping-port'), require('alphabet')) : typeof define === 'function' && define.amd ? define(['factory', 'baz', 'shipping-port', 'alphabet'], factory) : - factory(global.factory,global.baz,global.containers,global.alphabet); + (factory(global.factory,global.baz,global.containers,global.alphabet)); }(this, function (factory,baz,containers,alphabet) { 'use strict'; factory = 'default' in factory ? factory['default'] : factory; @@ -13,4 +13,4 @@ console.log( alphabet.a ); console.log( alphabet__default.length ); -})); +})); \ No newline at end of file diff --git a/test/form/indent-false/_expected/umd.js b/test/form/indent-false/_expected/umd.js index ad094b9..d09a506 100644 --- a/test/form/indent-false/_expected/umd.js +++ b/test/form/indent-false/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.foo = factory(); + (global.foo = factory()); }(this, function () { 'use strict'; function foo () { @@ -10,4 +10,4 @@ function foo () { return foo; -})); +})); \ No newline at end of file diff --git a/test/form/indent-true-spaces/_expected/umd.js b/test/form/indent-true-spaces/_expected/umd.js index ecbc24d..fbc898e 100644 --- a/test/form/indent-true-spaces/_expected/umd.js +++ b/test/form/indent-true-spaces/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.foo = factory(); + (global.foo = factory()); }(this, function () { 'use strict'; function foo () { @@ -10,4 +10,4 @@ return foo; -})); +})); \ No newline at end of file diff --git a/test/form/indent-true/_expected/umd.js b/test/form/indent-true/_expected/umd.js index e06c50d..a2b634e 100644 --- a/test/form/indent-true/_expected/umd.js +++ b/test/form/indent-true/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.foo = factory(); + (global.foo = factory()); }(this, function () { 'use strict'; function foo () { @@ -10,4 +10,4 @@ return foo; -})); +})); \ No newline at end of file diff --git a/test/form/internal-conflict-resolution/_expected/umd.js b/test/form/internal-conflict-resolution/_expected/umd.js index c879634..a07cece 100644 --- a/test/form/internal-conflict-resolution/_expected/umd.js +++ b/test/form/internal-conflict-resolution/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var bar$1 = 42; @@ -16,4 +16,4 @@ bar(); -})); +})); \ No newline at end of file diff --git a/test/form/intro-and-outro/_expected/umd.js b/test/form/intro-and-outro/_expected/umd.js index c26e76b..c08f507 100644 --- a/test/form/intro-and-outro/_expected/umd.js +++ b/test/form/intro-and-outro/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; /* this is an intro */ console.log( 'hello world' ); /* this is an outro */ -})); +})); \ No newline at end of file diff --git a/test/form/multiple-exports/_expected/umd.js b/test/form/multiple-exports/_expected/umd.js index 687b75c..485e381 100644 --- a/test/form/multiple-exports/_expected/umd.js +++ b/test/form/multiple-exports/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : - factory((global.myBundle = {})); + (factory((global.myBundle = {}))); }(this, function (exports) { 'use strict'; var foo = 1; @@ -10,4 +10,4 @@ exports.foo = foo; exports.bar = bar; -})); +})); \ No newline at end of file diff --git a/test/form/namespace-optimization-b/_expected/umd.js b/test/form/namespace-optimization-b/_expected/umd.js index c2ad84b..866a3bd 100644 --- a/test/form/namespace-optimization-b/_expected/umd.js +++ b/test/form/namespace-optimization-b/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function foo () { diff --git a/test/form/namespace-optimization/_expected/umd.js b/test/form/namespace-optimization/_expected/umd.js index 38f7835..67adf52 100644 --- a/test/form/namespace-optimization/_expected/umd.js +++ b/test/form/namespace-optimization/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function a () {} a(); -})); +})); \ No newline at end of file diff --git a/test/form/namespaced-default-exports/_expected/umd.js b/test/form/namespaced-default-exports/_expected/umd.js index 5d69d93..b06132b 100644 --- a/test/form/namespaced-default-exports/_expected/umd.js +++ b/test/form/namespaced-default-exports/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = factory(); + (global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = factory()); }(this, function () { 'use strict'; var main = 42; return main; -})); +})); \ No newline at end of file diff --git a/test/form/namespaced-named-exports/_expected/umd.js b/test/form/namespaced-named-exports/_expected/umd.js index 81a3688..aeb7775 100644 --- a/test/form/namespaced-named-exports/_expected/umd.js +++ b/test/form/namespaced-named-exports/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : - factory((global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = {})); + (factory((global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = {}))); }(this, function (exports) { 'use strict'; var answer = 42; exports.answer = answer; -})); +})); \ No newline at end of file diff --git a/test/form/no-imports-or-exports/_expected/umd.js b/test/form/no-imports-or-exports/_expected/umd.js index 37794fa..5c8c7d3 100644 --- a/test/form/no-imports-or-exports/_expected/umd.js +++ b/test/form/no-imports-or-exports/_expected/umd.js @@ -1,9 +1,9 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; console.log( 'this is it' ); -})); +})); \ No newline at end of file diff --git a/test/form/object-destructuring-default-values/_expected/umd.js b/test/form/object-destructuring-default-values/_expected/umd.js index e13c8f3..a3e661b 100644 --- a/test/form/object-destructuring-default-values/_expected/umd.js +++ b/test/form/object-destructuring-default-values/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; const a = 1; diff --git a/test/form/preserves-comments-after-imports/_expected/umd.js b/test/form/preserves-comments-after-imports/_expected/umd.js index 96fec25..ac58856 100644 --- a/test/form/preserves-comments-after-imports/_expected/umd.js +++ b/test/form/preserves-comments-after-imports/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : - factory((global.myBundle = {})); + (factory((global.myBundle = {}))); }(this, function (exports) { 'use strict'; /** A comment for a number */ @@ -12,4 +12,4 @@ exports.obj = obj; -})); +})); \ No newline at end of file diff --git a/test/form/removes-existing-sourcemap-comments/_expected/umd.js b/test/form/removes-existing-sourcemap-comments/_expected/umd.js index 79f644c..ef0186e 100644 --- a/test/form/removes-existing-sourcemap-comments/_expected/umd.js +++ b/test/form/removes-existing-sourcemap-comments/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function foo () { @@ -10,4 +10,4 @@ console.log( foo() ); -})); +})); \ No newline at end of file diff --git a/test/form/self-contained-bundle/_expected/umd.js b/test/form/self-contained-bundle/_expected/umd.js index d29ef88..f828537 100644 --- a/test/form/self-contained-bundle/_expected/umd.js +++ b/test/form/self-contained-bundle/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function foo () { @@ -19,4 +19,4 @@ foo(); console.log( 3 ); -})); +})); \ No newline at end of file diff --git a/test/form/shorthand-properties/_expected/umd.js b/test/form/shorthand-properties/_expected/umd.js index b027a94..1a19210 100644 --- a/test/form/shorthand-properties/_expected/umd.js +++ b/test/form/shorthand-properties/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function x () { @@ -26,4 +26,4 @@ assert.equal( bar.x(), 'bar' ); assert.equal( baz.x(), 'baz' ); -})); +})); \ No newline at end of file diff --git a/test/form/side-effect-b/_expected/umd.js b/test/form/side-effect-b/_expected/umd.js index 7f83fb9..16d2890 100644 --- a/test/form/side-effect-b/_expected/umd.js +++ b/test/form/side-effect-b/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var main = 42; diff --git a/test/form/side-effect-c/_expected/umd.js b/test/form/side-effect-c/_expected/umd.js index 7f83fb9..16d2890 100644 --- a/test/form/side-effect-c/_expected/umd.js +++ b/test/form/side-effect-c/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var main = 42; diff --git a/test/form/side-effect-d/_expected/umd.js b/test/form/side-effect-d/_expected/umd.js index b5aa08a..16d2890 100644 --- a/test/form/side-effect-d/_expected/umd.js +++ b/test/form/side-effect-d/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var main = 42; return main; -})); +})); \ No newline at end of file diff --git a/test/form/side-effect-e/_expected/umd.js b/test/form/side-effect-e/_expected/umd.js index 12803ec..ef3393d 100644 --- a/test/form/side-effect-e/_expected/umd.js +++ b/test/form/side-effect-e/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; function foo () { @@ -21,4 +21,4 @@ return main; -})); +})); \ No newline at end of file diff --git a/test/form/side-effect-f/_expected/umd.js b/test/form/side-effect-f/_expected/umd.js index b5aa08a..16d2890 100644 --- a/test/form/side-effect-f/_expected/umd.js +++ b/test/form/side-effect-f/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var main = 42; return main; -})); +})); \ No newline at end of file diff --git a/test/form/side-effect-g/_expected/umd.js b/test/form/side-effect-g/_expected/umd.js index b5aa08a..16d2890 100644 --- a/test/form/side-effect-g/_expected/umd.js +++ b/test/form/side-effect-g/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var main = 42; return main; -})); +})); \ No newline at end of file diff --git a/test/form/side-effect-h/_expected/umd.js b/test/form/side-effect-h/_expected/umd.js index b5aa08a..16d2890 100644 --- a/test/form/side-effect-h/_expected/umd.js +++ b/test/form/side-effect-h/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var main = 42; return main; -})); +})); \ No newline at end of file diff --git a/test/form/side-effect-i/_expected/umd.js b/test/form/side-effect-i/_expected/umd.js index 767e79a..b090f9a 100644 --- a/test/form/side-effect-i/_expected/umd.js +++ b/test/form/side-effect-i/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; if ( !ok ) { @@ -12,4 +12,4 @@ return main; -})); +})); \ No newline at end of file diff --git a/test/form/side-effect-j/_expected/umd.js b/test/form/side-effect-j/_expected/umd.js index e6e853f..2da816b 100644 --- a/test/form/side-effect-j/_expected/umd.js +++ b/test/form/side-effect-j/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; var augment; diff --git a/test/form/side-effect-k/_expected/umd.js b/test/form/side-effect-k/_expected/umd.js index 45f170b..5b7f3d6 100644 --- a/test/form/side-effect-k/_expected/umd.js +++ b/test/form/side-effect-k/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.myBundle = factory(); + (global.myBundle = factory()); }(this, function () { 'use strict'; function augment ( x ) { diff --git a/test/form/side-effect-l/_expected/umd.js b/test/form/side-effect-l/_expected/umd.js index c833540..f3395b7 100644 --- a/test/form/side-effect-l/_expected/umd.js +++ b/test/form/side-effect-l/_expected/umd.js @@ -1,9 +1,9 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; -})); +})); \ No newline at end of file diff --git a/test/form/side-effect/_expected/umd.js b/test/form/side-effect/_expected/umd.js index f96fd30..79b4cc2 100644 --- a/test/form/side-effect/_expected/umd.js +++ b/test/form/side-effect/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var foo = 42; assert.equal( foo, 42 ); -})); +})); \ No newline at end of file diff --git a/test/form/sourcemaps-inline/_expected/umd.js b/test/form/sourcemaps-inline/_expected/umd.js index e331a57..b934854 100644 --- a/test/form/sourcemaps-inline/_expected/umd.js +++ b/test/form/sourcemaps-inline/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function foo () { diff --git a/test/form/sourcemaps/_expected/umd.js b/test/form/sourcemaps/_expected/umd.js index 224c196..5e77403 100644 --- a/test/form/sourcemaps/_expected/umd.js +++ b/test/form/sourcemaps/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function foo () { diff --git a/test/form/spacing-after-function-with-semicolon/_expected/umd.js b/test/form/spacing-after-function-with-semicolon/_expected/umd.js index 5c2fdac..56bca25 100644 --- a/test/form/spacing-after-function-with-semicolon/_expected/umd.js +++ b/test/form/spacing-after-function-with-semicolon/_expected/umd.js @@ -1,11 +1,11 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; function x () { return 'x' }; assert.equal( x(), 'x' ); -})); +})); \ No newline at end of file diff --git a/test/form/string-indentation-b/_expected/umd.js b/test/form/string-indentation-b/_expected/umd.js index c137f1b..ad0bc29 100644 --- a/test/form/string-indentation-b/_expected/umd.js +++ b/test/form/string-indentation-b/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var a = 'a'; diff --git a/test/form/string-indentation/_expected/umd.js b/test/form/string-indentation/_expected/umd.js index a35d9d0..285a53f 100644 --- a/test/form/string-indentation/_expected/umd.js +++ b/test/form/string-indentation/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var a = '1\ @@ -21,4 +21,4 @@ assert.equal( c, '1\n 2' ); assert.equal( d, '1\n\t2' ); -})); +})); \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_config.js b/test/form/transform-bundle-plugin/_config.js new file mode 100644 index 0000000..6b54ad3 --- /dev/null +++ b/test/form/transform-bundle-plugin/_config.js @@ -0,0 +1,17 @@ +module.exports = { + description: 'allows plugins to transform bundle', + options: { + plugins: [ + { + transformBundle: function (code) { + return '/* first plugin */'; + } + }, + { + transformBundle: function (code) { + return code + '\n/* second plugin */'; + } + } + ] + } +} diff --git a/test/form/transform-bundle-plugin/_expected/amd.js b/test/form/transform-bundle-plugin/_expected/amd.js new file mode 100644 index 0000000..f783236 --- /dev/null +++ b/test/form/transform-bundle-plugin/_expected/amd.js @@ -0,0 +1,2 @@ +/* first plugin */ +/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_expected/cjs.js b/test/form/transform-bundle-plugin/_expected/cjs.js new file mode 100644 index 0000000..f783236 --- /dev/null +++ b/test/form/transform-bundle-plugin/_expected/cjs.js @@ -0,0 +1,2 @@ +/* first plugin */ +/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_expected/es6.js b/test/form/transform-bundle-plugin/_expected/es6.js new file mode 100644 index 0000000..f783236 --- /dev/null +++ b/test/form/transform-bundle-plugin/_expected/es6.js @@ -0,0 +1,2 @@ +/* first plugin */ +/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_expected/iife.js b/test/form/transform-bundle-plugin/_expected/iife.js new file mode 100644 index 0000000..f783236 --- /dev/null +++ b/test/form/transform-bundle-plugin/_expected/iife.js @@ -0,0 +1,2 @@ +/* first plugin */ +/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_expected/umd.js b/test/form/transform-bundle-plugin/_expected/umd.js new file mode 100644 index 0000000..f783236 --- /dev/null +++ b/test/form/transform-bundle-plugin/_expected/umd.js @@ -0,0 +1,2 @@ +/* first plugin */ +/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/main.js b/test/form/transform-bundle-plugin/main.js new file mode 100644 index 0000000..934dee7 --- /dev/null +++ b/test/form/transform-bundle-plugin/main.js @@ -0,0 +1 @@ +console.log( 1 + 1 ); diff --git a/test/form/unmodified-default-exports-function-argument/_expected/umd.js b/test/form/unmodified-default-exports-function-argument/_expected/umd.js index 2a4c64c..07f1781 100644 --- a/test/form/unmodified-default-exports-function-argument/_expected/umd.js +++ b/test/form/unmodified-default-exports-function-argument/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var foo = function () { @@ -17,4 +17,4 @@ console.log( answer ); -})); +})); \ No newline at end of file diff --git a/test/form/unmodified-default-exports/_expected/umd.js b/test/form/unmodified-default-exports/_expected/umd.js index 63cf07d..d83a806 100644 --- a/test/form/unmodified-default-exports/_expected/umd.js +++ b/test/form/unmodified-default-exports/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var Foo = function () { @@ -16,4 +16,4 @@ var foo = new Foo(); -})); +})); \ No newline at end of file diff --git a/test/form/unused-default-exports/_expected/umd.js b/test/form/unused-default-exports/_expected/umd.js index 140a92b..8c9c2e0 100644 --- a/test/form/unused-default-exports/_expected/umd.js +++ b/test/form/unused-default-exports/_expected/umd.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : - factory(); + (factory()); }(this, function () { 'use strict'; var foo = { value: 1 }; @@ -15,4 +15,4 @@ assert.equal( foo.value, 2 ); -})); +})); \ No newline at end of file diff --git a/test/function/export-destruction/_config.js b/test/function/export-destruction/_config.js new file mode 100644 index 0000000..263c8d1 --- /dev/null +++ b/test/function/export-destruction/_config.js @@ -0,0 +1,12 @@ +var assert = require( 'assert' ); + +module.exports = { + description: 'handle destruction patterns in export declarations', + babel: true, + + exports: function ( exports ) { + assert.deepEqual( Object.keys( exports ), [ 'baz', 'quux' ] ); + assert.equal( exports.baz, 5 ); + assert.equal( exports.quux, 17 ); + } +}; diff --git a/test/function/export-destruction/main.js b/test/function/export-destruction/main.js new file mode 100644 index 0000000..d178da4 --- /dev/null +++ b/test/function/export-destruction/main.js @@ -0,0 +1,5 @@ +var foo = { bar: { baz: 5 } }; +var arr = [ { quux: 'wrong' }, { quux: 17 } ]; + +export var { bar: { baz } } = foo; +export var [ /* skip */, { quux } ] = arr; diff --git a/test/function/top-level-arrow-function/_config.js b/test/function/top-level-arrow-function/_config.js new file mode 100644 index 0000000..6ce4fd3 --- /dev/null +++ b/test/function/top-level-arrow-function/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'handles naked return value from top-level arrow function expression (#403)', + babel: true +}; diff --git a/test/function/top-level-arrow-function/main.js b/test/function/top-level-arrow-function/main.js new file mode 100644 index 0000000..fa5a9a5 --- /dev/null +++ b/test/function/top-level-arrow-function/main.js @@ -0,0 +1,2 @@ +const f = a => a; +assert.equal( f( 42 ), 42 ); diff --git a/test/function/vars-not-removed/_config.js b/test/function/vars-not-removed/_config.js new file mode 100644 index 0000000..b3daeef --- /dev/null +++ b/test/function/vars-not-removed/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not erroneously remove var/let/const keywords (#390)' +}; diff --git a/test/function/vars-not-removed/bar.js b/test/function/vars-not-removed/bar.js new file mode 100644 index 0000000..1f25023 --- /dev/null +++ b/test/function/vars-not-removed/bar.js @@ -0,0 +1,3 @@ +var a = 2, b = 3; + +assert.equal( a + b, 5 ); diff --git a/test/function/vars-not-removed/foo.js b/test/function/vars-not-removed/foo.js new file mode 100644 index 0000000..ca5062c --- /dev/null +++ b/test/function/vars-not-removed/foo.js @@ -0,0 +1,3 @@ +var a = 1, b = 2; + +assert.equal( a + b, 3 ); diff --git a/test/function/vars-not-removed/main.js b/test/function/vars-not-removed/main.js new file mode 100644 index 0000000..f257022 --- /dev/null +++ b/test/function/vars-not-removed/main.js @@ -0,0 +1,2 @@ +import './foo.js'; +import './bar.js'; diff --git a/test/sourcemaps/names-transformed/_config.js b/test/sourcemaps/names-transformed/_config.js new file mode 100644 index 0000000..16d3d34 --- /dev/null +++ b/test/sourcemaps/names-transformed/_config.js @@ -0,0 +1,58 @@ +var assert = require( 'assert' ); +var uglify = require( 'uglify-js' ); +var MagicString = require( 'magic-string' ); +var getLocation = require( '../../utils/getLocation' ); +var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer; + +module.exports = { + description: 'names are recovered if transforms are used', + options: { + plugins: [ + { + transform: function ( code ) { + var s = new MagicString( code ); + var pattern = /mangleMe/g; + var match; + + while ( match = pattern.exec( code ) ) { + s.overwrite( match.index, match.index + match[0].length, 'mangleMePlease', true ); + } + + return { + code: s.toString(), + map: s.generateMap({ hires: true }) + }; + }, + transformBundle: function ( code ) { + return uglify.minify( code, { + fromString: true, + outSourceMap: 'x' + }); + } + } + ] + }, + test: function ( code, map ) { + var smc = new SourceMapConsumer( map ); + + var generatedLoc = getLocation( code, /\w+=1/.exec( code ).index ); + var originalLoc = smc.originalPositionFor( generatedLoc ); + + assert.deepEqual( originalLoc, { + source: '../a.js', + line: 1, + column: 4, + name: 'mangleMe' + }); + + generatedLoc = getLocation( code, /\w+=2/.exec( code ).index ); + originalLoc = smc.originalPositionFor( generatedLoc ); + + assert.deepEqual( originalLoc, { + source: '../b.js', + line: 1, + column: 4, + name: 'mangleMe' + }); + } +}; diff --git a/test/sourcemaps/names-transformed/a.js b/test/sourcemaps/names-transformed/a.js new file mode 100644 index 0000000..e436b38 --- /dev/null +++ b/test/sourcemaps/names-transformed/a.js @@ -0,0 +1,4 @@ +var mangleMe = 1; +export default function () { + assert.equal( mangleMe, 1 ); +} diff --git a/test/sourcemaps/names-transformed/b.js b/test/sourcemaps/names-transformed/b.js new file mode 100644 index 0000000..23de2f6 --- /dev/null +++ b/test/sourcemaps/names-transformed/b.js @@ -0,0 +1,4 @@ +var mangleMe = 2; +export default function () { + assert.equal( mangleMe, 2 ); +} diff --git a/test/sourcemaps/names-transformed/main.js b/test/sourcemaps/names-transformed/main.js new file mode 100644 index 0000000..1cc1b21 --- /dev/null +++ b/test/sourcemaps/names-transformed/main.js @@ -0,0 +1,5 @@ +import a from './a.js'; +import b from './b.js'; + +a(); +b(); diff --git a/test/sourcemaps/transform-bundle/_config.js b/test/sourcemaps/transform-bundle/_config.js new file mode 100644 index 0000000..10a9d43 --- /dev/null +++ b/test/sourcemaps/transform-bundle/_config.js @@ -0,0 +1,38 @@ +var uglify = require( 'uglify-js' ); +var assert = require( 'assert' ); +var getLocation = require( '../../utils/getLocation' ); +var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer; + +module.exports = { + description: 'preserves sourcemap chains when transforming', + options: { + plugins: [ + { + transformBundle: function ( code ) { + var options = { + fromString: true, + outSourceMap: 'x' // trigger sourcemap generation + }; + + return uglify.minify( code, options ); + } + } + ] + }, + test: function ( code, map ) { + var smc = new SourceMapConsumer( map ); + + var generatedLoc = getLocation( code, code.indexOf( '42' ) ); + var originalLoc = smc.originalPositionFor( generatedLoc ); + + assert.ok( /main/.test( originalLoc.source ) ); + assert.equal( originalLoc.line, 1 ); + assert.equal( originalLoc.column, 13 ); + + generatedLoc = getLocation( code, code.indexOf( 'log' ) ); + originalLoc = smc.originalPositionFor( generatedLoc ); + + assert.equal( originalLoc.line, 1 ); + assert.equal( originalLoc.column, 8 ); + } +}; diff --git a/test/sourcemaps/transform-bundle/main.js b/test/sourcemaps/transform-bundle/main.js new file mode 100644 index 0000000..5c72ff3 --- /dev/null +++ b/test/sourcemaps/transform-bundle/main.js @@ -0,0 +1 @@ +console.log( 42 );