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.es.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
@@ -5772,7 +5772,43 @@ simdTypes.forEach( function (t) {
5772
5772
 
5773
5773
  var currentlyCalling = new Set();
5774
5774
 
5775
- function fnHasEffects ( fn ) {
5775
+ function isES5Function ( node ) {
5776
+ return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
5777
+ }
5778
+
5779
+ function hasEffectsNew ( node, scope ) {
5780
+ var inner = node;
5781
+
5782
+ if ( inner.type === 'ExpressionStatement' ) {
5783
+ inner = inner.expression;
5784
+
5785
+ if ( inner.type === 'AssignmentExpression' ) {
5786
+ if ( inner.right.hasEffects( scope ) ) {
5787
+ return true;
5788
+
5789
+ } else {
5790
+ inner = inner.left;
5791
+
5792
+ if ( inner.type === 'MemberExpression' ) {
5793
+ if ( inner.computed && inner.property.hasEffects( scope ) ) {
5794
+ return true;
5795
+
5796
+ } else {
5797
+ inner = inner.object;
5798
+
5799
+ if ( inner.type === 'ThisExpression' ) {
5800
+ return false;
5801
+ }
5802
+ }
5803
+ }
5804
+ }
5805
+ }
5806
+ }
5807
+
5808
+ return node.hasEffects( scope );
5809
+ }
5810
+
5811
+ function fnHasEffects ( fn, isNew ) {
5776
5812
  if ( currentlyCalling.has( fn ) ) return false; // prevent infinite loops... TODO there must be a better way
5777
5813
  currentlyCalling.add( fn );
5778
5814
 
@@ -5781,7 +5817,7 @@ function fnHasEffects ( fn ) {
5781
5817
  var body = fn.body.type === 'BlockStatement' ? fn.body.body : [ fn.body ];
5782
5818
 
5783
5819
  for ( var node of body ) {
5784
- if ( node.hasEffects( scope ) ) {
5820
+ if ( isNew ? hasEffectsNew( node, scope ) : node.hasEffects( scope ) ) {
5785
5821
  currentlyCalling.delete( fn );
5786
5822
  return true;
5787
5823
  }
@@ -5791,14 +5827,14 @@ function fnHasEffects ( fn ) {
5791
5827
  return false;
5792
5828
  }
5793
5829
 
5794
- function callHasEffects ( scope, callee ) {
5830
+ function callHasEffects ( scope, callee, isNew ) {
5795
5831
  var values = new Set([ callee ]);
5796
5832
 
5797
5833
  for ( var node of values ) {
5798
5834
  if ( node === UNKNOWN ) return true; // err on side of caution
5799
5835
 
5800
5836
  if ( /Function/.test( node.type ) ) {
5801
- if ( fnHasEffects( node ) ) return true;
5837
+ if ( fnHasEffects( node, isNew && isES5Function( node ) ) ) return true;
5802
5838
  }
5803
5839
 
5804
5840
  else if ( isReference( node ) ) {
@@ -5864,7 +5900,7 @@ var CallExpression = (function (Node) {
5864
5900
  };
5865
5901
 
5866
5902
  CallExpression.prototype.hasEffects = function hasEffects ( scope ) {
5867
- return callHasEffects( scope, this.callee );
5903
+ return callHasEffects( scope, this.callee, false );
5868
5904
  };
5869
5905
 
5870
5906
  CallExpression.prototype.initialise = function initialise ( scope ) {
@@ -6791,7 +6827,7 @@ var NewExpression = (function (Node) {
6791
6827
  NewExpression.prototype.constructor = NewExpression;
6792
6828
 
6793
6829
  NewExpression.prototype.hasEffects = function hasEffects ( scope ) {
6794
- return callHasEffects( scope, this.callee );
6830
+ return callHasEffects( scope, this.callee, true );
6795
6831
  };
6796
6832
 
6797
6833
  return NewExpression;
@@ -7032,6 +7068,16 @@ var VariableDeclarator = (function (Node) {
7032
7068
  this.activated = true;
7033
7069
 
7034
7070
  this.run( this.findScope() );
7071
+
7072
+ // if declaration is inside a block, ensure that the block
7073
+ // is marked for inclusion
7074
+ if ( this.parent.kind === 'var' ) {
7075
+ var node = this.parent.parent;
7076
+ while ( /Statement/.test( node.type ) ) {
7077
+ node.shouldInclude = true;
7078
+ node = node.parent;
7079
+ }
7080
+ }
7035
7081
  };
7036
7082
 
7037
7083
  VariableDeclarator.prototype.hasEffects = function hasEffects ( scope ) {
@@ -7432,7 +7478,7 @@ var Module = function Module (ref) {
7432
7478
  });
7433
7479
 
7434
7480
  // remove existing sourceMappingURL comments
7435
- var pattern = new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' );
7481
+ var pattern = new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' );
7436
7482
  var match;
7437
7483
  while ( match = pattern.exec( code ) ) {
7438
7484
  this$1.magicString.remove( match.index, match.index + match[0].length );
@@ -7467,7 +7513,7 @@ Module.prototype.addExport = function addExport ( node ) {
7467
7513
  }
7468
7514
 
7469
7515
  else {
7470
- node.specifiers.forEach( function (specifier) {
7516
+ node.specifiers.forEach( function (specifier) {
7471
7517
  var name = specifier.exported.name;
7472
7518
 
7473
7519
  if ( this$1.exports[ name ] || this$1.reexports[ name ] ) {
@@ -7880,6 +7926,7 @@ function amd ( bundle, magicString, ref, options ) {
7880
7926
  var exportMode = ref.exportMode;
7881
7927
  var indentString = ref.indentString;
7882
7928
  var intro = ref.intro;
7929
+ var outro = ref.outro;
7883
7930
 
7884
7931
  var deps = bundle.externalModules.map( quotePath );
7885
7932
  var args = bundle.externalModules.map( getName );
@@ -7905,7 +7952,7 @@ function amd ( bundle, magicString, ref, options ) {
7905
7952
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
7906
7953
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7907
7954
  if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
7908
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
7955
+ if ( outro ) magicString.append( outro );
7909
7956
 
7910
7957
  return magicString
7911
7958
  .indent( indentString )
@@ -7916,6 +7963,7 @@ function amd ( bundle, magicString, ref, options ) {
7916
7963
  function cjs ( bundle, magicString, ref, options ) {
7917
7964
  var exportMode = ref.exportMode;
7918
7965
  var intro = ref.intro;
7966
+ var outro = ref.outro;
7919
7967
 
7920
7968
  intro = ( options.useStrict === false ? intro : ("'use strict';\n\n" + intro) ) +
7921
7969
  ( exportMode === 'named' && options.legacy !== true ? (esModuleExport + "\n\n") : '' );
@@ -7960,7 +8008,7 @@ function cjs ( bundle, magicString, ref, options ) {
7960
8008
 
7961
8009
  var exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
7962
8010
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7963
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8011
+ if ( outro ) magicString.append( outro );
7964
8012
 
7965
8013
  return magicString;
7966
8014
  }
@@ -7969,8 +8017,9 @@ function notDefault ( name ) {
7969
8017
  return name !== 'default';
7970
8018
  }
7971
8019
 
7972
- function es ( bundle, magicString, ref, options ) {
8020
+ function es ( bundle, magicString, ref ) {
7973
8021
  var intro = ref.intro;
8022
+ var outro = ref.outro;
7974
8023
 
7975
8024
  var importBlock = bundle.externalModules
7976
8025
  .map( function (module) {
@@ -8037,7 +8086,7 @@ function es ( bundle, magicString, ref, options ) {
8037
8086
  }
8038
8087
 
8039
8088
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock.trim() );
8040
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8089
+ if ( outro ) magicString.append( outro );
8041
8090
 
8042
8091
  return magicString.trim();
8043
8092
  }
@@ -8090,6 +8139,7 @@ function iife ( bundle, magicString, ref, options ) {
8090
8139
  var exportMode = ref.exportMode;
8091
8140
  var indentString = ref.indentString;
8092
8141
  var intro = ref.intro;
8142
+ var outro = ref.outro;
8093
8143
 
8094
8144
  var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
8095
8145
 
@@ -8130,7 +8180,7 @@ function iife ( bundle, magicString, ref, options ) {
8130
8180
 
8131
8181
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8132
8182
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8133
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8183
+ if ( outro ) magicString.append( outro );
8134
8184
 
8135
8185
  return magicString
8136
8186
  .indent( indentString )
@@ -8161,6 +8211,7 @@ function umd ( bundle, magicString, ref, options ) {
8161
8211
  var exportMode = ref.exportMode;
8162
8212
  var indentString = ref.indentString;
8163
8213
  var intro = ref.intro;
8214
+ var outro = ref.outro;
8164
8215
 
8165
8216
  if ( exportMode !== 'none' && !options.moduleName ) {
8166
8217
  throw new Error( 'You must supply options.moduleName for UMD bundles' );
@@ -8206,7 +8257,7 @@ function umd ( bundle, magicString, ref, options ) {
8206
8257
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8207
8258
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8208
8259
  if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
8209
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8260
+ if ( outro ) magicString.append( outro );
8210
8261
 
8211
8262
  return magicString
8212
8263
  .trim()
@@ -9009,7 +9060,16 @@ Bundle.prototype.render = function render ( options ) {
9009
9060
  .filter( Boolean )
9010
9061
  .join( '\n\n' );
9011
9062
 
9012
- if ( intro ) intro += '\n';
9063
+ if ( intro ) intro += '\n\n';
9064
+
9065
+ var outro = [ options.outro ]
9066
+ .concat(
9067
+ this.plugins.map( function (plugin) { return plugin.outro && plugin.outro(); } )
9068
+ )
9069
+ .filter( Boolean )
9070
+ .join( '\n\n' );
9071
+
9072
+ if ( outro ) outro = "\n\n" + outro;
9013
9073
 
9014
9074
  var indentString = getIndentString( magicString, options );
9015
9075
 
@@ -9018,7 +9078,7 @@ Bundle.prototype.render = function render ( options ) {
9018
9078
 
9019
9079
  timeStart( 'render format' );
9020
9080
 
9021
- magicString = finalise( this, magicString.trim(), { exportMode: exportMode, indentString: indentString, intro: intro }, options );
9081
+ magicString = finalise( this, magicString.trim(), { exportMode: exportMode, indentString: indentString, intro: intro, outro: outro }, options );
9022
9082
 
9023
9083
  timeEnd( 'render format' );
9024
9084
 
@@ -9042,7 +9102,7 @@ Bundle.prototype.render = function render ( options ) {
9042
9102
  var bundleSourcemapChain = [];
9043
9103
 
9044
9104
  code = transformBundle( code, this.plugins, bundleSourcemapChain, options )
9045
- .replace( new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' ), '' );
9105
+ .replace( new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' ), '' );
9046
9106
 
9047
9107
  if ( options.sourceMap ) {
9048
9108
  timeStart( 'sourceMap' );
@@ -9069,7 +9129,7 @@ Bundle.prototype.render = function render ( options ) {
9069
9129
  return { code: code, map: map };
9070
9130
  };
9071
9131
 
9072
- Bundle.prototype.sort = function sort () {
9132
+ Bundle.prototype.sort = function sort () {
9073
9133
  var this$1 = this;
9074
9134
 
9075
9135
  var hasCycles;
@@ -9145,7 +9205,7 @@ Bundle.prototype.render = function render ( options ) {
9145
9205
 
9146
9206
  this$1.onwarn(
9147
9207
  ("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")
9148
- );
9208
+ );
9149
9209
  }
9150
9210
  };
9151
9211
 
@@ -9156,7 +9216,7 @@ Bundle.prototype.render = function render ( options ) {
9156
9216
  return ordered;
9157
9217
  };
9158
9218
 
9159
- var VERSION = '0.37.1';
9219
+ var VERSION = '0.37.2';
9160
9220
 
9161
9221
  var ALLOWED_KEYS = [
9162
9222
  'acorn',