esperanto-source 0.6.22 → 0.6.23

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.22 - 2015-03-30
2
+ esperanto.js v0.6.23 - 2015-03-31
3
3
  http://esperantojs.org
4
4
 
5
5
  Released under the MIT License.
@@ -9,10 +9,11 @@
9
9
 
10
10
  var acorn = require('acorn');
11
11
  var MagicString = require('magic-string');
12
- var path = require('path');
12
+ var _path = require('path');
13
13
  var sander = require('sander');
14
14
 
15
15
  var hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var utils_hasOwnProp = hasOwnProp;
16
17
 
17
18
  function hasNamedImports ( mod ) {
18
19
  var i = mod.imports.length;
@@ -38,27 +39,27 @@ function walk ( ast, leave) {var enter = leave.enter, leave = leave.leave;
38
39
  visit( ast, null, enter, leave );
39
40
  }
40
41
 
41
- var walk__context = {
42
- skip: function() {return walk__context.shouldSkip = true}
42
+ var ast_walk__context = {
43
+ skip: function() {return ast_walk__context.shouldSkip = true}
43
44
  };
44
45
 
45
- var walk__childKeys = {};
46
+ var ast_walk__childKeys = {};
46
47
 
47
- var walk__toString = Object.prototype.toString;
48
+ var ast_walk__toString = Object.prototype.toString;
48
49
 
49
50
  function isArray ( thing ) {
50
- return walk__toString.call( thing ) === '[object Array]';
51
+ return ast_walk__toString.call( thing ) === '[object Array]';
51
52
  }
52
53
 
53
54
  function visit ( node, parent, enter, leave ) {
54
55
  if ( enter ) {
55
- walk__context.shouldSkip = false;
56
- enter.call( walk__context, node, parent );
57
- if ( walk__context.shouldSkip ) return;
56
+ ast_walk__context.shouldSkip = false;
57
+ enter.call( ast_walk__context, node, parent );
58
+ if ( ast_walk__context.shouldSkip ) return;
58
59
  }
59
60
 
60
- var keys = walk__childKeys[ node.type ] || (
61
- walk__childKeys[ node.type ] = Object.keys( node ).filter( function(key ) {return typeof node[ key ] === 'object'} )
61
+ var keys = ast_walk__childKeys[ node.type ] || (
62
+ ast_walk__childKeys[ node.type ] = Object.keys( node ).filter( function(key ) {return typeof node[ key ] === 'object'} )
62
63
  );
63
64
 
64
65
  var key, value, i, j;
@@ -85,6 +86,30 @@ function visit ( node, parent, enter, leave ) {
85
86
  }
86
87
  }
87
88
 
89
+ function getId ( m ) {
90
+ return m.id;
91
+ }
92
+
93
+ function getName ( m ) {
94
+ return m.name;
95
+ }
96
+
97
+ function quote ( str ) {
98
+ return "'" + JSON.stringify(str).slice(1, -1).replace(/'/g, "\\'") + "'";
99
+ }
100
+
101
+ function req ( path ) {
102
+ return 'require(' + quote(path) + ')';
103
+ }
104
+
105
+ function globalify ( name ) {
106
+ if ( /^__dep\d+__$/.test( name ) ) {
107
+ return 'undefined';
108
+ } else {
109
+ return 'global.' + name;
110
+ }
111
+ }
112
+
88
113
  /*
89
114
  This module traverse a module's AST, attaching scope information
90
115
  to nodes as it goes, which is later used to determine which
@@ -154,9 +179,13 @@ function annotateAst ( ast ) {
154
179
  }
155
180
  }
156
181
 
182
+ var names = node.params.map( getName );
183
+
184
+ names.forEach( function(name ) {return declared[ name ] = true} );
185
+
157
186
  scope = node._scope = new Scope({
158
187
  parent: scope,
159
- params: node.params.map( function(x ) {return x.name} ) // TODO rest params?
188
+ params: names // TODO rest params?
160
189
  });
161
190
 
162
191
  break;
@@ -476,7 +505,7 @@ function getUnscopedNames ( mod ) {
476
505
  });
477
506
  });
478
507
  }
479
- return hasOwnProp.call( importedNames, name );
508
+ return utils_hasOwnProp.call( importedNames, name );
480
509
  }
481
510
 
482
511
  walk( mod.ast, {
@@ -528,7 +557,7 @@ function disallowConflictingImports ( imports ) {
528
557
  }
529
558
 
530
559
  function checkName ( name ) {
531
- if ( hasOwnProp.call( usedNames, name ) ) {
560
+ if ( utils_hasOwnProp.call( usedNames, name ) ) {
532
561
  throw new SyntaxError( (("Duplicated import ('" + name) + "')") );
533
562
  }
534
563
 
@@ -573,7 +602,7 @@ function getStandaloneModule ( options ) {
573
602
  sourceType: 'module',
574
603
  onComment: function ( block, text, start, end ) {
575
604
  // sourceMappingURL comments should be removed
576
- if ( !block && /^# sourceMappingURL=/.test( text ) ) {
605
+ if ( !block && SOURCEMAPPINGURL_REGEX.test( text ) ) {
577
606
  toRemove.push({ start: start, end: end });
578
607
  }
579
608
  }
@@ -616,7 +645,7 @@ function determineImportNames ( imports, userFn, usedNames ) {
616
645
  moduleId = x.path;
617
646
 
618
647
  // use existing value
619
- if ( hasOwnProp.call( nameById, moduleId ) ) {
648
+ if ( utils_hasOwnProp.call( nameById, moduleId ) ) {
620
649
  x.name = nameById[ moduleId ];
621
650
  return;
622
651
  }
@@ -625,9 +654,9 @@ function determineImportNames ( imports, userFn, usedNames ) {
625
654
  if ( userFn && ( name = userFn( moduleId ) ) ) {
626
655
  name = sanitize( name );
627
656
 
628
- if ( hasOwnProp.call( usedNames, name ) ) {
657
+ if ( utils_hasOwnProp.call( usedNames, name ) ) {
629
658
  // TODO write a test for this
630
- throw new Error( 'Naming collision: module ' + moduleId + ' cannot be called ' + name );
659
+ throw new Error( (("Naming collision: module " + moduleId) + (" cannot be called " + name) + "") );
631
660
  }
632
661
  }
633
662
 
@@ -639,7 +668,7 @@ function determineImportNames ( imports, userFn, usedNames ) {
639
668
  while ( i-- > 0 ) {
640
669
  candidate = prefix + sanitize( parts.slice( i ).join( '__' ) );
641
670
 
642
- if ( !hasOwnProp.call( usedNames, candidate ) ) {
671
+ if ( !utils_hasOwnProp.call( usedNames, candidate ) ) {
643
672
  name = candidate;
644
673
  break;
645
674
  }
@@ -658,13 +687,13 @@ function determineImportNames ( imports, userFn, usedNames ) {
658
687
  // use inferred names for default imports, wherever they
659
688
  // don't clash with path-based names
660
689
  imports.forEach( function(x ) {
661
- if ( x.as && !hasOwnProp.call( usedNames, x.as ) ) {
690
+ if ( x.as && !utils_hasOwnProp.call( usedNames, x.as ) ) {
662
691
  inferredNames[ x.path ] = x.as;
663
692
  }
664
693
  });
665
694
 
666
695
  imports.forEach( function(x ) {
667
- if ( hasOwnProp.call( inferredNames, x.path ) ) {
696
+ if ( utils_hasOwnProp.call( inferredNames, x.path ) ) {
668
697
  x.name = inferredNames[ x.path ];
669
698
  }
670
699
  });
@@ -712,7 +741,7 @@ function sortModules ( entry, moduleLookup ) {
712
741
  function visit ( mod ) {
713
742
  // ignore external modules, and modules we've
714
743
  // already included
715
- if ( !mod || hasOwnProp.call( seen, mod.id ) ) {
744
+ if ( !mod || utils_hasOwnProp.call( seen, mod.id ) ) {
716
745
  return;
717
746
  }
718
747
 
@@ -742,7 +771,7 @@ function resolveChains ( modules, moduleLookup ) {
742
771
  if ( s.isBatch ) {
743
772
  // if this is an internal module, we need to tell that module that
744
773
  // it needs to export an object full of getters
745
- if ( hasOwnProp.call( moduleLookup, x.id ) ) {
774
+ if ( utils_hasOwnProp.call( moduleLookup, x.id ) ) {
746
775
  moduleLookup[ x.id ]._exportsNamespace = true;
747
776
  }
748
777
 
@@ -757,7 +786,7 @@ function resolveChains ( modules, moduleLookup ) {
757
786
  if ( !x.specifiers ) return;
758
787
 
759
788
  x.specifiers.forEach( function(s ) {
760
- if ( hasOwnProp.call( origin, s.name ) ) {
789
+ if ( utils_hasOwnProp.call( origin, s.name ) ) {
761
790
  chains[ mod.id + '@' + s.name ] = origin[ s.name ];
762
791
  }
763
792
  });
@@ -771,28 +800,37 @@ function resolveChains ( modules, moduleLookup ) {
771
800
  // we add `exports` to this list, to avoid conflicst
772
801
  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( ' ' );
773
802
 
774
- function getUniqueNames ( modules, externalModules, userNames ) {
775
- var names = {}, used = {};
803
+ function getUniqueNames ( bundle ) {
804
+ var modules = bundle.modules, externalModules = bundle.externalModules;
805
+ var userNames = bundle.names;
806
+ var names = {};
807
+
808
+ var used = modules.reduce( function( declared, mod ) {
809
+ Object.keys( mod.ast._declared ).forEach( function(x ) {return declared[x] = true} );
810
+ return declared;
811
+ }, {} );
776
812
 
777
813
  // copy builtins
778
814
  builtins.forEach( function(n ) {return used[n] = true} );
779
815
 
780
816
  // copy user-specified names
781
817
  if ( userNames ) {
782
- Object.keys( userNames ).forEach( function(n ) {
783
- names[n] = userNames[n];
784
- used[ userNames[n] ] = true;
818
+ Object.keys( userNames ).forEach( function(id ) {
819
+ names[ id ] = userNames[ id ];
820
+ used[ userNames[ id ] ] = true;
785
821
  });
786
822
  }
787
823
 
788
- // infer names from default imports
824
+ // infer names from default imports - e.g. with `import _ from './utils'`,
825
+ // use '_' instead of generating a name from 'utils'
826
+ function inferName ( x ) {
827
+ if ( x.isDefault && !utils_hasOwnProp.call( names, x.id ) && !utils_hasOwnProp.call( used, x.as ) ) {
828
+ names[ x.id ] = x.as;
829
+ used[ x.as ] = true;
830
+ }
831
+ }
789
832
  modules.forEach( function(mod ) {
790
- mod.imports.forEach( function(x ) {
791
- if ( x.isDefault && !hasOwnProp.call( names, x.id ) && !hasOwnProp.call( used, x.as ) ) {
792
- names[ x.id ] = x.as;
793
- used[ x.as ] = true;
794
- }
795
- });
833
+ mod.imports.forEach( inferName );
796
834
  });
797
835
 
798
836
  // for the rest, make names as compact as possible without
@@ -801,7 +839,8 @@ function getUniqueNames ( modules, externalModules, userNames ) {
801
839
  var parts, i, name;
802
840
 
803
841
  // is this already named?
804
- if ( hasOwnProp.call( names, mod.id ) ) {
842
+ if ( utils_hasOwnProp.call( names, mod.id ) ) {
843
+ mod.name = names[ mod.id ];
805
844
  return;
806
845
  }
807
846
 
@@ -811,17 +850,17 @@ function getUniqueNames ( modules, externalModules, userNames ) {
811
850
  while ( i-- ) {
812
851
  name = sanitize( parts.slice( i ).join( '_' ) );
813
852
 
814
- if ( !hasOwnProp.call( used, name ) ) {
853
+ if ( !utils_hasOwnProp.call( used, name ) ) {
815
854
  break;
816
855
  }
817
856
  }
818
857
 
819
- while ( hasOwnProp.call( used, name ) ) {
858
+ while ( utils_hasOwnProp.call( used, name ) ) {
820
859
  name = '_' + name;
821
860
  }
822
861
 
823
862
  used[ name ] = true;
824
- names[ mod.id ] = name;
863
+ mod.name = name;
825
864
  });
826
865
 
827
866
  return names;
@@ -847,30 +886,6 @@ function populateExternalModuleImports ( bundle ) {
847
886
  });
848
887
  }
849
888
 
850
- function getId ( m ) {
851
- return m.id;
852
- }
853
-
854
- function getName ( m ) {
855
- return m.name;
856
- }
857
-
858
- function quote ( str ) {
859
- return "'" + JSON.stringify(str).slice(1, -1).replace(/'/g, "\\'") + "'";
860
- }
861
-
862
- function req ( path ) {
863
- return 'require(' + quote(path) + ')';
864
- }
865
-
866
- function globalify ( name ) {
867
- if ( /^__dep\d+__$/.test( name ) ) {
868
- return 'undefined';
869
- } else {
870
- return 'global.' + name;
871
- }
872
- }
873
-
874
889
  function getRenamedImports ( mod ) {
875
890
  var renamed = [];
876
891
 
@@ -910,7 +925,7 @@ function topLevelScopeConflicts ( bundle ) {
910
925
 
911
926
  // merge this module's top scope with bundle top scope
912
927
  names.forEach( function(name ) {
913
- if ( hasOwnProp.call( inBundle, name ) ) {
928
+ if ( utils_hasOwnProp.call( inBundle, name ) ) {
914
929
  conflicts[ name ] = true;
915
930
  } else {
916
931
  inBundle[ name ] = true;
@@ -934,11 +949,11 @@ function populateIdentifierReplacements ( bundle ) {
934
949
  var result;
935
950
 
936
951
  if ( x.hasDeclaration && x.name ) {
937
- result = hasOwnProp.call( conflicts, x.name ) || otherModulesDeclare( mod, x.name ) ?
952
+ result = utils_hasOwnProp.call( conflicts, x.name ) || otherModulesDeclare( mod, x.name ) ?
938
953
  (("" + (mod.name)) + ("__" + (x.name)) + "") :
939
954
  x.name;
940
955
  } else {
941
- result = hasOwnProp.call( conflicts, mod.name ) || ( x.value !== mod.name && ~mod.ast._topLevelNames.indexOf( mod.name )) || otherModulesDeclare( mod, mod.name ) ?
956
+ result = utils_hasOwnProp.call( conflicts, mod.name ) || ( x.value !== mod.name && ~mod.ast._topLevelNames.indexOf( mod.name )) || otherModulesDeclare( mod, mod.name ) ?
942
957
  (("" + (mod.name)) + "__default") :
943
958
  mod.name;
944
959
  }
@@ -955,7 +970,7 @@ function populateIdentifierReplacements ( bundle ) {
955
970
  moduleIdentifiers = mod.identifierReplacements;
956
971
 
957
972
  mod.ast._topLevelNames.forEach( function(n ) {
958
- moduleIdentifiers[n] = hasOwnProp.call( conflicts, n ) ?
973
+ moduleIdentifiers[n] = utils_hasOwnProp.call( conflicts, n ) ?
959
974
  mod.name + '__' + n :
960
975
  n;
961
976
  });
@@ -967,7 +982,7 @@ function populateIdentifierReplacements ( bundle ) {
967
982
  return;
968
983
  }
969
984
 
970
- externalModule = hasOwnProp.call( bundle.externalModuleLookup, x.id ) && bundle.externalModuleLookup[ x.id ];
985
+ externalModule = utils_hasOwnProp.call( bundle.externalModuleLookup, x.id ) && bundle.externalModuleLookup[ x.id ];
971
986
 
972
987
  x.specifiers.forEach( function(s ) {
973
988
  var moduleId, mod, moduleName, specifierName, replacement, hash, isChained, separatorIndex;
@@ -983,7 +998,7 @@ function populateIdentifierReplacements ( bundle ) {
983
998
 
984
999
  // If this is a chained import, get the origin
985
1000
  hash = moduleId + '@' + specifierName;
986
- while ( hasOwnProp.call( bundle.chains, hash ) ) {
1001
+ while ( utils_hasOwnProp.call( bundle.chains, hash ) ) {
987
1002
  hash = bundle.chains[ hash ];
988
1003
  isChained = true;
989
1004
  }
@@ -1011,7 +1026,7 @@ function populateIdentifierReplacements ( bundle ) {
1011
1026
  replacement = mod.identifierReplacements.default;
1012
1027
  }
1013
1028
  } else if ( !externalModule ) {
1014
- replacement = hasOwnProp.call( conflicts, specifierName ) ?
1029
+ replacement = utils_hasOwnProp.call( conflicts, specifierName ) ?
1015
1030
  moduleName + '__' + specifierName :
1016
1031
  specifierName;
1017
1032
  } else {
@@ -1037,7 +1052,7 @@ function populateIdentifierReplacements ( bundle ) {
1037
1052
  continue;
1038
1053
  }
1039
1054
 
1040
- if ( hasOwnProp.call( otherMod.ast._declared, replacement ) ) {
1055
+ if ( utils_hasOwnProp.call( otherMod.ast._declared, replacement ) ) {
1041
1056
  return true;
1042
1057
  }
1043
1058
  }
@@ -1066,12 +1081,6 @@ function resolveExports ( bundle ) {
1066
1081
  name = split[1];
1067
1082
 
1068
1083
  addExport( moduleId, name, s.name );
1069
-
1070
- // if ( !bundleExports[ moduleId ] ) {
1071
- // bundleExports[ moduleId ] = {};
1072
- // }
1073
-
1074
- // bundleExports[ moduleId ][ name ] = s.name;
1075
1084
  });
1076
1085
  }
1077
1086
 
@@ -1142,14 +1151,14 @@ function disallowIllegalReassignment ( node, importedBindings, importedNamespace
1142
1151
 
1143
1152
  name = assignee.name;
1144
1153
 
1145
- if ( hasOwnProp.call( isNamespaceAssignment ? importedNamespaces : importedBindings, name ) && !scope.contains( name ) ) {
1154
+ if ( utils_hasOwnProp.call( isNamespaceAssignment ? importedNamespaces : importedBindings, name ) && !scope.contains( name ) ) {
1146
1155
  throw new Error( ( isNamespaceAssignment ? namespaceMessage : bindingMessage ) + '`' + name + '`' );
1147
1156
  }
1148
1157
  }
1149
1158
 
1150
1159
  function replaceIdentifiers ( body, node, identifierReplacements, scope ) {
1151
1160
  var name = node.name;
1152
- var replacement = hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
1161
+ var replacement = utils_hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
1153
1162
 
1154
1163
  // TODO unchanged identifiers shouldn't have got this far -
1155
1164
  // remove the `replacement !== name` safeguard once that's the case
@@ -1159,7 +1168,7 @@ function replaceIdentifiers ( body, node, identifierReplacements, scope ) {
1159
1168
  }
1160
1169
  }
1161
1170
 
1162
- function rewriteExportAssignments ( body, node, exports, scope, alreadyExported, isTopLevelNode, capturedUpdates ) {
1171
+ function rewriteExportAssignments ( body, node, exports, scope, capturedUpdates ) {
1163
1172
  var assignee, name, exportAs;
1164
1173
 
1165
1174
  if ( node.type === 'AssignmentExpression' ) {
@@ -1180,7 +1189,7 @@ function rewriteExportAssignments ( body, node, exports, scope, alreadyExported,
1180
1189
  return; // shadows an export
1181
1190
  }
1182
1191
 
1183
- if ( exports && hasOwnProp.call( exports, name ) && ( exportAs = exports[ name ] ) ) {
1192
+ if ( exports && utils_hasOwnProp.call( exports, name ) && ( exportAs = exports[ name ] ) ) {
1184
1193
  if ( !!capturedUpdates ) {
1185
1194
  capturedUpdates.push({
1186
1195
  name: name,
@@ -1195,16 +1204,10 @@ function rewriteExportAssignments ( body, node, exports, scope, alreadyExported,
1195
1204
  } else {
1196
1205
  body.replace( node.start, node.start, (("exports." + exportAs) + " = ") );
1197
1206
  }
1198
-
1199
- // keep track of what we've already exported - we don't need to
1200
- // export it again later
1201
- if ( isTopLevelNode ) {
1202
- alreadyExported[ name ] = true;
1203
- }
1204
1207
  }
1205
1208
  }
1206
1209
 
1207
- function traverseAst ( ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames, alreadyExported ) {
1210
+ function traverseAst ( ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames ) {
1208
1211
  var scope = ast._scope,
1209
1212
  blockScope = ast._blockScope,
1210
1213
  capturedUpdates = null,
@@ -1236,9 +1239,11 @@ function traverseAst ( ast, body, identifierReplacements, importedBindings, impo
1236
1239
  // Catch illegal reassignments
1237
1240
  disallowIllegalReassignment( node, importedBindings, importedNamespaces, scope );
1238
1241
 
1239
- // Rewrite assignments to exports. This call may mutate `alreadyExported`
1240
- // and `capturedUpdates`, which are used elsewhere
1241
- rewriteExportAssignments( body, node, exportNames, scope, alreadyExported, scope === ast._scope, capturedUpdates );
1242
+ // Rewrite assignments to exports inside functions, to keep bindings live.
1243
+ // This call may mutate `capturedUpdates`, which is used elsewhere
1244
+ if ( scope !== ast._scope ) {
1245
+ rewriteExportAssignments( body, node, exportNames, scope, capturedUpdates );
1246
+ }
1242
1247
 
1243
1248
  if ( node.type === 'Identifier' && parent.type !== 'FunctionExpression' ) {
1244
1249
  replaceIdentifiers( body, node, identifierReplacements, scope );
@@ -1273,21 +1278,20 @@ function exportCapturedUpdate ( c ) {
1273
1278
  return ((" exports." + (c.name)) + (" = " + (c.exportAs)) + ";");
1274
1279
  }
1275
1280
 
1276
- function transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1281
+ function combine_transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1277
1282
  var identifierReplacements,
1278
1283
  importedBindings,
1279
1284
  importedNamespaces,
1280
1285
  exportNames,
1281
- alreadyExported = {},
1282
1286
  shouldExportEarly = {},
1283
1287
  exportBlock;
1284
1288
 
1285
1289
  identifierReplacements = mod.identifierReplacements;
1286
1290
  importedBindings = ($D$0 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$0[1], $D$0;
1287
1291
 
1288
- exportNames = hasOwnProp.call( bundle.exports, mod.id ) && bundle.exports[ mod.id ];
1292
+ exportNames = utils_hasOwnProp.call( bundle.exports, mod.id ) && bundle.exports[ mod.id ];
1289
1293
 
1290
- traverseAst( mod.ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames, alreadyExported );
1294
+ traverseAst( mod.ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames );
1291
1295
 
1292
1296
  // Remove import statements
1293
1297
  mod.imports.forEach( function(x ) {
@@ -1321,7 +1325,7 @@ function transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1321
1325
  if ( name === identifierReplacements.default ) {
1322
1326
  body.remove( x.start, x.end );
1323
1327
  } else {
1324
- var original = hasOwnProp.call( identifierReplacements, name ) ? identifierReplacements[ name ] : name;
1328
+ var original = utils_hasOwnProp.call( identifierReplacements, name ) ? identifierReplacements[ name ] : name;
1325
1329
  body.replace( x.start, x.end, (("var " + (identifierReplacements.default)) + (" = " + original) + ";") );
1326
1330
  }
1327
1331
  }
@@ -1380,12 +1384,8 @@ function transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1380
1384
  exportBlock = [];
1381
1385
 
1382
1386
  Object.keys( exportNames ).forEach( function(name ) {
1383
- var exportAs;
1384
-
1385
- if ( !alreadyExported[ name ] ) {
1386
- exportAs = exportNames[ name ];
1387
- exportBlock.push( (("exports." + exportAs) + (" = " + (identifierReplacements[name])) + ";") );
1388
- }
1387
+ var exportAs = exportNames[ name ];
1388
+ exportBlock.push( (("exports." + exportAs) + (" = " + (identifierReplacements[name])) + ";") );
1389
1389
  });
1390
1390
 
1391
1391
  if ( exportBlock.length ) {
@@ -1397,17 +1397,12 @@ function transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1397
1397
  ;$D$0 = void 0}
1398
1398
 
1399
1399
  function combine ( bundle ) {
1400
- var body;
1401
-
1402
- body = new MagicString.Bundle({
1400
+ bundle.body = new MagicString.Bundle({
1403
1401
  separator: '\n\n'
1404
1402
  });
1405
1403
 
1406
- // populate names
1407
- var uniqueNames = getUniqueNames( bundle.modules, bundle.externalModules, bundle.names );
1408
- var setName = function(mod ) {return mod.name = uniqueNames[ mod.id ]};
1409
- bundle.modules.forEach( setName );
1410
- bundle.externalModules.forEach( setName );
1404
+ // give each module in the bundle a unique name
1405
+ getUniqueNames( bundle );
1411
1406
 
1412
1407
  // determine which specifiers are imported from
1413
1408
  // external modules
@@ -1430,19 +1425,17 @@ function combine ( bundle ) {
1430
1425
 
1431
1426
  x.specifiers.forEach( function(s ) {
1432
1427
  if ( !importedModule.doesExport[ s.name ] ) {
1433
- throw new Error( 'Module ' + importedModule.id + ' does not export ' + s.name + ' (imported by ' + mod.id + ')' );
1428
+ throw new Error( (("Module '" + (importedModule.id)) + ("' does not export '" + (s.name)) + ("' (imported by '" + (mod.id)) + "')") );
1434
1429
  }
1435
1430
  });
1436
1431
  });
1437
1432
 
1438
- body.addSource({
1439
- filename: path.resolve( bundle.base, mod.relativePath ),
1440
- content: transformBody__transformBody( bundle, mod, mod.body ),
1433
+ bundle.body.addSource({
1434
+ filename: _path.resolve( bundle.base, mod.relativePath ),
1435
+ content: combine_transformBody__transformBody( bundle, mod, mod.body ),
1441
1436
  indentExclusionRanges: mod.ast._templateLiteralRanges
1442
1437
  });
1443
1438
  });
1444
-
1445
- bundle.body = body;
1446
1439
  }
1447
1440
 
1448
1441
  function getModule ( mod ) {var $D$1;
@@ -1514,7 +1507,7 @@ function getModule ( mod ) {var $D$1;
1514
1507
  return mod;
1515
1508
  ;$D$1 = void 0}
1516
1509
 
1517
- var getBundle__Promise = sander.Promise;
1510
+ var bundler_getBundle__Promise = sander.Promise;
1518
1511
 
1519
1512
  function getBundle ( options ) {
1520
1513
  var entry = options.entry.replace( /\.js$/, '' ),
@@ -1523,7 +1516,7 @@ function getBundle ( options ) {
1523
1516
  promiseByPath = {},
1524
1517
  skip = options.skip,
1525
1518
  names = options.names,
1526
- base = ( options.base ? path.resolve( options.base ) : process.cwd() ) + '/',
1519
+ base = ( options.base ? _path.resolve( options.base ) : process.cwd() ) + '/',
1527
1520
  externalModules = [],
1528
1521
  externalModuleLookup = {};
1529
1522
 
@@ -1564,7 +1557,7 @@ function getBundle ( options ) {
1564
1557
  });
1565
1558
 
1566
1559
  function fetchModule ( moduleId, modulePath ) {
1567
- if ( !hasOwnProp.call( promiseByPath, modulePath ) ) {
1560
+ if ( !utils_hasOwnProp.call( promiseByPath, modulePath ) ) {
1568
1561
  promiseByPath[ modulePath ] = sander.readFile( modulePath ).then( String ).then( function ( source ) {
1569
1562
  var module, promises;
1570
1563
 
@@ -1579,7 +1572,7 @@ function getBundle ( options ) {
1579
1572
  module = getModule({
1580
1573
  source: source,
1581
1574
  id: moduleId,
1582
- relativePath: path.relative( base, modulePath ),
1575
+ relativePath: _path.relative( base, modulePath ),
1583
1576
  path: modulePath
1584
1577
  });
1585
1578
 
@@ -1600,7 +1593,7 @@ function getBundle ( options ) {
1600
1593
 
1601
1594
  return resolvePath( base, x.id, modulePath, options.resolvePath ).then( function(modulePath ) {
1602
1595
  // short-circuit cycles
1603
- if ( hasOwnProp.call( promiseByPath, modulePath ) ) {
1596
+ if ( utils_hasOwnProp.call( promiseByPath, modulePath ) ) {
1604
1597
  return;
1605
1598
  }
1606
1599
 
@@ -1608,7 +1601,7 @@ function getBundle ( options ) {
1608
1601
  }, function handleError ( err ) {
1609
1602
  if ( err.code === 'ENOENT' ) {
1610
1603
  // Most likely an external module
1611
- if ( !hasOwnProp.call( externalModuleLookup, x.id ) ) {
1604
+ if ( !utils_hasOwnProp.call( externalModuleLookup, x.id ) ) {
1612
1605
  var externalModule = {
1613
1606
  id: x.id
1614
1607
  };
@@ -1622,7 +1615,7 @@ function getBundle ( options ) {
1622
1615
  } );
1623
1616
  });
1624
1617
 
1625
- return getBundle__Promise.all( promises );
1618
+ return bundler_getBundle__Promise.all( promises );
1626
1619
  });
1627
1620
  }
1628
1621
 
@@ -1631,9 +1624,9 @@ function getBundle ( options ) {
1631
1624
  }
1632
1625
 
1633
1626
  function resolvePath ( base, moduleId, importerPath, resolver ) {
1634
- return tryPath( path.resolve( base, moduleId + '.js' ) )
1627
+ return tryPath( _path.resolve( base, moduleId + '.js' ) )
1635
1628
  .catch( function () {
1636
- return tryPath( path.resolve( base, moduleId, 'index.js' ) );
1629
+ return tryPath( _path.resolve( base, moduleId, 'index.js' ) );
1637
1630
  })
1638
1631
  .catch( function ( err ) {
1639
1632
  if ( resolver ) {
@@ -1824,9 +1817,9 @@ function template ( str ) {
1824
1817
  };
1825
1818
  }
1826
1819
 
1827
- var amd__introTemplate = template( 'define(<%= amdName %><%= paths %>function (<%= names %>) {\n\n' );
1820
+ var defaultsMode_amd__introTemplate = template( 'define(<%= amdName %><%= paths %>function (<%= names %>) {\n\n' );
1828
1821
 
1829
- function amd__amd ( mod, options ) {
1822
+ function defaultsMode_amd__amd ( mod, options ) {
1830
1823
  var seen = {},
1831
1824
  importNames = [],
1832
1825
  importPaths = [],
@@ -1837,7 +1830,7 @@ function amd__amd ( mod, options ) {
1837
1830
  mod.imports.forEach( function(x ) {
1838
1831
  var path = options.absolutePaths ? resolveId( x.path, options.amdName ) : x.path;
1839
1832
 
1840
- if ( !hasOwnProp.call( seen, path ) ) {
1833
+ if ( !utils_hasOwnProp.call( seen, path ) ) {
1841
1834
  importPaths.push( path );
1842
1835
 
1843
1836
  if ( x.as ) {
@@ -1858,7 +1851,7 @@ function amd__amd ( mod, options ) {
1858
1851
 
1859
1852
  transformExportDeclaration( mod.exports[0], mod.body );
1860
1853
 
1861
- intro = amd__introTemplate({
1854
+ intro = defaultsMode_amd__introTemplate({
1862
1855
  amdName: options.amdName ? (("'" + (options.amdName)) + "', ") : '',
1863
1856
  paths: importPaths.length ? '[' + importPaths.map( quote ).join( ', ' ) + '], ' : '',
1864
1857
  names: importNames.join( ', ' )
@@ -1874,11 +1867,11 @@ function amd__amd ( mod, options ) {
1874
1867
  return packageResult( mod, mod.body, options, 'toAmd' );
1875
1868
  }
1876
1869
 
1877
- function cjs__cjs ( mod, options ) {
1870
+ function defaultsMode_cjs__cjs ( mod, options ) {
1878
1871
  var seen = {}, exportDeclaration;
1879
1872
 
1880
1873
  mod.imports.forEach( function(x ) {
1881
- if ( !hasOwnProp.call( seen, x.path ) ) {
1874
+ if ( !utils_hasOwnProp.call( seen, x.path ) ) {
1882
1875
  var replacement = x.isEmpty ? (("" + (req(x.path))) + ";") : (("var " + (x.as)) + (" = " + (req(x.path))) + ";");
1883
1876
  mod.body.replace( x.start, x.end, replacement );
1884
1877
 
@@ -1975,15 +1968,17 @@ EsperantoError.prototype = new Error();
1975
1968
  EsperantoError.prototype.constructor = EsperantoError;
1976
1969
  EsperantoError.prototype.name = 'EsperantoError';
1977
1970
 
1971
+ var utils_EsperantoError = EsperantoError;
1972
+
1978
1973
  function requireName ( options ) {
1979
1974
  if ( !options.name ) {
1980
- throw new EsperantoError( 'You must supply a `name` option for UMD modules', {
1975
+ throw new utils_EsperantoError( 'You must supply a `name` option for UMD modules', {
1981
1976
  code: 'MISSING_NAME'
1982
1977
  });
1983
1978
  }
1984
1979
  }
1985
1980
 
1986
- function umd__umd ( mod, options ) {
1981
+ function defaultsMode_umd__umd ( mod, options ) {
1987
1982
  var importNames = [];
1988
1983
  var importPaths = [];
1989
1984
  var seen = {};
@@ -2002,7 +1997,7 @@ function umd__umd ( mod, options ) {
2002
1997
  } else {
2003
1998
  // gather imports, and remove import declarations
2004
1999
  mod.imports.forEach( function(x ) {
2005
- if ( !hasOwnProp.call( seen, x.path ) ) {
2000
+ if ( !utils_hasOwnProp.call( seen, x.path ) ) {
2006
2001
  importPaths.push( x.path );
2007
2002
 
2008
2003
  if ( x.as ) {
@@ -2039,9 +2034,9 @@ function umd__umd ( mod, options ) {
2039
2034
  }
2040
2035
 
2041
2036
  var defaultsMode = {
2042
- amd: amd__amd,
2043
- cjs: cjs__cjs,
2044
- umd: umd__umd
2037
+ amd: defaultsMode_amd__amd,
2038
+ cjs: defaultsMode_cjs__cjs,
2039
+ umd: defaultsMode_umd__umd
2045
2040
  };
2046
2041
 
2047
2042
  function gatherImports ( imports ) {
@@ -2094,7 +2089,6 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2094
2089
  importedBindings = {},
2095
2090
  importedNamespaces = {},
2096
2091
  exportNames,
2097
- alreadyExported = {},
2098
2092
  earlyExports,
2099
2093
  lateExports;
2100
2094
 
@@ -2106,7 +2100,7 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2106
2100
  // ensure no conflict with `exports`
2107
2101
  identifierReplacements.exports = deconflict( 'exports', mod.ast._declared );
2108
2102
 
2109
- traverseAst( mod.ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames, alreadyExported );
2103
+ traverseAst( mod.ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames );
2110
2104
 
2111
2105
  // Remove import statements from the body of the module
2112
2106
  mod.imports.forEach( function(x ) {
@@ -2173,7 +2167,7 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2173
2167
  // functions should be exported early, in
2174
2168
  // case of cyclic dependencies
2175
2169
  earlyExports.push( (("exports." + exportAs) + (" = " + name) + ";") );
2176
- } else if ( !alreadyExported.hasOwnProperty( name ) ) {
2170
+ } else {
2177
2171
  lateExports.push( (("exports." + exportAs) + (" = " + name) + ";") );
2178
2172
  }
2179
2173
  });
@@ -2194,7 +2188,7 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2194
2188
  ;$D$2 = void 0}
2195
2189
 
2196
2190
  function deconflict ( name, declared ) {
2197
- while ( hasOwnProp.call( declared, name ) ) {
2191
+ while ( utils_hasOwnProp.call( declared, name ) ) {
2198
2192
  name = '_' + name;
2199
2193
  }
2200
2194
 
@@ -2205,7 +2199,7 @@ function getImportSummary ( mod ) {
2205
2199
  var importPaths = [], importNames = [], seen = {}, placeholders = 0;
2206
2200
 
2207
2201
  mod.imports.forEach( function(x ) {
2208
- if ( !hasOwnProp.call( seen, x.path ) ) {
2202
+ if ( !utils_hasOwnProp.call( seen, x.path ) ) {
2209
2203
  importPaths.push( x.path );
2210
2204
 
2211
2205
  if ( x.specifiers.length ) {
@@ -2263,7 +2257,7 @@ function strictMode_cjs__cjs ( mod, options ) {
2263
2257
  importBlock = mod.imports.map( function(x ) {
2264
2258
  var name, replacement;
2265
2259
 
2266
- if ( !hasOwnProp.call( seen, x.path ) ) {
2260
+ if ( !utils_hasOwnProp.call( seen, x.path ) ) {
2267
2261
  if ( x.isEmpty ) {
2268
2262
  replacement = (("" + (req(x.path))) + ";");
2269
2263
  } else {
@@ -2367,15 +2361,15 @@ var moduleBuilders = {
2367
2361
  strictMode: strictMode
2368
2362
  };
2369
2363
 
2370
- var defaultsMode_amd__introTemplate = template( 'define(<%= amdName %><%= amdDeps %>function (<%= names %>) {\n\n\t\'use strict\';\n\n' );
2364
+ var builders_defaultsMode_amd__introTemplate = template( 'define(<%= amdName %><%= amdDeps %>function (<%= names %>) {\n\n\t\'use strict\';\n\n' );
2371
2365
 
2372
- function defaultsMode_amd__amd ( bundle, options ) {
2366
+ function builders_defaultsMode_amd__amd ( bundle, options ) {
2373
2367
  var defaultName = bundle.entryModule.identifierReplacements.default;
2374
2368
  if ( defaultName ) {
2375
2369
  bundle.body.append( (("\n\nreturn " + defaultName) + ";") );
2376
2370
  }
2377
2371
 
2378
- var intro = defaultsMode_amd__introTemplate({
2372
+ var intro = builders_defaultsMode_amd__introTemplate({
2379
2373
  amdName: options.amdName ? (("" + (quote(options.amdName))) + ", ") : '',
2380
2374
  amdDeps: bundle.externalModules.length ? '[' + bundle.externalModules.map( quoteId ).join( ', ' ) + '], ' : '',
2381
2375
  names: bundle.externalModules.map( getName ).join( ', ' )
@@ -2389,7 +2383,7 @@ function quoteId ( m ) {
2389
2383
  return "'" + m.id + "'";
2390
2384
  }
2391
2385
 
2392
- function defaultsMode_cjs__cjs ( bundle, options ) {
2386
+ function builders_defaultsMode_cjs__cjs ( bundle, options ) {
2393
2387
  var importBlock = bundle.externalModules.map( function(x ) {
2394
2388
  return (("var " + (x.name)) + (" = " + (req(x.id))) + ";");
2395
2389
  }).join( '\n' );
@@ -2408,7 +2402,7 @@ function defaultsMode_cjs__cjs ( bundle, options ) {
2408
2402
  return packageResult( bundle, bundle.body, options, 'toCjs', true );
2409
2403
  }
2410
2404
 
2411
- function defaultsMode_umd__umd ( bundle, options ) {
2405
+ function builders_defaultsMode_umd__umd ( bundle, options ) {
2412
2406
  requireName( options );
2413
2407
 
2414
2408
  var entry = bundle.entryModule;
@@ -2446,9 +2440,9 @@ function defaultsMode_umd__umd ( bundle, options ) {
2446
2440
  }
2447
2441
 
2448
2442
  var builders_defaultsMode = {
2449
- amd: defaultsMode_amd__amd,
2450
- cjs: defaultsMode_cjs__cjs,
2451
- umd: defaultsMode_umd__umd
2443
+ amd: builders_defaultsMode_amd__amd,
2444
+ cjs: builders_defaultsMode_cjs__cjs,
2445
+ umd: builders_defaultsMode_umd__umd
2452
2446
  };
2453
2447
 
2454
2448
  function getExportBlock ( entry ) {
@@ -2679,7 +2673,7 @@ var esperanto = {
2679
2673
 
2680
2674
  bundle.modules.forEach( function(mod ) {
2681
2675
  mod.imports.forEach( function(x ) {
2682
- if ( hasOwnProp.call( bundle.externalModuleLookup, x.id ) && ( !x.isDefault && !x.isBatch ) ) {
2676
+ if ( utils_hasOwnProp.call( bundle.externalModuleLookup, x.id ) && ( !x.isDefault && !x.isBatch ) ) {
2683
2677
  throw new Error( 'You can only have named external imports in strict mode (pass `strict: true`)' );
2684
2678
  }
2685
2679
  });