esperanto-source 0.6.31 → 0.6.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/vendor/esperanto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- esperanto.js v0.6.30 - 2015-04-26
2
+ esperanto.js v0.6.32 - 2015-05-07
3
3
  http://esperantojs.org
4
4
 
5
5
  Released under the MIT License.
@@ -9,11 +9,9 @@
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
- var hasOwnProp = Object.prototype.hasOwnProperty;
16
-
17
15
  function hasNamedImports ( mod ) {
18
16
  var i = mod.imports.length;
19
17
 
@@ -38,29 +36,29 @@ function walk ( ast, leave) {var enter = leave.enter, leave = leave.leave;
38
36
  visit( ast, null, enter, leave );
39
37
  }
40
38
 
41
- var walk__context = {
42
- skip: function() {return walk__context.shouldSkip = true}
39
+ var ast_walk__context = {
40
+ skip: function() {return ast_walk__context.shouldSkip = true}
43
41
  };
44
42
 
45
- var walk__childKeys = {};
43
+ var ast_walk__childKeys = {};
46
44
 
47
- var walk__toString = Object.prototype.toString;
45
+ var ast_walk__toString = Object.prototype.toString;
48
46
 
49
47
  function isArray ( thing ) {
50
- return walk__toString.call( thing ) === '[object Array]';
48
+ return ast_walk__toString.call( thing ) === '[object Array]';
51
49
  }
52
50
 
53
51
  function visit ( node, parent, enter, leave ) {
54
52
  if ( !node ) return;
55
53
 
56
54
  if ( enter ) {
57
- walk__context.shouldSkip = false;
58
- enter.call( walk__context, node, parent );
59
- if ( walk__context.shouldSkip ) return;
55
+ ast_walk__context.shouldSkip = false;
56
+ enter.call( ast_walk__context, node, parent );
57
+ if ( ast_walk__context.shouldSkip ) return;
60
58
  }
61
59
 
62
- var keys = walk__childKeys[ node.type ] || (
63
- walk__childKeys[ node.type ] = Object.keys( node ).filter( function(key ) {return typeof node[ key ] === 'object'} )
60
+ var keys = ast_walk__childKeys[ node.type ] || (
61
+ ast_walk__childKeys[ node.type ] = Object.keys( node ).filter( function(key ) {return typeof node[ key ] === 'object'} )
64
62
  );
65
63
 
66
64
  var key, value, i, j;
@@ -349,7 +347,7 @@ function findImportsAndExports ( mod, source, ast ) {
349
347
  */
350
348
  function processImport ( node, passthrough ) {
351
349
  var x = {
352
- id: null, // used by bundler - filled in later
350
+ module: null, // used by bundler - filled in later
353
351
  node: node,
354
352
  start: node.start,
355
353
  end: node.end,
@@ -499,6 +497,9 @@ function processExport ( node, source ) {
499
497
  return result;
500
498
  }
501
499
 
500
+ var hasOwnProp = Object.prototype.hasOwnProperty;
501
+ var utils_hasOwnProp = hasOwnProp;
502
+
502
503
  function getUnscopedNames ( mod ) {
503
504
  var unscoped = [], importedNames, scope;
504
505
 
@@ -511,7 +512,7 @@ function getUnscopedNames ( mod ) {
511
512
  });
512
513
  });
513
514
  }
514
- return hasOwnProp.call( importedNames, name );
515
+ return utils_hasOwnProp.call( importedNames, name );
515
516
  }
516
517
 
517
518
  walk( mod.ast, {
@@ -563,7 +564,7 @@ function disallowConflictingImports ( imports ) {
563
564
  }
564
565
 
565
566
  function checkName ( name ) {
566
- if ( hasOwnProp.call( usedNames, name ) ) {
567
+ if ( utils_hasOwnProp.call( usedNames, name ) ) {
567
568
  throw new SyntaxError( (("Duplicated import ('" + name) + "')") );
568
569
  }
569
570
 
@@ -659,7 +660,7 @@ function determineImportNames ( imports, userFn, usedNames ) {
659
660
  moduleId = x.path;
660
661
 
661
662
  // use existing value
662
- if ( hasOwnProp.call( nameById, moduleId ) ) {
663
+ if ( utils_hasOwnProp.call( nameById, moduleId ) ) {
663
664
  x.name = nameById[ moduleId ];
664
665
  return;
665
666
  }
@@ -668,7 +669,7 @@ function determineImportNames ( imports, userFn, usedNames ) {
668
669
  if ( userFn && ( name = userFn( moduleId ) ) ) {
669
670
  name = sanitize( name );
670
671
 
671
- if ( hasOwnProp.call( usedNames, name ) ) {
672
+ if ( utils_hasOwnProp.call( usedNames, name ) ) {
672
673
  // TODO write a test for this
673
674
  throw new Error( (("Naming collision: module " + moduleId) + (" cannot be called " + name) + "") );
674
675
  }
@@ -685,7 +686,7 @@ function determineImportNames ( imports, userFn, usedNames ) {
685
686
  while ( i-- > 0 ) {
686
687
  candidate = prefix + sanitize( parts.slice( i ).join( '__' ) );
687
688
 
688
- if ( !hasOwnProp.call( usedNames, candidate ) ) {
689
+ if ( !utils_hasOwnProp.call( usedNames, candidate ) ) {
689
690
  name = candidate;
690
691
  break;
691
692
  }
@@ -704,13 +705,13 @@ function determineImportNames ( imports, userFn, usedNames ) {
704
705
  // use inferred names for default imports, wherever they
705
706
  // don't clash with path-based names
706
707
  imports.forEach( function(x ) {
707
- if ( x.as && !hasOwnProp.call( usedNames, x.as ) ) {
708
+ if ( x.as && !utils_hasOwnProp.call( usedNames, x.as ) ) {
708
709
  inferredNames[ x.path ] = x.as;
709
710
  }
710
711
  });
711
712
 
712
713
  imports.forEach( function(x ) {
713
- if ( hasOwnProp.call( inferredNames, x.path ) ) {
714
+ if ( utils_hasOwnProp.call( inferredNames, x.path ) ) {
714
715
  x.name = inferredNames[ x.path ];
715
716
  }
716
717
  });
@@ -751,7 +752,7 @@ function resolveAgainst ( importerPath ) {
751
752
  };
752
753
  }
753
754
 
754
- function sortModules ( entry, moduleLookup ) {
755
+ function sortModules ( entry ) {
755
756
  var seen = {};
756
757
  var ordered = [];
757
758
  var swapPairs = [];
@@ -760,12 +761,12 @@ function sortModules ( entry, moduleLookup ) {
760
761
  seen[ mod.id ] = true;
761
762
 
762
763
  mod.imports.forEach( function(x ) {
763
- var imported = moduleLookup[ x.id ];
764
+ var imported = x.module;
764
765
 
765
- if ( !imported ) return;
766
+ if ( imported.isExternal || imported.isSkipped ) return;
766
767
 
767
768
  // ignore modules we've already included
768
- if ( hasOwnProp.call( seen, imported.id ) ) {
769
+ if ( utils_hasOwnProp.call( seen, imported.id ) ) {
769
770
  if ( shouldSwap( imported, mod ) ) {
770
771
  swapPairs.push([ imported, mod ]);
771
772
  }
@@ -794,15 +795,15 @@ function sortModules ( entry, moduleLookup ) {
794
795
 
795
796
  function shouldSwap ( a, b ) {
796
797
  // if these modules don't import each other, abort
797
- if ( !( sortModules__imports( a, b ) && sortModules__imports( b, a ) ) ) return;
798
+ if ( !( utils_sortModules__imports( a, b ) && utils_sortModules__imports( b, a ) ) ) return;
798
799
 
799
800
  return usesAtTopLevel( b, a ) && !usesAtTopLevel( a, b );
800
801
  }
801
802
 
802
- function sortModules__imports ( a, b ) {
803
+ function utils_sortModules__imports ( a, b ) {
803
804
  var i = a.imports.length;
804
805
  while ( i-- ) {
805
- if ( a.imports[i].id === b.id ) {
806
+ if ( a.imports[i].module === b ) {
806
807
  return true;
807
808
  }
808
809
  }
@@ -814,7 +815,7 @@ function usesAtTopLevel ( a, b ) {
814
815
  // find out which bindings a imports from b
815
816
  var i = a.imports.length;
816
817
  while ( i-- ) {
817
- if ( a.imports[i].id === b.id ) {
818
+ if ( a.imports[i].module === b ) {
818
819
  bindings.push.apply( bindings, a.imports[i].specifiers.map( function(x ) {return x.as} ) );
819
820
  }
820
821
  }
@@ -849,18 +850,16 @@ function resolveChains ( modules, moduleLookup ) {
849
850
  var origin = {};
850
851
 
851
852
  mod.imports.forEach( function(x ) {
853
+ var imported = x.module;
854
+
852
855
  x.specifiers.forEach( function(s ) {
853
856
  if ( s.isBatch ) {
854
- // if this is an internal module, we need to tell that module that
855
- // it needs to export an object full of getters
856
- if ( hasOwnProp.call( moduleLookup, x.id ) ) {
857
- moduleLookup[ x.id ]._exportsNamespace = true;
858
- }
859
-
857
+ // tell that module that it needs to export an object full of getters
858
+ imported._exportsNamespace = true;
860
859
  return; // TODO can batch imports be chained?
861
860
  }
862
861
 
863
- origin[ s.as ] = (("" + (x.id)) + ("@" + (s.name)) + "");
862
+ origin[ s.as ] = (("" + (s.name)) + ("@" + (imported.id)) + "");
864
863
  });
865
864
  });
866
865
 
@@ -868,14 +867,49 @@ function resolveChains ( modules, moduleLookup ) {
868
867
  if ( !x.specifiers ) return;
869
868
 
870
869
  x.specifiers.forEach( function(s ) {
871
- if ( hasOwnProp.call( origin, s.name ) ) {
872
- chains[ (("" + (mod.id)) + ("@" + (s.name)) + "") ] = origin[ s.name ];
870
+ if ( utils_hasOwnProp.call( origin, s.name ) ) {
871
+ chains[ (("" + (s.name)) + ("@" + (mod.id)) + "") ] = origin[ s.name ];
873
872
  }
874
873
  });
875
874
  });
876
875
  });
877
876
 
878
- return chains;
877
+ // Second pass - assigning origins to specifiers
878
+ modules.forEach( function(mod ) {
879
+ mod.imports.forEach( function(x ) {
880
+ var imported = x.module;
881
+
882
+ x.specifiers.forEach( function(s ) {
883
+ if ( s.isBatch ) {
884
+ return; // TODO can batch imports be chained?
885
+ }
886
+
887
+ setOrigin( s, (("" + (s.name)) + ("@" + (imported.id)) + ""), chains, moduleLookup );
888
+ });
889
+ });
890
+
891
+ mod.exports.forEach( function(x ) {
892
+ if ( !x.specifiers ) return;
893
+
894
+ x.specifiers.forEach( function(s ) {
895
+ setOrigin( s, (("" + (s.name)) + ("@" + (mod.id)) + ""), chains, moduleLookup );
896
+ });
897
+ });
898
+ });
899
+ }
900
+
901
+ function setOrigin ( specifier, hash, chains, moduleLookup ) {
902
+ var isChained;
903
+
904
+ while ( utils_hasOwnProp.call( chains, hash ) ) {
905
+ hash = chains[ hash ];
906
+ isChained = true;
907
+ }
908
+
909
+ if ( isChained ) {
910
+ var name = (moduleId = hash.split( '@' ))[0], moduleId = moduleId[1];
911
+ specifier.origin = { module: moduleLookup[ moduleId ], name: name };
912
+ }
879
913
  }
880
914
 
881
915
  // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
@@ -906,8 +940,8 @@ function getUniqueNames ( bundle ) {
906
940
  // infer names from default imports - e.g. with `import _ from './utils'`,
907
941
  // use '_' instead of generating a name from 'utils'
908
942
  function inferName ( x ) {
909
- if ( x.isDefault && !hasOwnProp.call( names, x.id ) && !hasOwnProp.call( used, x.as ) ) {
910
- names[ x.id ] = x.as;
943
+ if ( x.isDefault && !utils_hasOwnProp.call( names, x.module.id ) && !utils_hasOwnProp.call( used, x.as ) ) {
944
+ names[ x.module.id ] = x.as;
911
945
  used[ x.as ] = true;
912
946
  }
913
947
  }
@@ -919,7 +953,7 @@ function getUniqueNames ( bundle ) {
919
953
  // introducing conflicts
920
954
  modules.concat( externalModules ).forEach( function(mod ) {
921
955
  // is this already named?
922
- if ( hasOwnProp.call( names, mod.id ) ) {
956
+ if ( utils_hasOwnProp.call( names, mod.id ) ) {
923
957
  mod.name = names[ mod.id ];
924
958
  return;
925
959
  }
@@ -931,12 +965,12 @@ function getUniqueNames ( bundle ) {
931
965
  while ( i-- ) {
932
966
  name = sanitize( parts.slice( i ).join( '_' ) );
933
967
 
934
- if ( !hasOwnProp.call( used, name ) ) {
968
+ if ( !utils_hasOwnProp.call( used, name ) ) {
935
969
  break;
936
970
  }
937
971
  }
938
972
 
939
- while ( hasOwnProp.call( used, name ) ) {
973
+ while ( utils_hasOwnProp.call( used, name ) ) {
940
974
  name = '_' + name;
941
975
  }
942
976
 
@@ -950,9 +984,9 @@ function getUniqueNames ( bundle ) {
950
984
  function populateExternalModuleImports ( bundle ) {
951
985
  bundle.modules.forEach( function(mod ) {
952
986
  mod.imports.forEach( function(x ) {
953
- var externalModule = bundle.externalModuleLookup[ x.id ];
987
+ var externalModule = x.module;
954
988
 
955
- if ( !externalModule ) {
989
+ if ( !externalModule.isExternal ) {
956
990
  return;
957
991
  }
958
992
 
@@ -1007,7 +1041,7 @@ function topLevelScopeConflicts ( bundle ) {
1007
1041
 
1008
1042
  // merge this module's top scope with bundle top scope
1009
1043
  names.forEach( function(name ) {
1010
- if ( hasOwnProp.call( inBundle, name ) ) {
1044
+ if ( utils_hasOwnProp.call( inBundle, name ) ) {
1011
1045
  conflicts[ name ] = true;
1012
1046
  } else {
1013
1047
  inBundle[ name ] = true;
@@ -1031,11 +1065,11 @@ function populateIdentifierReplacements ( bundle ) {
1031
1065
  var result;
1032
1066
 
1033
1067
  if ( x.hasDeclaration && x.name ) {
1034
- result = hasOwnProp.call( conflicts, x.name ) || otherModulesDeclare( mod, x.name ) ?
1068
+ result = utils_hasOwnProp.call( conflicts, x.name ) || otherModulesDeclare( mod, x.name ) ?
1035
1069
  (("" + (mod.name)) + ("__" + (x.name)) + "") :
1036
1070
  x.name;
1037
1071
  } else {
1038
- result = hasOwnProp.call( conflicts, mod.name ) || ( x.value !== mod.name && ~mod.ast._topLevelNames.indexOf( mod.name )) || otherModulesDeclare( mod, mod.name ) ?
1072
+ result = utils_hasOwnProp.call( conflicts, mod.name ) || ( x.value !== mod.name && ~mod.ast._topLevelNames.indexOf( mod.name )) || otherModulesDeclare( mod, mod.name ) ?
1039
1073
  (("" + (mod.name)) + "__default") :
1040
1074
  mod.name;
1041
1075
  }
@@ -1050,63 +1084,55 @@ function populateIdentifierReplacements ( bundle ) {
1050
1084
  var moduleIdentifiers = mod.identifierReplacements;
1051
1085
 
1052
1086
  mod.ast._topLevelNames.forEach( function(n ) {
1053
- moduleIdentifiers[n] = hasOwnProp.call( conflicts, n ) ?
1087
+ moduleIdentifiers[n] = utils_hasOwnProp.call( conflicts, n ) ?
1054
1088
  (("" + (mod.name)) + ("__" + n) + "") :
1055
1089
  n;
1056
1090
  });
1057
1091
 
1058
1092
  mod.imports.forEach( function(x ) {
1059
- var externalModule;
1060
-
1061
1093
  if ( x.passthrough ) {
1062
1094
  return;
1063
1095
  }
1064
1096
 
1065
- externalModule = hasOwnProp.call( bundle.externalModuleLookup, x.id ) && bundle.externalModuleLookup[ x.id ];
1097
+ var imported = x.module;
1066
1098
 
1067
1099
  x.specifiers.forEach( function(s ) {
1068
- var moduleId, mod, moduleName, specifierName, replacement, hash, isChained, separatorIndex;
1069
-
1070
- moduleId = x.id;
1100
+ var replacement;
1071
1101
 
1072
1102
  if ( s.isBatch ) {
1073
- replacement = ( bundle.moduleLookup[ moduleId ] || bundle.externalModuleLookup[ moduleId ] ).name;
1103
+ replacement = x.module.name;
1074
1104
  }
1075
1105
 
1076
1106
  else {
1077
- specifierName = s.name;
1078
-
1079
- // If this is a chained import, get the origin
1080
- hash = (("" + moduleId) + ("@" + specifierName) + "");
1081
- while ( hasOwnProp.call( bundle.chains, hash ) ) {
1082
- hash = bundle.chains[ hash ];
1083
- isChained = true;
1084
- }
1107
+ var mod;
1108
+ var specifierName;
1085
1109
 
1086
- if ( isChained ) {
1087
- separatorIndex = hash.indexOf( '@' );
1088
- moduleId = hash.substr( 0, separatorIndex );
1089
- specifierName = hash.substring( separatorIndex + 1 );
1110
+ if ( s.origin ) {
1111
+ // chained bindings
1112
+ mod = s.origin.module;
1113
+ specifierName = s.origin.name;
1114
+ } else {
1115
+ mod = imported;
1116
+ specifierName = s.name;
1090
1117
  }
1091
1118
 
1092
- mod = ( bundle.moduleLookup[ moduleId ] || bundle.externalModuleLookup[ moduleId ] );
1093
- moduleName = mod && mod.name;
1119
+ var moduleName = mod && mod.name;
1094
1120
 
1095
1121
  if ( specifierName === 'default' ) {
1096
1122
  // if it's an external module, always use __default if the
1097
1123
  // bundle also uses named imports
1098
- if ( !!externalModule ) {
1099
- replacement = externalModule.needsNamed ? (("" + moduleName) + "__default") : moduleName;
1124
+ if ( imported.isExternal ) {
1125
+ replacement = imported.needsNamed ? (("" + moduleName) + "__default") : moduleName;
1100
1126
  }
1101
1127
 
1102
1128
  // TODO We currently need to check for the existence of `mod`, because modules
1103
1129
  // can be skipped. Would be better to replace skipped modules with dummies
1104
1130
  // - see https://github.com/Rich-Harris/esperanto/issues/32
1105
- else if ( mod ) {
1131
+ else if ( mod && !mod.isSkipped ) {
1106
1132
  replacement = mod.identifierReplacements.default;
1107
1133
  }
1108
- } else if ( !externalModule ) {
1109
- replacement = hasOwnProp.call( conflicts, specifierName ) ?
1134
+ } else if ( !imported.isExternal ) {
1135
+ replacement = utils_hasOwnProp.call( conflicts, specifierName ) ?
1110
1136
  (("" + moduleName) + ("__" + specifierName) + "") :
1111
1137
  specifierName;
1112
1138
  } else {
@@ -1132,7 +1158,7 @@ function populateIdentifierReplacements ( bundle ) {
1132
1158
  continue;
1133
1159
  }
1134
1160
 
1135
- if ( hasOwnProp.call( otherMod.ast._declared, replacement ) ) {
1161
+ if ( utils_hasOwnProp.call( otherMod.ast._declared, replacement ) ) {
1136
1162
  return true;
1137
1163
  }
1138
1164
  }
@@ -1145,29 +1171,32 @@ function resolveExports ( bundle ) {
1145
1171
  bundle.entryModule.exports.forEach( function(x ) {
1146
1172
  if ( x.specifiers ) {
1147
1173
  x.specifiers.forEach( function(s ) {
1148
- var hash = (("" + (bundle.entryModule.id)) + ("@" + (s.name)) + "");
1174
+ var module;
1175
+ var name;
1149
1176
 
1150
- while ( bundle.chains[ hash ] ) {
1151
- hash = bundle.chains[ hash ];
1177
+ if ( s.origin ) {
1178
+ module = s.origin.module;
1179
+ name = s.origin.name;
1180
+ } else {
1181
+ module = bundle.entryModule;
1182
+ name = s.name;
1152
1183
  }
1153
1184
 
1154
- var moduleId = (name = hash.split( '@' ))[0], name = name[1];
1155
-
1156
- addExport( moduleId, name, s.name );
1185
+ addExport( module, name, s.name );
1157
1186
  });
1158
1187
  }
1159
1188
 
1160
1189
  else if ( !x.isDefault && x.name ) {
1161
- addExport( bundle.entry, x.name, x.name );
1190
+ addExport( bundle.entryModule, x.name, x.name );
1162
1191
  }
1163
1192
  });
1164
1193
 
1165
- function addExport ( moduleId, name, as ) {
1166
- if ( !bundleExports[ moduleId ] ) {
1167
- bundleExports[ moduleId ] = {};
1194
+ function addExport ( module, name, as ) {
1195
+ if ( !bundleExports[ module.id ] ) {
1196
+ bundleExports[ module.id ] = {};
1168
1197
  }
1169
1198
 
1170
- bundleExports[ moduleId ][ name ] = as;
1199
+ bundleExports[ module.id ][ name ] = as;
1171
1200
  }
1172
1201
 
1173
1202
  return bundleExports;
@@ -1224,14 +1253,14 @@ function disallowIllegalReassignment ( node, importedBindings, importedNamespace
1224
1253
 
1225
1254
  var name = assignee.name;
1226
1255
 
1227
- if ( hasOwnProp.call( isNamespaceAssignment ? importedNamespaces : importedBindings, name ) && !scope.contains( name ) ) {
1256
+ if ( utils_hasOwnProp.call( isNamespaceAssignment ? importedNamespaces : importedBindings, name ) && !scope.contains( name ) ) {
1228
1257
  throw new Error( ( isNamespaceAssignment ? namespaceMessage : bindingMessage ) + '`' + name + '`' );
1229
1258
  }
1230
1259
  }
1231
1260
 
1232
1261
  function replaceIdentifiers ( body, node, identifierReplacements, scope ) {
1233
1262
  var name = node.name;
1234
- var replacement = hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
1263
+ var replacement = utils_hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
1235
1264
 
1236
1265
  // TODO unchanged identifiers shouldn't have got this far -
1237
1266
  // remove the `replacement !== name` safeguard once that's the case
@@ -1262,7 +1291,7 @@ function rewriteExportAssignments ( body, node, parent, exports, scope, captured
1262
1291
  return; // shadows an export
1263
1292
  }
1264
1293
 
1265
- if ( exports && hasOwnProp.call( exports, name ) ) {
1294
+ if ( exports && utils_hasOwnProp.call( exports, name ) ) {
1266
1295
  var exportAs = exports[ name ];
1267
1296
 
1268
1297
  if ( !!capturedUpdates ) {
@@ -1359,11 +1388,11 @@ function exportCapturedUpdate ( c ) {
1359
1388
  return ((" exports." + (c.exportAs)) + (" = " + (c.name)) + ";");
1360
1389
  }
1361
1390
 
1362
- function transformBody__transformBody ( bundle, mod, body ) {
1391
+ function combine_transformBody__transformBody ( bundle, mod, body ) {
1363
1392
  var identifierReplacements = mod.identifierReplacements;
1364
1393
  var importedBindings = (importedNamespaces = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = importedNamespaces[1];
1365
1394
 
1366
- var exportNames = hasOwnProp.call( bundle.exports, mod.id ) && bundle.exports[ mod.id ];
1395
+ var exportNames = utils_hasOwnProp.call( bundle.exports, mod.id ) && bundle.exports[ mod.id ];
1367
1396
 
1368
1397
  traverseAst( mod.ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames );
1369
1398
 
@@ -1401,7 +1430,7 @@ function transformBody__transformBody ( bundle, mod, body ) {
1401
1430
  if ( name === identifierReplacements.default ) {
1402
1431
  body.remove( x.start, x.end );
1403
1432
  } else {
1404
- var original = hasOwnProp.call( identifierReplacements, name ) ? identifierReplacements[ name ] : name;
1433
+ var original = utils_hasOwnProp.call( identifierReplacements, name ) ? identifierReplacements[ name ] : name;
1405
1434
  body.replace( x.start, x.end, (("var " + (identifierReplacements.default)) + (" = " + original) + ";") );
1406
1435
  }
1407
1436
  }
@@ -1493,22 +1522,22 @@ function combine ( bundle ) {
1493
1522
  bundle.modules.forEach( function(mod ) {
1494
1523
  // verify that this module doesn't import non-exported identifiers
1495
1524
  mod.imports.forEach( function(x ) {
1496
- var importedModule = bundle.moduleLookup[ x.id ];
1525
+ var imported = x.module;
1497
1526
 
1498
- if ( !importedModule || x.isBatch ) {
1527
+ if ( imported.isExternal || imported.isSkipped || x.isBatch ) {
1499
1528
  return;
1500
1529
  }
1501
1530
 
1502
1531
  x.specifiers.forEach( function(s ) {
1503
- if ( !importedModule.doesExport[ s.name ] ) {
1504
- throw new Error( (("Module '" + (importedModule.id)) + ("' does not export '" + (s.name)) + ("' (imported by '" + (mod.id)) + "')") );
1532
+ if ( !imported.doesExport[ s.name ] ) {
1533
+ throw new Error( (("Module '" + (imported.id)) + ("' does not export '" + (s.name)) + ("' (imported by '" + (mod.id)) + "')") );
1505
1534
  }
1506
1535
  });
1507
1536
  });
1508
1537
 
1509
1538
  bundle.body.addSource({
1510
- filename: path.resolve( bundle.base, mod.relativePath ),
1511
- content: transformBody__transformBody( bundle, mod, mod.body ),
1539
+ filename: mod.path,
1540
+ content: combine_transformBody__transformBody( bundle, mod, mod.body ),
1512
1541
  indentExclusionRanges: mod.ast._templateLiteralRanges
1513
1542
  });
1514
1543
  });
@@ -1581,7 +1610,7 @@ function getModule ( mod ) {
1581
1610
  return mod;
1582
1611
  }
1583
1612
 
1584
- var getBundle__Promise = sander.Promise;
1613
+ var bundler_getBundle__Promise = sander.Promise;
1585
1614
 
1586
1615
  function getBundle ( options ) {
1587
1616
  var entry = options.entry.replace( /\.js$/, '' );
@@ -1591,7 +1620,7 @@ function getBundle ( options ) {
1591
1620
  var promiseByPath = {};
1592
1621
  var skip = options.skip;
1593
1622
  var names = options.names;
1594
- var base = ( options.base ? path.resolve( options.base ) : process.cwd() ) + '/';
1623
+ var base = ( options.base ? _path.resolve( options.base ) : process.cwd() ) + '/';
1595
1624
  var externalModules = [];
1596
1625
  var externalModuleLookup = {};
1597
1626
 
@@ -1599,27 +1628,31 @@ function getBundle ( options ) {
1599
1628
  entry = entry.substring( base.length );
1600
1629
  }
1601
1630
 
1602
- return resolvePath( base, userModules, entry, null ).then( function(relativePath ) {
1603
- return fetchModule( entry, relativePath ).then( function() {
1604
- var entryModule = moduleLookup[ entry ];
1605
- modules = sortModules( entryModule, moduleLookup );
1606
-
1607
- var bundle = {
1608
- entry: entry,
1609
- entryModule: entryModule,
1610
- base: base,
1611
- modules: modules,
1612
- moduleLookup: moduleLookup,
1613
- externalModules: externalModules,
1614
- externalModuleLookup: externalModuleLookup,
1615
- skip: skip,
1616
- names: names,
1617
- chains: resolveChains( modules, moduleLookup )
1618
- };
1631
+ // resolve user module paths
1632
+ options.modules && Object.keys( options.modules ).forEach( function(relativePath ) {
1633
+ userModules[ _path.resolve( base, relativePath ) ] = options.modules[ relativePath ];
1634
+ });
1619
1635
 
1620
- combine( bundle );
1636
+ var cyclicalModules = [];
1637
+
1638
+ return resolvePath( base, userModules, entry, null ).then( function(absolutePath ) {
1639
+ return fetchModule( entry, absolutePath ).then( function(entryModule ) {
1640
+ return bundler_getBundle__Promise.all( cyclicalModules ).then( function() {
1641
+ modules = sortModules( entryModule );
1642
+
1643
+ var bundle = {
1644
+ entryModule: entryModule,
1645
+ modules: modules,
1646
+ externalModules: externalModules,
1647
+ names: names
1648
+ };
1649
+
1650
+ resolveChains( modules, moduleLookup );
1651
+ combine( bundle );
1652
+
1653
+ return bundle;
1654
+ });
1621
1655
 
1622
- return bundle;
1623
1656
  });
1624
1657
  }, function ( err ) {
1625
1658
  if ( err.code === 'ENOENT' ) {
@@ -1629,13 +1662,11 @@ function getBundle ( options ) {
1629
1662
  throw err;
1630
1663
  });
1631
1664
 
1632
- function fetchModule ( moduleId, relativePath ) {
1633
- var absolutePath = path.resolve( base, relativePath );
1634
-
1635
- if ( !hasOwnProp.call( promiseByPath, relativePath ) ) {
1636
- promiseByPath[ relativePath ] = (
1637
- hasOwnProp.call( userModules, relativePath ) ?
1638
- getBundle__Promise.resolve( userModules[ relativePath ] ) :
1665
+ function fetchModule ( moduleId, absolutePath ) {
1666
+ if ( !utils_hasOwnProp.call( promiseByPath, absolutePath ) ) {
1667
+ promiseByPath[ absolutePath ] = (
1668
+ utils_hasOwnProp.call( userModules, absolutePath ) ?
1669
+ bundler_getBundle__Promise.resolve( userModules[ absolutePath ] ) :
1639
1670
  sander.readFile( absolutePath ).then( String )
1640
1671
  ).then( function ( source ) {
1641
1672
  var code, ast;
@@ -1662,41 +1693,62 @@ function getBundle ( options ) {
1662
1693
  path: absolutePath,
1663
1694
  code: code,
1664
1695
  ast: ast,
1665
- relativePath: relativePath
1696
+
1697
+ // TODO should not need this
1698
+ relativePath: _path.relative( base, absolutePath )
1666
1699
  });
1667
1700
 
1668
1701
  modules.push( module );
1669
1702
  moduleLookup[ moduleId ] = module;
1670
1703
 
1671
1704
  var promises = module.imports.map( function(x ) {
1672
- x.id = resolveId( x.path, module.relativePath );
1705
+ // TODO remove this, use x.module instead. more flexible, no lookups involved
1706
+ var id = resolveId( x.path, module.relativePath );
1673
1707
 
1674
- if ( x.id === moduleId ) {
1708
+ if ( id === moduleId ) {
1675
1709
  throw new Error( 'A module (' + moduleId + ') cannot import itself' );
1676
1710
  }
1677
1711
 
1678
1712
  // Some modules can be skipped
1679
- if ( skip && ~skip.indexOf( x.id ) ) {
1680
- return;
1713
+ if ( skip && ~skip.indexOf( id ) ) {
1714
+ var skippedModule = {
1715
+ id: id,
1716
+ isSkipped: true
1717
+ };
1718
+
1719
+ x.module = skippedModule;
1720
+ return skippedModule;
1681
1721
  }
1682
1722
 
1683
- return resolvePath( base, userModules, x.id, absolutePath, options.resolvePath ).then( function(relativePath ) {
1684
- // short-circuit cycles
1685
- if ( hasOwnProp.call( promiseByPath, relativePath ) ) {
1723
+ return resolvePath( base, userModules, id, absolutePath, options.resolvePath ).then( function(absolutePath ) {
1724
+ var promise = utils_hasOwnProp.call( promiseByPath, absolutePath ) && promiseByPath[ absolutePath ];
1725
+ var cyclical = !!promise;
1726
+
1727
+ if ( cyclical ) {
1728
+ // ensure all modules are set before we
1729
+ // create the bundle...
1730
+ cyclicalModules.push(
1731
+ promise.then( function(module ) {return x.module = module} )
1732
+ );
1733
+
1734
+ // ...then short-circuit
1686
1735
  return;
1687
1736
  }
1688
1737
 
1689
- return fetchModule( x.id, relativePath );
1738
+ return fetchModule( id, absolutePath ).then( function(module ) {return x.module = module} );
1690
1739
  }, function handleError ( err ) {
1691
1740
  if ( err.code === 'ENOENT' ) {
1692
1741
  // Most likely an external module
1693
- if ( !hasOwnProp.call( externalModuleLookup, x.id ) ) {
1742
+ if ( !utils_hasOwnProp.call( externalModuleLookup, id ) ) {
1694
1743
  var externalModule = {
1695
- id: x.id
1744
+ id: id,
1745
+ isExternal: true
1696
1746
  };
1697
1747
 
1748
+ x.module = externalModule;
1749
+
1698
1750
  externalModules.push( externalModule );
1699
- externalModuleLookup[ x.id ] = externalModule;
1751
+ externalModuleLookup[ id ] = externalModule;
1700
1752
  }
1701
1753
  } else {
1702
1754
  throw err;
@@ -1704,11 +1756,12 @@ function getBundle ( options ) {
1704
1756
  } );
1705
1757
  });
1706
1758
 
1707
- return getBundle__Promise.all( promises );
1759
+ return bundler_getBundle__Promise.all( promises )
1760
+ .then( function() {return module} );
1708
1761
  });
1709
1762
  }
1710
1763
 
1711
- return promiseByPath[ relativePath ];
1764
+ return promiseByPath[ absolutePath ];
1712
1765
  }
1713
1766
  }
1714
1767
 
@@ -1716,9 +1769,9 @@ function resolvePath ( base, userModules, moduleId, importerPath, resolver ) {
1716
1769
  var noExt = moduleId.replace( /\.js$/, '' );
1717
1770
 
1718
1771
  return tryPath( base, noExt + '.js', userModules )
1719
- .catch( function() {return tryPath( base, noExt + path.sep + 'index.js', userModules )} )
1772
+ .catch( function() {return tryPath( base, noExt + _path.sep + 'index.js', userModules )} )
1720
1773
  .catch( function ( err ) {
1721
- var resolvedPromise = resolver && getBundle__Promise.resolve( resolver( moduleId, importerPath ) );
1774
+ var resolvedPromise = resolver && bundler_getBundle__Promise.resolve( resolver( moduleId, importerPath ) );
1722
1775
 
1723
1776
  if ( resolvedPromise ) {
1724
1777
  return resolvedPromise.then( function(resolvedPath ) {
@@ -1729,7 +1782,7 @@ function resolvePath ( base, userModules, moduleId, importerPath, resolver ) {
1729
1782
  throw err;
1730
1783
  }
1731
1784
 
1732
- return sander.stat( resolvedPath ).then( function() {return resolvedPath} );
1785
+ return sander.stat( resolvedPath ).then( function() {return _path.resolve( base, resolvedPath )} );
1733
1786
  });
1734
1787
  } else {
1735
1788
  throw err;
@@ -1738,10 +1791,12 @@ function resolvePath ( base, userModules, moduleId, importerPath, resolver ) {
1738
1791
  }
1739
1792
 
1740
1793
  function tryPath ( base, filename, userModules ) {
1741
- if ( hasOwnProp.call( userModules, filename ) ) {
1742
- return getBundle__Promise.resolve( filename );
1794
+ var absolutePath = _path.resolve( base, filename );
1795
+
1796
+ if ( utils_hasOwnProp.call( userModules, absolutePath ) ) {
1797
+ return bundler_getBundle__Promise.resolve( absolutePath );
1743
1798
  }
1744
- return sander.stat( base, filename ).then( function() {return filename} );
1799
+ return sander.stat( absolutePath ).then( function() {return absolutePath} );
1745
1800
  }
1746
1801
 
1747
1802
  function isThenable ( obj ) {
@@ -1796,7 +1851,7 @@ function transformExportDeclaration ( declaration, body ) {
1796
1851
 
1797
1852
  var ABSOLUTE_PATH = /^(?:[A-Z]:)?[\/\\]/i;
1798
1853
 
1799
- var packageResult__warned = {};
1854
+ var utils_packageResult__warned = {};
1800
1855
 
1801
1856
  function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1802
1857
  // wrap output
@@ -1848,9 +1903,9 @@ function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1848
1903
  code: code,
1849
1904
  map: map,
1850
1905
  toString: function () {
1851
- if ( !packageResult__warned[ methodName ] ) {
1906
+ if ( !utils_packageResult__warned[ methodName ] ) {
1852
1907
  console.log( (("Warning: esperanto." + methodName) + "() returns an object with a 'code' property. You should use this instead of using the returned value directly") );
1853
- packageResult__warned[ methodName ] = true;
1908
+ utils_packageResult__warned[ methodName ] = true;
1854
1909
  }
1855
1910
 
1856
1911
  return code;
@@ -1966,7 +2021,7 @@ function amdIntro (useStrict) {var name = useStrict.name, imports = useStrict.im
1966
2021
  return intro;
1967
2022
  }
1968
2023
 
1969
- function amd__amd ( mod, options ) {
2024
+ function defaultsMode_amd__amd ( mod, options ) {
1970
2025
  mod.imports.forEach( function(x ) {
1971
2026
  mod.body.remove( x.start, x.next );
1972
2027
  });
@@ -1990,11 +2045,11 @@ function amd__amd ( mod, options ) {
1990
2045
  return packageResult( mod, mod.body, options, 'toAmd' );
1991
2046
  }
1992
2047
 
1993
- function cjs__cjs ( mod, options ) {
2048
+ function defaultsMode_cjs__cjs ( mod, options ) {
1994
2049
  var seen = {};
1995
2050
 
1996
2051
  mod.imports.forEach( function(x ) {
1997
- if ( !hasOwnProp.call( seen, x.path ) ) {
2052
+ if ( !utils_hasOwnProp.call( seen, x.path ) ) {
1998
2053
  var replacement = x.isEmpty ? (("" + (req(x.path))) + ";") : (("var " + (x.as)) + (" = " + (req(x.path))) + ";");
1999
2054
  mod.body.replace( x.start, x.end, replacement );
2000
2055
 
@@ -2104,15 +2159,17 @@ EsperantoError.prototype = new Error();
2104
2159
  EsperantoError.prototype.constructor = EsperantoError;
2105
2160
  EsperantoError.prototype.name = 'EsperantoError';
2106
2161
 
2162
+ var utils_EsperantoError = EsperantoError;
2163
+
2107
2164
  function requireName ( options ) {
2108
2165
  if ( !options.name ) {
2109
- throw new EsperantoError( 'You must supply a `name` option for UMD modules', {
2166
+ throw new utils_EsperantoError( 'You must supply a `name` option for UMD modules', {
2110
2167
  code: 'MISSING_NAME'
2111
2168
  });
2112
2169
  }
2113
2170
  }
2114
2171
 
2115
- function umd__umd ( mod, options ) {
2172
+ function defaultsMode_umd__umd ( mod, options ) {
2116
2173
  requireName( options );
2117
2174
 
2118
2175
  mod.imports.forEach( function(x ) {
@@ -2137,9 +2194,9 @@ function umd__umd ( mod, options ) {
2137
2194
  }
2138
2195
 
2139
2196
  var defaultsMode = {
2140
- amd: amd__amd,
2141
- cjs: cjs__cjs,
2142
- umd: umd__umd
2197
+ amd: defaultsMode_amd__amd,
2198
+ cjs: defaultsMode_cjs__cjs,
2199
+ umd: defaultsMode_umd__umd
2143
2200
  };
2144
2201
 
2145
2202
  function gatherImports ( imports ) {
@@ -2276,7 +2333,7 @@ function utils_transformBody__transformBody ( mod, body, options ) {
2276
2333
  }
2277
2334
 
2278
2335
  function deconflict ( name, declared ) {
2279
- while ( hasOwnProp.call( declared, name ) ) {
2336
+ while ( utils_hasOwnProp.call( declared, name ) ) {
2280
2337
  name = '_' + name;
2281
2338
  }
2282
2339
 
@@ -2307,7 +2364,7 @@ function strictMode_cjs__cjs ( mod, options ) {
2307
2364
 
2308
2365
  // Create block of require statements
2309
2366
  var importBlock = mod.imports.map( function(x ) {
2310
- if ( !hasOwnProp.call( seen, x.path ) ) {
2367
+ if ( !utils_hasOwnProp.call( seen, x.path ) ) {
2311
2368
  seen[ x.path ] = true;
2312
2369
 
2313
2370
  if ( x.isEmpty ) {
@@ -2365,7 +2422,7 @@ var moduleBuilders = {
2365
2422
  strictMode: strictMode
2366
2423
  };
2367
2424
 
2368
- function defaultsMode_amd__amd ( bundle, options ) {
2425
+ function builders_defaultsMode_amd__amd ( bundle, options ) {
2369
2426
  var defaultName = bundle.entryModule.identifierReplacements.default;
2370
2427
  if ( defaultName ) {
2371
2428
  bundle.body.append( (("\n\nreturn " + defaultName) + ";") );
@@ -2382,7 +2439,7 @@ function defaultsMode_amd__amd ( bundle, options ) {
2382
2439
  return packageResult( bundle, bundle.body, options, 'toAmd', true );
2383
2440
  }
2384
2441
 
2385
- function defaultsMode_cjs__cjs ( bundle, options ) {
2442
+ function builders_defaultsMode_cjs__cjs ( bundle, options ) {
2386
2443
  var importBlock = bundle.externalModules.map( function(x ) {
2387
2444
  return (("var " + (x.name)) + (" = " + (req(x.id))) + ";");
2388
2445
  }).join( '\n' );
@@ -2403,7 +2460,7 @@ function defaultsMode_cjs__cjs ( bundle, options ) {
2403
2460
  return packageResult( bundle, bundle.body, options, 'toCjs', true );
2404
2461
  }
2405
2462
 
2406
- function defaultsMode_umd__umd ( bundle, options ) {
2463
+ function builders_defaultsMode_umd__umd ( bundle, options ) {
2407
2464
  requireName( options );
2408
2465
 
2409
2466
  var entry = bundle.entryModule;
@@ -2427,9 +2484,9 @@ function defaultsMode_umd__umd ( bundle, options ) {
2427
2484
  }
2428
2485
 
2429
2486
  var builders_defaultsMode = {
2430
- amd: defaultsMode_amd__amd,
2431
- cjs: defaultsMode_cjs__cjs,
2432
- umd: defaultsMode_umd__umd
2487
+ amd: builders_defaultsMode_amd__amd,
2488
+ cjs: builders_defaultsMode_cjs__cjs,
2489
+ umd: builders_defaultsMode_umd__umd
2433
2490
  };
2434
2491
 
2435
2492
  function getExportBlock ( entry ) {
@@ -2641,7 +2698,7 @@ var esperanto = {
2641
2698
 
2642
2699
  bundle.modules.forEach( function(mod ) {
2643
2700
  mod.imports.forEach( function(x ) {
2644
- if ( hasOwnProp.call( bundle.externalModuleLookup, x.id ) && ( !x.isDefault && !x.isBatch ) ) {
2701
+ if ( x.module.isExternal && ( !x.isDefault && !x.isBatch ) ) {
2645
2702
  throw new Error( 'You can only have named external imports in strict mode (pass `strict: true`)' );
2646
2703
  }
2647
2704
  });
@@ -2678,4 +2735,5 @@ function flattenExports ( exports ) {
2678
2735
  return flattened;
2679
2736
  }
2680
2737
 
2681
- module.exports = esperanto;
2738
+ module.exports = esperanto;
2739
+ //# sourceMappingURL=/Users/tricknotes/src/github.com/esperantojs/esperanto/test/.gobble-build/01-esperantoBundle/1/esperanto.js.map