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.es.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
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import { basename, dirname, resolve, relative, extname } from 'path';
12
+ import { readFileSync, readdirSync, realpathSync, lstatSync } from 'fs';
12
13
  import * as fs from 'fs';
13
14
 
14
15
  var DEBUG = false;
@@ -94,15 +95,6 @@ function mkdirpath ( path ) {
94
95
  }
95
96
  }
96
97
 
97
- function isFile ( file ) {
98
- try {
99
- var stats = fs.statSync( file );
100
- return stats.isFile();
101
- } catch ( err ) {
102
- return false;
103
- }
104
- }
105
-
106
98
  function writeFile ( dest, data ) {
107
99
  return new Promise( function ( fulfil, reject ) {
108
100
  mkdirpath( dest );
@@ -117,9 +109,6 @@ function writeFile ( dest, data ) {
117
109
  });
118
110
  }
119
111
 
120
- var readdirSync = fs.readdirSync;
121
- var readFileSync = fs.readFileSync;
122
-
123
112
  var keys = Object.keys;
124
113
 
125
114
  function blank () {
@@ -5004,6 +4993,16 @@ function makeLegalIdentifier ( str ) {
5004
4993
  return str;
5005
4994
  }
5006
4995
 
4996
+ function error ( props ) {
4997
+ var err = new Error( props.message );
4998
+
4999
+ Object.keys( props ).forEach( function (key) {
5000
+ err[ key ] = props[ key ];
5001
+ });
5002
+
5003
+ throw err;
5004
+ }
5005
+
5007
5006
  function relativeId ( id ) {
5008
5007
  if ( typeof process === 'undefined' ) return id;
5009
5008
  return id.replace( process.cwd(), '' ).replace( /^[\/\\]/, '' );
@@ -5059,10 +5058,11 @@ SyntheticNamespaceDeclaration.prototype.renderBlock = function renderBlock ( es,
5059
5058
  var members = keys( this.originals ).map( function (name) {
5060
5059
  var original = this$1.originals[ name ];
5061
5060
 
5062
- if ( original.isReassigned ) {
5061
+ if ( original.isReassigned && !legacy ) {
5063
5062
  return (indentString + "get " + name + " () { return " + (original.getName( es )) + "; }");
5064
5063
  }
5065
5064
 
5065
+ if ( legacy && ~reservedWords$1.indexOf( name ) ) name = "'" + name + "'";
5066
5066
  return ("" + indentString + name + ": " + (original.getName( es )));
5067
5067
  });
5068
5068
 
@@ -5093,6 +5093,10 @@ ExternalDeclaration.prototype.addReference = function addReference ( reference )
5093
5093
  }
5094
5094
  };
5095
5095
 
5096
+ ExternalDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
5097
+ values.add( UNKNOWN );
5098
+ };
5099
+
5096
5100
  ExternalDeclaration.prototype.getName = function getName ( es ) {
5097
5101
  if ( this.name === '*' ) {
5098
5102
  return this.module.name;
@@ -5291,7 +5295,7 @@ Parameter.prototype.getName = function getName () {
5291
5295
  };
5292
5296
 
5293
5297
  var Scope = function Scope ( options ) {
5294
- options = options || {};
5298
+ if ( options === void 0 ) options = {};
5295
5299
 
5296
5300
  this.parent = options.parent;
5297
5301
  this.isBlockScope = !!options.isBlockScope;
@@ -5408,16 +5412,6 @@ var ArrowFunctionExpression = (function (Node) {
5408
5412
  return ArrowFunctionExpression;
5409
5413
  }(Node$1));
5410
5414
 
5411
- function error ( props ) {
5412
- var err = new Error( props.message );
5413
-
5414
- Object.keys( props ).forEach( function (key) {
5415
- err[ key ] = props[ key ];
5416
- });
5417
-
5418
- throw err;
5419
- }
5420
-
5421
5415
  // TODO tidy this up a bit (e.g. they can both use node.module.imports)
5422
5416
  function disallowIllegalReassignment ( scope, node ) {
5423
5417
  if ( node.type === 'MemberExpression' && node.object.type === 'Identifier' ) {
@@ -5445,8 +5439,6 @@ function disallowIllegalReassignment ( scope, node ) {
5445
5439
  }
5446
5440
 
5447
5441
  function isUsedByBundle ( scope, node ) {
5448
- while ( node.type === 'ParenthesizedExpression' ) node = node.expression;
5449
-
5450
5442
  // const expression = node;
5451
5443
  while ( node.type === 'MemberExpression' ) node = node.object;
5452
5444
 
@@ -5483,6 +5475,17 @@ function isUsedByBundle ( scope, node ) {
5483
5475
  return false;
5484
5476
  }
5485
5477
 
5478
+ function isProgramLevel ( node ) {
5479
+ do {
5480
+ if ( node.type === 'Program' ) {
5481
+ return true;
5482
+ }
5483
+ node = node.parent;
5484
+ } while ( node && !/Function/.test( node.type ) );
5485
+
5486
+ return false;
5487
+ }
5488
+
5486
5489
  var AssignmentExpression = (function (Node) {
5487
5490
  function AssignmentExpression () {
5488
5491
  Node.apply(this, arguments);
@@ -5494,7 +5497,6 @@ var AssignmentExpression = (function (Node) {
5494
5497
 
5495
5498
  AssignmentExpression.prototype.bind = function bind ( scope ) {
5496
5499
  var subject = this.left;
5497
- while ( this.left.type === 'ParenthesizedExpression' ) subject = subject.expression;
5498
5500
 
5499
5501
  this.subject = subject;
5500
5502
  disallowIllegalReassignment( scope, subject );
@@ -5525,7 +5527,10 @@ var AssignmentExpression = (function (Node) {
5525
5527
  AssignmentExpression.prototype.initialise = function initialise ( scope ) {
5526
5528
  this.scope = scope;
5527
5529
 
5528
- this.module.bundle.dependentExpressions.push( this );
5530
+ if ( isProgramLevel( this ) ) {
5531
+ this.module.bundle.dependentExpressions.push( this );
5532
+ }
5533
+
5529
5534
  Node.prototype.initialise.call( this, scope );
5530
5535
  };
5531
5536
 
@@ -5767,16 +5772,52 @@ simdTypes.forEach( function (t) {
5767
5772
 
5768
5773
  var currentlyCalling = new Set();
5769
5774
 
5770
- 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 ) {
5771
5812
  if ( currentlyCalling.has( fn ) ) return false; // prevent infinite loops... TODO there must be a better way
5772
5813
  currentlyCalling.add( fn );
5773
5814
 
5774
5815
  // handle body-less arrow functions
5775
5816
  var scope = fn.body.scope || fn.scope;
5776
- var body = fn.body.body || [ fn.body ];
5817
+ var body = fn.body.type === 'BlockStatement' ? fn.body.body : [ fn.body ];
5777
5818
 
5778
5819
  for ( var node of body ) {
5779
- if ( node.hasEffects( scope ) ) {
5820
+ if ( isNew ? hasEffectsNew( node, scope ) : node.hasEffects( scope ) ) {
5780
5821
  currentlyCalling.delete( fn );
5781
5822
  return true;
5782
5823
  }
@@ -5786,14 +5827,14 @@ function fnHasEffects ( fn ) {
5786
5827
  return false;
5787
5828
  }
5788
5829
 
5789
- function callHasEffects ( scope, callee ) {
5830
+ function callHasEffects ( scope, callee, isNew ) {
5790
5831
  var values = new Set([ callee ]);
5791
5832
 
5792
5833
  for ( var node of values ) {
5793
5834
  if ( node === UNKNOWN ) return true; // err on side of caution
5794
5835
 
5795
5836
  if ( /Function/.test( node.type ) ) {
5796
- if ( fnHasEffects( node ) ) return true;
5837
+ if ( fnHasEffects( node, isNew && isES5Function( node ) ) ) return true;
5797
5838
  }
5798
5839
 
5799
5840
  else if ( isReference( node ) ) {
@@ -5859,11 +5900,13 @@ var CallExpression = (function (Node) {
5859
5900
  };
5860
5901
 
5861
5902
  CallExpression.prototype.hasEffects = function hasEffects ( scope ) {
5862
- return callHasEffects( scope, this.callee );
5903
+ return callHasEffects( scope, this.callee, false );
5863
5904
  };
5864
5905
 
5865
5906
  CallExpression.prototype.initialise = function initialise ( scope ) {
5866
- this.module.bundle.dependentExpressions.push( this );
5907
+ if ( isProgramLevel( this ) ) {
5908
+ this.module.bundle.dependentExpressions.push( this );
5909
+ }
5867
5910
  Node.prototype.initialise.call( this, scope );
5868
5911
  };
5869
5912
 
@@ -6130,11 +6173,18 @@ var ExportDefaultDeclaration = (function (Node) {
6130
6173
  var treeshake = this.module.bundle.treeshake;
6131
6174
  var name = this.getName( es );
6132
6175
 
6176
+ // paren workaround: find first non-whitespace character position after `export default`
6177
+ var declaration_start;
6178
+ if ( this.declaration ) {
6179
+ var statementStr = code.original.slice( this.start, this.end );
6180
+ declaration_start = this.start + statementStr.match(/^\s*export\s+default\s+/)[0].length;
6181
+ }
6182
+
6133
6183
  if ( this.shouldInclude || this.declaration.activated ) {
6134
6184
  if ( this.activated ) {
6135
6185
  if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
6136
6186
  if ( this.declaration.id ) {
6137
- code.remove( this.start, this.declaration.start );
6187
+ code.remove( this.start, declaration_start );
6138
6188
  } else {
6139
6189
  throw new Error( 'TODO anonymous class/function declaration' );
6140
6190
  }
@@ -6146,14 +6196,14 @@ var ExportDefaultDeclaration = (function (Node) {
6146
6196
  code.remove( this.leadingCommentStart || this.start, this.next || this.end );
6147
6197
  return; // don't render children. TODO this seems like a bit of a hack
6148
6198
  } else {
6149
- code.overwrite( this.start, this.declaration.start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6199
+ code.overwrite( this.start, declaration_start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6150
6200
  }
6151
6201
 
6152
6202
  this.insertSemicolon( code );
6153
6203
  }
6154
6204
  } else {
6155
6205
  // remove `var foo` from `var foo = bar()`, if `foo` is unused
6156
- code.remove( this.start, this.declaration.start );
6206
+ code.remove( this.start, declaration_start );
6157
6207
  }
6158
6208
 
6159
6209
  Node.prototype.render.call( this, code, es );
@@ -6163,10 +6213,10 @@ var ExportDefaultDeclaration = (function (Node) {
6163
6213
  code.remove( this.leadingCommentStart || this.start, this.next || this.end );
6164
6214
  } else {
6165
6215
  var hasEffects = this.declaration.hasEffects( this.module.scope );
6166
- code.remove( this.start, hasEffects ? this.declaration.start : this.next || this.end );
6216
+ code.remove( this.start, hasEffects ? declaration_start : this.next || this.end );
6167
6217
  }
6168
6218
  } else {
6169
- code.overwrite( this.start, this.declaration.start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6219
+ code.overwrite( this.start, declaration_start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
6170
6220
  }
6171
6221
  // code.remove( this.start, this.next || this.end );
6172
6222
  }
@@ -6322,8 +6372,6 @@ function assignToForLoopLeft ( node, scope, value ) {
6322
6372
  }
6323
6373
 
6324
6374
  else {
6325
- while ( node.type === 'ParenthesizedExpression' ) node = node.expression;
6326
-
6327
6375
  if ( node.type === 'MemberExpression' ) {
6328
6376
  // apparently this is legal JavaScript? Though I don't know what
6329
6377
  // kind of monster would write `for ( foo.bar of thing ) {...}`
@@ -6710,12 +6758,18 @@ var MemberExpression = (function (Node) {
6710
6758
  var declaration = scope.findDeclaration( keypath.root.name );
6711
6759
 
6712
6760
  while ( declaration.isNamespace && keypath.parts.length ) {
6761
+ var exporterId = declaration.module.id;
6762
+
6713
6763
  var part = keypath.parts[0];
6714
6764
  declaration = declaration.module.traceExport( part.name );
6715
6765
 
6716
6766
  if ( !declaration ) {
6717
- this$1.module.bundle.onwarn( ("Export '" + (part.name) + "' is not defined by '" + (this$1.module.id) + "'") );
6718
- break;
6767
+ var ref = getLocation( this$1.module.code, this$1.start );
6768
+ var line = ref.line;
6769
+ var column = ref.column;
6770
+ 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") );
6771
+ this$1.replacement = 'undefined';
6772
+ return;
6719
6773
  }
6720
6774
 
6721
6775
  keypath.parts.shift();
@@ -6748,6 +6802,10 @@ var MemberExpression = (function (Node) {
6748
6802
  if ( name !== this.name ) code.overwrite( this.start, this.end, name, true );
6749
6803
  }
6750
6804
 
6805
+ else if ( this.replacement ) {
6806
+ code.overwrite( this.start, this.end, this.replacement, true );
6807
+ }
6808
+
6751
6809
  Node.prototype.render.call( this, code, es );
6752
6810
  };
6753
6811
 
@@ -6769,7 +6827,7 @@ var NewExpression = (function (Node) {
6769
6827
  NewExpression.prototype.constructor = NewExpression;
6770
6828
 
6771
6829
  NewExpression.prototype.hasEffects = function hasEffects ( scope ) {
6772
- return callHasEffects( scope, this.callee );
6830
+ return callHasEffects( scope, this.callee, true );
6773
6831
  };
6774
6832
 
6775
6833
  return NewExpression;
@@ -6791,26 +6849,6 @@ var ObjectExpression = (function (Node) {
6791
6849
  return ObjectExpression;
6792
6850
  }(Node$1));
6793
6851
 
6794
- var ParenthesizedExpression = (function (Node) {
6795
- function ParenthesizedExpression () {
6796
- Node.apply(this, arguments);
6797
- }
6798
-
6799
- if ( Node ) ParenthesizedExpression.__proto__ = Node;
6800
- ParenthesizedExpression.prototype = Object.create( Node && Node.prototype );
6801
- ParenthesizedExpression.prototype.constructor = ParenthesizedExpression;
6802
-
6803
- ParenthesizedExpression.prototype.getPossibleValues = function getPossibleValues ( values ) {
6804
- return this.expression.getPossibleValues( values );
6805
- };
6806
-
6807
- ParenthesizedExpression.prototype.getValue = function getValue () {
6808
- return this.expression.getValue();
6809
- };
6810
-
6811
- return ParenthesizedExpression;
6812
- }(Node$1));
6813
-
6814
6852
  var ReturnStatement = (function (Node) {
6815
6853
  function ReturnStatement () {
6816
6854
  Node.apply(this, arguments);
@@ -6944,7 +6982,6 @@ var UpdateExpression = (function (Node) {
6944
6982
 
6945
6983
  UpdateExpression.prototype.bind = function bind ( scope ) {
6946
6984
  var subject = this.argument;
6947
- while ( this.argument.type === 'ParenthesizedExpression' ) subject = subject.expression;
6948
6985
 
6949
6986
  this.subject = subject;
6950
6987
  disallowIllegalReassignment( scope, this.argument );
@@ -7031,6 +7068,16 @@ var VariableDeclarator = (function (Node) {
7031
7068
  this.activated = true;
7032
7069
 
7033
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
+ }
7034
7081
  };
7035
7082
 
7036
7083
  VariableDeclarator.prototype.hasEffects = function hasEffects ( scope ) {
@@ -7226,7 +7273,6 @@ var nodes = {
7226
7273
  MemberExpression: MemberExpression,
7227
7274
  NewExpression: NewExpression,
7228
7275
  ObjectExpression: ObjectExpression,
7229
- ParenthesizedExpression: ParenthesizedExpression,
7230
7276
  ReturnStatement: ReturnStatement,
7231
7277
  SwitchStatement: Statement,
7232
7278
  TemplateLiteral: TemplateLiteral,
@@ -7370,7 +7416,7 @@ function tryParse ( code, comments, acornOptions, id ) {
7370
7416
  ecmaVersion: 7,
7371
7417
  sourceType: 'module',
7372
7418
  onComment: function ( block, text, start, end ) { return comments.push({ block: block, text: text, start: start, end: end }); },
7373
- preserveParens: true
7419
+ preserveParens: false
7374
7420
  }, acornOptions ));
7375
7421
  } catch ( err ) {
7376
7422
  err.code = 'PARSE_ERROR';
@@ -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 );
@@ -7561,7 +7607,7 @@ Module.prototype.addImport = function addImport ( node ) {
7561
7607
 
7562
7608
  if ( this$1.imports[ localName ] ) {
7563
7609
  var err = new Error( ("Duplicated import '" + localName + "'") );
7564
- err.file = this$1.id;
7610
+ err.file = this$1.id;
7565
7611
  err.loc = getLocation( this$1.code, specifier.start );
7566
7612
  throw err;
7567
7613
  }
@@ -7570,7 +7616,7 @@ Module.prototype.addImport = function addImport ( node ) {
7570
7616
  var isNamespace = specifier.type === 'ImportNamespaceSpecifier';
7571
7617
 
7572
7618
  var name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name;
7573
- this$1.imports[ localName ] = { source: source, name: name, module: null };
7619
+ this$1.imports[ localName ] = { source: source, specifier: specifier, name: name, module: null };
7574
7620
  });
7575
7621
  };
7576
7622
 
@@ -7658,11 +7704,11 @@ Module.prototype.getExports = function getExports () {
7658
7704
  });
7659
7705
 
7660
7706
  keys( this.reexports ).forEach( function (name) {
7661
- exports[ name ] = true;
7662
- });
7707
+ exports[ name ] = true;
7708
+ });
7663
7709
 
7664
7710
  this.exportAllModules.forEach( function (module) {
7665
- if ( module.isExternal ) return; // TODO
7711
+ if ( module.isExternal ) return; // TODO
7666
7712
 
7667
7713
  module.getExports().forEach( function (name) {
7668
7714
  if ( name !== 'default' ) exports[ name ] = true;
@@ -7732,7 +7778,14 @@ Module.prototype.trace = function trace ( name ) {
7732
7778
 
7733
7779
  var declaration = otherModule.traceExport( importDeclaration.name );
7734
7780
 
7735
- 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") );
7781
+ if ( !declaration ) {
7782
+ error({
7783
+ 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"),
7784
+ file: this.id,
7785
+ loc: getLocation( this.code, importDeclaration.specifier.start )
7786
+ });
7787
+ }
7788
+
7736
7789
  return declaration;
7737
7790
  }
7738
7791
 
@@ -7748,10 +7801,11 @@ Module.prototype.traceExport = function traceExport ( name ) {
7748
7801
  var declaration = reexportDeclaration.module.traceExport( reexportDeclaration.localName );
7749
7802
 
7750
7803
  if ( !declaration ) {
7751
- var err = new Error( ("'" + (reexportDeclaration.localName) + "' is not exported by '" + (reexportDeclaration.module.id) + "' (imported by '" + (this.id) + "')") );
7752
- err.file = this.id;
7753
- err.loc = getLocation( this.code, reexportDeclaration.start );
7754
- throw err;
7804
+ error({
7805
+ message: ("'" + (reexportDeclaration.localName) + "' is not exported by '" + (reexportDeclaration.module.id) + "' (imported by '" + (this.id) + "')"),
7806
+ file: this.id,
7807
+ loc: getLocation( this.code, reexportDeclaration.start )
7808
+ });
7755
7809
  }
7756
7810
 
7757
7811
  return declaration;
@@ -7765,6 +7819,8 @@ Module.prototype.traceExport = function traceExport ( name ) {
7765
7819
  return declaration$1 || this.bundle.scope.findDeclaration( name$1 );
7766
7820
  }
7767
7821
 
7822
+ if ( name === 'default' ) return;
7823
+
7768
7824
  for ( var i = 0; i < this.exportAllModules.length; i += 1 ) {
7769
7825
  var module = this$1.exportAllModules[i];
7770
7826
  var declaration$2 = module.traceExport( name );
@@ -7870,6 +7926,7 @@ function amd ( bundle, magicString, ref, options ) {
7870
7926
  var exportMode = ref.exportMode;
7871
7927
  var indentString = ref.indentString;
7872
7928
  var intro = ref.intro;
7929
+ var outro = ref.outro;
7873
7930
 
7874
7931
  var deps = bundle.externalModules.map( quotePath );
7875
7932
  var args = bundle.externalModules.map( getName );
@@ -7894,8 +7951,8 @@ function amd ( bundle, magicString, ref, options ) {
7894
7951
 
7895
7952
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
7896
7953
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7897
- if ( exportMode === 'named' ) magicString.append( ("\n\n" + esModuleExport) );
7898
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
7954
+ if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
7955
+ if ( outro ) magicString.append( outro );
7899
7956
 
7900
7957
  return magicString
7901
7958
  .indent( indentString )
@@ -7906,9 +7963,10 @@ function amd ( bundle, magicString, ref, options ) {
7906
7963
  function cjs ( bundle, magicString, ref, options ) {
7907
7964
  var exportMode = ref.exportMode;
7908
7965
  var intro = ref.intro;
7966
+ var outro = ref.outro;
7909
7967
 
7910
7968
  intro = ( options.useStrict === false ? intro : ("'use strict';\n\n" + intro) ) +
7911
- ( exportMode === 'named' ? (esModuleExport + "\n\n") : '' );
7969
+ ( exportMode === 'named' && options.legacy !== true ? (esModuleExport + "\n\n") : '' );
7912
7970
 
7913
7971
  var needsInterop = false;
7914
7972
 
@@ -7950,7 +8008,7 @@ function cjs ( bundle, magicString, ref, options ) {
7950
8008
 
7951
8009
  var exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
7952
8010
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
7953
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8011
+ if ( outro ) magicString.append( outro );
7954
8012
 
7955
8013
  return magicString;
7956
8014
  }
@@ -7959,8 +8017,9 @@ function notDefault ( name ) {
7959
8017
  return name !== 'default';
7960
8018
  }
7961
8019
 
7962
- function es ( bundle, magicString, ref, options ) {
8020
+ function es ( bundle, magicString, ref ) {
7963
8021
  var intro = ref.intro;
8022
+ var outro = ref.outro;
7964
8023
 
7965
8024
  var importBlock = bundle.externalModules
7966
8025
  .map( function (module) {
@@ -8027,7 +8086,7 @@ function es ( bundle, magicString, ref, options ) {
8027
8086
  }
8028
8087
 
8029
8088
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock.trim() );
8030
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8089
+ if ( outro ) magicString.append( outro );
8031
8090
 
8032
8091
  return magicString.trim();
8033
8092
  }
@@ -8044,15 +8103,35 @@ function getGlobalNameMaker ( globals, onwarn ) {
8044
8103
  };
8045
8104
  }
8046
8105
 
8106
+ // Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
8107
+ // if the property name isn't trivial
8108
+
8109
+ var shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/;
8110
+ var dereferenceString = function (prop) { return prop.match(shouldUseDot) ? ("." + prop) : ("['" + prop + "']"); };
8111
+
8112
+ /**
8113
+ * returns a function which generates property dereference strings for the given name
8114
+ *
8115
+ * const getGlobalProp = propertyStringFor('global');
8116
+ * getGlobalProp('foo.bar-baz.qux') => `global.bar['bar-baz'].qux`
8117
+ */
8118
+ var propertyStringFor = function (objName) { return function (propName) { return objName + propName.split('.').map(dereferenceString).join(''); }; };
8119
+
8120
+ // thisProp('foo.bar-baz.qux') === "this.foo['bar-baz'].qux"
8121
+ var thisProp = propertyStringFor('this');
8122
+
8123
+ // propString('foo.bar-baz.qux') === ".foo['bar-baz'].qux"
8124
+ var propString = propertyStringFor('');
8125
+
8047
8126
  function setupNamespace ( keypath ) {
8048
- var parts = keypath.split( '.' ); // TODO support e.g. `foo['something-hyphenated']`?
8127
+ var parts = keypath.split( '.' );
8049
8128
 
8050
8129
  parts.pop();
8051
8130
 
8052
8131
  var acc = 'this';
8053
8132
 
8054
8133
  return parts
8055
- .map( function (part) { return ( acc += "." + part, (acc + " = " + acc + " || {};") ); } )
8134
+ .map( function (part) { return ( acc += propString(part), (acc + " = " + acc + " || {};") ); } )
8056
8135
  .join( '\n' ) + '\n';
8057
8136
  }
8058
8137
 
@@ -8060,6 +8139,7 @@ function iife ( bundle, magicString, ref, options ) {
8060
8139
  var exportMode = ref.exportMode;
8061
8140
  var indentString = ref.indentString;
8062
8141
  var intro = ref.intro;
8142
+ var outro = ref.outro;
8063
8143
 
8064
8144
  var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
8065
8145
 
@@ -8075,7 +8155,7 @@ function iife ( bundle, magicString, ref, options ) {
8075
8155
  }
8076
8156
 
8077
8157
  if ( exportMode === 'named' ) {
8078
- dependencies.unshift( ("(this." + name + " = this." + name + " || {})") );
8158
+ dependencies.unshift( ("(" + (thisProp(name)) + " = " + (thisProp(name)) + " || {})") );
8079
8159
  args.unshift( 'exports' );
8080
8160
  }
8081
8161
 
@@ -8085,7 +8165,7 @@ function iife ( bundle, magicString, ref, options ) {
8085
8165
  var wrapperOutro = "\n\n}(" + dependencies + "));";
8086
8166
 
8087
8167
  if ( exportMode === 'default' ) {
8088
- wrapperIntro = ( isNamespaced ? "this." : ((bundle.varOrConst) + " ") ) + name + " = " + wrapperIntro;
8168
+ wrapperIntro = ( isNamespaced ? thisProp(name) : ((bundle.varOrConst) + " " + name) ) + " = " + wrapperIntro;
8089
8169
  }
8090
8170
 
8091
8171
  if ( isNamespaced ) {
@@ -8100,7 +8180,7 @@ function iife ( bundle, magicString, ref, options ) {
8100
8180
 
8101
8181
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8102
8182
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8103
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8183
+ if ( outro ) magicString.append( outro );
8104
8184
 
8105
8185
  return magicString
8106
8186
  .indent( indentString )
@@ -8108,14 +8188,20 @@ function iife ( bundle, magicString, ref, options ) {
8108
8188
  .append( wrapperOutro );
8109
8189
  }
8110
8190
 
8191
+ // globalProp('foo.bar-baz') === "global.foo['bar-baz']"
8192
+ var globalProp = propertyStringFor('global');
8193
+
8194
+ // propString('foo.bar-baz') === ".foo['bar']"
8195
+ var propString$1 = propertyStringFor('');
8196
+
8111
8197
  function setupNamespace$1 ( name ) {
8112
8198
  var parts = name.split( '.' );
8113
8199
  parts.pop();
8114
8200
 
8115
8201
  var acc = 'global';
8116
8202
  return parts
8117
- .map( function (part) { return ( acc += "." + part, (acc + " = " + acc + " || {}") ); } )
8118
- .concat( ("global." + name) )
8203
+ .map( function (part) { return ( acc += propString$1(part), (acc + " = " + acc + " || {}") ); } )
8204
+ .concat( globalProp(name) )
8119
8205
  .join( ', ' );
8120
8206
  }
8121
8207
 
@@ -8125,6 +8211,7 @@ function umd ( bundle, magicString, ref, options ) {
8125
8211
  var exportMode = ref.exportMode;
8126
8212
  var indentString = ref.indentString;
8127
8213
  var intro = ref.intro;
8214
+ var outro = ref.outro;
8128
8215
 
8129
8216
  if ( exportMode !== 'none' && !options.moduleName ) {
8130
8217
  throw new Error( 'You must supply options.moduleName for UMD bundles' );
@@ -8134,14 +8221,14 @@ function umd ( bundle, magicString, ref, options ) {
8134
8221
 
8135
8222
  var amdDeps = bundle.externalModules.map( quotePath );
8136
8223
  var cjsDeps = bundle.externalModules.map( req );
8137
- var globalDeps = bundle.externalModules.map( function (module) { return ("global." + (globalNameMaker( module ))); } );
8224
+ var globalDeps = bundle.externalModules.map( function (module) { return globalProp(globalNameMaker( module )); } );
8138
8225
 
8139
8226
  var args = bundle.externalModules.map( getName );
8140
8227
 
8141
8228
  if ( exportMode === 'named' ) {
8142
8229
  amdDeps.unshift( "'exports'" );
8143
8230
  cjsDeps.unshift( "exports" );
8144
- globalDeps.unshift( ("(" + (setupNamespace$1(options.moduleName)) + " = global." + (options.moduleName) + " || {})") );
8231
+ globalDeps.unshift( ("(" + (setupNamespace$1(options.moduleName)) + " = " + (globalProp(options.moduleName)) + " || {})") );
8145
8232
 
8146
8233
  args.unshift( 'exports' );
8147
8234
  }
@@ -8156,7 +8243,7 @@ function umd ( bundle, magicString, ref, options ) {
8156
8243
  var useStrict = options.useStrict !== false ? " 'use strict';" : "";
8157
8244
 
8158
8245
  var globalExport = options.noConflict === true ?
8159
- ("(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 + "))");
8246
+ ("(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 + "))");
8160
8247
 
8161
8248
  var wrapperIntro =
8162
8249
  ("(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() );
@@ -8169,8 +8256,8 @@ function umd ( bundle, magicString, ref, options ) {
8169
8256
 
8170
8257
  var exportBlock = getExportBlock( bundle.entryModule, exportMode );
8171
8258
  if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
8172
- if ( exportMode === 'named' ) magicString.append( ("\n\n" + esModuleExport) );
8173
- if ( options.outro ) magicString.append( ("\n" + (options.outro)) );
8259
+ if ( exportMode === 'named' && options.legacy !== true ) magicString.append( ("\n\n" + esModuleExport) );
8260
+ if ( outro ) magicString.append( outro );
8174
8261
 
8175
8262
  return magicString
8176
8263
  .trim()
@@ -8187,22 +8274,29 @@ function ensureArray ( thing ) {
8187
8274
  return [ thing ];
8188
8275
  }
8189
8276
 
8277
+ // eslint-disable-line
8190
8278
  function load ( id ) {
8191
8279
  return readFileSync( id, 'utf-8' );
8192
8280
  }
8193
8281
 
8194
- function addJsExtensionIfNecessary ( file ) {
8282
+ function findFile ( file ) {
8195
8283
  try {
8196
- var name = basename( file );
8197
- var files = readdirSync( dirname( file ) );
8284
+ var stats = lstatSync( file );
8285
+ if ( stats.isSymbolicLink() ) return findFile( realpathSync( file ) );
8286
+ if ( stats.isFile() ) {
8287
+ // check case
8288
+ var name = basename( file );
8289
+ var files = readdirSync( dirname( file ) );
8198
8290
 
8199
- if ( ~files.indexOf( name ) && isFile( file ) ) return file;
8200
- if ( ~files.indexOf( (name + ".js") ) && isFile( (file + ".js") ) ) return (file + ".js");
8291
+ if ( ~files.indexOf( name ) ) return file;
8292
+ }
8201
8293
  } catch ( err ) {
8202
- // noop
8294
+ // suppress
8203
8295
  }
8296
+ }
8204
8297
 
8205
- return null;
8298
+ function addJsExtensionIfNecessary ( file ) {
8299
+ return findFile( file ) || findFile( file + '.js' );
8206
8300
  }
8207
8301
 
8208
8302
  function resolveId ( importee, importer ) {
@@ -8966,7 +9060,16 @@ Bundle.prototype.render = function render ( options ) {
8966
9060
  .filter( Boolean )
8967
9061
  .join( '\n\n' );
8968
9062
 
8969
- 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;
8970
9073
 
8971
9074
  var indentString = getIndentString( magicString, options );
8972
9075
 
@@ -8975,7 +9078,7 @@ Bundle.prototype.render = function render ( options ) {
8975
9078
 
8976
9079
  timeStart( 'render format' );
8977
9080
 
8978
- 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 );
8979
9082
 
8980
9083
  timeEnd( 'render format' );
8981
9084
 
@@ -8999,7 +9102,7 @@ Bundle.prototype.render = function render ( options ) {
8999
9102
  var bundleSourcemapChain = [];
9000
9103
 
9001
9104
  code = transformBundle( code, this.plugins, bundleSourcemapChain, options )
9002
- .replace( new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' ), '' );
9105
+ .replace( new RegExp( ("^\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'gm' ), '' );
9003
9106
 
9004
9107
  if ( options.sourceMap ) {
9005
9108
  timeStart( 'sourceMap' );
@@ -9026,7 +9129,7 @@ Bundle.prototype.render = function render ( options ) {
9026
9129
  return { code: code, map: map };
9027
9130
  };
9028
9131
 
9029
- Bundle.prototype.sort = function sort () {
9132
+ Bundle.prototype.sort = function sort () {
9030
9133
  var this$1 = this;
9031
9134
 
9032
9135
  var hasCycles;
@@ -9102,7 +9205,7 @@ Bundle.prototype.render = function render ( options ) {
9102
9205
 
9103
9206
  this$1.onwarn(
9104
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")
9105
- );
9208
+ );
9106
9209
  }
9107
9210
  };
9108
9211
 
@@ -9113,7 +9216,7 @@ Bundle.prototype.render = function render ( options ) {
9113
9216
  return ordered;
9114
9217
  };
9115
9218
 
9116
- var VERSION = '0.36.3';
9219
+ var VERSION = '0.37.2';
9117
9220
 
9118
9221
  var ALLOWED_KEYS = [
9119
9222
  'acorn',