From 8e42a7cd2434835d807eb941ecd774cbce722287 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 30 Dec 2015 05:05:56 +0300 Subject: [PATCH 01/27] Add transformBundle plugin hook --- src/Bundle.js | 7 ++- src/utils/transformBundle.js | 53 +++++++++++++++++++ test/form/transform-bundle-plugin/_config.js | 21 ++++++++ .../transform-bundle-plugin/_expected/amd.js | 2 + .../transform-bundle-plugin/_expected/cjs.js | 2 + .../transform-bundle-plugin/_expected/es6.js | 2 + .../transform-bundle-plugin/_expected/iife.js | 2 + .../transform-bundle-plugin/_expected/umd.js | 2 + test/form/transform-bundle-plugin/main.js | 1 + 9 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/utils/transformBundle.js create mode 100644 test/form/transform-bundle-plugin/_config.js create mode 100644 test/form/transform-bundle-plugin/_expected/amd.js create mode 100644 test/form/transform-bundle-plugin/_expected/cjs.js create mode 100644 test/form/transform-bundle-plugin/_expected/es6.js create mode 100644 test/form/transform-bundle-plugin/_expected/iife.js create mode 100644 test/form/transform-bundle-plugin/_expected/umd.js create mode 100644 test/form/transform-bundle-plugin/main.js diff --git a/src/Bundle.js b/src/Bundle.js index 950ae9c..d224bef 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -11,6 +11,7 @@ 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 callIfFunction from './utils/callIfFunction.js'; import { isRelative } from './utils/path.js'; @@ -46,6 +47,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 = []; @@ -257,7 +262,7 @@ export default class Bundle { map.sources = map.sources.map( unixizePath ); } - return { code, map }; + return transformBundle( { code, map }, this.bundleTransformers ); } sort () { diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js new file mode 100644 index 0000000..188e777 --- /dev/null +++ b/src/utils/transformBundle.js @@ -0,0 +1,53 @@ +import Promise from 'es6-promise/lib/es6-promise/promise.js'; + +export default function transformBundle ( source, transformers ) { + if ( typeof source === 'string' ) { + source = { + code: source, + map: null + }; + } + + return transformers.reduce( ( previous, transformer ) => { + let result = transformer( previous ) + + if ( result == null ) return previous; + + if ( typeof result === 'string' ) { + result = { + code: result, + map: null + }; + } + // `result.map` can only be a string if `result` isn't + else if ( typeof result.map === 'string' ) { + result.map = JSON.parse( result.map ); + } + + return result; + + }, source ); + + // Promisified version + // return transformers.reduce( ( promise, transformer ) => { + // return promise.then( previous => { + // return Promise.resolve( transformer( previous ) ).then( result => { + // if ( result == null ) return previous; + + // if ( typeof result === 'string' ) { + // result = { + // code: result, + // map: null + // }; + // } + // // `result.map` can only be a string if `result` isn't + // else if ( typeof result.map === 'string' ) { + // result.map = JSON.parse( result.map ); + // } + + // return result; + // }); + // }); + + // }, Promise.resolve( source ) ); +} diff --git a/test/form/transform-bundle-plugin/_config.js b/test/form/transform-bundle-plugin/_config.js new file mode 100644 index 0000000..5e96ee6 --- /dev/null +++ b/test/form/transform-bundle-plugin/_config.js @@ -0,0 +1,21 @@ +module.exports = { + description: 'allows plugins to set banner and footer options', + options: { + plugins: [ + { + transformBundle: function (result) { + return { + code: '/* first plugin */' + }; + } + }, + { + transformBundle: function (result) { + return { + code: result.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 ); From f8e68f425923b11dff76def32291322d6db5d700 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 29 Dec 2015 21:09:46 -0500 Subject: [PATCH 02/27] support --environment in CLI (#378) --- bin/help.md | 11 ++++++++++- bin/runRollup.js | 11 +++++++++++ test/cli/config-env/_config.js | 5 +++++ test/cli/config-env/main.js | 2 ++ test/cli/config-env/rollup.config.js | 12 ++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/cli/config-env/_config.js create mode 100644 test/cli/config-env/main.js create mode 100644 test/cli/config-env/rollup.config.js diff --git a/bin/help.md b/bin/help.md index 5ec5719..85aa7e0 100644 --- a/bin/help.md +++ b/bin/help.md @@ -20,14 +20,23 @@ 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) 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..d789ba8 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 ) { 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 + }) + ] +}; From 6d429321d9a9ab8e5245472f3b59928466e58627 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 30 Dec 2015 05:10:47 +0300 Subject: [PATCH 03/27] Fix lint --- src/utils/transformBundle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js index 188e777..4867235 100644 --- a/src/utils/transformBundle.js +++ b/src/utils/transformBundle.js @@ -1,4 +1,4 @@ -import Promise from 'es6-promise/lib/es6-promise/promise.js'; +// import Promise from 'es6-promise/lib/es6-promise/promise.js'; export default function transformBundle ( source, transformers ) { if ( typeof source === 'string' ) { @@ -9,7 +9,7 @@ export default function transformBundle ( source, transformers ) { } return transformers.reduce( ( previous, transformer ) => { - let result = transformer( previous ) + let result = transformer( previous ); if ( result == null ) return previous; From f2e950914e93bb60f6ebc0679b1cce0a7588e47c Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 30 Dec 2015 05:25:30 +0300 Subject: [PATCH 04/27] Remove promise version comment --- src/utils/transformBundle.js | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js index 4867235..12c1e65 100644 --- a/src/utils/transformBundle.js +++ b/src/utils/transformBundle.js @@ -1,5 +1,3 @@ -// import Promise from 'es6-promise/lib/es6-promise/promise.js'; - export default function transformBundle ( source, transformers ) { if ( typeof source === 'string' ) { source = { @@ -27,27 +25,4 @@ export default function transformBundle ( source, transformers ) { return result; }, source ); - - // Promisified version - // return transformers.reduce( ( promise, transformer ) => { - // return promise.then( previous => { - // return Promise.resolve( transformer( previous ) ).then( result => { - // if ( result == null ) return previous; - - // if ( typeof result === 'string' ) { - // result = { - // code: result, - // map: null - // }; - // } - // // `result.map` can only be a string if `result` isn't - // else if ( typeof result.map === 'string' ) { - // result.map = JSON.parse( result.map ); - // } - - // return result; - // }); - // }); - - // }, Promise.resolve( source ) ); } From 4c661edd0a2d54e6703e9ff2bb99458ed3c206e8 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 30 Dec 2015 05:27:37 +0300 Subject: [PATCH 05/27] Fix test title --- test/form/transform-bundle-plugin/_config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/form/transform-bundle-plugin/_config.js b/test/form/transform-bundle-plugin/_config.js index 5e96ee6..3f13d23 100644 --- a/test/form/transform-bundle-plugin/_config.js +++ b/test/form/transform-bundle-plugin/_config.js @@ -1,5 +1,5 @@ module.exports = { - description: 'allows plugins to set banner and footer options', + description: 'allows plugins to transform bundle', options: { plugins: [ { From 8936840c052041402352c4558acd6461dde5a41e Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 29 Dec 2015 23:17:58 -0500 Subject: [PATCH 06/27] =?UTF-8?q?squelch=20external=20dependency=20warning?= =?UTF-8?q?s=20coming=20from=20rollup.config.js=20=E2=80=93=20fixes=20#333?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/runRollup.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/runRollup.js b/bin/runRollup.js index bff21a1..9af07eb 100644 --- a/bin/runRollup.js +++ b/bin/runRollup.js @@ -27,7 +27,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' From 002369740c0143bdd407932aa58d5f5aab2b6941 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 29 Dec 2015 23:22:44 -0500 Subject: [PATCH 07/27] -> 0.22.1 --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab04a6d..628f847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # rollup changelog +## 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/package.json b/package.json index db12e6c..fce0cc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.22.0", + "version": "0.22.1", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "jsnext:main": "src/rollup.js", From 10c4933ed6c26ac04d60fdb0d7b14340000f1734 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 30 Dec 2015 15:30:01 +0300 Subject: [PATCH 08/27] Add sourcemaps test --- package.json | 3 +- src/utils/transformBundle.js | 13 +++++- test/form/transform-bundle-plugin/_config.js | 8 +--- test/sourcemaps/transform-bundle/_config.js | 47 ++++++++++++++++++++ test/sourcemaps/transform-bundle/main.js | 1 + 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 test/sourcemaps/transform-bundle/_config.js create mode 100644 test/sourcemaps/transform-bundle/main.js diff --git a/package.json b/package.json index db12e6c..d610e8c 100644 --- a/package.json +++ b/package.json @@ -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/utils/transformBundle.js b/src/utils/transformBundle.js index 12c1e65..2bebeea 100644 --- a/src/utils/transformBundle.js +++ b/src/utils/transformBundle.js @@ -1,3 +1,5 @@ +import MagicString from 'magic-string'; + export default function transformBundle ( source, transformers ) { if ( typeof source === 'string' ) { source = { @@ -22,7 +24,16 @@ export default function transformBundle ( source, transformers ) { result.map = JSON.parse( result.map ); } - return result; + if (result.map != null) { + let map = new MagicString.Bundle().generateMap({}); + map.file = result.map.file; + map.sources = result.map.sources; + map.sourcesContent = result.map.sourcesContent; + map.names = result.map.names; + map.mappings = result.map.mappings; + result.map = map; + } + return result; }, source ); } diff --git a/test/form/transform-bundle-plugin/_config.js b/test/form/transform-bundle-plugin/_config.js index 3f13d23..36a30ab 100644 --- a/test/form/transform-bundle-plugin/_config.js +++ b/test/form/transform-bundle-plugin/_config.js @@ -4,16 +4,12 @@ module.exports = { plugins: [ { transformBundle: function (result) { - return { - code: '/* first plugin */' - }; + return '/* first plugin */'; } }, { transformBundle: function (result) { - return { - code: result.code + '\n/* second plugin */' - }; + return result.code + '\n/* second plugin */'; } } ] diff --git a/test/sourcemaps/transform-bundle/_config.js b/test/sourcemaps/transform-bundle/_config.js new file mode 100644 index 0000000..f83ae5f --- /dev/null +++ b/test/sourcemaps/transform-bundle/_config.js @@ -0,0 +1,47 @@ +var uglify = require( 'uglify-js' ); +var MagicString = require( 'magic-string' ); +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 ( source ) { + var options = { fromString: true }; + + if ( source.map != null ) { + options.inSourceMap = source.map; + options.outSourceMap = "out"; + } + + var result = uglify.minify( source.code, options ); + + if (source.map != null) { + result.code = result.code.slice( 0, -25 ); + } + + return result; + } + } + ] + }, + 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 ); From e786b5b7bf7460da9af9f5d543bb70ddcb2951b2 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 30 Dec 2015 15:40:19 +0300 Subject: [PATCH 09/27] Make transformers more straightforward --- src/utils/transformBundle.js | 2 +- test/form/transform-bundle-plugin/_config.js | 6 +++--- test/sourcemaps/transform-bundle/_config.js | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js index 2bebeea..efbe3a1 100644 --- a/src/utils/transformBundle.js +++ b/src/utils/transformBundle.js @@ -9,7 +9,7 @@ export default function transformBundle ( source, transformers ) { } return transformers.reduce( ( previous, transformer ) => { - let result = transformer( previous ); + let result = transformer( previous.code, previous.map ); if ( result == null ) return previous; diff --git a/test/form/transform-bundle-plugin/_config.js b/test/form/transform-bundle-plugin/_config.js index 36a30ab..6b54ad3 100644 --- a/test/form/transform-bundle-plugin/_config.js +++ b/test/form/transform-bundle-plugin/_config.js @@ -3,13 +3,13 @@ module.exports = { options: { plugins: [ { - transformBundle: function (result) { + transformBundle: function (code) { return '/* first plugin */'; } }, { - transformBundle: function (result) { - return result.code + '\n/* second plugin */'; + transformBundle: function (code) { + return code + '\n/* second plugin */'; } } ] diff --git a/test/sourcemaps/transform-bundle/_config.js b/test/sourcemaps/transform-bundle/_config.js index f83ae5f..abb986d 100644 --- a/test/sourcemaps/transform-bundle/_config.js +++ b/test/sourcemaps/transform-bundle/_config.js @@ -9,17 +9,17 @@ module.exports = { options: { plugins: [ { - transformBundle: function ( source ) { + transformBundle: function ( code, map ) { var options = { fromString: true }; - if ( source.map != null ) { - options.inSourceMap = source.map; + if ( map != null ) { + options.inSourceMap = map; options.outSourceMap = "out"; } - var result = uglify.minify( source.code, options ); + var result = uglify.minify( code, options ); - if (source.map != null) { + if ( map != null ) { result.code = result.code.slice( 0, -25 ); } From fbc81f15b740d3f3ace151abeffe7b06d575e52e Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 11:07:48 -0500 Subject: [PATCH 10/27] update magic-string --- package.json | 2 +- test/function/vars-not-removed/_config.js | 3 +++ test/function/vars-not-removed/bar.js | 3 +++ test/function/vars-not-removed/foo.js | 3 +++ test/function/vars-not-removed/main.js | 2 ++ 5 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/function/vars-not-removed/_config.js create mode 100644 test/function/vars-not-removed/bar.js create mode 100644 test/function/vars-not-removed/foo.js create mode 100644 test/function/vars-not-removed/main.js diff --git a/package.json b/package.json index fce0cc4..233cada 100644 --- a/package.json +++ b/package.json @@ -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", 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'; From a60986d6267135b6e0916a5371178e5d3919a1cb Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 11:08:32 -0500 Subject: [PATCH 11/27] -> 0.22.2 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 628f847..0269ab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # rollup changelog +## 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)) diff --git a/package.json b/package.json index 233cada..67b1596 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.22.1", + "version": "0.22.2", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "jsnext:main": "src/rollup.js", From fc0c253101562c96e43faa1fb4f622fb35c64ce6 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 14:16:11 -0500 Subject: [PATCH 12/27] collapse sourcemaps from bundle transformers --- src/Bundle.js | 22 +++-- src/Module.js | 2 +- src/rollup.js | 2 +- src/utils/collapseSourcemaps.js | 72 --------------- src/utils/sourcemap/collapseSourcemaps.js | 87 +++++++++++++++++++ src/utils/sourcemap/removeSourceMappingURL.js | 3 + src/utils/{ => sourcemap}/sourceMappingURL.js | 0 src/utils/transformBundle.js | 36 ++------ test/sourcemaps/transform-bundle/_config.js | 20 ++--- 9 files changed, 119 insertions(+), 125 deletions(-) delete mode 100644 src/utils/collapseSourcemaps.js create mode 100644 src/utils/sourcemap/collapseSourcemaps.js create mode 100644 src/utils/sourcemap/removeSourceMappingURL.js rename src/utils/{ => sourcemap}/sourceMappingURL.js (100%) diff --git a/src/Bundle.js b/src/Bundle.js index d224bef..4a8da0e 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -12,7 +12,8 @@ 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 collapseSourcemaps from './utils/sourcemap/collapseSourcemaps.js'; +import SOURCEMAPPING_URL from './utils/sourcemap/sourceMappingURL.js'; import callIfFunction from './utils/callIfFunction.js'; import { isRelative } from './utils/path.js'; @@ -247,22 +248,25 @@ 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 ) { const file = options.sourceMapFile || options.dest; - map = magicString.generateMap({ - includeContent: true, - file - // TODO - }); + map = magicString.generateMap({ file, includeContent: true }); + + if ( this.transformers.length || this.bundleTransformers.length ) { + map = collapseSourcemaps( map, usedModules, bundleSourcemapChain ); + } - if ( this.transformers.length ) map = collapseSourcemaps( map, usedModules ); map.sources = map.sources.map( unixizePath ); } - return transformBundle( { code, map }, this.bundleTransformers ); + return { code, map }; } sort () { diff --git a/src/Module.js b/src/Module.js index e1965ab..32471a1 100644 --- a/src/Module.js +++ b/src/Module.js @@ -6,7 +6,7 @@ import { blank, keys } from './utils/object.js'; import { basename, extname } from './utils/path.js'; import getLocation from './utils/getLocation.js'; import makeLegalIdentifier from './utils/makeLegalIdentifier.js'; -import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; +import SOURCEMAPPING_URL from './utils/sourcemap/sourceMappingURL.js'; import { SyntheticDefaultDeclaration, SyntheticNamespaceDeclaration } from './Declaration.js'; import { isFalsy, isTruthy } from './ast/conditions.js'; import { emptyBlockStatement } from './ast/create.js'; diff --git a/src/rollup.js b/src/rollup.js index d509bd2..1be02a5 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -3,7 +3,7 @@ import { basename } from './utils/path.js'; import { writeFile } from './utils/fs.js'; import { keys } from './utils/object.js'; import validateKeys from './utils/validateKeys.js'; -import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; +import SOURCEMAPPING_URL from './utils/sourcemap/sourceMappingURL.js'; import Bundle from './Bundle.js'; export const VERSION = '<@VERSION@>'; diff --git a/src/utils/collapseSourcemaps.js b/src/utils/collapseSourcemaps.js deleted file mode 100644 index 8e583cf..0000000 --- a/src/utils/collapseSourcemaps.js +++ /dev/null @@ -1,72 +0,0 @@ -import { encode, decode } from 'sourcemap-codec'; - -function traceSegment ( loc, mappings ) { - const line = loc[0]; - const column = loc[1]; - - const segments = mappings[ line ]; - - if ( !segments ) return null; - - for ( let i = 0; i < segments.length; i += 1 ) { - const segment = segments[i]; - - if ( segment[0] > column ) return null; - - if ( segment[0] === column ) { - if ( segment[1] !== 0 ) { - throw new Error( 'Bad sourcemap' ); - } - - return [ segment[2], segment[3] ]; - } - } - - return null; -} - -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 ); - }); - }); - - const decodedMappings = decode( map.mappings ); - - const tracedMappings = decodedMappings.map( line => { - let tracedLine = []; - - line.forEach( segment => { - const sourceIndex = segment[1]; - const sourceCodeLine = segment[2]; - const sourceCodeColumn = segment[3]; - - const chain = chains[ sourceIndex ]; - - let i = chain.length; - let traced = [ sourceCodeLine, sourceCodeColumn ]; - - while ( i-- && traced ) { - traced = traceSegment( traced, chain[i] ); - } - - if ( traced ) { - tracedLine.push([ - segment[0], - segment[1], - traced[0], - traced[1] - // TODO name? - ]); - } - }); - - return tracedLine; - }); - - map.sourcesContent = modules.map( module => module.originalCode ); - map.mappings = encode( tracedMappings ); - return map; -} diff --git a/src/utils/sourcemap/collapseSourcemaps.js b/src/utils/sourcemap/collapseSourcemaps.js new file mode 100644 index 0000000..f6d7acf --- /dev/null +++ b/src/utils/sourcemap/collapseSourcemaps.js @@ -0,0 +1,87 @@ +import { encode, decode } from 'sourcemap-codec'; + +function Source ( map, sources ) { + if ( !map ) throw new Error( 'Cannot generate a sourcemap if non-sourcemap-generating transformers are used' ); + + this.sources = sources; + this.names = map.names; + this.mappings = decode( map.mappings ); +} + +Source.prototype = { // TODO bring into line with others post-https://github.com/rollup/rollup/pull/386 + traceMappings () { + return this.mappings.map( line => { + let tracedLine = []; + + line.forEach( segment => { + const source = this.sources[ segment[1] ]; + + const sourceCodeLine = segment[2]; + const sourceCodeColumn = segment[3]; + + const traced = source.traceSegment( sourceCodeLine, sourceCodeColumn ); + + if ( traced ) { + tracedLine.push([ + segment[0], + traced.index, + traced.line, + traced.column + // TODO name? + ]); + } + }); + + return tracedLine; + }); + }, + + traceSegment ( line, column ) { + const segments = this.mappings[ line ]; + + if ( !segments ) return null; + + for ( let i = 0; i < segments.length; i += 1 ) { + const segment = segments[i]; + + if ( segment[0] > column ) return null; + + if ( segment[0] === column ) { + const source = this.sources[ segment[1] ]; + + if ( !source ) throw new Error( 'Bad sourcemap' ); + + if ( source.isOriginal ) { + return { index: source.index, line: segment[2], column: segment[3] }; + } + + return source.traceSegment( segment[2], segment[3] ); + } + } + + return null; + } +}; + +export default function collapseSourcemaps ( map, modules, bundleSourcemapChain ) { + const sources = modules.map( ( module, i ) => { + let source = { isOriginal: true, index: i }; + + module.sourceMapChain.forEach( map => { + source = new Source( map, [ source ]); + }); + + return source; + }); + + let source = new Source( map, sources ); + + bundleSourcemapChain.forEach( map => { + source = new Source( map, [ source ] ); + }); + + // we re-use the `map` object because it has convenient toString/toURL methods + map.sourcesContent = modules.map( module => module.originalCode ); + map.mappings = encode( source.traceMappings() ); + return map; +} diff --git a/src/utils/sourcemap/removeSourceMappingURL.js b/src/utils/sourcemap/removeSourceMappingURL.js new file mode 100644 index 0000000..1a555fe --- /dev/null +++ b/src/utils/sourcemap/removeSourceMappingURL.js @@ -0,0 +1,3 @@ +export default function removeSourceMappingURL ( code ) { + +} diff --git a/src/utils/sourceMappingURL.js b/src/utils/sourcemap/sourceMappingURL.js similarity index 100% rename from src/utils/sourceMappingURL.js rename to src/utils/sourcemap/sourceMappingURL.js diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js index efbe3a1..f82bfb6 100644 --- a/src/utils/transformBundle.js +++ b/src/utils/transformBundle.js @@ -1,17 +1,8 @@ -import MagicString from 'magic-string'; +export default function transformBundle ( code, transformers, sourceMapChain ) { + return transformers.reduce( ( code, transformer ) => { + let result = transformer( code ); -export default function transformBundle ( source, transformers ) { - if ( typeof source === 'string' ) { - source = { - code: source, - map: null - }; - } - - return transformers.reduce( ( previous, transformer ) => { - let result = transformer( previous.code, previous.map ); - - if ( result == null ) return previous; + if ( result == null ) return code; if ( typeof result === 'string' ) { result = { @@ -19,21 +10,10 @@ export default function transformBundle ( source, transformers ) { map: null }; } - // `result.map` can only be a string if `result` isn't - else if ( typeof result.map === 'string' ) { - result.map = JSON.parse( result.map ); - } - if (result.map != null) { - let map = new MagicString.Bundle().generateMap({}); - map.file = result.map.file; - map.sources = result.map.sources; - map.sourcesContent = result.map.sourcesContent; - map.names = result.map.names; - map.mappings = result.map.mappings; - result.map = map; - } + const map = typeof result.map === 'string' ? JSON.parse( result.map ) : map; + sourceMapChain.push( map ); - return result; - }, source ); + return result.code; + }, code ); } diff --git a/test/sourcemaps/transform-bundle/_config.js b/test/sourcemaps/transform-bundle/_config.js index abb986d..f1e16ef 100644 --- a/test/sourcemaps/transform-bundle/_config.js +++ b/test/sourcemaps/transform-bundle/_config.js @@ -9,21 +9,13 @@ module.exports = { options: { plugins: [ { - transformBundle: function ( code, map ) { - var options = { fromString: true }; + transformBundle: function ( code ) { + var options = { + fromString: true, + outSourceMap: 'x' // trigger sourcemap generation + }; - if ( map != null ) { - options.inSourceMap = map; - options.outSourceMap = "out"; - } - - var result = uglify.minify( code, options ); - - if ( map != null ) { - result.code = result.code.slice( 0, -25 ); - } - - return result; + return uglify.minify( code, options ); } } ] From a7bb2e3f4152bfb6ed41335076ef73ac7c5202bc Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 14:19:16 -0500 Subject: [PATCH 13/27] put files back where they were --- src/Bundle.js | 4 ++-- src/Module.js | 2 +- src/rollup.js | 2 +- src/utils/{sourcemap => }/collapseSourcemaps.js | 0 src/utils/{sourcemap => }/sourceMappingURL.js | 0 src/utils/sourcemap/removeSourceMappingURL.js | 3 --- 6 files changed, 4 insertions(+), 7 deletions(-) rename src/utils/{sourcemap => }/collapseSourcemaps.js (100%) rename src/utils/{sourcemap => }/sourceMappingURL.js (100%) delete mode 100644 src/utils/sourcemap/removeSourceMappingURL.js diff --git a/src/Bundle.js b/src/Bundle.js index 4a8da0e..23cf9f1 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -12,8 +12,8 @@ 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/sourcemap/collapseSourcemaps.js'; -import SOURCEMAPPING_URL from './utils/sourcemap/sourceMappingURL.js'; +import collapseSourcemaps from './utils/collapseSourcemaps.js'; +import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; import callIfFunction from './utils/callIfFunction.js'; import { isRelative } from './utils/path.js'; diff --git a/src/Module.js b/src/Module.js index 32471a1..e1965ab 100644 --- a/src/Module.js +++ b/src/Module.js @@ -6,7 +6,7 @@ import { blank, keys } from './utils/object.js'; import { basename, extname } from './utils/path.js'; import getLocation from './utils/getLocation.js'; import makeLegalIdentifier from './utils/makeLegalIdentifier.js'; -import SOURCEMAPPING_URL from './utils/sourcemap/sourceMappingURL.js'; +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'; diff --git a/src/rollup.js b/src/rollup.js index 1be02a5..d509bd2 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -3,7 +3,7 @@ import { basename } from './utils/path.js'; import { writeFile } from './utils/fs.js'; import { keys } from './utils/object.js'; import validateKeys from './utils/validateKeys.js'; -import SOURCEMAPPING_URL from './utils/sourcemap/sourceMappingURL.js'; +import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; import Bundle from './Bundle.js'; export const VERSION = '<@VERSION@>'; diff --git a/src/utils/sourcemap/collapseSourcemaps.js b/src/utils/collapseSourcemaps.js similarity index 100% rename from src/utils/sourcemap/collapseSourcemaps.js rename to src/utils/collapseSourcemaps.js diff --git a/src/utils/sourcemap/sourceMappingURL.js b/src/utils/sourceMappingURL.js similarity index 100% rename from src/utils/sourcemap/sourceMappingURL.js rename to src/utils/sourceMappingURL.js diff --git a/src/utils/sourcemap/removeSourceMappingURL.js b/src/utils/sourcemap/removeSourceMappingURL.js deleted file mode 100644 index 1a555fe..0000000 --- a/src/utils/sourcemap/removeSourceMappingURL.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function removeSourceMappingURL ( code ) { - -} From 5e4b54c92b379ee0a032972ab4cf7dee70c1802a Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 15:12:31 -0500 Subject: [PATCH 14/27] handle names in sourcemaps --- src/utils/collapseSourcemaps.js | 47 +++++++++++----- test/sourcemaps/names-transformed/_config.js | 58 ++++++++++++++++++++ test/sourcemaps/names-transformed/a.js | 4 ++ test/sourcemaps/names-transformed/b.js | 4 ++ test/sourcemaps/names-transformed/main.js | 5 ++ test/sourcemaps/transform-bundle/_config.js | 1 - 6 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 test/sourcemaps/names-transformed/_config.js create mode 100644 test/sourcemaps/names-transformed/a.js create mode 100644 test/sourcemaps/names-transformed/b.js create mode 100644 test/sourcemaps/names-transformed/main.js diff --git a/src/utils/collapseSourcemaps.js b/src/utils/collapseSourcemaps.js index f6d7acf..9399f11 100644 --- a/src/utils/collapseSourcemaps.js +++ b/src/utils/collapseSourcemaps.js @@ -10,33 +10,45 @@ function Source ( map, sources ) { Source.prototype = { // TODO bring into line with others post-https://github.com/rollup/rollup/pull/386 traceMappings () { - return this.mappings.map( line => { + let names = []; + + const mappings = this.mappings.map( line => { let tracedLine = []; line.forEach( segment => { const source = this.sources[ segment[1] ]; - - const sourceCodeLine = segment[2]; - const sourceCodeColumn = segment[3]; - - const traced = source.traceSegment( sourceCodeLine, sourceCodeColumn ); + const traced = source.traceSegment( segment[2], segment[3], this.names[ segment[4] ] ); if ( traced ) { - tracedLine.push([ + let nameIndex = null; + segment = [ segment[0], traced.index, traced.line, traced.column - // TODO name? - ]); + ]; + + 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; }); + + return { names, mappings }; }, - traceSegment ( line, column ) { + traceSegment ( line, column, name ) { const segments = this.mappings[ line ]; if ( !segments ) return null; @@ -52,10 +64,15 @@ Source.prototype = { // TODO bring into line with others post-https://github.com if ( !source ) throw new Error( 'Bad sourcemap' ); if ( source.isOriginal ) { - return { index: source.index, line: segment[2], column: segment[3] }; + return { + index: source.index, + line: segment[2], + column: segment[3], + name: this.names[ segment[4] ] || name + }; } - return source.traceSegment( segment[2], segment[3] ); + return source.traceSegment( segment[2], segment[3], name ); } } @@ -80,8 +97,12 @@ export default function collapseSourcemaps ( map, modules, bundleSourcemapChain 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( source.traceMappings() ); + map.mappings = encode( mappings ); + map.names = names; + return map; } 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 index f1e16ef..10a9d43 100644 --- a/test/sourcemaps/transform-bundle/_config.js +++ b/test/sourcemaps/transform-bundle/_config.js @@ -1,5 +1,4 @@ var uglify = require( 'uglify-js' ); -var MagicString = require( 'magic-string' ); var assert = require( 'assert' ); var getLocation = require( '../../utils/getLocation' ); var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer; From a739c51d32110eb653e9d18724c6a9381259d932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Wed, 30 Dec 2015 21:12:39 +0100 Subject: [PATCH 15/27] Add failing test --- test/function/export-destruction/_config.js | 12 ++++++++++++ test/function/export-destruction/main.js | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 test/function/export-destruction/_config.js create mode 100644 test/function/export-destruction/main.js 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; From b5ddcea06d73abd8e51832feccd4ae449741c0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Wed, 30 Dec 2015 21:16:05 +0100 Subject: [PATCH 16/27] Ensure names are properly exported --- src/Module.js | 25 ++++++++++++++++--------- src/ast/Scope.js | 9 ++++----- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Module.js b/src/Module.js index e1965ab..5ff129c 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/Scope.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..75a6c53 100644 --- a/src/ast/Scope.js +++ b/src/ast/Scope.js @@ -8,7 +8,7 @@ const extractors = { ObjectPattern ( names, param ) { param.properties.forEach( prop => { - extractors[ prop.key.type ]( names, prop.key ); + extractors[ prop.value.type ]( names, prop.value ); }); }, @@ -23,13 +23,12 @@ const extractors = { }, AssignmentPattern ( names, param ) { - return extractors[ param.left.type ]( names, param.left ); + extractors[ param.left.type ]( names, param.left ); } }; -function extractNames ( param ) { - let names = []; - +export function extractNames ( param ) { + const names = []; extractors[ param.type ]( names, param ); return names; } From bb53cbbf02083242cf76b4ae58c6003efaee6d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Wed, 30 Dec 2015 21:29:06 +0100 Subject: [PATCH 17/27] Move `extractNames` to its own file --- src/Module.js | 2 +- src/ast/Scope.js | 33 +-------------------------------- src/ast/extractNames.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 src/ast/extractNames.js diff --git a/src/Module.js b/src/Module.js index 5ff129c..be6117f 100644 --- a/src/Module.js +++ b/src/Module.js @@ -10,7 +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/Scope.js'; +import extractNames from './ast/extractNames.js'; export default class Module { constructor ({ id, code, originalCode, ast, sourceMapChain, bundle }) { diff --git a/src/ast/Scope.js b/src/ast/Scope.js index 75a6c53..0dc48ec 100644 --- a/src/ast/Scope.js +++ b/src/ast/Scope.js @@ -1,37 +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.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 ); - } -}; - -export function extractNames ( param ) { - const 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 ); + } +}; From d16d8aabe0291cdcd241b72c0dcdd38140e3b3a5 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 30 Dec 2015 05:05:56 +0300 Subject: [PATCH 18/27] Add transformBundle plugin hook --- package.json | 3 +- src/Bundle.js | 7 ++- src/utils/transformBundle.js | 39 +++++++++++++++ test/form/transform-bundle-plugin/_config.js | 17 +++++++ .../transform-bundle-plugin/_expected/amd.js | 2 + .../transform-bundle-plugin/_expected/cjs.js | 2 + .../transform-bundle-plugin/_expected/es6.js | 2 + .../transform-bundle-plugin/_expected/iife.js | 2 + .../transform-bundle-plugin/_expected/umd.js | 2 + test/form/transform-bundle-plugin/main.js | 1 + test/sourcemaps/transform-bundle/_config.js | 47 +++++++++++++++++++ test/sourcemaps/transform-bundle/main.js | 1 + 12 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 src/utils/transformBundle.js create mode 100644 test/form/transform-bundle-plugin/_config.js create mode 100644 test/form/transform-bundle-plugin/_expected/amd.js create mode 100644 test/form/transform-bundle-plugin/_expected/cjs.js create mode 100644 test/form/transform-bundle-plugin/_expected/es6.js create mode 100644 test/form/transform-bundle-plugin/_expected/iife.js create mode 100644 test/form/transform-bundle-plugin/_expected/umd.js create mode 100644 test/form/transform-bundle-plugin/main.js create mode 100644 test/sourcemaps/transform-bundle/_config.js create mode 100644 test/sourcemaps/transform-bundle/main.js diff --git a/package.json b/package.json index db12e6c..d610e8c 100644 --- a/package.json +++ b/package.json @@ -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 950ae9c..d224bef 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -11,6 +11,7 @@ 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 callIfFunction from './utils/callIfFunction.js'; import { isRelative } from './utils/path.js'; @@ -46,6 +47,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 = []; @@ -257,7 +262,7 @@ export default class Bundle { map.sources = map.sources.map( unixizePath ); } - return { code, map }; + return transformBundle( { code, map }, this.bundleTransformers ); } sort () { diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js new file mode 100644 index 0000000..efbe3a1 --- /dev/null +++ b/src/utils/transformBundle.js @@ -0,0 +1,39 @@ +import MagicString from 'magic-string'; + +export default function transformBundle ( source, transformers ) { + if ( typeof source === 'string' ) { + source = { + code: source, + map: null + }; + } + + return transformers.reduce( ( previous, transformer ) => { + let result = transformer( previous.code, previous.map ); + + if ( result == null ) return previous; + + if ( typeof result === 'string' ) { + result = { + code: result, + map: null + }; + } + // `result.map` can only be a string if `result` isn't + else if ( typeof result.map === 'string' ) { + result.map = JSON.parse( result.map ); + } + + if (result.map != null) { + let map = new MagicString.Bundle().generateMap({}); + map.file = result.map.file; + map.sources = result.map.sources; + map.sourcesContent = result.map.sourcesContent; + map.names = result.map.names; + map.mappings = result.map.mappings; + result.map = map; + } + + return result; + }, source ); +} 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/sourcemaps/transform-bundle/_config.js b/test/sourcemaps/transform-bundle/_config.js new file mode 100644 index 0000000..abb986d --- /dev/null +++ b/test/sourcemaps/transform-bundle/_config.js @@ -0,0 +1,47 @@ +var uglify = require( 'uglify-js' ); +var MagicString = require( 'magic-string' ); +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, map ) { + var options = { fromString: true }; + + if ( map != null ) { + options.inSourceMap = map; + options.outSourceMap = "out"; + } + + var result = uglify.minify( code, options ); + + if ( map != null ) { + result.code = result.code.slice( 0, -25 ); + } + + return result; + } + } + ] + }, + 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 ); From d6c9733e114755b08e6b11cd09914c5dfdaae2cc Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 30 Dec 2015 16:07:27 -0500 Subject: [PATCH 19/27] Revert "Add transformBundle plugin hook" --- package.json | 3 +- src/Bundle.js | 7 +-- src/utils/transformBundle.js | 39 --------------- test/form/transform-bundle-plugin/_config.js | 17 ------- .../transform-bundle-plugin/_expected/amd.js | 2 - .../transform-bundle-plugin/_expected/cjs.js | 2 - .../transform-bundle-plugin/_expected/es6.js | 2 - .../transform-bundle-plugin/_expected/iife.js | 2 - .../transform-bundle-plugin/_expected/umd.js | 2 - test/form/transform-bundle-plugin/main.js | 1 - test/sourcemaps/transform-bundle/_config.js | 47 ------------------- test/sourcemaps/transform-bundle/main.js | 1 - 12 files changed, 2 insertions(+), 123 deletions(-) delete mode 100644 src/utils/transformBundle.js delete mode 100644 test/form/transform-bundle-plugin/_config.js delete mode 100644 test/form/transform-bundle-plugin/_expected/amd.js delete mode 100644 test/form/transform-bundle-plugin/_expected/cjs.js delete mode 100644 test/form/transform-bundle-plugin/_expected/es6.js delete mode 100644 test/form/transform-bundle-plugin/_expected/iife.js delete mode 100644 test/form/transform-bundle-plugin/_expected/umd.js delete mode 100644 test/form/transform-bundle-plugin/main.js delete mode 100644 test/sourcemaps/transform-bundle/_config.js delete mode 100644 test/sourcemaps/transform-bundle/main.js diff --git a/package.json b/package.json index eaea497..67b1596 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,7 @@ "rollup-plugin-replace": "^1.0.1", "sander": "^0.4.0", "source-map": "^0.5.3", - "sourcemap-codec": "^1.2.1", - "uglify-js": "^2.6.1" + "sourcemap-codec": "^1.2.1" }, "dependencies": { "chalk": "^1.1.1", diff --git a/src/Bundle.js b/src/Bundle.js index d224bef..950ae9c 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -11,7 +11,6 @@ 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 callIfFunction from './utils/callIfFunction.js'; import { isRelative } from './utils/path.js'; @@ -47,10 +46,6 @@ 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 = []; @@ -262,7 +257,7 @@ export default class Bundle { map.sources = map.sources.map( unixizePath ); } - return transformBundle( { code, map }, this.bundleTransformers ); + return { code, map }; } sort () { diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js deleted file mode 100644 index efbe3a1..0000000 --- a/src/utils/transformBundle.js +++ /dev/null @@ -1,39 +0,0 @@ -import MagicString from 'magic-string'; - -export default function transformBundle ( source, transformers ) { - if ( typeof source === 'string' ) { - source = { - code: source, - map: null - }; - } - - return transformers.reduce( ( previous, transformer ) => { - let result = transformer( previous.code, previous.map ); - - if ( result == null ) return previous; - - if ( typeof result === 'string' ) { - result = { - code: result, - map: null - }; - } - // `result.map` can only be a string if `result` isn't - else if ( typeof result.map === 'string' ) { - result.map = JSON.parse( result.map ); - } - - if (result.map != null) { - let map = new MagicString.Bundle().generateMap({}); - map.file = result.map.file; - map.sources = result.map.sources; - map.sourcesContent = result.map.sourcesContent; - map.names = result.map.names; - map.mappings = result.map.mappings; - result.map = map; - } - - return result; - }, source ); -} diff --git a/test/form/transform-bundle-plugin/_config.js b/test/form/transform-bundle-plugin/_config.js deleted file mode 100644 index 6b54ad3..0000000 --- a/test/form/transform-bundle-plugin/_config.js +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/amd.js +++ /dev/null @@ -1,2 +0,0 @@ -/* 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 deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/cjs.js +++ /dev/null @@ -1,2 +0,0 @@ -/* 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 deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/es6.js +++ /dev/null @@ -1,2 +0,0 @@ -/* 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 deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/iife.js +++ /dev/null @@ -1,2 +0,0 @@ -/* 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 deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/umd.js +++ /dev/null @@ -1,2 +0,0 @@ -/* 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 deleted file mode 100644 index 934dee7..0000000 --- a/test/form/transform-bundle-plugin/main.js +++ /dev/null @@ -1 +0,0 @@ -console.log( 1 + 1 ); diff --git a/test/sourcemaps/transform-bundle/_config.js b/test/sourcemaps/transform-bundle/_config.js deleted file mode 100644 index abb986d..0000000 --- a/test/sourcemaps/transform-bundle/_config.js +++ /dev/null @@ -1,47 +0,0 @@ -var uglify = require( 'uglify-js' ); -var MagicString = require( 'magic-string' ); -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, map ) { - var options = { fromString: true }; - - if ( map != null ) { - options.inSourceMap = map; - options.outSourceMap = "out"; - } - - var result = uglify.minify( code, options ); - - if ( map != null ) { - result.code = result.code.slice( 0, -25 ); - } - - return result; - } - } - ] - }, - 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 deleted file mode 100644 index 5c72ff3..0000000 --- a/test/sourcemaps/transform-bundle/main.js +++ /dev/null @@ -1 +0,0 @@ -console.log( 42 ); From f6dd25c9a87cf81352774555e8c217068171c492 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 16:14:53 -0500 Subject: [PATCH 20/27] -> 0.23.0 --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0269ab2..e67a81f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # rollup changelog +## 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)) diff --git a/package.json b/package.json index eaea497..4f3a2ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.22.2", + "version": "0.23.0", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "jsnext:main": "src/rollup.js", From aac5365f428f2f5b0b06fa32a895d6e80518ea20 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 16:25:25 -0500 Subject: [PATCH 21/27] reinstate #392 fix --- src/finalisers/umd.js | 2 +- test/cli/indent-none/_expected.js | 2 +- test/cli/module-name/_expected.js | 2 +- test/form/banner-and-footer-plugin/_expected/umd.js | 4 ++-- test/form/banner-and-footer/_expected/umd.js | 4 ++-- test/form/block-comments/_expected/umd.js | 4 ++-- test/form/dedupes-external-imports/_expected/umd.js | 4 ++-- test/form/exclude-unnecessary-modifications/_expected/umd.js | 4 ++-- test/form/export-all-from-internal/_expected/umd.js | 4 ++-- test/form/export-default-2/_expected/umd.js | 4 ++-- test/form/export-default-3/_expected/umd.js | 4 ++-- test/form/export-default/_expected/umd.js | 4 ++-- test/form/export-multiple-vars/_expected/umd.js | 4 ++-- test/form/exports-at-end-if-possible/_expected/umd.js | 4 ++-- test/form/external-imports-custom-names/_expected/umd.js | 4 ++-- test/form/external-imports/_expected/umd.js | 4 ++-- test/form/indent-false/_expected/umd.js | 4 ++-- test/form/indent-true-spaces/_expected/umd.js | 4 ++-- test/form/indent-true/_expected/umd.js | 4 ++-- test/form/internal-conflict-resolution/_expected/umd.js | 4 ++-- test/form/intro-and-outro/_expected/umd.js | 4 ++-- test/form/multiple-exports/_expected/umd.js | 4 ++-- test/form/namespace-optimization-b/_expected/umd.js | 2 +- test/form/namespace-optimization/_expected/umd.js | 4 ++-- test/form/namespaced-default-exports/_expected/umd.js | 4 ++-- test/form/namespaced-named-exports/_expected/umd.js | 4 ++-- test/form/no-imports-or-exports/_expected/umd.js | 4 ++-- .../form/object-destructuring-default-values/_expected/umd.js | 2 +- test/form/preserves-comments-after-imports/_expected/umd.js | 4 ++-- .../form/removes-existing-sourcemap-comments/_expected/umd.js | 4 ++-- test/form/self-contained-bundle/_expected/umd.js | 4 ++-- test/form/shorthand-properties/_expected/umd.js | 4 ++-- test/form/side-effect-b/_expected/umd.js | 2 +- test/form/side-effect-c/_expected/umd.js | 2 +- test/form/side-effect-d/_expected/umd.js | 4 ++-- test/form/side-effect-e/_expected/umd.js | 4 ++-- test/form/side-effect-f/_expected/umd.js | 4 ++-- test/form/side-effect-g/_expected/umd.js | 4 ++-- test/form/side-effect-h/_expected/umd.js | 4 ++-- test/form/side-effect-i/_expected/umd.js | 4 ++-- test/form/side-effect-j/_expected/umd.js | 2 +- test/form/side-effect-k/_expected/umd.js | 2 +- test/form/side-effect-l/_expected/umd.js | 4 ++-- test/form/side-effect/_expected/umd.js | 4 ++-- test/form/sourcemaps-inline/_expected/umd.js | 2 +- test/form/sourcemaps/_expected/umd.js | 2 +- .../spacing-after-function-with-semicolon/_expected/umd.js | 4 ++-- test/form/string-indentation-b/_expected/umd.js | 2 +- test/form/string-indentation/_expected/umd.js | 4 ++-- .../_expected/umd.js | 4 ++-- test/form/unmodified-default-exports/_expected/umd.js | 4 ++-- test/form/unused-default-exports/_expected/umd.js | 4 ++-- 52 files changed, 92 insertions(+), 92 deletions(-) diff --git a/src/finalisers/umd.js b/src/finalisers/umd.js index fd296e7..bdd999e 100644 --- a/src/finalisers/umd.js +++ b/src/finalisers/umd.js @@ -50,7 +50,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/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/_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/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 From c502eaa678dc449a159fe022a4aec49d4bba2ee5 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 16:43:30 -0500 Subject: [PATCH 22/27] -> 0.23.1 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e67a81f..49ed70c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 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)) diff --git a/package.json b/package.json index 4f3a2ad..81893b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.23.0", + "version": "0.23.1", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "jsnext:main": "src/rollup.js", From 1ef38cf131c0a7f374d0999cb743df47035c8418 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 18:11:08 -0500 Subject: [PATCH 23/27] allow options.globals to be a function, warn on miss (#293) --- src/finalisers/iife.js | 8 ++++---- src/finalisers/shared/getGlobalNameMaker.js | 11 +++++++++++ src/finalisers/umd.js | 7 +++---- .../external-imports-custom-names-function/_config.js | 8 ++++++++ .../_expected/amd.js | 5 +++++ .../_expected/cjs.js | 5 +++++ .../_expected/es6.js | 3 +++ .../_expected/iife.js | 5 +++++ .../_expected/umd.js | 9 +++++++++ .../external-imports-custom-names-function/main.js | 2 ++ 10 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 src/finalisers/shared/getGlobalNameMaker.js create mode 100644 test/form/external-imports-custom-names-function/_config.js create mode 100644 test/form/external-imports-custom-names-function/_expected/amd.js create mode 100644 test/form/external-imports-custom-names-function/_expected/cjs.js create mode 100644 test/form/external-imports-custom-names-function/_expected/es6.js create mode 100644 test/form/external-imports-custom-names-function/_expected/iife.js create mode 100644 test/form/external-imports-custom-names-function/_expected/umd.js create mode 100644 test/form/external-imports-custom-names-function/main.js 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 bdd999e..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 ); 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(); From 3e7c453c57ceed4d8136a5834083b6975b7fb239 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 30 Dec 2015 18:51:46 -0500 Subject: [PATCH 24/27] support banner/footer/intro/outro options via CLI --- bin/help.md | 4 ++++ bin/runRollup.js | 10 +++++++--- test/cli/banner-intro-outro-footer/_config.js | 5 +++++ test/cli/banner-intro-outro-footer/_expected.js | 9 +++++++++ test/cli/banner-intro-outro-footer/main.js | 1 + 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 test/cli/banner-intro-outro-footer/_config.js create mode 100644 test/cli/banner-intro-outro-footer/_expected.js create mode 100644 test/cli/banner-intro-outro-footer/main.js diff --git a/bin/help.md b/bin/help.md index 85aa7e0..7713f67 100644 --- a/bin/help.md +++ b/bin/help.md @@ -21,6 +21,10 @@ Basic options: --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: diff --git a/bin/runRollup.js b/bin/runRollup.js index 4603c28..74b1135 100644 --- a/bin/runRollup.js +++ b/bin/runRollup.js @@ -74,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/test/cli/banner-intro-outro-footer/_config.js b/test/cli/banner-intro-outro-footer/_config.js new file mode 100644 index 0000000..2341f48 --- /dev/null +++ b/test/cli/banner-intro-outro-footer/_config.js @@ -0,0 +1,5 @@ +module.exports = { + solo: true, + 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 ); From aae8a0964910a9c1d34ec84614610f9b417d5537 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 1 Jan 2016 12:42:36 -0500 Subject: [PATCH 25/27] =?UTF-8?q?handle=20a=20=3D>=20a=20at=20top=20level?= =?UTF-8?q?=20=E2=80=93=20fixes=20#403?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast/isReference.js | 2 ++ test/function/top-level-arrow-function/_config.js | 3 +++ test/function/top-level-arrow-function/main.js | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 test/function/top-level-arrow-function/_config.js create mode 100644 test/function/top-level-arrow-function/main.js diff --git a/src/ast/isReference.js b/src/ast/isReference.js index 7e0c8db..4b8c71b 100644 --- a/src/ast/isReference.js +++ b/src/ast/isReference.js @@ -4,6 +4,8 @@ export default function isReference ( node, parent ) { } if ( node.type === 'Identifier' ) { + if ( !parent ) return true; + // TODO is this right? if ( parent.type === 'MemberExpression' ) return parent.computed || node === parent.object; 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..95d2df9 --- /dev/null +++ b/test/function/top-level-arrow-function/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'handles naked return value from top-level arrow function expression (#403)' +}; 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 ); From 271cd915cd891893f271388970cc03d2df760168 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 1 Jan 2016 12:56:28 -0500 Subject: [PATCH 26/27] argh, node 0.12 --- test/function/top-level-arrow-function/_config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/function/top-level-arrow-function/_config.js b/test/function/top-level-arrow-function/_config.js index 95d2df9..6ce4fd3 100644 --- a/test/function/top-level-arrow-function/_config.js +++ b/test/function/top-level-arrow-function/_config.js @@ -1,3 +1,4 @@ module.exports = { - description: 'handles naked return value from top-level arrow function expression (#403)' + description: 'handles naked return value from top-level arrow function expression (#403)', + babel: true }; From a7de73fbe94d1c33ca71bf2bd8becdaea27fe73b Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 2 Jan 2016 10:26:22 -0500 Subject: [PATCH 27/27] add comment re arrow function expression special case --- src/ast/isReference.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ast/isReference.js b/src/ast/isReference.js index 4b8c71b..98d8df5 100644 --- a/src/ast/isReference.js +++ b/src/ast/isReference.js @@ -4,6 +4,9 @@ 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?