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/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
- Rollup.js v0.37.1
3
- Tue Dec 20 2016 20:08:52 GMT-0500 (EST) - commit b3b10986cc181511d681a80c3535bfd644b986f9
2
+ Rollup.js v0.37.2
3
+ Tue Dec 20 2016 23:13:07 GMT-0500 (EST) - commit 37a6869ef967e0bed8fd20dfc70f86dfdb993804
4
4
 
5
5
 
6
6
  https://github.com/rollup/rollup
@@ -5775,7 +5775,43 @@ simdTypes.forEach( function (t) {
5775
5775
 
5776
5776
  var currentlyCalling = new Set();
5777
5777
 
5778
- function fnHasEffects ( fn ) {
5778
+ function isES5Function ( node ) {
5779
+ return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
5780
+ }
5781
+
5782
+ function hasEffectsNew ( node, scope ) {
5783
+ var inner = node;
5784
+
5785
+ if ( inner.type === 'ExpressionStatement' ) {
5786
+ inner = inner.expression;
5787
+
5788
+ if ( inner.type === 'AssignmentExpression' ) {
5789
+ if ( inner.right.hasEffects( scope ) ) {
5790
+ return true;
5791
+
5792
+ } else {
5793
+ inner = inner.left;
5794
+
5795
+ if ( inner.type === 'MemberExpression' ) {
5796
+ if ( inner.computed && inner.property.hasEffects( scope ) ) {
5797
+ return true;
5798
+
5799
+ } else {
5800
+ inner = inner.object;
5801
+
5802
+ if ( inner.type === 'ThisExpression' ) {
5803
+ return false;
5804
+ }
5805
+ }
5806
+ }
5807
+ }
5808
+ }
5809
+ }
5810
+
5811
+ return node.hasEffects( scope );
5812
+ }
5813
+
5814
+ function fnHasEffects ( fn, isNew ) {
5779
5815
  if ( currentlyCalling.has( fn ) ) return false; // prevent infinite loops... TODO there must be a better way
5780
5816
  currentlyCalling.add( fn );
5781
5817
 
@@ -5784,7 +5820,7 @@ function fnHasEffects ( fn ) {
5784
5820
  var body = fn.body.type === 'BlockStatement' ? fn.body.body : [ fn.body ];
5785
5821
 
5786
5822
  for ( var node of body ) {
5787
- if ( node.hasEffects( scope ) ) {
5823
+ if ( isNew ? hasEffectsNew( node, scope ) : node.hasEffects( scope ) ) {
5788
5824
  currentlyCalling.delete( fn );
5789
5825
  return true;
5790
5826
  }
@@ -5794,14 +5830,14 @@ function fnHasEffects ( fn ) {
5794
5830
  return false;
5795
5831
  }
5796
5832
 
5797
- function callHasEffects ( scope, callee ) {
5833
+ function callHasEffects ( scope, callee, isNew ) {
5798
5834
  var values = new Set([ callee ]);
5799
5835
 
5800
5836
  for ( var node of values ) {
5801
5837
  if ( node === UNKNOWN ) return true; // err on side of caution
5802
5838
 
5803
5839
  if ( /Function/.test( node.type ) ) {
5804
- if ( fnHasEffects( node ) ) return true;
5840
+ if ( fnHasEffects( node, isNew && isES5Function( node ) ) ) return true;
5805
5841
  }
5806
5842
 
5807
5843
  else if ( isReference( node ) ) {
@@ -5867,7 +5903,7 @@ var CallExpression = (function (Node) {
5867
5903
  };
5868
5904
 
5869
5905
  CallExpression.prototype.hasEffects = function hasEffects ( scope ) {
5870
- return callHasEffects( scope, this.callee );
5906
+ return callHasEffects( scope, this.callee, false );
5871
5907
  };
5872
5908
 
5873
5909
  CallExpression.prototype.initialise = function initialise ( scope ) {
@@ -6794,7 +6830,7 @@ var NewExpression = (function (Node) {
6794
6830
  NewExpression.prototype.constructor = NewExpression;
6795
6831
 
6796
6832
  NewExpression.prototype.hasEffects = function hasEffects ( scope ) {
6797
- return callHasEffects( scope, this.callee );
6833
+ return callHasEffects( scope, this.callee, true );
6798
6834
  };
6799
6835
 
6800
6836
  return NewExpression;
@@ -7035,6 +7071,16 @@ var VariableDeclarator = (function (Node) {
7035
7071
  this.activated = true;
7036
7072
 
7037
7073
  this.run( this.findScope() );
7074
+
7075
+ // if declaration is inside a block, ensure that the block
7076
+ // is marked for inclusion
7077
+ if ( this.parent.kind === 'var' ) {
7078
+ var node = this.parent.parent;
7079
+ while ( /Statement/.test( node.type ) ) {
7080
+ node.shouldInclude = true;
7081
+ node = node.parent;
7082
+ }
7083
+ }
7038
7084
  };
7039
7085
 
7040
7086
  VariableDeclarator.prototype.hasEffects = function hasEffects ( scope ) {
@@ -7435,7 +7481,7 @@ var Module = function Module (ref) {
7435
7481
  });
7436
7482
 
7437
7483
  // remove existing sourceMappingURL comments
7438
- var pattern = new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' );
7484
+ var pattern = new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' );
7439
7485
  var match;
7440
7486
  while ( match = pattern.exec( code ) ) {
7441
7487
  this$1.magicString.remove( match.index, match.index + match[0].length );
@@ -7470,7 +7516,7 @@ Module.prototype.addExport = function addExport ( node ) {
7470
7516
  }
7471
7517
 
7472
7518
  else {
7473
- node.specifiers.forEach( function (specifier) {
7519
+ node.specifiers.forEach( function (specifier) {
7474
7520
  var name = specifier.exported.name;
7475
7521
 
7476
7522
  if ( this$1.exports[ name ] || this$1.reexports[ name ] ) {
@@ -7883,6 +7929,7 @@ function amd ( bundle, magicString, ref, options ) {
7883
7929
  var exportMode = ref.exportMode;
7884
7930
  var indentString = ref.indentString;
7885
7931
  var intro = ref.intro;
7932
+ var outro = ref.outro;
7886
7933
 
7887
7934
  var deps = bundle.externalModules.map( quotePath );
7888
7935
  var args = bundle.externalModules.map( getName );
@@ -7908,7 +7955,7 @@ function amd ( bundle, magicString, ref, options ) {
7908
7955
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
7909
7956
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7910
7957
  if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
7911
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
7958
+ if ( outro ) magicString.append( outro );
7912
7959
 
7913
7960
  return magicString
7914
7961
  .indent( indentString )
@@ -7919,6 +7966,7 @@ function amd ( bundle, magicString, ref, options ) {
7919
7966
  function cjs ( bundle, magicString, ref, options ) {
7920
7967
  var exportMode = ref.exportMode;
7921
7968
  var intro = ref.intro;
7969
+ var outro = ref.outro;
7922
7970
 
7923
7971
  intro = ( options.useStrict === false ? intro : ("'use strict';\n\n" + intro) ) +
7924
7972
  ( exportMode === 'named' && options.legacy !== true ? (esModuleExport + "\n\n") : '' );
@@ -7963,7 +8011,7 @@ function cjs ( bundle, magicString, ref, options ) {
7963
8011
 
7964
8012
  var exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
7965
8013
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7966
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8014
+ if ( outro ) magicString.append( outro );
7967
8015
 
7968
8016
  return magicString;
7969
8017
  }
@@ -7972,8 +8020,9 @@ function notDefault ( name ) {
7972
8020
  return name !== 'default';
7973
8021
  }
7974
8022
 
7975
- function es ( bundle, magicString, ref, options ) {
8023
+ function es ( bundle, magicString, ref ) {
7976
8024
  var intro = ref.intro;
8025
+ var outro = ref.outro;
7977
8026
 
7978
8027
  var importBlock = bundle.externalModules
7979
8028
  .map( function (module) {
@@ -8040,7 +8089,7 @@ function es ( bundle, magicString, ref, options ) {
8040
8089
  }
8041
8090
 
8042
8091
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock.trim() );
8043
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8092
+ if ( outro ) magicString.append( outro );
8044
8093
 
8045
8094
  return magicString.trim();
8046
8095
  }
@@ -8093,6 +8142,7 @@ function iife ( bundle, magicString, ref, options ) {
8093
8142
  var exportMode = ref.exportMode;
8094
8143
  var indentString = ref.indentString;
8095
8144
  var intro = ref.intro;
8145
+ var outro = ref.outro;
8096
8146
 
8097
8147
  var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
8098
8148
 
@@ -8133,7 +8183,7 @@ function iife ( bundle, magicString, ref, options ) {
8133
8183
 
8134
8184
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8135
8185
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8136
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8186
+ if ( outro ) magicString.append( outro );
8137
8187
 
8138
8188
  return magicString
8139
8189
  .indent( indentString )
@@ -8164,6 +8214,7 @@ function umd ( bundle, magicString, ref, options ) {
8164
8214
  var exportMode = ref.exportMode;
8165
8215
  var indentString = ref.indentString;
8166
8216
  var intro = ref.intro;
8217
+ var outro = ref.outro;
8167
8218
 
8168
8219
  if ( exportMode !== 'none' && !options.moduleName ) {
8169
8220
  throw new Error( 'You must supply options.moduleName for UMD bundles' );
@@ -8209,7 +8260,7 @@ function umd ( bundle, magicString, ref, options ) {
8209
8260
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8210
8261
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8211
8262
  if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
8212
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8263
+ if ( outro ) magicString.append( outro );
8213
8264
 
8214
8265
  return magicString
8215
8266
  .trim()
@@ -9012,7 +9063,16 @@ Bundle.prototype.render = function render ( options ) {
9012
9063
  .filter( Boolean )
9013
9064
  .join( '\n\n' );
9014
9065
 
9015
- if ( intro ) intro += '\n';
9066
+ if ( intro ) intro += '\n\n';
9067
+
9068
+ var outro = [ options.outro ]
9069
+ .concat(
9070
+ this.plugins.map( function (plugin) { return plugin.outro && plugin.outro(); } )
9071
+ )
9072
+ .filter( Boolean )
9073
+ .join( '\n\n' );
9074
+
9075
+ if ( outro ) outro = "\n\n" + outro;
9016
9076
 
9017
9077
  var indentString = getIndentString( magicString, options );
9018
9078
 
@@ -9021,7 +9081,7 @@ Bundle.prototype.render = function render ( options ) {
9021
9081
 
9022
9082
  timeStart( 'render format' );
9023
9083
 
9024
- magicString = finalise( this, magicString.trim(), { exportMode: exportMode, indentString: indentString, intro: intro }, options );
9084
+ magicString = finalise( this, magicString.trim(), { exportMode: exportMode, indentString: indentString, intro: intro, outro: outro }, options );
9025
9085
 
9026
9086
  timeEnd( 'render format' );
9027
9087
 
@@ -9045,7 +9105,7 @@ Bundle.prototype.render = function render ( options ) {
9045
9105
  var bundleSourcemapChain = [];
9046
9106
 
9047
9107
  code = transformBundle( code, this.plugins, bundleSourcemapChain, options )
9048
- .replace( new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' ), '' );
9108
+ .replace( new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' ), '' );
9049
9109
 
9050
9110
  if ( options.sourceMap ) {
9051
9111
  timeStart( 'sourceMap' );
@@ -9072,7 +9132,7 @@ Bundle.prototype.render = function render ( options ) {
9072
9132
  return { code: code, map: map };
9073
9133
  };
9074
9134
 
9075
- Bundle.prototype.sort = function sort () {
9135
+ Bundle.prototype.sort = function sort () {
9076
9136
  var this$1 = this;
9077
9137
 
9078
9138
  var hasCycles;
@@ -9148,7 +9208,7 @@ Bundle.prototype.render = function render ( options ) {
9148
9208
 
9149
9209
  this$1.onwarn(
9150
9210
  ("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")
9151
- );
9211
+ );
9152
9212
  }
9153
9213
  };
9154
9214
 
@@ -9159,7 +9219,7 @@ Bundle.prototype.render = function render ( options ) {
9159
9219
  return ordered;
9160
9220
  };
9161
9221
 
9162
- var VERSION = '0.37.1';
9222
+ var VERSION = '0.37.2';
9163
9223
 
9164
9224
  var ALLOWED_KEYS = [
9165
9225
  'acorn',