rollup 0.37.1 → 0.37.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # rollup changelog
2
2
 
3
+ ## 0.37.2
4
+
5
+ * Remove unused `new` expressions without side-effects ([#179](https://github.com/rollup/rollup/issues/179))
6
+ * Only remove valid sourceMappingURL comments ([#1132](https://github.com/rollup/rollup/issues/1132))
7
+ * Ensure blocks containing activated `var` declarations are included in output ([#1113](https://github.com/rollup/rollup/issues/1113))
8
+ * Support plugin outros ([#1116](https://github.com/rollup/rollup/issues/1116))
9
+
3
10
  ## 0.37.1
4
11
 
5
12
  * Follow symlinks ([#447](https://github.com/rollup/rollup/issues/447))
package/bin/rollup CHANGED
@@ -257,7 +257,7 @@ var minimist = interopDefault(index);
257
257
 
258
258
  var help = "rollup version __VERSION__\n=====================================\n\nUsage: rollup [options] <entry file>\n\nBasic options:\n\n-v, --version Show version number\n-h, --help Show this help message\n-c, --config Use this config file (if argument is used but value\n is unspecified, defaults to rollup.config.js)\n-w, --watch Watch files in bundle and rebuild on changes\n-i, --input Input (alternative to <entry file>)\n-o, --output <output> Output (if absent, prints to stdout)\n-f, --format [es] Type of output (amd, cjs, es, iife, umd)\n-e, --external Comma-separate list of module IDs to exclude\n-g, --globals Comma-separate list of `module ID:Global` pairs\n Any module IDs defined here are added to external\n-n, --name Name for UMD export\n-u, --id ID for AMD module (default is anonymous)\n-m, --sourcemap Generate sourcemap (`-m inline` for inline map)\n--no-strict Don't emit a `\"use strict\";` in the generated modules.\n--no-indent Don't indent result\n--environment <values> Settings passed to config file (see example)\n--no-conflict Generate a noConflict method for UMD globals\n--intro Content to insert at top of bundle (inside wrapper)\n--outro Content to insert at end of bundle (inside wrapper)\n--banner Content to insert at top of bundle (outside wrapper)\n--footer Content to insert at end of bundle (outside wrapper)\n\nExamples:\n\n# use settings in config file\nrollup -c\n\n# in config file, process.env.INCLUDE_DEPS === 'true'\n# and process.env.BUILD === 'production'\nrollup -c --environment INCLUDE_DEPS,BUILD:production\n\n# create CommonJS bundle.js from src/main.js\nrollup --format=cjs --output=bundle.js -- src/main.js\n\n# create self-executing IIFE using `window.jQuery`\n# and `window._` as external globals\nrollup -f iife --globals jquery:jQuery,lodash:_ \\\n -i src/app.js -o build/app.js -m build/app.js.map\n\nNotes:\n\n* When piping to stdout, only inline sourcemaps are permitted\n\nFor more information visit https://github.com/rollup/rollup/wiki\n";
259
259
 
260
- var version = "0.37.1";
260
+ var version = "0.37.2";
261
261
 
262
262
  var index$1 = createCommonjsModule(function (module) {
263
263
  /*
@@ -1,6 +1,6 @@
1
1
  /*
2
- Rollup.js v0.37.1
3
- Tue Dec 20 2016 20:09:03 GMT-0500 (EST) - commit b3b10986cc181511d681a80c3535bfd644b986f9
2
+ Rollup.js v0.37.2
3
+ Tue Dec 20 2016 23:13:18 GMT-0500 (EST) - commit 37a6869ef967e0bed8fd20dfc70f86dfdb993804
4
4
 
5
5
 
6
6
  https://github.com/rollup/rollup
@@ -5827,7 +5827,43 @@ simdTypes.forEach( function (t) {
5827
5827
 
5828
5828
  var currentlyCalling = new Set();
5829
5829
 
5830
- function fnHasEffects ( fn ) {
5830
+ function isES5Function ( node ) {
5831
+ return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
5832
+ }
5833
+
5834
+ function hasEffectsNew ( node, scope ) {
5835
+ var inner = node;
5836
+
5837
+ if ( inner.type === 'ExpressionStatement' ) {
5838
+ inner = inner.expression;
5839
+
5840
+ if ( inner.type === 'AssignmentExpression' ) {
5841
+ if ( inner.right.hasEffects( scope ) ) {
5842
+ return true;
5843
+
5844
+ } else {
5845
+ inner = inner.left;
5846
+
5847
+ if ( inner.type === 'MemberExpression' ) {
5848
+ if ( inner.computed && inner.property.hasEffects( scope ) ) {
5849
+ return true;
5850
+
5851
+ } else {
5852
+ inner = inner.object;
5853
+
5854
+ if ( inner.type === 'ThisExpression' ) {
5855
+ return false;
5856
+ }
5857
+ }
5858
+ }
5859
+ }
5860
+ }
5861
+ }
5862
+
5863
+ return node.hasEffects( scope );
5864
+ }
5865
+
5866
+ function fnHasEffects ( fn, isNew ) {
5831
5867
  if ( currentlyCalling.has( fn ) ) return false; // prevent infinite loops... TODO there must be a better way
5832
5868
  currentlyCalling.add( fn );
5833
5869
 
@@ -5836,7 +5872,7 @@ function fnHasEffects ( fn ) {
5836
5872
  var body = fn.body.type === 'BlockStatement' ? fn.body.body : [ fn.body ];
5837
5873
 
5838
5874
  for ( var node of body ) {
5839
- if ( node.hasEffects( scope ) ) {
5875
+ if ( isNew ? hasEffectsNew( node, scope ) : node.hasEffects( scope ) ) {
5840
5876
  currentlyCalling.delete( fn );
5841
5877
  return true;
5842
5878
  }
@@ -5846,14 +5882,14 @@ function fnHasEffects ( fn ) {
5846
5882
  return false;
5847
5883
  }
5848
5884
 
5849
- function callHasEffects ( scope, callee ) {
5885
+ function callHasEffects ( scope, callee, isNew ) {
5850
5886
  var values = new Set([ callee ]);
5851
5887
 
5852
5888
  for ( var node of values ) {
5853
5889
  if ( node === UNKNOWN ) return true; // err on side of caution
5854
5890
 
5855
5891
  if ( /Function/.test( node.type ) ) {
5856
- if ( fnHasEffects( node ) ) return true;
5892
+ if ( fnHasEffects( node, isNew && isES5Function( node ) ) ) return true;
5857
5893
  }
5858
5894
 
5859
5895
  else if ( isReference( node ) ) {
@@ -5919,7 +5955,7 @@ var CallExpression = (function (Node) {
5919
5955
  };
5920
5956
 
5921
5957
  CallExpression.prototype.hasEffects = function hasEffects ( scope ) {
5922
- return callHasEffects( scope, this.callee );
5958
+ return callHasEffects( scope, this.callee, false );
5923
5959
  };
5924
5960
 
5925
5961
  CallExpression.prototype.initialise = function initialise ( scope ) {
@@ -6846,7 +6882,7 @@ var NewExpression = (function (Node) {
6846
6882
  NewExpression.prototype.constructor = NewExpression;
6847
6883
 
6848
6884
  NewExpression.prototype.hasEffects = function hasEffects ( scope ) {
6849
- return callHasEffects( scope, this.callee );
6885
+ return callHasEffects( scope, this.callee, true );
6850
6886
  };
6851
6887
 
6852
6888
  return NewExpression;
@@ -7087,6 +7123,16 @@ var VariableDeclarator = (function (Node) {
7087
7123
  this.activated = true;
7088
7124
 
7089
7125
  this.run( this.findScope() );
7126
+
7127
+ // if declaration is inside a block, ensure that the block
7128
+ // is marked for inclusion
7129
+ if ( this.parent.kind === 'var' ) {
7130
+ var node = this.parent.parent;
7131
+ while ( /Statement/.test( node.type ) ) {
7132
+ node.shouldInclude = true;
7133
+ node = node.parent;
7134
+ }
7135
+ }
7090
7136
  };
7091
7137
 
7092
7138
  VariableDeclarator.prototype.hasEffects = function hasEffects ( scope ) {
@@ -7487,7 +7533,7 @@ var Module = function Module (ref) {
7487
7533
  });
7488
7534
 
7489
7535
  // remove existing sourceMappingURL comments
7490
- var pattern = new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' );
7536
+ var pattern = new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' );
7491
7537
  var match;
7492
7538
  while ( match = pattern.exec( code ) ) {
7493
7539
  this$1.magicString.remove( match.index, match.index + match[0].length );
@@ -7522,7 +7568,7 @@ Module.prototype.addExport = function addExport ( node ) {
7522
7568
  }
7523
7569
 
7524
7570
  else {
7525
- node.specifiers.forEach( function (specifier) {
7571
+ node.specifiers.forEach( function (specifier) {
7526
7572
  var name = specifier.exported.name;
7527
7573
 
7528
7574
  if ( this$1.exports[ name ] || this$1.reexports[ name ] ) {
@@ -7935,6 +7981,7 @@ function amd ( bundle, magicString, ref, options ) {
7935
7981
  var exportMode = ref.exportMode;
7936
7982
  var indentString = ref.indentString;
7937
7983
  var intro = ref.intro;
7984
+ var outro = ref.outro;
7938
7985
 
7939
7986
  var deps = bundle.externalModules.map( quotePath );
7940
7987
  var args = bundle.externalModules.map( getName );
@@ -7960,7 +8007,7 @@ function amd ( bundle, magicString, ref, options ) {
7960
8007
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
7961
8008
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7962
8009
  if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
7963
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8010
+ if ( outro ) magicString.append( outro );
7964
8011
 
7965
8012
  return magicString
7966
8013
  .indent( indentString )
@@ -7971,6 +8018,7 @@ function amd ( bundle, magicString, ref, options ) {
7971
8018
  function cjs ( bundle, magicString, ref, options ) {
7972
8019
  var exportMode = ref.exportMode;
7973
8020
  var intro = ref.intro;
8021
+ var outro = ref.outro;
7974
8022
 
7975
8023
  intro = ( options.useStrict === false ? intro : ("'use strict';\n\n" + intro) ) +
7976
8024
  ( exportMode === 'named' && options.legacy !== true ? (esModuleExport + "\n\n") : '' );
@@ -8015,7 +8063,7 @@ function cjs ( bundle, magicString, ref, options ) {
8015
8063
 
8016
8064
  var exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
8017
8065
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8018
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8066
+ if ( outro ) magicString.append( outro );
8019
8067
 
8020
8068
  return magicString;
8021
8069
  }
@@ -8024,8 +8072,9 @@ function notDefault ( name ) {
8024
8072
  return name !== 'default';
8025
8073
  }
8026
8074
 
8027
- function es ( bundle, magicString, ref, options ) {
8075
+ function es ( bundle, magicString, ref ) {
8028
8076
  var intro = ref.intro;
8077
+ var outro = ref.outro;
8029
8078
 
8030
8079
  var importBlock = bundle.externalModules
8031
8080
  .map( function (module) {
@@ -8092,7 +8141,7 @@ function es ( bundle, magicString, ref, options ) {
8092
8141
  }
8093
8142
 
8094
8143
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock.trim() );
8095
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8144
+ if ( outro ) magicString.append( outro );
8096
8145
 
8097
8146
  return magicString.trim();
8098
8147
  }
@@ -8145,6 +8194,7 @@ function iife ( bundle, magicString, ref, options ) {
8145
8194
  var exportMode = ref.exportMode;
8146
8195
  var indentString = ref.indentString;
8147
8196
  var intro = ref.intro;
8197
+ var outro = ref.outro;
8148
8198
 
8149
8199
  var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
8150
8200
 
@@ -8185,7 +8235,7 @@ function iife ( bundle, magicString, ref, options ) {
8185
8235
 
8186
8236
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8187
8237
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8188
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8238
+ if ( outro ) magicString.append( outro );
8189
8239
 
8190
8240
  return magicString
8191
8241
  .indent( indentString )
@@ -8216,6 +8266,7 @@ function umd ( bundle, magicString, ref, options ) {
8216
8266
  var exportMode = ref.exportMode;
8217
8267
  var indentString = ref.indentString;
8218
8268
  var intro = ref.intro;
8269
+ var outro = ref.outro;
8219
8270
 
8220
8271
  if ( exportMode !== 'none' && !options.moduleName ) {
8221
8272
  throw new Error( 'You must supply options.moduleName for UMD bundles' );
@@ -8261,7 +8312,7 @@ function umd ( bundle, magicString, ref, options ) {
8261
8312
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8262
8313
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8263
8314
  if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
8264
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8315
+ if ( outro ) magicString.append( outro );
8265
8316
 
8266
8317
  return magicString
8267
8318
  .trim()
@@ -9064,7 +9115,16 @@ Bundle.prototype.render = function render ( options ) {
9064
9115
  .filter( Boolean )
9065
9116
  .join( '\n\n' );
9066
9117
 
9067
- if ( intro ) intro += '\n';
9118
+ if ( intro ) intro += '\n\n';
9119
+
9120
+ var outro = [ options.outro ]
9121
+ .concat(
9122
+ this.plugins.map( function (plugin) { return plugin.outro && plugin.outro(); } )
9123
+ )
9124
+ .filter( Boolean )
9125
+ .join( '\n\n' );
9126
+
9127
+ if ( outro ) outro = "\n\n" + outro;
9068
9128
 
9069
9129
  var indentString = getIndentString( magicString, options );
9070
9130
 
@@ -9073,7 +9133,7 @@ Bundle.prototype.render = function render ( options ) {
9073
9133
 
9074
9134
  timeStart( 'render format' );
9075
9135
 
9076
- magicString = finalise( this, magicString.trim(), { exportMode: exportMode, indentString: indentString, intro: intro }, options );
9136
+ magicString = finalise( this, magicString.trim(), { exportMode: exportMode, indentString: indentString, intro: intro, outro: outro }, options );
9077
9137
 
9078
9138
  timeEnd( 'render format' );
9079
9139
 
@@ -9097,7 +9157,7 @@ Bundle.prototype.render = function render ( options ) {
9097
9157
  var bundleSourcemapChain = [];
9098
9158
 
9099
9159
  code = transformBundle( code, this.plugins, bundleSourcemapChain, options )
9100
- .replace( new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' ), '' );
9160
+ .replace( new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' ), '' );
9101
9161
 
9102
9162
  if ( options.sourceMap ) {
9103
9163
  timeStart( 'sourceMap' );
@@ -9124,7 +9184,7 @@ Bundle.prototype.render = function render ( options ) {
9124
9184
  return { code: code, map: map };
9125
9185
  };
9126
9186
 
9127
- Bundle.prototype.sort = function sort () {
9187
+ Bundle.prototype.sort = function sort () {
9128
9188
  var this$1 = this;
9129
9189
 
9130
9190
  var hasCycles;
@@ -9200,7 +9260,7 @@ Bundle.prototype.render = function render ( options ) {
9200
9260
 
9201
9261
  this$1.onwarn(
9202
9262
  ("Module " + (a.id) + " may be unable to evaluate without " + (b.id) + ", but is included first due to a cyclical dependency. Consider swapping the import statements in " + parent + " to ensure correct ordering")
9203
- );
9263
+ );
9204
9264
  }
9205
9265
  };
9206
9266
 
@@ -9211,7 +9271,7 @@ Bundle.prototype.render = function render ( options ) {
9211
9271
  return ordered;
9212
9272
  };
9213
9273
 
9214
- var VERSION = '0.37.1';
9274
+ var VERSION = '0.37.2';
9215
9275
 
9216
9276
  var ALLOWED_KEYS = [
9217
9277
  'acorn',