esperanto-source 0.6.23 → 0.6.24

Sign up to get free protection for your applications and to get access to all the features.
data/vendor/esperanto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- esperanto.js v0.6.23 - 2015-03-31
2
+ esperanto.js v0.6.24 - 2015-03-31
3
3
  http://esperantojs.org
4
4
 
5
5
  Released under the MIT License.
@@ -7,10 +7,10 @@
7
7
 
8
8
  'use strict';
9
9
 
10
- var acorn = require('acorn');
11
- var MagicString = require('magic-string');
12
10
  var _path = require('path');
13
11
  var sander = require('sander');
12
+ var acorn = require('acorn');
13
+ var MagicString = require('magic-string');
14
14
 
15
15
  var hasOwnProp = Object.prototype.hasOwnProperty;
16
16
  var utils_hasOwnProp = hasOwnProp;
@@ -99,14 +99,14 @@ function quote ( str ) {
99
99
  }
100
100
 
101
101
  function req ( path ) {
102
- return 'require(' + quote(path) + ')';
102
+ return (("require(" + (quote(path))) + ")");
103
103
  }
104
104
 
105
105
  function globalify ( name ) {
106
106
  if ( /^__dep\d+__$/.test( name ) ) {
107
107
  return 'undefined';
108
108
  } else {
109
- return 'global.' + name;
109
+ return ("global." + name);
110
110
  }
111
111
  }
112
112
 
@@ -116,12 +116,12 @@ function globalify ( name ) {
116
116
  identifiers need to be rewritten to avoid collisions
117
117
  */
118
118
 
119
- var Scope = function ( options ) {
119
+ function Scope ( options ) {
120
120
  options = options || {};
121
121
 
122
122
  this.parent = options.parent;
123
123
  this.names = options.params || [];
124
- };
124
+ }
125
125
 
126
126
  Scope.prototype = {
127
127
  add: function ( name ) {
@@ -146,7 +146,11 @@ Scope.prototype = {
146
146
  };
147
147
 
148
148
  function annotateAst ( ast ) {
149
- var scope = new Scope(), blockScope = new Scope(), declared = {}, topLevelFunctionNames = [], templateLiteralRanges = [];
149
+ var scope = new Scope();
150
+ var blockScope = new Scope();
151
+ var declared = {};
152
+ var topLevelFunctionNames = [];
153
+ var templateLiteralRanges = [];
150
154
 
151
155
  var envDepth = 0;
152
156
 
@@ -164,7 +168,7 @@ function annotateAst ( ast ) {
164
168
  case 'FunctionExpression':
165
169
  case 'FunctionDeclaration':
166
170
 
167
- envDepth++;
171
+ envDepth += 1;
168
172
 
169
173
  // fallthrough
170
174
 
@@ -233,7 +237,7 @@ function annotateAst ( ast ) {
233
237
  case 'FunctionExpression':
234
238
  case 'FunctionDeclaration':
235
239
 
236
- envDepth--;
240
+ envDepth -= 1;
237
241
 
238
242
  // fallthrough
239
243
 
@@ -486,8 +490,11 @@ function processExport ( node, source ) {
486
490
  else {
487
491
  result.type = 'named';
488
492
  result.specifiers = node.specifiers.map( function(s ) {
489
- return { name: s.local.name };
490
- }); // TODO as?
493
+ return {
494
+ name: s.local.name,
495
+ as: s.exported.name
496
+ };
497
+ });
491
498
  }
492
499
 
493
500
  return result;
@@ -565,7 +572,9 @@ function disallowConflictingImports ( imports ) {
565
572
  }
566
573
  }
567
574
 
568
- var reserved = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield'.split( ' ' );
575
+ var RESERVED = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield'.split( ' ' );
576
+ var INVALID_CHAR = /[^a-zA-Z0-9_$]/g;
577
+ var INVALID_LEADING_CHAR = /[^a-zA-Z_$]/;
569
578
 
570
579
  /**
571
580
  * Generates a sanitized (i.e. valid identifier) name from a module ID
@@ -573,13 +582,10 @@ var reserved = 'break case class catch const continue debugger default delete do
573
582
  * @returns {string}
574
583
  */
575
584
  function sanitize ( name ) {
576
- name = name.replace( /[^a-zA-Z0-9_$]/g, '_' );
577
- if ( /[^a-zA-Z_$]/.test( name[0] ) ) {
578
- name = '_' + name;
579
- }
585
+ name = name.replace( INVALID_CHAR, '_' );
580
586
 
581
- if ( ~reserved.indexOf( name ) ) {
582
- name = '_' + name;
587
+ if ( INVALID_LEADING_CHAR.test( name[0] ) || ~RESERVED.indexOf( name ) ) {
588
+ name = ("_" + name);
583
589
  }
584
590
 
585
591
  return name;
@@ -635,12 +641,12 @@ function getStandaloneModule ( options ) {
635
641
  }
636
642
 
637
643
  function determineImportNames ( imports, userFn, usedNames ) {
638
- var nameById = {}, inferredNames = {};
639
-
640
- usedNames = usedNames || {};
644
+ var nameById = {};
645
+ var inferredNames = {};
641
646
 
642
647
  imports.forEach( function(x ) {
643
- var moduleId, parts, i, prefix = '', name, candidate;
648
+ var moduleId = x.path;
649
+ var name;
644
650
 
645
651
  moduleId = x.path;
646
652
 
@@ -661,7 +667,10 @@ function determineImportNames ( imports, userFn, usedNames ) {
661
667
  }
662
668
 
663
669
  else {
664
- parts = splitPath( moduleId );
670
+ var parts = splitPath( moduleId );
671
+ var i;
672
+ var prefix = '';
673
+ var candidate;
665
674
 
666
675
  do {
667
676
  i = parts.length;
@@ -778,7 +787,7 @@ function resolveChains ( modules, moduleLookup ) {
778
787
  return; // TODO can batch imports be chained?
779
788
  }
780
789
 
781
- origin[ s.as ] = x.id + '@' + s.name;
790
+ origin[ s.as ] = (("" + (x.id)) + ("@" + (s.name)) + "");
782
791
  });
783
792
  });
784
793
 
@@ -787,7 +796,7 @@ function resolveChains ( modules, moduleLookup ) {
787
796
 
788
797
  x.specifiers.forEach( function(s ) {
789
798
  if ( utils_hasOwnProp.call( origin, s.name ) ) {
790
- chains[ mod.id + '@' + s.name ] = origin[ s.name ];
799
+ chains[ (("" + (mod.id)) + ("@" + (s.name)) + "") ] = origin[ s.name ];
791
800
  }
792
801
  });
793
802
  });
@@ -797,7 +806,7 @@ function resolveChains ( modules, moduleLookup ) {
797
806
  }
798
807
 
799
808
  // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
800
- // we add `exports` to this list, to avoid conflicst
809
+ // we add `exports` to this list, to avoid conflicts
801
810
  var builtins = 'Array ArrayBuffer DataView Date Error EvalError Float32Array Float64Array Function Generator GeneratorFunction Infinity Int16Array Int32Array Int8Array InternalError Intl Iterator JSON Map Math NaN Number Object ParallelArray Promise Proxy RangeError ReferenceError Reflect RegExp Set StopIteration String Symbol SyntaxError TypeError TypedArray URIError Uint16Array Uint32Array Uint8Array Uint8ClampedArray WeakMap WeakSet decodeURI decodeURIComponent encodeURI encodeURIComponent escape eval exports isFinite isNaN null parseFloat parseInt undefined unescape uneval'.split( ' ' );
802
811
 
803
812
  function getUniqueNames ( bundle ) {
@@ -836,17 +845,16 @@ function getUniqueNames ( bundle ) {
836
845
  // for the rest, make names as compact as possible without
837
846
  // introducing conflicts
838
847
  modules.concat( externalModules ).forEach( function(mod ) {
839
- var parts, i, name;
840
-
841
848
  // is this already named?
842
849
  if ( utils_hasOwnProp.call( names, mod.id ) ) {
843
850
  mod.name = names[ mod.id ];
844
851
  return;
845
852
  }
846
853
 
847
- parts = splitPath( mod.id );
854
+ var name;
855
+ var parts = splitPath( mod.id );
856
+ var i = parts.length;
848
857
 
849
- i = parts.length;
850
858
  while ( i-- ) {
851
859
  name = sanitize( parts.slice( i ).join( '_' ) );
852
860
 
@@ -903,7 +911,8 @@ function getRenamedImports ( mod ) {
903
911
  }
904
912
 
905
913
  function topLevelScopeConflicts ( bundle ) {
906
- var conflicts = {}, inBundle = {};
914
+ var conflicts = {};
915
+ var inBundle = {};
907
916
  var importNames = bundle.externalModules.map( getName );
908
917
 
909
918
  bundle.modules.forEach( function(mod ) {
@@ -965,13 +974,11 @@ function populateIdentifierReplacements ( bundle ) {
965
974
  // then determine which existing identifiers
966
975
  // need to be replaced
967
976
  bundle.modules.forEach( function(mod ) {
968
- var moduleIdentifiers;
969
-
970
- moduleIdentifiers = mod.identifierReplacements;
977
+ var moduleIdentifiers = mod.identifierReplacements;
971
978
 
972
979
  mod.ast._topLevelNames.forEach( function(n ) {
973
980
  moduleIdentifiers[n] = utils_hasOwnProp.call( conflicts, n ) ?
974
- mod.name + '__' + n :
981
+ (("" + (mod.name)) + ("__" + n) + "") :
975
982
  n;
976
983
  });
977
984
 
@@ -997,7 +1004,7 @@ function populateIdentifierReplacements ( bundle ) {
997
1004
  specifierName = s.name;
998
1005
 
999
1006
  // If this is a chained import, get the origin
1000
- hash = moduleId + '@' + specifierName;
1007
+ hash = (("" + moduleId) + ("@" + specifierName) + "");
1001
1008
  while ( utils_hasOwnProp.call( bundle.chains, hash ) ) {
1002
1009
  hash = bundle.chains[ hash ];
1003
1010
  isChained = true;
@@ -1016,7 +1023,7 @@ function populateIdentifierReplacements ( bundle ) {
1016
1023
  // if it's an external module, always use __default if the
1017
1024
  // bundle also uses named imports
1018
1025
  if ( !!externalModule ) {
1019
- replacement = externalModule.needsNamed ? moduleName + '__default' : moduleName;
1026
+ replacement = externalModule.needsNamed ? (("" + moduleName) + "__default") : moduleName;
1020
1027
  }
1021
1028
 
1022
1029
  // TODO We currently need to check for the existence of `mod`, because modules
@@ -1027,7 +1034,7 @@ function populateIdentifierReplacements ( bundle ) {
1027
1034
  }
1028
1035
  } else if ( !externalModule ) {
1029
1036
  replacement = utils_hasOwnProp.call( conflicts, specifierName ) ?
1030
- moduleName + '__' + specifierName :
1037
+ (("" + moduleName) + ("__" + specifierName) + "") :
1031
1038
  specifierName;
1032
1039
  } else {
1033
1040
  replacement = moduleName + '.' + specifierName;
@@ -1063,29 +1070,22 @@ function resolveExports ( bundle ) {
1063
1070
  var bundleExports = {};
1064
1071
 
1065
1072
  bundle.entryModule.exports.forEach( function(x ) {
1066
- var name;
1067
-
1068
1073
  if ( x.specifiers ) {
1069
1074
  x.specifiers.forEach( function(s ) {
1070
- var hash = bundle.entryModule.id + '@' + s.name,
1071
- split,
1072
- moduleId,
1073
- name;
1075
+ var hash = (("" + (bundle.entryModule.id)) + ("@" + (s.name)) + "");
1074
1076
 
1075
1077
  while ( bundle.chains[ hash ] ) {
1076
1078
  hash = bundle.chains[ hash ];
1077
1079
  }
1078
1080
 
1079
- split = hash.split( '@' );
1080
- moduleId = split[0];
1081
- name = split[1];
1081
+ var moduleId = (name = hash.split( '@' ))[0], name = name[1];
1082
1082
 
1083
1083
  addExport( moduleId, name, s.name );
1084
1084
  });
1085
1085
  }
1086
1086
 
1087
- else if ( !x.isDefault && ( name = x.name ) ) {
1088
- addExport( bundle.entry, name, name );
1087
+ else if ( !x.isDefault && x.name ) {
1088
+ addExport( bundle.entry, x.name, x.name );
1089
1089
  }
1090
1090
  });
1091
1091
 
@@ -1104,7 +1104,7 @@ function resolveExports ( bundle ) {
1104
1104
  * Scans an array of imports, and determines which identifiers
1105
1105
  are readonly, and which cannot be assigned to. For example
1106
1106
  you cannot `import foo from 'foo'` then do `foo = 42`, nor
1107
- can you `import * from 'foo'` then do `foo.answer = 42`
1107
+ can you `import * as foo from 'foo'` then do `foo.answer = 42`
1108
1108
  * @param {array} imports - the array of imports
1109
1109
  * @returns {array} [ importedBindings, importedNamespaces ]
1110
1110
  */
@@ -1130,7 +1130,7 @@ var bindingMessage = 'Cannot reassign imported binding ',
1130
1130
  namespaceMessage = 'Cannot reassign imported binding of namespace ';
1131
1131
 
1132
1132
  function disallowIllegalReassignment ( node, importedBindings, importedNamespaces, scope ) {
1133
- var assignee, name, isNamespaceAssignment;
1133
+ var assignee, isNamespaceAssignment;
1134
1134
 
1135
1135
  if ( node.type === 'AssignmentExpression' ) {
1136
1136
  assignee = node.left;
@@ -1149,7 +1149,7 @@ function disallowIllegalReassignment ( node, importedBindings, importedNamespace
1149
1149
  return; // not assigning to a binding
1150
1150
  }
1151
1151
 
1152
- name = assignee.name;
1152
+ var name = assignee.name;
1153
1153
 
1154
1154
  if ( utils_hasOwnProp.call( isNamespaceAssignment ? importedNamespaces : importedBindings, name ) && !scope.contains( name ) ) {
1155
1155
  throw new Error( ( isNamespaceAssignment ? namespaceMessage : bindingMessage ) + '`' + name + '`' );
@@ -1169,7 +1169,7 @@ function replaceIdentifiers ( body, node, identifierReplacements, scope ) {
1169
1169
  }
1170
1170
 
1171
1171
  function rewriteExportAssignments ( body, node, exports, scope, capturedUpdates ) {
1172
- var assignee, name, exportAs;
1172
+ var assignee;
1173
1173
 
1174
1174
  if ( node.type === 'AssignmentExpression' ) {
1175
1175
  assignee = node.left;
@@ -1183,18 +1183,17 @@ function rewriteExportAssignments ( body, node, exports, scope, capturedUpdates
1183
1183
  return;
1184
1184
  }
1185
1185
 
1186
- name = assignee.name;
1186
+ var name = assignee.name;
1187
1187
 
1188
1188
  if ( scope.contains( name, true ) ) {
1189
1189
  return; // shadows an export
1190
1190
  }
1191
1191
 
1192
- if ( exports && utils_hasOwnProp.call( exports, name ) && ( exportAs = exports[ name ] ) ) {
1192
+ if ( exports && utils_hasOwnProp.call( exports, name ) ) {
1193
+ var exportAs = exports[ name ];
1194
+
1193
1195
  if ( !!capturedUpdates ) {
1194
- capturedUpdates.push({
1195
- name: name,
1196
- exportAs: exportAs
1197
- });
1196
+ capturedUpdates.push({ name: name, exportAs: exportAs });
1198
1197
  return;
1199
1198
  }
1200
1199
 
@@ -1208,10 +1207,10 @@ function rewriteExportAssignments ( body, node, exports, scope, capturedUpdates
1208
1207
  }
1209
1208
 
1210
1209
  function traverseAst ( ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames ) {
1211
- var scope = ast._scope,
1212
- blockScope = ast._blockScope,
1213
- capturedUpdates = null,
1214
- previousCapturedUpdates = null;
1210
+ var scope = ast._scope;
1211
+ var blockScope = ast._blockScope;
1212
+ var capturedUpdates = null;
1213
+ var previousCapturedUpdates = null;
1215
1214
 
1216
1215
  walk( ast, {
1217
1216
  enter: function ( node, parent ) {
@@ -1236,7 +1235,6 @@ function traverseAst ( ast, body, identifierReplacements, importedBindings, impo
1236
1235
  return;
1237
1236
  }
1238
1237
 
1239
- // Catch illegal reassignments
1240
1238
  disallowIllegalReassignment( node, importedBindings, importedNamespaces, scope );
1241
1239
 
1242
1240
  // Rewrite assignments to exports inside functions, to keep bindings live.
@@ -1275,21 +1273,14 @@ function traverseAst ( ast, body, identifierReplacements, importedBindings, impo
1275
1273
  }
1276
1274
 
1277
1275
  function exportCapturedUpdate ( c ) {
1278
- return ((" exports." + (c.name)) + (" = " + (c.exportAs)) + ";");
1276
+ return ((" exports." + (c.exportAs)) + (" = " + (c.name)) + ";");
1279
1277
  }
1280
1278
 
1281
- function combine_transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1282
- var identifierReplacements,
1283
- importedBindings,
1284
- importedNamespaces,
1285
- exportNames,
1286
- shouldExportEarly = {},
1287
- exportBlock;
1279
+ function combine_transformBody__transformBody ( bundle, mod, body ) {
1280
+ var identifierReplacements = mod.identifierReplacements;
1281
+ var importedBindings = (importedNamespaces = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = importedNamespaces[1];
1288
1282
 
1289
- identifierReplacements = mod.identifierReplacements;
1290
- importedBindings = ($D$0 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$0[1], $D$0;
1291
-
1292
- exportNames = utils_hasOwnProp.call( bundle.exports, mod.id ) && bundle.exports[ mod.id ];
1283
+ var exportNames = utils_hasOwnProp.call( bundle.exports, mod.id ) && bundle.exports[ mod.id ];
1293
1284
 
1294
1285
  traverseAst( mod.ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames );
1295
1286
 
@@ -1300,6 +1291,8 @@ function combine_transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1300
1291
  }
1301
1292
  });
1302
1293
 
1294
+ var shouldExportEarly = {};
1295
+
1303
1296
  // Remove export statements
1304
1297
  mod.exports.forEach( function(x ) {
1305
1298
  var name;
@@ -1381,7 +1374,7 @@ function combine_transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1381
1374
  // (it doesn't have to be the entry module, which could re-export
1382
1375
  // a binding from another module), we write exports here
1383
1376
  if ( exportNames ) {
1384
- exportBlock = [];
1377
+ var exportBlock = [];
1385
1378
 
1386
1379
  Object.keys( exportNames ).forEach( function(name ) {
1387
1380
  var exportAs = exportNames[ name ];
@@ -1394,7 +1387,7 @@ function combine_transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1394
1387
  }
1395
1388
 
1396
1389
  return body.trim();
1397
- ;$D$0 = void 0}
1390
+ }
1398
1391
 
1399
1392
  function combine ( bundle ) {
1400
1393
  bundle.body = new MagicString.Bundle({
@@ -1438,9 +1431,7 @@ function combine ( bundle ) {
1438
1431
  });
1439
1432
  }
1440
1433
 
1441
- function getModule ( mod ) {var $D$1;
1442
- var imports, exports;
1443
-
1434
+ function getModule ( mod ) {
1444
1435
  mod.body = new MagicString( mod.source );
1445
1436
 
1446
1437
  var toRemove = [];
@@ -1469,7 +1460,7 @@ function getModule ( mod ) {var $D$1;
1469
1460
  throw err;
1470
1461
  }
1471
1462
 
1472
- imports = ($D$1 = findImportsAndExports( mod, mod.source, mod.ast ))[0], exports = $D$1[1], $D$1;
1463
+ var imports = (exports = findImportsAndExports( mod, mod.source, mod.ast ))[0], exports = exports[1];
1473
1464
 
1474
1465
  disallowConflictingImports( imports );
1475
1466
 
@@ -1505,20 +1496,20 @@ function getModule ( mod ) {var $D$1;
1505
1496
  });
1506
1497
 
1507
1498
  return mod;
1508
- ;$D$1 = void 0}
1499
+ }
1509
1500
 
1510
1501
  var bundler_getBundle__Promise = sander.Promise;
1511
1502
 
1512
1503
  function getBundle ( options ) {
1513
- var entry = options.entry.replace( /\.js$/, '' ),
1514
- modules = [],
1515
- moduleLookup = {},
1516
- promiseByPath = {},
1517
- skip = options.skip,
1518
- names = options.names,
1519
- base = ( options.base ? _path.resolve( options.base ) : process.cwd() ) + '/',
1520
- externalModules = [],
1521
- externalModuleLookup = {};
1504
+ var entry = options.entry.replace( /\.js$/, '' );
1505
+ var modules = [];
1506
+ var moduleLookup = {};
1507
+ var promiseByPath = {};
1508
+ var skip = options.skip;
1509
+ var names = options.names;
1510
+ var base = ( options.base ? _path.resolve( options.base ) : process.cwd() ) + '/';
1511
+ var externalModules = [];
1512
+ var externalModuleLookup = {};
1522
1513
 
1523
1514
  if ( !entry.indexOf( base ) ) {
1524
1515
  entry = entry.substring( base.length );
@@ -1526,12 +1517,10 @@ function getBundle ( options ) {
1526
1517
 
1527
1518
  return resolvePath( base, entry, null ).then( function(entryPath ) {
1528
1519
  return fetchModule( entry, entryPath ).then( function() {
1529
- var entryModule, bundle;
1530
-
1531
- entryModule = moduleLookup[ entry ];
1520
+ var entryModule = moduleLookup[ entry ];
1532
1521
  modules = sortModules( entryModule, moduleLookup ); // TODO is this necessary? surely it's already sorted because of the fetch order? or do we need to prevent parallel reads?
1533
1522
 
1534
- bundle = {
1523
+ var bundle = {
1535
1524
  entry: entry,
1536
1525
  entryModule: entryModule,
1537
1526
  base: base,
@@ -1625,9 +1614,7 @@ function getBundle ( options ) {
1625
1614
 
1626
1615
  function resolvePath ( base, moduleId, importerPath, resolver ) {
1627
1616
  return tryPath( _path.resolve( base, moduleId + '.js' ) )
1628
- .catch( function () {
1629
- return tryPath( _path.resolve( base, moduleId, 'index.js' ) );
1630
- })
1617
+ .catch( function() {return tryPath( _path.resolve( base, moduleId, 'index.js' ) )} )
1631
1618
  .catch( function ( err ) {
1632
1619
  if ( resolver ) {
1633
1620
  return resolver( moduleId, importerPath );
@@ -1638,9 +1625,7 @@ function resolvePath ( base, moduleId, importerPath, resolver ) {
1638
1625
  }
1639
1626
 
1640
1627
  function tryPath ( path ) {
1641
- return sander.stat( path ).then( function () {
1642
- return path;
1643
- });
1628
+ return sander.stat( path ).then( function() {return path} );
1644
1629
  }
1645
1630
 
1646
1631
  function isThenable ( obj ) {
@@ -1689,23 +1674,24 @@ function transformExportDeclaration ( declaration, body ) {
1689
1674
  }
1690
1675
 
1691
1676
  if ( exportedValue ) {
1692
- body.append( '\nreturn ' + exportedValue + ';' );
1677
+ body.append( (("\nreturn " + exportedValue) + ";") );
1693
1678
  }
1694
1679
  }
1695
1680
 
1696
- var warned = {};
1681
+ var ABSOLUTE_PATH = /^(?:[A-Z]:)?[\/\\]/i;
1697
1682
 
1698
- function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1699
- var code, map;
1683
+ var utils_packageResult__warned = {};
1700
1684
 
1685
+ function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1701
1686
  // wrap output
1702
1687
  if ( options.banner ) body.prepend( options.banner );
1703
1688
  if ( options.footer ) body.append( options.footer );
1704
1689
 
1705
- code = body.toString();
1690
+ var code = body.toString();
1691
+ var map;
1706
1692
 
1707
1693
  if ( !!options.sourceMap ) {
1708
- if ( options.sourceMap !== 'inline' && !options.sourceMapFile) {
1694
+ if ( options.sourceMap !== 'inline' && !options.sourceMapFile ) {
1709
1695
  throw new Error( 'You must provide `sourceMapFile` option' );
1710
1696
  }
1711
1697
 
@@ -1714,10 +1700,10 @@ function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1714
1700
  }
1715
1701
 
1716
1702
  var sourceMapFile;
1717
- if (options.sourceMap === 'inline') {
1703
+ if ( options.sourceMap === 'inline' ) {
1718
1704
  sourceMapFile = null;
1719
1705
  } else {
1720
- sourceMapFile = isAbsolutePath( options.sourceMapFile ) ? options.sourceMapFile : './' + splitPath( options.sourceMapFile ).pop();
1706
+ sourceMapFile = ABSOLUTE_PATH.test( options.sourceMapFile ) ? options.sourceMapFile : './' + splitPath( options.sourceMapFile ).pop();
1721
1707
  }
1722
1708
 
1723
1709
  if ( isBundle ) {
@@ -1729,7 +1715,7 @@ function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1729
1715
  map = body.generateMap({
1730
1716
  includeContent: true,
1731
1717
  file: sourceMapFile,
1732
- source: (sourceMapFile && !isBundle) ? getRelativePath( sourceMapFile, options.sourceMapSource ) : null
1718
+ source: ( sourceMapFile && !isBundle ) ? getRelativePath( sourceMapFile, options.sourceMapSource ) : null
1733
1719
  });
1734
1720
 
1735
1721
  if ( options.sourceMap === 'inline' ) {
@@ -1746,9 +1732,9 @@ function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1746
1732
  code: code,
1747
1733
  map: map,
1748
1734
  toString: function () {
1749
- if ( !warned[ methodName ] ) {
1750
- console.log( 'Warning: esperanto.' + methodName + '() returns an object with a \'code\' property. You should use this instead of using the returned value directly' );
1751
- warned[ methodName ] = true;
1735
+ if ( !utils_packageResult__warned[ methodName ] ) {
1736
+ console.log( (("Warning: esperanto." + methodName) + "() returns an object with a 'code' property. You should use this instead of using the returned value directly") );
1737
+ utils_packageResult__warned[ methodName ] = true;
1752
1738
  }
1753
1739
 
1754
1740
  return code;
@@ -1756,10 +1742,6 @@ function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1756
1742
  };
1757
1743
  }
1758
1744
 
1759
- function isAbsolutePath ( path ) {
1760
- return /^(?:[A-Z]:)?[\/\\]/i.test( path );
1761
- }
1762
-
1763
1745
  function getRelativePath ( from, to ) {
1764
1746
  var fromParts, toParts, i;
1765
1747
 
@@ -1802,73 +1784,91 @@ function markModuleSourcemapLocations ( mod ) {
1802
1784
  });
1803
1785
  }
1804
1786
 
1805
- /**
1806
- * Creates a template function from a template string. The template
1807
- may have `<%= someVar %>` interpolators, and the returned function
1808
- should be called with a data object e.g. `{ someVar: 'someData' }`
1809
- * @param {string} str - the template string
1810
- * @returns {function}
1811
- */
1812
- function template ( str ) {
1813
- return function ( data ) {
1814
- return str.replace( /<%=\s*([^\s]+)\s*%>/g, function ( match, $1 ) {
1815
- return $1 in data ? data[ $1 ] : match;
1816
- });
1817
- };
1818
- }
1819
-
1820
- var defaultsMode_amd__introTemplate = template( 'define(<%= amdName %><%= paths %>function (<%= names %>) {\n\n' );
1787
+ function getImportSummary (name) {var imports = name.imports, absolutePaths = name.absolutePaths, name = name.name;
1788
+ var paths = [];
1789
+ var names = [];
1790
+ var seen = {};
1791
+ var placeholders = 0;
1821
1792
 
1822
- function defaultsMode_amd__amd ( mod, options ) {
1823
- var seen = {},
1824
- importNames = [],
1825
- importPaths = [],
1826
- intro,
1827
- placeholders = 0;
1793
+ imports.forEach( function(x ) {
1794
+ var path = x.id || x.path; // TODO unify these
1828
1795
 
1829
- // gather imports, and remove import declarations
1830
- mod.imports.forEach( function(x ) {
1831
- var path = options.absolutePaths ? resolveId( x.path, options.amdName ) : x.path;
1796
+ if ( !seen[ path ] ) {
1797
+ seen[ path ] = true;
1832
1798
 
1833
- if ( !utils_hasOwnProp.call( seen, path ) ) {
1834
- importPaths.push( path );
1799
+ paths.push( path );
1835
1800
 
1836
- if ( x.as ) {
1801
+ // TODO x could be an external module, or an internal one.
1802
+ // they have different shapes, resulting in the confusing
1803
+ // code below
1804
+ if ( ( x.needsDefault || x.needsNamed ) || ( x.specifiers && x.specifiers.length ) ) {
1837
1805
  while ( placeholders ) {
1838
- importNames.push( '__dep' + importNames.length + '__' );
1806
+ names.push( (("__dep" + (names.length)) + "__") );
1839
1807
  placeholders--;
1840
1808
  }
1841
- importNames.push( x.as );
1809
+ names.push( x.name );
1842
1810
  } else {
1843
1811
  placeholders++;
1844
1812
  }
1845
-
1846
- seen[ path ] = true;
1847
1813
  }
1814
+ });
1815
+
1816
+ var ids = absolutePaths ? paths.map( function(relativePath ) {return resolveId( relativePath, name )} ) : paths.slice();
1817
+
1818
+ return { ids: ids, paths: paths, names: names };
1819
+ }
1820
+
1821
+ function processName ( name ) {
1822
+ return name ? quote( name ) + ', ' : '';
1823
+ }
1848
1824
 
1825
+ function processIds ( ids ) {
1826
+ return ids.length ? '[' + ids.map( quote ).join( ', ' ) + '], ' : '';
1827
+ }
1828
+
1829
+ function amdIntro (absolutePaths) {var name = absolutePaths.name, imports = absolutePaths.imports, hasExports = absolutePaths.hasExports, indentStr = absolutePaths.indentStr, absolutePaths = absolutePaths.absolutePaths;
1830
+ var ids = (names = getImportSummary({ name: name, imports: imports, absolutePaths: absolutePaths })).ids, names = names.names;
1831
+
1832
+ if ( hasExports ) {
1833
+ ids.unshift( 'exports' );
1834
+ names.unshift( 'exports' );
1835
+ }
1836
+
1837
+ var intro = (("\
1838
+ \ndefine(" + (processName(name))) + ("" + (processIds(ids))) + ("function (" + (names.join( ', ' ))) + ") {\
1839
+ \n\
1840
+ \n 'use strict';\
1841
+ \n\
1842
+ \n");
1843
+
1844
+ return intro.replace( /\t/g, indentStr );
1845
+ }
1846
+
1847
+ function defaultsMode_amd__amd ( mod, options ) {
1848
+ mod.imports.forEach( function(x ) {
1849
1849
  mod.body.remove( x.start, x.next );
1850
1850
  });
1851
1851
 
1852
1852
  transformExportDeclaration( mod.exports[0], mod.body );
1853
1853
 
1854
- intro = defaultsMode_amd__introTemplate({
1855
- amdName: options.amdName ? (("'" + (options.amdName)) + "', ") : '',
1856
- paths: importPaths.length ? '[' + importPaths.map( quote ).join( ', ' ) + '], ' : '',
1857
- names: importNames.join( ', ' )
1854
+ var intro = amdIntro({
1855
+ name: options.amdName,
1856
+ imports: mod.imports,
1857
+ absolutePaths: options.absolutePaths,
1858
+ indentStr: mod.body.getIndentString()
1858
1859
  });
1859
1860
 
1860
1861
  mod.body.trim()
1861
- .prepend( "'use strict';\n\n" )
1862
- .trim()
1863
1862
  .indent()
1864
1863
  .prepend( intro )
1864
+ .trim()
1865
1865
  .append( '\n\n});' );
1866
1866
 
1867
1867
  return packageResult( mod, mod.body, options, 'toAmd' );
1868
1868
  }
1869
1869
 
1870
1870
  function defaultsMode_cjs__cjs ( mod, options ) {
1871
- var seen = {}, exportDeclaration;
1871
+ var seen = {};
1872
1872
 
1873
1873
  mod.imports.forEach( function(x ) {
1874
1874
  if ( !utils_hasOwnProp.call( seen, x.path ) ) {
@@ -1881,18 +1881,18 @@ function defaultsMode_cjs__cjs ( mod, options ) {
1881
1881
  }
1882
1882
  });
1883
1883
 
1884
- exportDeclaration = mod.exports[0];
1884
+ var exportDeclaration = mod.exports[0];
1885
1885
 
1886
1886
  if ( exportDeclaration ) {
1887
1887
  switch ( exportDeclaration.type ) {
1888
1888
  case 'namedFunction':
1889
1889
  case 'namedClass':
1890
- mod.body.remove( exportDeclaration.start, exportDeclaration.node.declaration.start );
1890
+ mod.body.remove( exportDeclaration.start, exportDeclaration.valueStart );
1891
1891
  mod.body.replace( exportDeclaration.end, exportDeclaration.end, (("\nmodule.exports = " + (exportDeclaration.node.declaration.id.name)) + ";") );
1892
1892
  break;
1893
1893
 
1894
1894
  default:
1895
- mod.body.replace( exportDeclaration.start, exportDeclaration.node.declaration.start, 'module.exports = ' );
1895
+ mod.body.replace( exportDeclaration.start, exportDeclaration.valueStart, 'module.exports = ' );
1896
1896
  break;
1897
1897
  }
1898
1898
  }
@@ -1902,53 +1902,63 @@ function defaultsMode_cjs__cjs ( mod, options ) {
1902
1902
  return packageResult( mod, mod.body, options, 'toCjs' );
1903
1903
  }
1904
1904
 
1905
- function standaloneUmdIntro ( options, indentStr ) {
1906
- var amdName = options.amdName ?
1907
- quote(options.amdName) + ", " :
1908
- '';
1905
+ function umdIntro (strict) {var amdName = strict.amdName, name = strict.name, hasExports = strict.hasExports, imports = strict.imports, absolutePaths = strict.absolutePaths, externalDefaults = strict.externalDefaults, indentStr = strict.indentStr, strict = strict.strict;
1906
+ var intro;
1909
1907
 
1910
- var intro =
1911
- (("(function (factory) {\
1912
- \n !(typeof exports === 'object' && typeof module !== 'undefined') &&\
1913
- \n typeof define === 'function' && define.amd ? define(" + amdName) + "factory) :\
1914
- \n factory()\
1915
- \n}(function () { 'use strict';\
1908
+ if ( !hasExports && !imports.length ) {
1909
+ intro =
1910
+ (("(function (factory) {\
1911
+ \n !(typeof exports === 'object' && typeof module !== 'undefined') &&\
1912
+ \n typeof define === 'function' && define.amd ? define(" + (processName(amdName))) + "factory) :\
1913
+ \n factory()\
1914
+ \n }(function () { 'use strict';\
1916
1915
  \n\
1917
- \n");
1916
+ \n ");
1917
+ }
1918
1918
 
1919
- return intro.replace( /\t/g, indentStr );
1920
- }
1919
+ else {
1920
+ var ids = (names = getImportSummary({ imports: imports, name: amdName, absolutePaths: absolutePaths })).ids, paths = names.paths, names = names.names;
1921
1921
 
1922
- function defaultUmdIntro ( options, indentStr ) {
1923
- var hasExports = options.hasExports;
1922
+ var amdExport, cjsExport, globalExport, defaultsBlock;
1924
1923
 
1925
- var amdName = options.amdName ?
1926
- quote(options.amdName) + ", " :
1927
- '';
1928
- var amdDeps = options.importPaths.length > 0 ?
1929
- '[' + ( options.absolutePaths ? options.importPaths.map( resolveAgainst( options.amdName ) ) : options.importPaths ).map( quote ).join( ', ' ) + '], ' :
1930
- '';
1931
- var cjsDeps = options.importPaths.map( req ).join( ', ' );
1932
- var globalDeps = options.importNames.map( globalify ).join( ', ' );
1933
- var args = options.importNames.join( ', ' );
1924
+ if ( strict ) {
1925
+ cjsExport = (("factory(" + (( hasExports ? [ 'exports' ] : [] ).concat( paths.map( req ) ).join( ', ' ))) + ")");
1926
+ var globalDeps = ( hasExports ? [ (("(global." + name) + " = {})") ] : [] ).concat( names.map( globalify ) ).join( ', ' );
1927
+ globalExport = (("factory(" + globalDeps) + ")");
1934
1928
 
1935
- var cjsExport =
1936
- (hasExports ? 'module.exports = ' : '') + (("factory(" + cjsDeps) + ")");
1929
+ if ( hasExports ) {
1930
+ ids.unshift( 'exports' );
1931
+ names.unshift( 'exports' );
1932
+ }
1937
1933
 
1938
- var globalExport =
1939
- (hasExports ? (("global." + (options.name)) + " = ") : '') + (("factory(" + globalDeps) + ")");
1934
+ amdExport = (("define(" + (processName(amdName))) + ("" + (processIds(ids))) + "factory)");
1935
+ defaultsBlock = '';
1936
+ if ( externalDefaults && externalDefaults.length > 0 ) {
1937
+ defaultsBlock = externalDefaults.map( function(x )
1938
+ {return '\t' + ( x.needsNamed ? (("var " + (x.name)) + "__default") : x.name ) +
1939
+ ((" = ('default' in " + (x.name)) + (" ? " + (x.name)) + ("['default'] : " + (x.name)) + ");")}
1940
+ ).join('\n') + '\n\n';
1941
+ }
1942
+ } else {
1943
+ amdExport = (("define(" + (processName(amdName))) + ("" + (processIds(ids))) + "factory)");
1944
+ cjsExport = ( hasExports ? 'module.exports = ' : '' ) + (("factory(" + (paths.map( req ).join( ', ' ))) + ")");
1945
+ globalExport = ( hasExports ? (("global." + name) + " = ") : '' ) + (("factory(" + (names.map( globalify ).join( ', ' ))) + ")");
1940
1946
 
1947
+ defaultsBlock = '';
1948
+ }
1941
1949
 
1942
- var intro =
1943
- (("(function (global, factory) {\
1944
- \n typeof exports === 'object' && typeof module !== 'undefined' ? " + cjsExport) + (" :\
1945
- \n typeof define === 'function' && define.amd ? define(" + amdName) + ("" + amdDeps) + ("factory) :\
1946
- \n " + globalExport) + ("\
1947
- \n}(this, function (" + args) + ") { 'use strict';\
1950
+ intro =
1951
+ (("(function (global, factory) {\
1952
+ \n typeof exports === 'object' && typeof module !== 'undefined' ? " + cjsExport) + (" :\
1953
+ \n typeof define === 'function' && define.amd ? " + amdExport) + (" :\
1954
+ \n " + globalExport) + ("\
1955
+ \n }(this, function (" + (names.join( ', ' ))) + (") { 'use strict';\
1948
1956
  \n\
1949
- \n");
1957
+ \n " + defaultsBlock) + "");
1950
1958
 
1951
- return intro.replace( /\t/g, indentStr );
1959
+ }
1960
+
1961
+ return intro.replace( /^\t\t\t/gm, '' ).replace( /\t/g, indentStr );
1952
1962
  }
1953
1963
 
1954
1964
  var EsperantoError = function ( message, data ) {
@@ -1979,54 +1989,22 @@ function requireName ( options ) {
1979
1989
  }
1980
1990
 
1981
1991
  function defaultsMode_umd__umd ( mod, options ) {
1982
- var importNames = [];
1983
- var importPaths = [];
1984
- var seen = {};
1985
- var placeholders = 0;
1986
-
1987
1992
  requireName( options );
1988
1993
 
1989
- var hasImports = mod.imports.length > 0;
1990
- var hasExports = mod.exports.length > 0;
1991
-
1992
- var intro;
1993
- if (!hasImports && !hasExports) {
1994
- intro = standaloneUmdIntro({
1995
- amdName: options.amdName,
1996
- }, mod.body.getIndentString() );
1997
- } else {
1998
- // gather imports, and remove import declarations
1999
- mod.imports.forEach( function(x ) {
2000
- if ( !utils_hasOwnProp.call( seen, x.path ) ) {
2001
- importPaths.push( x.path );
2002
-
2003
- if ( x.as ) {
2004
- while ( placeholders ) {
2005
- importNames.push( '__dep' + importNames.length + '__' );
2006
- placeholders--;
2007
- }
2008
- importNames.push( x.as );
2009
- } else {
2010
- placeholders++;
2011
- }
2012
-
2013
- seen[ x.path ] = true;
2014
- }
2015
-
2016
- mod.body.remove( x.start, x.next );
2017
- });
1994
+ mod.imports.forEach( function(x ) {
1995
+ mod.body.remove( x.start, x.next );
1996
+ });
2018
1997
 
2019
- transformExportDeclaration( mod.exports[0], mod.body );
1998
+ var intro = umdIntro({
1999
+ hasExports: mod.exports.length > 0,
2000
+ imports: mod.imports,
2001
+ amdName: options.amdName,
2002
+ absolutePaths: options.absolutePaths,
2003
+ name: options.name,
2004
+ indentStr: mod.body.getIndentString()
2005
+ });
2020
2006
 
2021
- intro = defaultUmdIntro({
2022
- hasExports: hasExports,
2023
- importPaths: importPaths,
2024
- importNames: importNames,
2025
- amdName: options.amdName,
2026
- absolutePaths: options.absolutePaths,
2027
- name: options.name
2028
- }, mod.body.getIndentString() );
2029
- }
2007
+ transformExportDeclaration( mod.exports[0], mod.body );
2030
2008
 
2031
2009
  mod.body.indent().prepend( intro ).trimLines().append( '\n\n}));' );
2032
2010
 
@@ -2040,18 +2018,17 @@ var defaultsMode = {
2040
2018
  };
2041
2019
 
2042
2020
  function gatherImports ( imports ) {
2043
- var chains = {}, identifierReplacements = {};
2021
+ var chains = {};
2022
+ var identifierReplacements = {};
2044
2023
 
2045
2024
  imports.forEach( function(x ) {
2046
2025
  x.specifiers.forEach( function(s ) {
2047
- var name, replacement;
2048
-
2049
2026
  if ( s.isBatch ) {
2050
2027
  return;
2051
2028
  }
2052
2029
 
2053
- name = s.as;
2054
- replacement = x.name + ( s.isDefault ? ("['default']") : ("." + (s.name)) );
2030
+ var name = s.as;
2031
+ var replacement = x.name + ( s.isDefault ? ("['default']") : ("." + (s.name)) );
2055
2032
 
2056
2033
  if ( !x.passthrough ) {
2057
2034
  identifierReplacements[ name ] = replacement;
@@ -2076,26 +2053,18 @@ function getExportNames ( exports ) {
2076
2053
  }
2077
2054
 
2078
2055
  x.specifiers.forEach( function(s ) {
2079
- result[ s.name ] = s.name;
2056
+ result[ s.name ] = s.as;
2080
2057
  });
2081
2058
  });
2082
2059
 
2083
2060
  return result;
2084
2061
  }
2085
2062
 
2086
- function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2087
- var chains,
2088
- identifierReplacements,
2089
- importedBindings = {},
2090
- importedNamespaces = {},
2091
- exportNames,
2092
- earlyExports,
2093
- lateExports;
2063
+ function utils_transformBody__transformBody ( mod, body, options ) {
2064
+ var chains = (identifierReplacements = gatherImports( mod.imports ))[0], identifierReplacements = identifierReplacements[1];
2065
+ var exportNames = getExportNames( mod.exports );
2094
2066
 
2095
- chains = ($D$2 = gatherImports( mod.imports ))[0], identifierReplacements = $D$2[1], $D$2;
2096
- exportNames = getExportNames( mod.exports );
2097
-
2098
- importedBindings = ($D$2 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$2[1], $D$2;
2067
+ var importedBindings = (importedNamespaces = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = importedNamespaces[1];
2099
2068
 
2100
2069
  // ensure no conflict with `exports`
2101
2070
  identifierReplacements.exports = deconflict( 'exports', mod.ast._declared );
@@ -2104,12 +2073,6 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2104
2073
 
2105
2074
  // Remove import statements from the body of the module
2106
2075
  mod.imports.forEach( function(x ) {
2107
- if ( x.passthrough ) {
2108
- // this is an `export { foo } from './bar'` statement -
2109
- // it will be dealt with in the next section
2110
- return;
2111
- }
2112
-
2113
2076
  body.remove( x.start, x.next );
2114
2077
  });
2115
2078
 
@@ -2150,8 +2113,8 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2150
2113
  });
2151
2114
 
2152
2115
  // Append export block (this is the same for all module types, unlike imports)
2153
- earlyExports = [];
2154
- lateExports = [];
2116
+ var earlyExports = [];
2117
+ var lateExports = [];
2155
2118
 
2156
2119
  Object.keys( exportNames ).forEach( function(name ) {
2157
2120
  var exportAs = exportNames[ name ];
@@ -2185,7 +2148,7 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2185
2148
  if ( options.intro && options.outro ) {
2186
2149
  body.indent().prepend( options.intro ).trimLines().append( options.outro );
2187
2150
  }
2188
- ;$D$2 = void 0}
2151
+ }
2189
2152
 
2190
2153
  function deconflict ( name, declared ) {
2191
2154
  while ( utils_hasOwnProp.call( declared, name ) ) {
@@ -2195,52 +2158,15 @@ function deconflict ( name, declared ) {
2195
2158
  return name;
2196
2159
  }
2197
2160
 
2198
- function getImportSummary ( mod ) {
2199
- var importPaths = [], importNames = [], seen = {}, placeholders = 0;
2200
-
2201
- mod.imports.forEach( function(x ) {
2202
- if ( !utils_hasOwnProp.call( seen, x.path ) ) {
2203
- importPaths.push( x.path );
2204
-
2205
- if ( x.specifiers.length ) {
2206
- while ( placeholders ) {
2207
- importNames.push( '__dep' + importNames.length + '__' );
2208
- placeholders--;
2209
- }
2210
- importNames.push( x.name );
2211
- } else {
2212
- placeholders++;
2213
- }
2214
-
2215
- seen[ x.path ] = true;
2216
- }
2161
+ function strictMode_amd__amd ( mod, options ) {
2162
+ var intro = amdIntro({
2163
+ name: options.amdName,
2164
+ absolutePaths: options.absolutePaths,
2165
+ imports: mod.imports,
2166
+ indentStr: mod.body.getIndentString(),
2167
+ hasExports: mod.exports.length
2217
2168
  });
2218
2169
 
2219
- return [ importPaths, importNames ];
2220
- }
2221
-
2222
- var strictMode_amd__introTemplate;
2223
-
2224
- strictMode_amd__introTemplate = template( 'define(<%= amdName %><%= paths %>function (<%= names %>) {\n\n\t\'use strict\';\n\n' );
2225
-
2226
- function strictMode_amd__amd ( mod, options ) {var $D$3;
2227
- var importPaths,
2228
- importNames,
2229
- intro;
2230
-
2231
- importPaths = ($D$3 = getImportSummary( mod ))[0], importNames = $D$3[1], $D$3;
2232
-
2233
- if ( mod.exports.length ) {
2234
- importPaths.unshift( 'exports' );
2235
- importNames.unshift( 'exports' );
2236
- }
2237
-
2238
- intro = strictMode_amd__introTemplate({
2239
- amdName: options.amdName ? (("'" + (options.amdName)) + "', ") : '',
2240
- paths: importPaths.length ? '[' + ( options.absolutePaths ? importPaths.map( resolveAgainst( options.amdName ) ) : importPaths ).map( quote ).join( ', ' ) + '], ' : '',
2241
- names: importNames.join( ', ' )
2242
- }).replace( /\t/g, mod.body.getIndentString() );
2243
-
2244
2170
  utils_transformBody__transformBody( mod, mod.body, {
2245
2171
  intro: intro,
2246
2172
  outro: '\n\n});',
@@ -2248,26 +2174,22 @@ function strictMode_amd__amd ( mod, options ) {var $D$3;
2248
2174
  });
2249
2175
 
2250
2176
  return packageResult( mod, mod.body, options, 'toAmd' );
2251
- ;$D$3 = void 0}
2177
+ }
2252
2178
 
2253
2179
  function strictMode_cjs__cjs ( mod, options ) {
2254
- var importBlock, seen = {};
2180
+ var seen = {};
2255
2181
 
2256
2182
  // Create block of require statements
2257
- importBlock = mod.imports.map( function(x ) {
2258
- var name, replacement;
2259
-
2183
+ var importBlock = mod.imports.map( function(x ) {
2260
2184
  if ( !utils_hasOwnProp.call( seen, x.path ) ) {
2185
+ seen[ x.path ] = true;
2186
+
2261
2187
  if ( x.isEmpty ) {
2262
- replacement = (("" + (req(x.path))) + ";");
2263
- } else {
2264
- replacement = (("var " + (x.name)) + (" = " + (req(x.path))) + ";");
2188
+ return (("" + (req(x.path))) + ";");
2265
2189
  }
2266
2190
 
2267
- seen[ x.path ] = true;
2191
+ return (("var " + (x.name)) + (" = " + (req(x.path))) + ";");
2268
2192
  }
2269
-
2270
- return replacement;
2271
2193
  }).filter( Boolean ).join( '\n' );
2272
2194
 
2273
2195
  utils_transformBody__transformBody( mod, mod.body, {
@@ -2280,65 +2202,18 @@ function strictMode_cjs__cjs ( mod, options ) {
2280
2202
  return packageResult( mod, mod.body, options, 'toCjs' );
2281
2203
  }
2282
2204
 
2283
- function strictUmdIntro ( options, indentStr ) {
2284
- var hasExports = options.hasExports;
2285
-
2286
- var amdName = options.amdName ?
2287
- "'" + options.amdName + "', " :
2288
- '';
2289
- var amdDeps = hasExports || options.importPaths.length > 0 ?
2290
- '[' +
2291
- ( hasExports ? [ 'exports' ] : [] ).concat( options.absolutePaths ? options.importPaths.map( resolveAgainst( options.amdName ) ) : options.importPaths ).map( quote ).join( ', ' ) +
2292
- '], ' :
2293
- '';
2294
- var cjsDeps = ( hasExports ? [ 'exports' ] : [] ).concat( options.importPaths.map( req ) ).join( ', ' );
2295
- var globalDeps = ( hasExports ? [ (("(global." + (options.name)) + " = {})") ] : [] )
2296
- .concat( options.importNames.map( globalify ) ).join( ', ' );
2297
- var args = ( hasExports ? [ 'exports' ] : [] ).concat( options.importNames ).join( ', ' );
2298
-
2299
- var defaultsBlock = '';
2300
- if ( options.externalDefaults && options.externalDefaults.length > 0 ) {
2301
- defaultsBlock = options.externalDefaults.map( function(x )
2302
- {return '\t' + ( x.needsNamed ? (("var " + (x.name)) + "__default") : x.name ) +
2303
- ((" = ('default' in " + (x.name)) + (" ? " + (x.name)) + ("['default'] : " + (x.name)) + ");")}
2304
- ).join('\n') + '\n\n';
2305
- }
2306
-
2307
- var intro =
2308
- (("(function (global, factory) {\
2309
- \n typeof exports === 'object' && typeof module !== 'undefined' ? factory(" + cjsDeps) + (") :\
2310
- \n typeof define === 'function' && define.amd ? define(" + amdName) + ("" + amdDeps) + ("factory) :\
2311
- \n factory(" + globalDeps) + (")\
2312
- \n}(this, function (" + args) + (") { 'use strict';\
2313
- \n\
2314
- \n" + defaultsBlock) + "");
2315
-
2316
- return intro.replace( /\t/g, indentStr );
2317
- }
2318
-
2319
2205
  function strictMode_umd__umd ( mod, options ) {
2320
2206
  requireName( options );
2321
2207
 
2322
- var importPaths = (importNames = getImportSummary( mod ))[0], importNames = importNames[1];
2323
-
2324
- var hasImports = mod.imports.length > 0;
2325
- var hasExports = mod.exports.length > 0;
2326
-
2327
- var intro;
2328
- if (!hasImports && !hasExports) {
2329
- intro = standaloneUmdIntro({
2330
- amdName: options.amdName,
2331
- }, mod.body.getIndentString() );
2332
- } else {
2333
- intro = strictUmdIntro({
2334
- hasExports: hasExports,
2335
- importPaths: importPaths,
2336
- importNames: importNames,
2337
- amdName: options.amdName,
2338
- absolutePaths: options.absolutePaths,
2339
- name: options.name
2340
- }, mod.body.getIndentString() );
2341
- }
2208
+ var intro = umdIntro({
2209
+ hasExports: mod.exports.length > 0,
2210
+ imports: mod.imports,
2211
+ amdName: options.amdName,
2212
+ absolutePaths: options.absolutePaths,
2213
+ name: options.name,
2214
+ indentStr: mod.body.getIndentString(),
2215
+ strict: true
2216
+ });
2342
2217
 
2343
2218
  utils_transformBody__transformBody( mod, mod.body, {
2344
2219
  intro: intro,
@@ -2361,28 +2236,22 @@ var moduleBuilders = {
2361
2236
  strictMode: strictMode
2362
2237
  };
2363
2238
 
2364
- var builders_defaultsMode_amd__introTemplate = template( 'define(<%= amdName %><%= amdDeps %>function (<%= names %>) {\n\n\t\'use strict\';\n\n' );
2365
-
2366
2239
  function builders_defaultsMode_amd__amd ( bundle, options ) {
2367
2240
  var defaultName = bundle.entryModule.identifierReplacements.default;
2368
2241
  if ( defaultName ) {
2369
2242
  bundle.body.append( (("\n\nreturn " + defaultName) + ";") );
2370
2243
  }
2371
2244
 
2372
- var intro = builders_defaultsMode_amd__introTemplate({
2373
- amdName: options.amdName ? (("" + (quote(options.amdName))) + ", ") : '',
2374
- amdDeps: bundle.externalModules.length ? '[' + bundle.externalModules.map( quoteId ).join( ', ' ) + '], ' : '',
2375
- names: bundle.externalModules.map( getName ).join( ', ' )
2376
- }).replace( /\t/g, bundle.body.getIndentString() );
2245
+ var intro = amdIntro({
2246
+ name: options.amdName,
2247
+ imports: bundle.externalModules,
2248
+ indentStr: bundle.body.getIndentString()
2249
+ });
2377
2250
 
2378
2251
  bundle.body.indent().prepend( intro ).trimLines().append( '\n\n});' );
2379
2252
  return packageResult( bundle, bundle.body, options, 'toAmd', true );
2380
2253
  }
2381
2254
 
2382
- function quoteId ( m ) {
2383
- return "'" + m.id + "'";
2384
- }
2385
-
2386
2255
  function builders_defaultsMode_cjs__cjs ( bundle, options ) {
2387
2256
  var importBlock = bundle.externalModules.map( function(x ) {
2388
2257
  return (("var " + (x.name)) + (" = " + (req(x.id))) + ";");
@@ -2407,31 +2276,16 @@ function builders_defaultsMode_umd__umd ( bundle, options ) {
2407
2276
 
2408
2277
  var entry = bundle.entryModule;
2409
2278
 
2410
- var hasImports = bundle.externalModules.length > 0;
2411
- var hasExports = entry.exports.length > 0;
2412
-
2413
- var intro;
2414
- if (!hasImports && !hasExports) {
2415
- intro = standaloneUmdIntro({
2416
- amdName: options.amdName,
2417
- }, bundle.body.getIndentString() );
2418
- } else {
2419
-
2420
- var defaultName = entry.identifierReplacements.default;
2421
- if ( defaultName ) {
2422
- bundle.body.append( (("\n\nreturn " + defaultName) + ";") );
2423
- }
2424
-
2425
- var importPaths = bundle.externalModules.map( getId );
2426
- var importNames = bundle.externalModules.map( getName );
2279
+ var intro = umdIntro({
2280
+ hasExports: entry.exports.length > 0,
2281
+ imports: bundle.externalModules,
2282
+ amdName: options.amdName,
2283
+ name: options.name,
2284
+ indentStr: bundle.body.getIndentString()
2285
+ });
2427
2286
 
2428
- intro = defaultUmdIntro({
2429
- hasExports: hasExports,
2430
- importPaths: importPaths,
2431
- importNames: importNames,
2432
- amdName: options.amdName,
2433
- name: options.name
2434
- }, bundle.body.getIndentString() );
2287
+ if ( entry.defaultExport ) {
2288
+ bundle.body.append( (("\n\nreturn " + (entry.identifierReplacements.default)) + ";") );
2435
2289
  }
2436
2290
 
2437
2291
  bundle.body.indent().prepend( intro ).trimLines().append('\n\n}));');
@@ -2450,15 +2304,10 @@ function getExportBlock ( entry ) {
2450
2304
  return (("exports['default'] = " + name) + ";");
2451
2305
  }
2452
2306
 
2453
- var builders_strictMode_amd__introTemplate = template( 'define(<%= amdName %><%= amdDeps %>function (<%= names %>) {\n\n\t\'use strict\';\n\n' );
2454
-
2455
2307
  function builders_strictMode_amd__amd ( bundle, options ) {
2456
2308
  var externalDefaults = bundle.externalModules.filter( builders_strictMode_amd__needsDefault );
2457
2309
  var entry = bundle.entryModule;
2458
2310
 
2459
- var importIds = bundle.externalModules.map( getId );
2460
- var importNames = bundle.externalModules.map( getName );
2461
-
2462
2311
  if ( externalDefaults.length ) {
2463
2312
  var defaultsBlock = externalDefaults.map( function(x ) {
2464
2313
  // Case 1: default is used, and named is not
@@ -2473,20 +2322,16 @@ function builders_strictMode_amd__amd ( bundle, options ) {
2473
2322
  bundle.body.prepend( defaultsBlock + '\n\n' );
2474
2323
  }
2475
2324
 
2476
- if ( entry.exports.length ) {
2477
- importIds.unshift( 'exports' );
2478
- importNames.unshift( 'exports' );
2479
-
2480
- if ( entry.defaultExport ) {
2481
- bundle.body.append( '\n\n' + getExportBlock( entry ) );
2482
- }
2325
+ if ( entry.defaultExport ) {
2326
+ bundle.body.append( '\n\n' + getExportBlock( entry ) );
2483
2327
  }
2484
2328
 
2485
- var intro = builders_strictMode_amd__introTemplate({
2486
- amdName: options.amdName ? (("" + (quote(options.amdName))) + ", ") : '',
2487
- amdDeps: importIds.length ? '[' + importIds.map( quote ).join( ', ' ) + '], ' : '',
2488
- names: importNames.join( ', ' )
2489
- }).replace( /\t/g, bundle.body.getIndentString() );
2329
+ var intro = amdIntro({
2330
+ name: options.amdName,
2331
+ imports: bundle.externalModules,
2332
+ hasExports: entry.exports.length,
2333
+ indentStr: bundle.body.getIndentString()
2334
+ });
2490
2335
 
2491
2336
  bundle.body.indent().prepend( intro ).trimLines().append( '\n\n});' );
2492
2337
  return packageResult( bundle, bundle.body, options, 'toAmd', true );
@@ -2529,31 +2374,18 @@ function builders_strictMode_umd__umd ( bundle, options ) {
2529
2374
 
2530
2375
  var entry = bundle.entryModule;
2531
2376
 
2532
- var hasImports = bundle.externalModules.length > 0;
2533
- var hasExports = entry.exports.length > 0;
2534
-
2535
- var intro;
2536
- if (!hasImports && !hasExports) {
2537
- intro = standaloneUmdIntro({
2538
- amdName: options.amdName,
2539
- }, bundle.body.getIndentString() );
2540
- } else {
2541
-
2542
- if ( hasExports && entry.defaultExport ) {
2543
- bundle.body.append( '\n\n' + getExportBlock( entry ) );
2544
- }
2545
-
2546
- var importPaths = bundle.externalModules.map( getId );
2547
- var importNames = bundle.externalModules.map( getName );
2377
+ var intro = umdIntro({
2378
+ hasExports: entry.exports.length > 0,
2379
+ imports: bundle.externalModules,
2380
+ externalDefaults: bundle.externalModules.filter( builders_strictMode_umd__needsDefault ),
2381
+ amdName: options.amdName,
2382
+ name: options.name,
2383
+ indentStr: bundle.body.getIndentString(),
2384
+ strict: true
2385
+ });
2548
2386
 
2549
- intro = strictUmdIntro({
2550
- hasExports: hasExports,
2551
- importPaths: importPaths,
2552
- importNames: importNames,
2553
- externalDefaults: bundle.externalModules.filter( builders_strictMode_umd__needsDefault ),
2554
- amdName: options.amdName,
2555
- name: options.name,
2556
- }, bundle.body.getIndentString() );
2387
+ if ( entry.defaultExport ) {
2388
+ bundle.body.append( '\n\n' + getExportBlock( entry ) );
2557
2389
  }
2558
2390
 
2559
2391
  bundle.body.indent().prepend( intro ).trimLines().append('\n\n}));');
@@ -2578,16 +2410,15 @@ var bundleBuilders = {
2578
2410
  };
2579
2411
 
2580
2412
  function concat ( bundle, options ) {
2581
- var intro, outro, indent;
2582
-
2583
2413
  // This bundle must be self-contained - no imports or exports
2584
2414
  if ( bundle.externalModules.length || bundle.entryModule.exports.length ) {
2585
2415
  throw new Error( (("bundle.concat() can only be used with bundles that have no imports/exports (imports: [" + (bundle.externalModules.map(function(x){return x.id}).join(', '))) + ("], exports: [" + (bundle.entryModule.exports.join(', '))) + "])") );
2586
2416
  }
2587
2417
 
2588
2418
  // TODO test these options
2589
- intro = 'intro' in options ? options.intro : ("(function () { 'use strict';\n\n");
2590
- outro = 'outro' in options ? options.outro : '\n\n})();';
2419
+ var intro = 'intro' in options ? options.intro : ("(function () { 'use strict';\n\n");
2420
+ var outro = 'outro' in options ? options.outro : '\n\n})();';
2421
+ var indent;
2591
2422
 
2592
2423
  if ( !( 'indent' in options ) || options.indent === true ) {
2593
2424
  indent = bundle.body.getIndentString();
@@ -2600,27 +2431,29 @@ function concat ( bundle, options ) {
2600
2431
  return packageResult( bundle, bundle.body, options, 'toString', true );
2601
2432
  }
2602
2433
 
2603
- var deprecateMessage = 'options.defaultOnly has been deprecated, and is now standard behaviour. To use named imports/exports, pass `strict: true`.',
2604
- alreadyWarned = false;
2434
+ var esperanto__deprecateMessage = 'options.defaultOnly has been deprecated, and is now standard behaviour. To use named imports/exports, pass `strict: true`.';
2435
+ var esperanto__alreadyWarned = false;
2605
2436
 
2606
2437
  function transpileMethod ( format ) {
2607
2438
  return function ( source ) {var options = arguments[1];if(options === void 0)options = {};
2608
- var mod,
2609
- body,
2610
- builder;
2611
-
2612
- mod = getStandaloneModule({ source: source, getModuleName: options.getModuleName, strict: options.strict });
2439
+ var mod = getStandaloneModule({
2440
+ source: source,
2441
+ getModuleName: options.getModuleName,
2442
+ strict: options.strict
2443
+ });
2613
2444
 
2614
- if ( 'defaultOnly' in options && !alreadyWarned ) {
2445
+ if ( 'defaultOnly' in options && !esperanto__alreadyWarned ) {
2615
2446
  // TODO link to a wiki page explaining this, or something
2616
- console.log( deprecateMessage );
2617
- alreadyWarned = true;
2447
+ console.log( esperanto__deprecateMessage );
2448
+ esperanto__alreadyWarned = true;
2618
2449
  }
2619
2450
 
2620
2451
  if ( options.absolutePaths && !options.amdName ) {
2621
2452
  throw new Error( 'You must specify an `amdName` in order to use the `absolutePaths` option' );
2622
2453
  }
2623
2454
 
2455
+ var builder;
2456
+
2624
2457
  if ( !options.strict ) {
2625
2458
  // ensure there are no named imports/exports. TODO link to a wiki page...
2626
2459
  if ( hasNamedImports( mod ) || hasNamedExports( mod ) ) {
@@ -2654,17 +2487,15 @@ var esperanto = {
2654
2487
  concat: function(options ) {return concat( bundle, options || {} )}
2655
2488
  };
2656
2489
 
2657
- function transpile ( format, options ) {
2658
- var builder;
2659
-
2660
- options = options || {};
2661
-
2662
- if ( 'defaultOnly' in options && !alreadyWarned ) {
2490
+ function transpile ( format ) {var options = arguments[1];if(options === void 0)options = {};
2491
+ if ( 'defaultOnly' in options && !esperanto__alreadyWarned ) {
2663
2492
  // TODO link to a wiki page explaining this, or something
2664
- console.log( deprecateMessage );
2665
- alreadyWarned = true;
2493
+ console.log( esperanto__deprecateMessage );
2494
+ esperanto__alreadyWarned = true;
2666
2495
  }
2667
2496
 
2497
+ var builder;
2498
+
2668
2499
  if ( !options.strict ) {
2669
2500
  // ensure there are no named imports/exports
2670
2501
  if ( hasNamedExports( bundle.entryModule ) ) {