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.
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
- Rollup.js v0.36.3
3
- Sun Oct 09 2016 16:03:05 GMT-0400 (EDT) - commit 5344665d7256c7192cb69068635ff0d3f6c6cd8b
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
@@ -98,15 +98,6 @@ function mkdirpath ( path$$ ) {
98
98
  }
99
99
  }
100
100
 
101
- function isFile ( file ) {
102
- try {
103
- var stats = fs.statSync( file );
104
- return stats.isFile();
105
- } catch ( err ) {
106
- return false;
107
- }
108
- }
109
-
110
101
  function writeFile ( dest, data ) {
111
102
  return new Promise( function ( fulfil, reject ) {
112
103
  mkdirpath( dest );
@@ -121,9 +112,6 @@ function writeFile ( dest, data ) {
121
112
  });
122
113
  }
123
114
 
124
- var readdirSync = fs.readdirSync;
125
- var readFileSync = fs.readFileSync;
126
-
127
115
  var keys = Object.keys;
128
116
 
129
117
  function blank () {
@@ -5008,6 +4996,16 @@ function makeLegalIdentifier ( str ) {
5008
4996
  return str;
5009
4997
  }
5010
4998
 
4999
+ function error ( props ) {
5000
+ var err = new Error( props.message );
5001
+
5002
+ Object.keys( props ).forEach( function (key) {
5003
+ err[ key ] = props[ key ];
5004
+ });
5005
+
5006
+ throw err;
5007
+ }
5008
+
5011
5009
  function relativeId ( id ) {
5012
5010
  if ( typeof process === 'undefined' ) return id;
5013
5011
  return id.replace( process.cwd(), '' ).replace( /^[\/\\]/, '' );
@@ -5063,10 +5061,11 @@ SyntheticNamespaceDeclaration.prototype.renderBlock = function renderBlock ( es,
5063
5061
  var members = keys( this.originals ).map( function (name) {
5064
5062
  var original = this$1.originals[ name ];
5065
5063
 
5066
- if ( original.isReassigned ) {
5064
+ if ( original.isReassigned && !legacy ) {
5067
5065
  return (indentString + "get " + name + " () { return " + (original.getName( es )) + "; }");
5068
5066
  }
5069
5067
 
5068
+ if ( legacy && ~reservedWords$1.indexOf( name ) ) name = "'" + name + "'";
5070
5069
  return ("" + indentString + name + ": " + (original.getName( es )));
5071
5070
  });
5072
5071
 
@@ -5097,6 +5096,10 @@ ExternalDeclaration.prototype.addReference = function addReference ( reference )
5097
5096
  }
5098
5097
  };
5099
5098
 
5099
+ ExternalDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
5100
+ values.add( UNKNOWN );
5101
+ };
5102
+
5100
5103
  ExternalDeclaration.prototype.getName = function getName ( es ) {
5101
5104
  if ( this.name === '*' ) {
5102
5105
  return this.module.name;
@@ -5295,7 +5298,7 @@ Parameter.prototype.getName = function getName () {
5295
5298
  };
5296
5299
 
5297
5300
  var Scope = function Scope ( options ) {
5298
- options = options || {};
5301
+ if ( options === void 0 ) options = {};
5299
5302
 
5300
5303
  this.parent = options.parent;
5301
5304
  this.isBlockScope = !!options.isBlockScope;
@@ -5412,16 +5415,6 @@ var ArrowFunctionExpression = (function (Node) {
5412
5415
  return ArrowFunctionExpression;
5413
5416
  }(Node$1));
5414
5417
 
5415
- function error ( props ) {
5416
- var err = new Error( props.message );
5417
-
5418
- Object.keys( props ).forEach( function (key) {
5419
- err[ key ] = props[ key ];
5420
- });
5421
-
5422
- throw err;
5423
- }
5424
-
5425
5418
  // TODO tidy this up a bit (e.g. they can both use node.module.imports)
5426
5419
  function disallowIllegalReassignment ( scope, node ) {
5427
5420
  if ( node.type === 'MemberExpression' && node.object.type === 'Identifier' ) {
@@ -5449,8 +5442,6 @@ function disallowIllegalReassignment ( scope, node ) {
5449
5442
  }
5450
5443
 
5451
5444
  function isUsedByBundle ( scope, node ) {
5452
- while ( node.type === 'ParenthesizedExpression' ) node = node.expression;
5453
-
5454
5445
  // const expression = node;
5455
5446
  while ( node.type === 'MemberExpression' ) node = node.object;
5456
5447
 
@@ -5487,6 +5478,17 @@ function isUsedByBundle ( scope, node ) {
5487
5478
  return false;
5488
5479
  }
5489
5480
 
5481
+ function isProgramLevel ( node ) {
5482
+ do {
5483
+ if ( node.type === 'Program' ) {
5484
+ return true;
5485
+ }
5486
+ node = node.parent;
5487
+ } while ( node && !/Function/.test( node.type ) );
5488
+
5489
+ return false;
5490
+ }
5491
+
5490
5492
  var AssignmentExpression = (function (Node) {
5491
5493
  function AssignmentExpression () {
5492
5494
  Node.apply(this, arguments);
@@ -5498,7 +5500,6 @@ var AssignmentExpression = (function (Node) {
5498
5500
 
5499
5501
  AssignmentExpression.prototype.bind = function bind ( scope ) {
5500
5502
  var subject = this.left;
5501
- while ( this.left.type === 'ParenthesizedExpression' ) subject = subject.expression;
5502
5503
 
5503
5504
  this.subject = subject;
5504
5505
  disallowIllegalReassignment( scope, subject );
@@ -5529,7 +5530,10 @@ var AssignmentExpression = (function (Node) {
5529
5530
  AssignmentExpression.prototype.initialise = function initialise ( scope ) {
5530
5531
  this.scope = scope;
5531
5532
 
5532
- this.module.bundle.dependentExpressions.push( this );
5533
+ if ( isProgramLevel( this ) ) {
5534
+ this.module.bundle.dependentExpressions.push( this );
5535
+ }
5536
+
5533
5537
  Node.prototype.initialise.call( this, scope );
5534
5538
  };
5535
5539
 
@@ -5771,16 +5775,52 @@ simdTypes.forEach( function (t) {
5771
5775
 
5772
5776
  var currentlyCalling = new Set();
5773
5777
 
5774
- 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 ) {
5775
5815
  if ( currentlyCalling.has( fn ) ) return false; // prevent infinite loops... TODO there must be a better way
5776
5816
  currentlyCalling.add( fn );
5777
5817
 
5778
5818
  // handle body-less arrow functions
5779
5819
  var scope = fn.body.scope || fn.scope;
5780
- var body = fn.body.body || [ fn.body ];
5820
+ var body = fn.body.type === 'BlockStatement' ? fn.body.body : [ fn.body ];
5781
5821
 
5782
5822
  for ( var node of body ) {
5783
- if ( node.hasEffects( scope ) ) {
5823
+ if ( isNew ? hasEffectsNew( node, scope ) : node.hasEffects( scope ) ) {
5784
5824
  currentlyCalling.delete( fn );
5785
5825
  return true;
5786
5826
  }
@@ -5790,14 +5830,14 @@ function fnHasEffects ( fn ) {
5790
5830
  return false;
5791
5831
  }
5792
5832
 
5793
- function callHasEffects ( scope, callee ) {
5833
+ function callHasEffects ( scope, callee, isNew ) {
5794
5834
  var values = new Set([ callee ]);
5795
5835
 
5796
5836
  for ( var node of values ) {
5797
5837
  if ( node === UNKNOWN ) return true; // err on side of caution
5798
5838
 
5799
5839
  if ( /Function/.test( node.type ) ) {
5800
- if ( fnHasEffects( node ) ) return true;
5840
+ if ( fnHasEffects( node, isNew && isES5Function( node ) ) ) return true;
5801
5841
  }
5802
5842
 
5803
5843
  else if ( isReference( node ) ) {
@@ -5863,11 +5903,13 @@ var CallExpression = (function (Node) {
5863
5903
  };
5864
5904
 
5865
5905
  CallExpression.prototype.hasEffects = function hasEffects ( scope ) {
5866
- return callHasEffects( scope, this.callee );
5906
+ return callHasEffects( scope, this.callee, false );
5867
5907
  };
5868
5908
 
5869
5909
  CallExpression.prototype.initialise = function initialise ( scope ) {
5870
- this.module.bundle.dependentExpressions.push( this );
5910
+ if ( isProgramLevel( this ) ) {
5911
+ this.module.bundle.dependentExpressions.push( this );
5912
+ }
5871
5913
  Node.prototype.initialise.call( this, scope );
5872
5914
  };
5873
5915
 
@@ -6134,11 +6176,18 @@ var ExportDefaultDeclaration = (function (Node) {
6134
6176
  var treeshake = this.module.bundle.treeshake;
6135
6177
  var name = this.getName( es );
6136
6178
 
6179
+ // paren workaround: find first non-whitespace character position after `export default`
6180
+ var declaration_start;
6181
+ if ( this.declaration ) {
6182
+ var statementStr = code.original.slice( this.start, this.end );
6183
+ declaration_start = this.start + statementStr.match(/^\s*export\s+default\s+/)[0].length;
6184
+ }
6185
+
6137
6186
  if ( this.shouldInclude || this.declaration.activated ) {
6138
6187
  if ( this.activated ) {
6139
6188
  if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
6140
6189
  if ( this.declaration.id ) {
6141
- code.remove( this.start, this.declaration.start );
6190
+ code.remove( this.start, declaration_start );
6142
6191
  } else {
6143
6192
  throw new Error( 'TODO anonymous class/function declaration' );
6144
6193
  }
@@ -6150,14 +6199,14 @@ var ExportDefaultDeclaration = (function (Node) {
6150
6199
  code.remove( this.leadingCommentStart || this.start, this.next || this.end );
6151
6200
  return; // don't render children. TODO this seems like a bit of a hack
6152
6201
  } else {
6153
- code.overwrite( this.start, this.declaration.start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6202
+ code.overwrite( this.start, declaration_start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6154
6203
  }
6155
6204
 
6156
6205
  this.insertSemicolon( code );
6157
6206
  }
6158
6207
  } else {
6159
6208
  // remove `var foo` from `var foo = bar()`, if `foo` is unused
6160
- code.remove( this.start, this.declaration.start );
6209
+ code.remove( this.start, declaration_start );
6161
6210
  }
6162
6211
 
6163
6212
  Node.prototype.render.call( this, code, es );
@@ -6167,10 +6216,10 @@ var ExportDefaultDeclaration = (function (Node) {
6167
6216
  code.remove( this.leadingCommentStart || this.start, this.next || this.end );
6168
6217
  } else {
6169
6218
  var hasEffects = this.declaration.hasEffects( this.module.scope );
6170
- code.remove( this.start, hasEffects ? this.declaration.start : this.next || this.end );
6219
+ code.remove( this.start, hasEffects ? declaration_start : this.next || this.end );
6171
6220
  }
6172
6221
  } else {
6173
- code.overwrite( this.start, this.declaration.start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6222
+ code.overwrite( this.start, declaration_start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6174
6223
  }
6175
6224
  // code.remove( this.start, this.next || this.end );
6176
6225
  }
@@ -6326,8 +6375,6 @@ function assignToForLoopLeft ( node, scope, value ) {
6326
6375
  }
6327
6376
 
6328
6377
  else {
6329
- while ( node.type === 'ParenthesizedExpression' ) node = node.expression;
6330
-
6331
6378
  if ( node.type === 'MemberExpression' ) {
6332
6379
  // apparently this is legal JavaScript? Though I don't know what
6333
6380
  // kind of monster would write `for ( foo.bar of thing ) {...}`
@@ -6714,12 +6761,18 @@ var MemberExpression = (function (Node) {
6714
6761
  var declaration = scope.findDeclaration( keypath.root.name );
6715
6762
 
6716
6763
  while ( declaration.isNamespace && keypath.parts.length ) {
6764
+ var exporterId = declaration.module.id;
6765
+
6717
6766
  var part = keypath.parts[0];
6718
6767
  declaration = declaration.module.traceExport( part.name );
6719
6768
 
6720
6769
  if ( !declaration ) {
6721
- this$1.module.bundle.onwarn( ("Export '" + (part.name) + "' is not defined by '" + (this$1.module.id) + "'") );
6722
- break;
6770
+ var ref = getLocation( this$1.module.code, this$1.start );
6771
+ var line = ref.line;
6772
+ var column = ref.column;
6773
+ 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") );
6774
+ this$1.replacement = 'undefined';
6775
+ return;
6723
6776
  }
6724
6777
 
6725
6778
  keypath.parts.shift();
@@ -6752,6 +6805,10 @@ var MemberExpression = (function (Node) {
6752
6805
  if ( name !== this.name ) code.overwrite( this.start, this.end, name, true );
6753
6806
  }
6754
6807
 
6808
+ else if ( this.replacement ) {
6809
+ code.overwrite( this.start, this.end, this.replacement, true );
6810
+ }
6811
+
6755
6812
  Node.prototype.render.call( this, code, es );
6756
6813
  };
6757
6814
 
@@ -6773,7 +6830,7 @@ var NewExpression = (function (Node) {
6773
6830
  NewExpression.prototype.constructor = NewExpression;
6774
6831
 
6775
6832
  NewExpression.prototype.hasEffects = function hasEffects ( scope ) {
6776
- return callHasEffects( scope, this.callee );
6833
+ return callHasEffects( scope, this.callee, true );
6777
6834
  };
6778
6835
 
6779
6836
  return NewExpression;
@@ -6795,26 +6852,6 @@ var ObjectExpression = (function (Node) {
6795
6852
  return ObjectExpression;
6796
6853
  }(Node$1));
6797
6854
 
6798
- var ParenthesizedExpression = (function (Node) {
6799
- function ParenthesizedExpression () {
6800
- Node.apply(this, arguments);
6801
- }
6802
-
6803
- if ( Node ) ParenthesizedExpression.__proto__ = Node;
6804
- ParenthesizedExpression.prototype = Object.create( Node && Node.prototype );
6805
- ParenthesizedExpression.prototype.constructor = ParenthesizedExpression;
6806
-
6807
- ParenthesizedExpression.prototype.getPossibleValues = function getPossibleValues ( values ) {
6808
- return this.expression.getPossibleValues( values );
6809
- };
6810
-
6811
- ParenthesizedExpression.prototype.getValue = function getValue () {
6812
- return this.expression.getValue();
6813
- };
6814
-
6815
- return ParenthesizedExpression;
6816
- }(Node$1));
6817
-
6818
6855
  var ReturnStatement = (function (Node) {
6819
6856
  function ReturnStatement () {
6820
6857
  Node.apply(this, arguments);
@@ -6948,7 +6985,6 @@ var UpdateExpression = (function (Node) {
6948
6985
 
6949
6986
  UpdateExpression.prototype.bind = function bind ( scope ) {
6950
6987
  var subject = this.argument;
6951
- while ( this.argument.type === 'ParenthesizedExpression' ) subject = subject.expression;
6952
6988
 
6953
6989
  this.subject = subject;
6954
6990
  disallowIllegalReassignment( scope, this.argument );
@@ -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 ) {
@@ -7230,7 +7276,6 @@ var nodes = {
7230
7276
  MemberExpression: MemberExpression,
7231
7277
  NewExpression: NewExpression,
7232
7278
  ObjectExpression: ObjectExpression,
7233
- ParenthesizedExpression: ParenthesizedExpression,
7234
7279
  ReturnStatement: ReturnStatement,
7235
7280
  SwitchStatement: Statement,
7236
7281
  TemplateLiteral: TemplateLiteral,
@@ -7374,7 +7419,7 @@ function tryParse ( code, comments, acornOptions, id ) {
7374
7419
  ecmaVersion: 7,
7375
7420
  sourceType: 'module',
7376
7421
  onComment: function ( block, text, start, end ) { return comments.push({ block: block, text: text, start: start, end: end }); },
7377
- preserveParens: true
7422
+ preserveParens: false
7378
7423
  }, acornOptions ));
7379
7424
  } catch ( err ) {
7380
7425
  err.code = 'PARSE_ERROR';
@@ -7436,7 +7481,7 @@ var Module = function Module (ref) {
7436
7481
  });
7437
7482
 
7438
7483
  // remove existing sourceMappingURL comments
7439
- var pattern = new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' );
7484
+ var pattern = new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' );
7440
7485
  var match;
7441
7486
  while ( match = pattern.exec( code ) ) {
7442
7487
  this$1.magicString.remove( match.index, match.index + match[0].length );
@@ -7565,7 +7610,7 @@ Module.prototype.addImport = function addImport ( node ) {
7565
7610
 
7566
7611
  if ( this$1.imports[ localName ] ) {
7567
7612
  var err = new Error( ("Duplicated import '" + localName + "'") );
7568
- err.file = this$1.id;
7613
+ err.file = this$1.id;
7569
7614
  err.loc = getLocation( this$1.code, specifier.start );
7570
7615
  throw err;
7571
7616
  }
@@ -7574,7 +7619,7 @@ Module.prototype.addImport = function addImport ( node ) {
7574
7619
  var isNamespace = specifier.type === 'ImportNamespaceSpecifier';
7575
7620
 
7576
7621
  var name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name;
7577
- this$1.imports[ localName ] = { source: source, name: name, module: null };
7622
+ this$1.imports[ localName ] = { source: source, specifier: specifier, name: name, module: null };
7578
7623
  });
7579
7624
  };
7580
7625
 
@@ -7662,11 +7707,11 @@ Module.prototype.getExports = function getExports () {
7662
7707
  });
7663
7708
 
7664
7709
  keys( this.reexports ).forEach( function (name) {
7665
- exports[ name ] = true;
7666
- });
7710
+ exports[ name ] = true;
7711
+ });
7667
7712
 
7668
7713
  this.exportAllModules.forEach( function (module) {
7669
- if ( module.isExternal ) return; // TODO
7714
+ if ( module.isExternal ) return; // TODO
7670
7715
 
7671
7716
  module.getExports().forEach( function (name) {
7672
7717
  if ( name !== 'default' ) exports[ name ] = true;
@@ -7736,7 +7781,14 @@ Module.prototype.trace = function trace ( name ) {
7736
7781
 
7737
7782
  var declaration = otherModule.traceExport( importDeclaration.name );
7738
7783
 
7739
- 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") );
7784
+ if ( !declaration ) {
7785
+ error({
7786
+ 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"),
7787
+ file: this.id,
7788
+ loc: getLocation( this.code, importDeclaration.specifier.start )
7789
+ });
7790
+ }
7791
+
7740
7792
  return declaration;
7741
7793
  }
7742
7794
 
@@ -7752,10 +7804,11 @@ Module.prototype.traceExport = function traceExport ( name ) {
7752
7804
  var declaration = reexportDeclaration.module.traceExport( reexportDeclaration.localName );
7753
7805
 
7754
7806
  if ( !declaration ) {
7755
- var err = new Error( ("'" + (reexportDeclaration.localName) + "' is not exported by '" + (reexportDeclaration.module.id) + "' (imported by '" + (this.id) + "')") );
7756
- err.file = this.id;
7757
- err.loc = getLocation( this.code, reexportDeclaration.start );
7758
- throw err;
7807
+ error({
7808
+ message: ("'" + (reexportDeclaration.localName) + "' is not exported by '" + (reexportDeclaration.module.id) + "' (imported by '" + (this.id) + "')"),
7809
+ file: this.id,
7810
+ loc: getLocation( this.code, reexportDeclaration.start )
7811
+ });
7759
7812
  }
7760
7813
 
7761
7814
  return declaration;
@@ -7769,6 +7822,8 @@ Module.prototype.traceExport = function traceExport ( name ) {
7769
7822
  return declaration$1 || this.bundle.scope.findDeclaration( name$1 );
7770
7823
  }
7771
7824
 
7825
+ if ( name === 'default' ) return;
7826
+
7772
7827
  for ( var i = 0; i < this.exportAllModules.length; i += 1 ) {
7773
7828
  var module = this$1.exportAllModules[i];
7774
7829
  var declaration$2 = module.traceExport( name );
@@ -7874,6 +7929,7 @@ function amd ( bundle, magicString, ref, options ) {
7874
7929
  var exportMode = ref.exportMode;
7875
7930
  var indentString = ref.indentString;
7876
7931
  var intro = ref.intro;
7932
+ var outro = ref.outro;
7877
7933
 
7878
7934
  var deps = bundle.externalModules.map( quotePath );
7879
7935
  var args = bundle.externalModules.map( getName );
@@ -7898,8 +7954,8 @@ function amd ( bundle, magicString, ref, options ) {
7898
7954
 
7899
7955
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
7900
7956
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7901
- if ( exportMode === 'named' ) magicString.append( ("\n\n" + esModuleExport) );
7902
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
7957
+ if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
7958
+ if ( outro ) magicString.append( outro );
7903
7959
 
7904
7960
  return magicString
7905
7961
  .indent( indentString )
@@ -7910,9 +7966,10 @@ function amd ( bundle, magicString, ref, options ) {
7910
7966
  function cjs ( bundle, magicString, ref, options ) {
7911
7967
  var exportMode = ref.exportMode;
7912
7968
  var intro = ref.intro;
7969
+ var outro = ref.outro;
7913
7970
 
7914
7971
  intro = ( options.useStrict === false ? intro : ("'use strict';\n\n" + intro) ) +
7915
- ( exportMode === 'named' ? (esModuleExport + "\n\n") : '' );
7972
+ ( exportMode === 'named' && options.legacy !== true ? (esModuleExport + "\n\n") : '' );
7916
7973
 
7917
7974
  var needsInterop = false;
7918
7975
 
@@ -7954,7 +8011,7 @@ function cjs ( bundle, magicString, ref, options ) {
7954
8011
 
7955
8012
  var exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
7956
8013
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7957
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8014
+ if ( outro ) magicString.append( outro );
7958
8015
 
7959
8016
  return magicString;
7960
8017
  }
@@ -7963,8 +8020,9 @@ function notDefault ( name ) {
7963
8020
  return name !== 'default';
7964
8021
  }
7965
8022
 
7966
- function es ( bundle, magicString, ref, options ) {
8023
+ function es ( bundle, magicString, ref ) {
7967
8024
  var intro = ref.intro;
8025
+ var outro = ref.outro;
7968
8026
 
7969
8027
  var importBlock = bundle.externalModules
7970
8028
  .map( function (module) {
@@ -8031,7 +8089,7 @@ function es ( bundle, magicString, ref, options ) {
8031
8089
  }
8032
8090
 
8033
8091
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock.trim() );
8034
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8092
+ if ( outro ) magicString.append( outro );
8035
8093
 
8036
8094
  return magicString.trim();
8037
8095
  }
@@ -8048,15 +8106,35 @@ function getGlobalNameMaker ( globals, onwarn ) {
8048
8106
  };
8049
8107
  }
8050
8108
 
8109
+ // Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
8110
+ // if the property name isn't trivial
8111
+
8112
+ var shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/;
8113
+ var dereferenceString = function (prop) { return prop.match(shouldUseDot) ? ("." + prop) : ("['" + prop + "']"); };
8114
+
8115
+ /**
8116
+ * returns a function which generates property dereference strings for the given name
8117
+ *
8118
+ * const getGlobalProp = propertyStringFor('global');
8119
+ * getGlobalProp('foo.bar-baz.qux') => `global.bar['bar-baz'].qux`
8120
+ */
8121
+ var propertyStringFor = function (objName) { return function (propName) { return objName + propName.split('.').map(dereferenceString).join(''); }; };
8122
+
8123
+ // thisProp('foo.bar-baz.qux') === "this.foo['bar-baz'].qux"
8124
+ var thisProp = propertyStringFor('this');
8125
+
8126
+ // propString('foo.bar-baz.qux') === ".foo['bar-baz'].qux"
8127
+ var propString = propertyStringFor('');
8128
+
8051
8129
  function setupNamespace ( keypath ) {
8052
- var parts = keypath.split( '.' ); // TODO support e.g. `foo['something-hyphenated']`?
8130
+ var parts = keypath.split( '.' );
8053
8131
 
8054
8132
  parts.pop();
8055
8133
 
8056
8134
  var acc = 'this';
8057
8135
 
8058
8136
  return parts
8059
- .map( function (part) { return ( acc += "." + part, (acc + " = " + acc + " || {};") ); } )
8137
+ .map( function (part) { return ( acc += propString(part), (acc + " = " + acc + " || {};") ); } )
8060
8138
  .join( '\n' ) + '\n';
8061
8139
  }
8062
8140
 
@@ -8064,6 +8142,7 @@ function iife ( bundle, magicString, ref, options ) {
8064
8142
  var exportMode = ref.exportMode;
8065
8143
  var indentString = ref.indentString;
8066
8144
  var intro = ref.intro;
8145
+ var outro = ref.outro;
8067
8146
 
8068
8147
  var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
8069
8148
 
@@ -8079,7 +8158,7 @@ function iife ( bundle, magicString, ref, options ) {
8079
8158
  }
8080
8159
 
8081
8160
  if ( exportMode === 'named' ) {
8082
- dependencies.unshift( ("(this." + name + " = this." + name + " || {})") );
8161
+ dependencies.unshift( ("(" + (thisProp(name)) + " = " + (thisProp(name)) + " || {})") );
8083
8162
  args.unshift( 'exports' );
8084
8163
  }
8085
8164
 
@@ -8089,7 +8168,7 @@ function iife ( bundle, magicString, ref, options ) {
8089
8168
  var wrapperOutro = "\n\n}(" + dependencies + "));";
8090
8169
 
8091
8170
  if ( exportMode === 'default' ) {
8092
- wrapperIntro = ( isNamespaced ? "this." : ((bundle.varOrConst) + " ") ) + name + " = " + wrapperIntro;
8171
+ wrapperIntro = ( isNamespaced ? thisProp(name) : ((bundle.varOrConst) + " " + name) ) + " = " + wrapperIntro;
8093
8172
  }
8094
8173
 
8095
8174
  if ( isNamespaced ) {
@@ -8104,7 +8183,7 @@ function iife ( bundle, magicString, ref, options ) {
8104
8183
 
8105
8184
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8106
8185
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8107
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8186
+ if ( outro ) magicString.append( outro );
8108
8187
 
8109
8188
  return magicString
8110
8189
  .indent( indentString )
@@ -8112,14 +8191,20 @@ function iife ( bundle, magicString, ref, options ) {
8112
8191
  .append( wrapperOutro );
8113
8192
  }
8114
8193
 
8194
+ // globalProp('foo.bar-baz') === "global.foo['bar-baz']"
8195
+ var globalProp = propertyStringFor('global');
8196
+
8197
+ // propString('foo.bar-baz') === ".foo['bar']"
8198
+ var propString$1 = propertyStringFor('');
8199
+
8115
8200
  function setupNamespace$1 ( name ) {
8116
8201
  var parts = name.split( '.' );
8117
8202
  parts.pop();
8118
8203
 
8119
8204
  var acc = 'global';
8120
8205
  return parts
8121
- .map( function (part) { return ( acc += "." + part, (acc + " = " + acc + " || {}") ); } )
8122
- .concat( ("global." + name) )
8206
+ .map( function (part) { return ( acc += propString$1(part), (acc + " = " + acc + " || {}") ); } )
8207
+ .concat( globalProp(name) )
8123
8208
  .join( ', ' );
8124
8209
  }
8125
8210
 
@@ -8129,6 +8214,7 @@ function umd ( bundle, magicString, ref, options ) {
8129
8214
  var exportMode = ref.exportMode;
8130
8215
  var indentString = ref.indentString;
8131
8216
  var intro = ref.intro;
8217
+ var outro = ref.outro;
8132
8218
 
8133
8219
  if ( exportMode !== 'none' && !options.moduleName ) {
8134
8220
  throw new Error( 'You must supply options.moduleName for UMD bundles' );
@@ -8138,14 +8224,14 @@ function umd ( bundle, magicString, ref, options ) {
8138
8224
 
8139
8225
  var amdDeps = bundle.externalModules.map( quotePath );
8140
8226
  var cjsDeps = bundle.externalModules.map( req );
8141
- var globalDeps = bundle.externalModules.map( function (module) { return ("global." + (globalNameMaker( module ))); } );
8227
+ var globalDeps = bundle.externalModules.map( function (module) { return globalProp(globalNameMaker( module )); } );
8142
8228
 
8143
8229
  var args = bundle.externalModules.map( getName );
8144
8230
 
8145
8231
  if ( exportMode === 'named' ) {
8146
8232
  amdDeps.unshift( "'exports'" );
8147
8233
  cjsDeps.unshift( "exports" );
8148
- globalDeps.unshift( ("(" + (setupNamespace$1(options.moduleName)) + " = global." + (options.moduleName) + " || {})") );
8234
+ globalDeps.unshift( ("(" + (setupNamespace$1(options.moduleName)) + " = " + (globalProp(options.moduleName)) + " || {})") );
8149
8235
 
8150
8236
  args.unshift( 'exports' );
8151
8237
  }
@@ -8160,7 +8246,7 @@ function umd ( bundle, magicString, ref, options ) {
8160
8246
  var useStrict = options.useStrict !== false ? " 'use strict';" : "";
8161
8247
 
8162
8248
  var globalExport = options.noConflict === true ?
8163
- ("(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 + "))");
8249
+ ("(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 + "))");
8164
8250
 
8165
8251
  var wrapperIntro =
8166
8252
  ("(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() );
@@ -8173,8 +8259,8 @@ function umd ( bundle, magicString, ref, options ) {
8173
8259
 
8174
8260
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8175
8261
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8176
- if ( exportMode === 'named' ) magicString.append( ("\n\n" + esModuleExport) );
8177
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8262
+ if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
8263
+ if ( outro ) magicString.append( outro );
8178
8264
 
8179
8265
  return magicString
8180
8266
  .trim()
@@ -8191,22 +8277,29 @@ function ensureArray ( thing ) {
8191
8277
  return [ thing ];
8192
8278
  }
8193
8279
 
8280
+ // eslint-disable-line
8194
8281
  function load ( id ) {
8195
- return readFileSync( id, 'utf-8' );
8282
+ return fs.readFileSync( id, 'utf-8' );
8196
8283
  }
8197
8284
 
8198
- function addJsExtensionIfNecessary ( file ) {
8285
+ function findFile ( file ) {
8199
8286
  try {
8200
- var name = path.basename( file );
8201
- var files = readdirSync( path.dirname( file ) );
8287
+ var stats = fs.lstatSync( file );
8288
+ if ( stats.isSymbolicLink() ) return findFile( fs.realpathSync( file ) );
8289
+ if ( stats.isFile() ) {
8290
+ // check case
8291
+ var name = path.basename( file );
8292
+ var files = fs.readdirSync( path.dirname( file ) );
8202
8293
 
8203
- if ( ~files.indexOf( name ) && isFile( file ) ) return file;
8204
- if ( ~files.indexOf( (name + ".js") ) && isFile( (file + ".js") ) ) return (file + ".js");
8294
+ if ( ~files.indexOf( name ) ) return file;
8295
+ }
8205
8296
  } catch ( err ) {
8206
- // noop
8297
+ // suppress
8207
8298
  }
8299
+ }
8208
8300
 
8209
- return null;
8301
+ function addJsExtensionIfNecessary ( file ) {
8302
+ return findFile( file ) || findFile( file + '.js' );
8210
8303
  }
8211
8304
 
8212
8305
  function resolveId ( importee, importer ) {
@@ -8970,7 +9063,16 @@ Bundle.prototype.render = function render ( options ) {
8970
9063
  .filter( Boolean )
8971
9064
  .join( '\n\n' );
8972
9065
 
8973
- 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;
8974
9076
 
8975
9077
  var indentString = getIndentString( magicString, options );
8976
9078
 
@@ -8979,7 +9081,7 @@ Bundle.prototype.render = function render ( options ) {
8979
9081
 
8980
9082
  timeStart( 'render format' );
8981
9083
 
8982
- 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 );
8983
9085
 
8984
9086
  timeEnd( 'render format' );
8985
9087
 
@@ -9003,7 +9105,7 @@ Bundle.prototype.render = function render ( options ) {
9003
9105
  var bundleSourcemapChain = [];
9004
9106
 
9005
9107
  code = transformBundle( code, this.plugins, bundleSourcemapChain, options )
9006
- .replace( new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' ), '' );
9108
+ .replace( new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' ), '' );
9007
9109
 
9008
9110
  if ( options.sourceMap ) {
9009
9111
  timeStart( 'sourceMap' );
@@ -9030,7 +9132,7 @@ Bundle.prototype.render = function render ( options ) {
9030
9132
  return { code: code, map: map };
9031
9133
  };
9032
9134
 
9033
- Bundle.prototype.sort = function sort () {
9135
+ Bundle.prototype.sort = function sort () {
9034
9136
  var this$1 = this;
9035
9137
 
9036
9138
  var hasCycles;
@@ -9106,7 +9208,7 @@ Bundle.prototype.render = function render ( options ) {
9106
9208
 
9107
9209
  this$1.onwarn(
9108
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")
9109
- );
9211
+ );
9110
9212
  }
9111
9213
  };
9112
9214
 
@@ -9117,7 +9219,7 @@ Bundle.prototype.render = function render ( options ) {
9117
9219
  return ordered;
9118
9220
  };
9119
9221
 
9120
- var VERSION = '0.36.3';
9222
+ var VERSION = '0.37.2';
9121
9223
 
9122
9224
  var ALLOWED_KEYS = [
9123
9225
  'acorn',