rollup 0.36.3 → 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.
@@ -1,6 +1,6 @@
1
1
  /*
2
- Rollup.js v0.36.3
3
- Sun Oct 09 2016 16:03:12 GMT-0400 (EDT) - commit 5344665d7256c7192cb69068635ff0d3f6c6cd8b
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
@@ -158,9 +158,10 @@ function resolve () {
158
158
 
159
159
  var nope = function (method) { return ("Cannot use fs." + method + " inside browser"); };
160
160
 
161
- var isFile = function () { return false; };
161
+ var lstatSync = nope( 'lstatSync' );
162
162
  var readdirSync = nope( 'readdirSync' );
163
163
  var readFileSync = nope( 'readFileSync' );
164
+ var realpathSync = nope( 'realpathSync' );
164
165
  var writeFile = nope( 'writeFile' );
165
166
 
166
167
  var keys = Object.keys;
@@ -5047,6 +5048,16 @@ function makeLegalIdentifier ( str ) {
5047
5048
  return str;
5048
5049
  }
5049
5050
 
5051
+ function error ( props ) {
5052
+ var err = new Error( props.message );
5053
+
5054
+ Object.keys( props ).forEach( function (key) {
5055
+ err[ key ] = props[ key ];
5056
+ });
5057
+
5058
+ throw err;
5059
+ }
5060
+
5050
5061
  function relativeId ( id ) {
5051
5062
  if ( typeof process === 'undefined' ) return id;
5052
5063
  return id.replace( process.cwd(), '' ).replace( /^[\/\\]/, '' );
@@ -5102,10 +5113,11 @@ SyntheticNamespaceDeclaration.prototype.renderBlock = function renderBlock ( es,
5102
5113
  var members = keys( this.originals ).map( function (name) {
5103
5114
  var original = this$1.originals[ name ];
5104
5115
 
5105
- if ( original.isReassigned ) {
5116
+ if ( original.isReassigned && !legacy ) {
5106
5117
  return (indentString + "get " + name + " () { return " + (original.getName( es )) + "; }");
5107
5118
  }
5108
5119
 
5120
+ if ( legacy && ~reservedWords$1.indexOf( name ) ) name = "'" + name + "'";
5109
5121
  return ("" + indentString + name + ": " + (original.getName( es )));
5110
5122
  });
5111
5123
 
@@ -5136,6 +5148,10 @@ ExternalDeclaration.prototype.addReference = function addReference ( reference )
5136
5148
  }
5137
5149
  };
5138
5150
 
5151
+ ExternalDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
5152
+ values.add( UNKNOWN );
5153
+ };
5154
+
5139
5155
  ExternalDeclaration.prototype.getName = function getName ( es ) {
5140
5156
  if ( this.name === '*' ) {
5141
5157
  return this.module.name;
@@ -5334,7 +5350,7 @@ Parameter.prototype.getName = function getName () {
5334
5350
  };
5335
5351
 
5336
5352
  var Scope = function Scope ( options ) {
5337
- options = options || {};
5353
+ if ( options === void 0 ) options = {};
5338
5354
 
5339
5355
  this.parent = options.parent;
5340
5356
  this.isBlockScope = !!options.isBlockScope;
@@ -5451,16 +5467,6 @@ var ArrowFunctionExpression = (function (Node) {
5451
5467
  return ArrowFunctionExpression;
5452
5468
  }(Node$1));
5453
5469
 
5454
- function error ( props ) {
5455
- var err = new Error( props.message );
5456
-
5457
- Object.keys( props ).forEach( function (key) {
5458
- err[ key ] = props[ key ];
5459
- });
5460
-
5461
- throw err;
5462
- }
5463
-
5464
5470
  // TODO tidy this up a bit (e.g. they can both use node.module.imports)
5465
5471
  function disallowIllegalReassignment ( scope, node ) {
5466
5472
  if ( node.type === 'MemberExpression' && node.object.type === 'Identifier' ) {
@@ -5488,8 +5494,6 @@ function disallowIllegalReassignment ( scope, node ) {
5488
5494
  }
5489
5495
 
5490
5496
  function isUsedByBundle ( scope, node ) {
5491
- while ( node.type === 'ParenthesizedExpression' ) node = node.expression;
5492
-
5493
5497
  // const expression = node;
5494
5498
  while ( node.type === 'MemberExpression' ) node = node.object;
5495
5499
 
@@ -5526,6 +5530,17 @@ function isUsedByBundle ( scope, node ) {
5526
5530
  return false;
5527
5531
  }
5528
5532
 
5533
+ function isProgramLevel ( node ) {
5534
+ do {
5535
+ if ( node.type === 'Program' ) {
5536
+ return true;
5537
+ }
5538
+ node = node.parent;
5539
+ } while ( node && !/Function/.test( node.type ) );
5540
+
5541
+ return false;
5542
+ }
5543
+
5529
5544
  var AssignmentExpression = (function (Node) {
5530
5545
  function AssignmentExpression () {
5531
5546
  Node.apply(this, arguments);
@@ -5537,7 +5552,6 @@ var AssignmentExpression = (function (Node) {
5537
5552
 
5538
5553
  AssignmentExpression.prototype.bind = function bind ( scope ) {
5539
5554
  var subject = this.left;
5540
- while ( this.left.type === 'ParenthesizedExpression' ) subject = subject.expression;
5541
5555
 
5542
5556
  this.subject = subject;
5543
5557
  disallowIllegalReassignment( scope, subject );
@@ -5568,7 +5582,10 @@ var AssignmentExpression = (function (Node) {
5568
5582
  AssignmentExpression.prototype.initialise = function initialise ( scope ) {
5569
5583
  this.scope = scope;
5570
5584
 
5571
- this.module.bundle.dependentExpressions.push( this );
5585
+ if ( isProgramLevel( this ) ) {
5586
+ this.module.bundle.dependentExpressions.push( this );
5587
+ }
5588
+
5572
5589
  Node.prototype.initialise.call( this, scope );
5573
5590
  };
5574
5591
 
@@ -5810,16 +5827,52 @@ simdTypes.forEach( function (t) {
5810
5827
 
5811
5828
  var currentlyCalling = new Set();
5812
5829
 
5813
- 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 ) {
5814
5867
  if ( currentlyCalling.has( fn ) ) return false; // prevent infinite loops... TODO there must be a better way
5815
5868
  currentlyCalling.add( fn );
5816
5869
 
5817
5870
  // handle body-less arrow functions
5818
5871
  var scope = fn.body.scope || fn.scope;
5819
- var body = fn.body.body || [ fn.body ];
5872
+ var body = fn.body.type === 'BlockStatement' ? fn.body.body : [ fn.body ];
5820
5873
 
5821
5874
  for ( var node of body ) {
5822
- if ( node.hasEffects( scope ) ) {
5875
+ if ( isNew ? hasEffectsNew( node, scope ) : node.hasEffects( scope ) ) {
5823
5876
  currentlyCalling.delete( fn );
5824
5877
  return true;
5825
5878
  }
@@ -5829,14 +5882,14 @@ function fnHasEffects ( fn ) {
5829
5882
  return false;
5830
5883
  }
5831
5884
 
5832
- function callHasEffects ( scope, callee ) {
5885
+ function callHasEffects ( scope, callee, isNew ) {
5833
5886
  var values = new Set([ callee ]);
5834
5887
 
5835
5888
  for ( var node of values ) {
5836
5889
  if ( node === UNKNOWN ) return true; // err on side of caution
5837
5890
 
5838
5891
  if ( /Function/.test( node.type ) ) {
5839
- if ( fnHasEffects( node ) ) return true;
5892
+ if ( fnHasEffects( node, isNew && isES5Function( node ) ) ) return true;
5840
5893
  }
5841
5894
 
5842
5895
  else if ( isReference( node ) ) {
@@ -5902,11 +5955,13 @@ var CallExpression = (function (Node) {
5902
5955
  };
5903
5956
 
5904
5957
  CallExpression.prototype.hasEffects = function hasEffects ( scope ) {
5905
- return callHasEffects( scope, this.callee );
5958
+ return callHasEffects( scope, this.callee, false );
5906
5959
  };
5907
5960
 
5908
5961
  CallExpression.prototype.initialise = function initialise ( scope ) {
5909
- this.module.bundle.dependentExpressions.push( this );
5962
+ if ( isProgramLevel( this ) ) {
5963
+ this.module.bundle.dependentExpressions.push( this );
5964
+ }
5910
5965
  Node.prototype.initialise.call( this, scope );
5911
5966
  };
5912
5967
 
@@ -6173,11 +6228,18 @@ var ExportDefaultDeclaration = (function (Node) {
6173
6228
  var treeshake = this.module.bundle.treeshake;
6174
6229
  var name = this.getName( es );
6175
6230
 
6231
+ // paren workaround: find first non-whitespace character position after `export default`
6232
+ var declaration_start;
6233
+ if ( this.declaration ) {
6234
+ var statementStr = code.original.slice( this.start, this.end );
6235
+ declaration_start = this.start + statementStr.match(/^\s*export\s+default\s+/)[0].length;
6236
+ }
6237
+
6176
6238
  if ( this.shouldInclude || this.declaration.activated ) {
6177
6239
  if ( this.activated ) {
6178
6240
  if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
6179
6241
  if ( this.declaration.id ) {
6180
- code.remove( this.start, this.declaration.start );
6242
+ code.remove( this.start, declaration_start );
6181
6243
  } else {
6182
6244
  throw new Error( 'TODO anonymous class/function declaration' );
6183
6245
  }
@@ -6189,14 +6251,14 @@ var ExportDefaultDeclaration = (function (Node) {
6189
6251
  code.remove( this.leadingCommentStart || this.start, this.next || this.end );
6190
6252
  return; // don't render children. TODO this seems like a bit of a hack
6191
6253
  } else {
6192
- code.overwrite( this.start, this.declaration.start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6254
+ code.overwrite( this.start, declaration_start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6193
6255
  }
6194
6256
 
6195
6257
  this.insertSemicolon( code );
6196
6258
  }
6197
6259
  } else {
6198
6260
  // remove `var foo` from `var foo = bar()`, if `foo` is unused
6199
- code.remove( this.start, this.declaration.start );
6261
+ code.remove( this.start, declaration_start );
6200
6262
  }
6201
6263
 
6202
6264
  Node.prototype.render.call( this, code, es );
@@ -6206,10 +6268,10 @@ var ExportDefaultDeclaration = (function (Node) {
6206
6268
  code.remove( this.leadingCommentStart || this.start, this.next || this.end );
6207
6269
  } else {
6208
6270
  var hasEffects = this.declaration.hasEffects( this.module.scope );
6209
- code.remove( this.start, hasEffects ? this.declaration.start : this.next || this.end );
6271
+ code.remove( this.start, hasEffects ? declaration_start : this.next || this.end );
6210
6272
  }
6211
6273
  } else {
6212
- code.overwrite( this.start, this.declaration.start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6274
+ code.overwrite( this.start, declaration_start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6213
6275
  }
6214
6276
  // code.remove( this.start, this.next || this.end );
6215
6277
  }
@@ -6365,8 +6427,6 @@ function assignToForLoopLeft ( node, scope, value ) {
6365
6427
  }
6366
6428
 
6367
6429
  else {
6368
- while ( node.type === 'ParenthesizedExpression' ) node = node.expression;
6369
-
6370
6430
  if ( node.type === 'MemberExpression' ) {
6371
6431
  // apparently this is legal JavaScript? Though I don't know what
6372
6432
  // kind of monster would write `for ( foo.bar of thing ) {...}`
@@ -6753,12 +6813,18 @@ var MemberExpression = (function (Node) {
6753
6813
  var declaration = scope.findDeclaration( keypath.root.name );
6754
6814
 
6755
6815
  while ( declaration.isNamespace && keypath.parts.length ) {
6816
+ var exporterId = declaration.module.id;
6817
+
6756
6818
  var part = keypath.parts[0];
6757
6819
  declaration = declaration.module.traceExport( part.name );
6758
6820
 
6759
6821
  if ( !declaration ) {
6760
- this$1.module.bundle.onwarn( ("Export '" + (part.name) + "' is not defined by '" + (this$1.module.id) + "'") );
6761
- break;
6822
+ var ref = getLocation( this$1.module.code, this$1.start );
6823
+ var line = ref.line;
6824
+ var column = ref.column;
6825
+ this$1.module.bundle.onwarn( ((relativeId( this$1.module.id )) + " (" + line + ":" + column + ") '" + (part.name) + "' is not exported by '" + (relativeId( exporterId )) + "'. See https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module") );
6826
+ this$1.replacement = 'undefined';
6827
+ return;
6762
6828
  }
6763
6829
 
6764
6830
  keypath.parts.shift();
@@ -6791,6 +6857,10 @@ var MemberExpression = (function (Node) {
6791
6857
  if ( name !== this.name ) code.overwrite( this.start, this.end, name, true );
6792
6858
  }
6793
6859
 
6860
+ else if ( this.replacement ) {
6861
+ code.overwrite( this.start, this.end, this.replacement, true );
6862
+ }
6863
+
6794
6864
  Node.prototype.render.call( this, code, es );
6795
6865
  };
6796
6866
 
@@ -6812,7 +6882,7 @@ var NewExpression = (function (Node) {
6812
6882
  NewExpression.prototype.constructor = NewExpression;
6813
6883
 
6814
6884
  NewExpression.prototype.hasEffects = function hasEffects ( scope ) {
6815
- return callHasEffects( scope, this.callee );
6885
+ return callHasEffects( scope, this.callee, true );
6816
6886
  };
6817
6887
 
6818
6888
  return NewExpression;
@@ -6834,26 +6904,6 @@ var ObjectExpression = (function (Node) {
6834
6904
  return ObjectExpression;
6835
6905
  }(Node$1));
6836
6906
 
6837
- var ParenthesizedExpression = (function (Node) {
6838
- function ParenthesizedExpression () {
6839
- Node.apply(this, arguments);
6840
- }
6841
-
6842
- if ( Node ) ParenthesizedExpression.__proto__ = Node;
6843
- ParenthesizedExpression.prototype = Object.create( Node && Node.prototype );
6844
- ParenthesizedExpression.prototype.constructor = ParenthesizedExpression;
6845
-
6846
- ParenthesizedExpression.prototype.getPossibleValues = function getPossibleValues ( values ) {
6847
- return this.expression.getPossibleValues( values );
6848
- };
6849
-
6850
- ParenthesizedExpression.prototype.getValue = function getValue () {
6851
- return this.expression.getValue();
6852
- };
6853
-
6854
- return ParenthesizedExpression;
6855
- }(Node$1));
6856
-
6857
6907
  var ReturnStatement = (function (Node) {
6858
6908
  function ReturnStatement () {
6859
6909
  Node.apply(this, arguments);
@@ -6987,7 +7037,6 @@ var UpdateExpression = (function (Node) {
6987
7037
 
6988
7038
  UpdateExpression.prototype.bind = function bind ( scope ) {
6989
7039
  var subject = this.argument;
6990
- while ( this.argument.type === 'ParenthesizedExpression' ) subject = subject.expression;
6991
7040
 
6992
7041
  this.subject = subject;
6993
7042
  disallowIllegalReassignment( scope, this.argument );
@@ -7074,6 +7123,16 @@ var VariableDeclarator = (function (Node) {
7074
7123
  this.activated = true;
7075
7124
 
7076
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
+ }
7077
7136
  };
7078
7137
 
7079
7138
  VariableDeclarator.prototype.hasEffects = function hasEffects ( scope ) {
@@ -7269,7 +7328,6 @@ var nodes = {
7269
7328
  MemberExpression: MemberExpression,
7270
7329
  NewExpression: NewExpression,
7271
7330
  ObjectExpression: ObjectExpression,
7272
- ParenthesizedExpression: ParenthesizedExpression,
7273
7331
  ReturnStatement: ReturnStatement,
7274
7332
  SwitchStatement: Statement,
7275
7333
  TemplateLiteral: TemplateLiteral,
@@ -7413,7 +7471,7 @@ function tryParse ( code, comments, acornOptions, id ) {
7413
7471
  ecmaVersion: 7,
7414
7472
  sourceType: 'module',
7415
7473
  onComment: function ( block, text, start, end ) { return comments.push({ block: block, text: text, start: start, end: end }); },
7416
- preserveParens: true
7474
+ preserveParens: false
7417
7475
  }, acornOptions ));
7418
7476
  } catch ( err ) {
7419
7477
  err.code = 'PARSE_ERROR';
@@ -7475,7 +7533,7 @@ var Module = function Module (ref) {
7475
7533
  });
7476
7534
 
7477
7535
  // remove existing sourceMappingURL comments
7478
- var pattern = new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' );
7536
+ var pattern = new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' );
7479
7537
  var match;
7480
7538
  while ( match = pattern.exec( code ) ) {
7481
7539
  this$1.magicString.remove( match.index, match.index + match[0].length );
@@ -7604,7 +7662,7 @@ Module.prototype.addImport = function addImport ( node ) {
7604
7662
 
7605
7663
  if ( this$1.imports[ localName ] ) {
7606
7664
  var err = new Error( ("Duplicated import '" + localName + "'") );
7607
- err.file = this$1.id;
7665
+ err.file = this$1.id;
7608
7666
  err.loc = getLocation( this$1.code, specifier.start );
7609
7667
  throw err;
7610
7668
  }
@@ -7613,7 +7671,7 @@ Module.prototype.addImport = function addImport ( node ) {
7613
7671
  var isNamespace = specifier.type === 'ImportNamespaceSpecifier';
7614
7672
 
7615
7673
  var name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name;
7616
- this$1.imports[ localName ] = { source: source, name: name, module: null };
7674
+ this$1.imports[ localName ] = { source: source, specifier: specifier, name: name, module: null };
7617
7675
  });
7618
7676
  };
7619
7677
 
@@ -7701,11 +7759,11 @@ Module.prototype.getExports = function getExports () {
7701
7759
  });
7702
7760
 
7703
7761
  keys( this.reexports ).forEach( function (name) {
7704
- exports[ name ] = true;
7705
- });
7762
+ exports[ name ] = true;
7763
+ });
7706
7764
 
7707
7765
  this.exportAllModules.forEach( function (module) {
7708
- if ( module.isExternal ) return; // TODO
7766
+ if ( module.isExternal ) return; // TODO
7709
7767
 
7710
7768
  module.getExports().forEach( function (name) {
7711
7769
  if ( name !== 'default' ) exports[ name ] = true;
@@ -7775,7 +7833,14 @@ Module.prototype.trace = function trace ( name ) {
7775
7833
 
7776
7834
  var declaration = otherModule.traceExport( importDeclaration.name );
7777
7835
 
7778
- if ( !declaration ) throw new Error( ("'" + (importDeclaration.name) + "' is not exported by " + (relativeId( otherModule.id )) + " (imported by " + (relativeId( this.id )) + "). For help fixing this error see https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module") );
7836
+ if ( !declaration ) {
7837
+ error({
7838
+ message: ("'" + (importDeclaration.name) + "' is not exported by " + (relativeId( otherModule.id )) + " (imported by " + (relativeId( this.id )) + "). For help fixing this error see https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module"),
7839
+ file: this.id,
7840
+ loc: getLocation( this.code, importDeclaration.specifier.start )
7841
+ });
7842
+ }
7843
+
7779
7844
  return declaration;
7780
7845
  }
7781
7846
 
@@ -7791,10 +7856,11 @@ Module.prototype.traceExport = function traceExport ( name ) {
7791
7856
  var declaration = reexportDeclaration.module.traceExport( reexportDeclaration.localName );
7792
7857
 
7793
7858
  if ( !declaration ) {
7794
- var err = new Error( ("'" + (reexportDeclaration.localName) + "' is not exported by '" + (reexportDeclaration.module.id) + "' (imported by '" + (this.id) + "')") );
7795
- err.file = this.id;
7796
- err.loc = getLocation( this.code, reexportDeclaration.start );
7797
- throw err;
7859
+ error({
7860
+ message: ("'" + (reexportDeclaration.localName) + "' is not exported by '" + (reexportDeclaration.module.id) + "' (imported by '" + (this.id) + "')"),
7861
+ file: this.id,
7862
+ loc: getLocation( this.code, reexportDeclaration.start )
7863
+ });
7798
7864
  }
7799
7865
 
7800
7866
  return declaration;
@@ -7808,6 +7874,8 @@ Module.prototype.traceExport = function traceExport ( name ) {
7808
7874
  return declaration$1 || this.bundle.scope.findDeclaration( name$1 );
7809
7875
  }
7810
7876
 
7877
+ if ( name === 'default' ) return;
7878
+
7811
7879
  for ( var i = 0; i < this.exportAllModules.length; i += 1 ) {
7812
7880
  var module = this$1.exportAllModules[i];
7813
7881
  var declaration$2 = module.traceExport( name );
@@ -7913,6 +7981,7 @@ function amd ( bundle, magicString, ref, options ) {
7913
7981
  var exportMode = ref.exportMode;
7914
7982
  var indentString = ref.indentString;
7915
7983
  var intro = ref.intro;
7984
+ var outro = ref.outro;
7916
7985
 
7917
7986
  var deps = bundle.externalModules.map( quotePath );
7918
7987
  var args = bundle.externalModules.map( getName );
@@ -7937,8 +8006,8 @@ function amd ( bundle, magicString, ref, options ) {
7937
8006
 
7938
8007
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
7939
8008
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7940
- if ( exportMode === 'named' ) magicString.append( ("\n\n" + esModuleExport) );
7941
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8009
+ if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
8010
+ if ( outro ) magicString.append( outro );
7942
8011
 
7943
8012
  return magicString
7944
8013
  .indent( indentString )
@@ -7949,9 +8018,10 @@ function amd ( bundle, magicString, ref, options ) {
7949
8018
  function cjs ( bundle, magicString, ref, options ) {
7950
8019
  var exportMode = ref.exportMode;
7951
8020
  var intro = ref.intro;
8021
+ var outro = ref.outro;
7952
8022
 
7953
8023
  intro = ( options.useStrict === false ? intro : ("'use strict';\n\n" + intro) ) +
7954
- ( exportMode === 'named' ? (esModuleExport + "\n\n") : '' );
8024
+ ( exportMode === 'named' && options.legacy !== true ? (esModuleExport + "\n\n") : '' );
7955
8025
 
7956
8026
  var needsInterop = false;
7957
8027
 
@@ -7993,7 +8063,7 @@ function cjs ( bundle, magicString, ref, options ) {
7993
8063
 
7994
8064
  var exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
7995
8065
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7996
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8066
+ if ( outro ) magicString.append( outro );
7997
8067
 
7998
8068
  return magicString;
7999
8069
  }
@@ -8002,8 +8072,9 @@ function notDefault ( name ) {
8002
8072
  return name !== 'default';
8003
8073
  }
8004
8074
 
8005
- function es ( bundle, magicString, ref, options ) {
8075
+ function es ( bundle, magicString, ref ) {
8006
8076
  var intro = ref.intro;
8077
+ var outro = ref.outro;
8007
8078
 
8008
8079
  var importBlock = bundle.externalModules
8009
8080
  .map( function (module) {
@@ -8070,7 +8141,7 @@ function es ( bundle, magicString, ref, options ) {
8070
8141
  }
8071
8142
 
8072
8143
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock.trim() );
8073
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8144
+ if ( outro ) magicString.append( outro );
8074
8145
 
8075
8146
  return magicString.trim();
8076
8147
  }
@@ -8087,15 +8158,35 @@ function getGlobalNameMaker ( globals, onwarn ) {
8087
8158
  };
8088
8159
  }
8089
8160
 
8161
+ // Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
8162
+ // if the property name isn't trivial
8163
+
8164
+ var shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/;
8165
+ var dereferenceString = function (prop) { return prop.match(shouldUseDot) ? ("." + prop) : ("['" + prop + "']"); };
8166
+
8167
+ /**
8168
+ * returns a function which generates property dereference strings for the given name
8169
+ *
8170
+ * const getGlobalProp = propertyStringFor('global');
8171
+ * getGlobalProp('foo.bar-baz.qux') => `global.bar['bar-baz'].qux`
8172
+ */
8173
+ var propertyStringFor = function (objName) { return function (propName) { return objName + propName.split('.').map(dereferenceString).join(''); }; };
8174
+
8175
+ // thisProp('foo.bar-baz.qux') === "this.foo['bar-baz'].qux"
8176
+ var thisProp = propertyStringFor('this');
8177
+
8178
+ // propString('foo.bar-baz.qux') === ".foo['bar-baz'].qux"
8179
+ var propString = propertyStringFor('');
8180
+
8090
8181
  function setupNamespace ( keypath ) {
8091
- var parts = keypath.split( '.' ); // TODO support e.g. `foo['something-hyphenated']`?
8182
+ var parts = keypath.split( '.' );
8092
8183
 
8093
8184
  parts.pop();
8094
8185
 
8095
8186
  var acc = 'this';
8096
8187
 
8097
8188
  return parts
8098
- .map( function (part) { return ( acc += "." + part, (acc + " = " + acc + " || {};") ); } )
8189
+ .map( function (part) { return ( acc += propString(part), (acc + " = " + acc + " || {};") ); } )
8099
8190
  .join( '\n' ) + '\n';
8100
8191
  }
8101
8192
 
@@ -8103,6 +8194,7 @@ function iife ( bundle, magicString, ref, options ) {
8103
8194
  var exportMode = ref.exportMode;
8104
8195
  var indentString = ref.indentString;
8105
8196
  var intro = ref.intro;
8197
+ var outro = ref.outro;
8106
8198
 
8107
8199
  var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
8108
8200
 
@@ -8118,7 +8210,7 @@ function iife ( bundle, magicString, ref, options ) {
8118
8210
  }
8119
8211
 
8120
8212
  if ( exportMode === 'named' ) {
8121
- dependencies.unshift( ("(this." + name + " = this." + name + " || {})") );
8213
+ dependencies.unshift( ("(" + (thisProp(name)) + " = " + (thisProp(name)) + " || {})") );
8122
8214
  args.unshift( 'exports' );
8123
8215
  }
8124
8216
 
@@ -8128,7 +8220,7 @@ function iife ( bundle, magicString, ref, options ) {
8128
8220
  var wrapperOutro = "\n\n}(" + dependencies + "));";
8129
8221
 
8130
8222
  if ( exportMode === 'default' ) {
8131
- wrapperIntro = ( isNamespaced ? "this." : ((bundle.varOrConst) + " ") ) + name + " = " + wrapperIntro;
8223
+ wrapperIntro = ( isNamespaced ? thisProp(name) : ((bundle.varOrConst) + " " + name) ) + " = " + wrapperIntro;
8132
8224
  }
8133
8225
 
8134
8226
  if ( isNamespaced ) {
@@ -8143,7 +8235,7 @@ function iife ( bundle, magicString, ref, options ) {
8143
8235
 
8144
8236
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8145
8237
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8146
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8238
+ if ( outro ) magicString.append( outro );
8147
8239
 
8148
8240
  return magicString
8149
8241
  .indent( indentString )
@@ -8151,14 +8243,20 @@ function iife ( bundle, magicString, ref, options ) {
8151
8243
  .append( wrapperOutro );
8152
8244
  }
8153
8245
 
8246
+ // globalProp('foo.bar-baz') === "global.foo['bar-baz']"
8247
+ var globalProp = propertyStringFor('global');
8248
+
8249
+ // propString('foo.bar-baz') === ".foo['bar']"
8250
+ var propString$1 = propertyStringFor('');
8251
+
8154
8252
  function setupNamespace$1 ( name ) {
8155
8253
  var parts = name.split( '.' );
8156
8254
  parts.pop();
8157
8255
 
8158
8256
  var acc = 'global';
8159
8257
  return parts
8160
- .map( function (part) { return ( acc += "." + part, (acc + " = " + acc + " || {}") ); } )
8161
- .concat( ("global." + name) )
8258
+ .map( function (part) { return ( acc += propString$1(part), (acc + " = " + acc + " || {}") ); } )
8259
+ .concat( globalProp(name) )
8162
8260
  .join( ', ' );
8163
8261
  }
8164
8262
 
@@ -8168,6 +8266,7 @@ function umd ( bundle, magicString, ref, options ) {
8168
8266
  var exportMode = ref.exportMode;
8169
8267
  var indentString = ref.indentString;
8170
8268
  var intro = ref.intro;
8269
+ var outro = ref.outro;
8171
8270
 
8172
8271
  if ( exportMode !== 'none' && !options.moduleName ) {
8173
8272
  throw new Error( 'You must supply options.moduleName for UMD bundles' );
@@ -8177,14 +8276,14 @@ function umd ( bundle, magicString, ref, options ) {
8177
8276
 
8178
8277
  var amdDeps = bundle.externalModules.map( quotePath );
8179
8278
  var cjsDeps = bundle.externalModules.map( req );
8180
- var globalDeps = bundle.externalModules.map( function (module) { return ("global." + (globalNameMaker( module ))); } );
8279
+ var globalDeps = bundle.externalModules.map( function (module) { return globalProp(globalNameMaker( module )); } );
8181
8280
 
8182
8281
  var args = bundle.externalModules.map( getName );
8183
8282
 
8184
8283
  if ( exportMode === 'named' ) {
8185
8284
  amdDeps.unshift( "'exports'" );
8186
8285
  cjsDeps.unshift( "exports" );
8187
- globalDeps.unshift( ("(" + (setupNamespace$1(options.moduleName)) + " = global." + (options.moduleName) + " || {})") );
8286
+ globalDeps.unshift( ("(" + (setupNamespace$1(options.moduleName)) + " = " + (globalProp(options.moduleName)) + " || {})") );
8188
8287
 
8189
8288
  args.unshift( 'exports' );
8190
8289
  }
@@ -8199,7 +8298,7 @@ function umd ( bundle, magicString, ref, options ) {
8199
8298
  var useStrict = options.useStrict !== false ? " 'use strict';" : "";
8200
8299
 
8201
8300
  var globalExport = options.noConflict === true ?
8202
- ("(function() {\n\t\t\t\tvar current = global." + (options.moduleName) + ";\n\t\t\t\tvar exports = factory(" + globalDeps + ");\n\t\t\t\tglobal." + (options.moduleName) + " = exports;\n\t\t\t\texports.noConflict = function() { global." + (options.moduleName) + " = current; return exports; };\n\t\t\t})()") : ("(" + defaultExport + "factory(" + globalDeps + "))");
8301
+ ("(function() {\n\t\t\t\tvar current = " + (globalProp(options.moduleName)) + ";\n\t\t\t\tvar exports = factory(" + globalDeps + ");\n\t\t\t\t" + (globalProp(options.moduleName)) + " = exports;\n\t\t\t\texports.noConflict = function() { " + (globalProp(options.moduleName)) + " = current; return exports; };\n\t\t\t})()") : ("(" + defaultExport + "factory(" + globalDeps + "))");
8203
8302
 
8204
8303
  var wrapperIntro =
8205
8304
  ("(function (global, factory) {\n\t\t\ttypeof exports === 'object' && typeof module !== 'undefined' ? " + cjsExport + "factory(" + (cjsDeps.join( ', ' )) + ") :\n\t\t\ttypeof define === 'function' && define.amd ? define(" + amdParams + "factory) :\n\t\t\t" + globalExport + ";\n\t\t}(this, (function (" + args + ") {" + useStrict + "\n\n\t\t").replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() );
@@ -8212,8 +8311,8 @@ function umd ( bundle, magicString, ref, options ) {
8212
8311
 
8213
8312
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8214
8313
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8215
- if ( exportMode === 'named' ) magicString.append( ("\n\n" + esModuleExport) );
8216
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8314
+ if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
8315
+ if ( outro ) magicString.append( outro );
8217
8316
 
8218
8317
  return magicString
8219
8318
  .trim()
@@ -8230,22 +8329,29 @@ function ensureArray ( thing ) {
8230
8329
  return [ thing ];
8231
8330
  }
8232
8331
 
8332
+ // eslint-disable-line
8233
8333
  function load ( id ) {
8234
8334
  return readFileSync( id, 'utf-8' );
8235
8335
  }
8236
8336
 
8237
- function addJsExtensionIfNecessary ( file ) {
8337
+ function findFile ( file ) {
8238
8338
  try {
8239
- var name = basename( file );
8240
- var files = readdirSync( dirname( file ) );
8339
+ var stats = lstatSync( file );
8340
+ if ( stats.isSymbolicLink() ) return findFile( realpathSync( file ) );
8341
+ if ( stats.isFile() ) {
8342
+ // check case
8343
+ var name = basename( file );
8344
+ var files = readdirSync( dirname( file ) );
8241
8345
 
8242
- if ( ~files.indexOf( name ) && isFile( file ) ) return file;
8243
- if ( ~files.indexOf( (name + ".js") ) && isFile( (file + ".js") ) ) return (file + ".js");
8346
+ if ( ~files.indexOf( name ) ) return file;
8347
+ }
8244
8348
  } catch ( err ) {
8245
- // noop
8349
+ // suppress
8246
8350
  }
8351
+ }
8247
8352
 
8248
- return null;
8353
+ function addJsExtensionIfNecessary ( file ) {
8354
+ return findFile( file ) || findFile( file + '.js' );
8249
8355
  }
8250
8356
 
8251
8357
  function resolveId ( importee, importer ) {
@@ -9009,7 +9115,16 @@ Bundle.prototype.render = function render ( options ) {
9009
9115
  .filter( Boolean )
9010
9116
  .join( '\n\n' );
9011
9117
 
9012
- 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;
9013
9128
 
9014
9129
  var indentString = getIndentString( magicString, options );
9015
9130
 
@@ -9018,7 +9133,7 @@ Bundle.prototype.render = function render ( options ) {
9018
9133
 
9019
9134
  timeStart( 'render format' );
9020
9135
 
9021
- 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 );
9022
9137
 
9023
9138
  timeEnd( 'render format' );
9024
9139
 
@@ -9042,7 +9157,7 @@ Bundle.prototype.render = function render ( options ) {
9042
9157
  var bundleSourcemapChain = [];
9043
9158
 
9044
9159
  code = transformBundle( code, this.plugins, bundleSourcemapChain, options )
9045
- .replace( new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' ), '' );
9160
+ .replace( new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' ), '' );
9046
9161
 
9047
9162
  if ( options.sourceMap ) {
9048
9163
  timeStart( 'sourceMap' );
@@ -9069,7 +9184,7 @@ Bundle.prototype.render = function render ( options ) {
9069
9184
  return { code: code, map: map };
9070
9185
  };
9071
9186
 
9072
- Bundle.prototype.sort = function sort () {
9187
+ Bundle.prototype.sort = function sort () {
9073
9188
  var this$1 = this;
9074
9189
 
9075
9190
  var hasCycles;
@@ -9145,7 +9260,7 @@ Bundle.prototype.render = function render ( options ) {
9145
9260
 
9146
9261
  this$1.onwarn(
9147
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")
9148
- );
9263
+ );
9149
9264
  }
9150
9265
  };
9151
9266
 
@@ -9156,7 +9271,7 @@ Bundle.prototype.render = function render ( options ) {
9156
9271
  return ordered;
9157
9272
  };
9158
9273
 
9159
- var VERSION = '0.36.3';
9274
+ var VERSION = '0.37.2';
9160
9275
 
9161
9276
  var ALLOWED_KEYS = [
9162
9277
  'acorn',