esperanto-source 0.6.34.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c80d326f36ea02656ae51fdb93af783f6c05f182
4
- data.tar.gz: e4cf0bb2a55cd677418497d10f45e5cee6ca0a82
3
+ metadata.gz: a98d5b601e29366275a76d72e9234655c36d0648
4
+ data.tar.gz: 316a57604f6c072b894b40515d491a0fc744029d
5
5
  SHA512:
6
- metadata.gz: 4de81b2a68d5a09b1cfd7432ef7ce5aa6a9d496e6c3131b642b38889408958f95d398fbbd3a0d594b475caec70e018541615d0746dc4d67125b9aaa6795500c2
7
- data.tar.gz: 48ea237ba72a40119592355924554e48e989fbd0e5603e5a40c43c5c278ff4868bbf607db21f78920ada5e1b9a9b464ec99e598bda0f8a320e84e854fefd109b
6
+ metadata.gz: 0e53f43007bf4a985cdca9e133012ef276e0e5a90f09e25c77ef7d60289e246b9c1f51b9187c5a24e7ec1d3b635489493d720a74c5bfa10bd41c968fcab58101
7
+ data.tar.gz: 381b8dccc8c4e3f8a112124726711253c3031a7031a6cc366370b8489c5cad297a8dda07a4f1af4d9f843eb971370d90609798eed6522cda1c73dad3faea8b76
@@ -1,5 +1,5 @@
1
1
  module Esperanto
2
2
  module Source
3
- VERSION = '0.6.34.1'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
@@ -1,31 +1,35 @@
1
1
  /*
2
- esperanto.js v0.6.34 - 2015-05-12
2
+ esperanto.js v0.7.0 - 2015-05-12
3
3
  http://esperantojs.org
4
4
 
5
5
  Released under the MIT License.
6
6
  */
7
7
 
8
8
  (function (global, factory) {
9
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('acorn')) :
10
- typeof define === 'function' && define.amd ? define(['acorn'], factory) :
11
- global.esperanto = factory(global.acorn)
12
- }(this, function (acorn) { 'use strict';
9
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('acorn')) :
10
+ typeof define === 'function' && define.amd ? define(['exports', 'acorn'], factory) :
11
+ factory((global.esperanto = {}), global.acorn)
12
+ }(this, function (exports, acorn) { 'use strict';
13
13
 
14
- function hasNamedImports ( mod ) {
14
+ var utils_hasNamedImports = hasNamedImports;
15
+
16
+ function hasNamedImports(mod) {
15
17
  var i = mod.imports.length;
16
18
 
17
- while ( i-- ) {
18
- if ( mod.imports[i].isNamed ) {
19
+ while (i--) {
20
+ if (mod.imports[i].isNamed) {
19
21
  return true;
20
22
  }
21
23
  }
22
24
  }
23
25
 
24
- function hasNamedExports ( mod ) {
26
+ var utils_hasNamedExports = hasNamedExports;
27
+
28
+ function hasNamedExports(mod) {
25
29
  var i = mod.exports.length;
26
30
 
27
- while ( i-- ) {
28
- if ( !mod.exports[i].isDefault ) {
31
+ while (i--) {
32
+ if (!mod.exports[i].isDefault) {
29
33
  return true;
30
34
  }
31
35
  }
@@ -930,95 +934,105 @@
930
934
 
931
935
  var magic_string = MagicString;
932
936
 
933
- var ast_walk__shouldSkip;
934
- var ast_walk__shouldAbort;
937
+ var ast_walk = walk;
935
938
 
936
- function walk ( ast, leave) {var enter = leave.enter, leave = leave.leave;
937
- ast_walk__shouldAbort = false;
938
- visit( ast, null, enter, leave );
939
+ var shouldSkip = undefined;
940
+ var shouldAbort = undefined;
941
+ function walk(ast, _ref) {
942
+ var enter = _ref.enter;
943
+ var leave = _ref.leave;
944
+
945
+ shouldAbort = false;
946
+ visit(ast, null, enter, leave);
939
947
  }
940
948
 
941
- var ast_walk__context = {
942
- skip: function() {return ast_walk__shouldSkip = true},
943
- abort: function() {return ast_walk__shouldAbort = true}
949
+ var context = {
950
+ skip: function () {
951
+ return shouldSkip = true;
952
+ },
953
+ abort: function () {
954
+ return shouldAbort = true;
955
+ }
944
956
  };
945
957
 
946
- var ast_walk__childKeys = {};
958
+ var childKeys = {};
947
959
 
948
- var ast_walk__toString = Object.prototype.toString;
960
+ var toString = Object.prototype.toString;
949
961
 
950
- function isArray ( thing ) {
951
- return ast_walk__toString.call( thing ) === '[object Array]';
962
+ function isArray(thing) {
963
+ return toString.call(thing) === '[object Array]';
952
964
  }
953
965
 
954
- function visit ( node, parent, enter, leave ) {
955
- if ( !node || ast_walk__shouldAbort ) return;
966
+ function visit(node, parent, enter, leave) {
967
+ if (!node || shouldAbort) return;
956
968
 
957
- if ( enter ) {
958
- ast_walk__shouldSkip = false;
959
- enter.call( ast_walk__context, node, parent );
960
- if ( ast_walk__shouldSkip || ast_walk__shouldAbort ) return;
969
+ if (enter) {
970
+ shouldSkip = false;
971
+ enter.call(context, node, parent);
972
+ if (shouldSkip || shouldAbort) return;
961
973
  }
962
974
 
963
- var keys = ast_walk__childKeys[ node.type ] || (
964
- ast_walk__childKeys[ node.type ] = Object.keys( node ).filter( function(key ) {return typeof node[ key ] === 'object'} )
965
- );
975
+ var keys = childKeys[node.type] || (childKeys[node.type] = Object.keys(node).filter(function (key) {
976
+ return typeof node[key] === 'object';
977
+ }));
966
978
 
967
- var key, value, i, j;
979
+ var key = undefined,
980
+ value = undefined,
981
+ i = undefined,
982
+ j = undefined;
968
983
 
969
984
  i = keys.length;
970
- while ( i-- ) {
985
+ while (i--) {
971
986
  key = keys[i];
972
- value = node[ key ];
987
+ value = node[key];
973
988
 
974
- if ( isArray( value ) ) {
989
+ if (isArray(value)) {
975
990
  j = value.length;
976
- while ( j-- ) {
977
- visit( value[j], node, enter, leave );
991
+ while (j--) {
992
+ visit(value[j], node, enter, leave);
978
993
  }
979
- }
980
-
981
- else if ( value && value.type ) {
982
- visit( value, node, enter, leave );
994
+ } else if (value && value.type) {
995
+ visit(value, node, enter, leave);
983
996
  }
984
997
  }
985
998
 
986
- if ( leave && !ast_walk__shouldAbort ) {
987
- leave( node, parent );
999
+ if (leave && !shouldAbort) {
1000
+ leave(node, parent);
988
1001
  }
989
1002
  }
990
1003
 
991
- function getId ( m ) {
1004
+ function getId(m) {
992
1005
  return m.id;
993
1006
  }
994
1007
 
995
- function getName ( m ) {
1008
+ function getName(m) {
996
1009
  return m.name;
997
1010
  }
998
1011
 
999
- function quote ( str ) {
1012
+ function quote(str) {
1000
1013
  return "'" + JSON.stringify(str).slice(1, -1).replace(/'/g, "\\'") + "'";
1001
1014
  }
1002
1015
 
1003
- function req ( path ) {
1004
- return (("require(" + (quote(path))) + ")");
1016
+ function req(path) {
1017
+ return "require(" + quote(path) + ")";
1005
1018
  }
1006
1019
 
1007
- function globalify ( name ) {
1008
- if ( /^__dep\d+__$/.test( name ) ) {
1009
- return 'undefined';
1020
+ function globalify(name) {
1021
+ if (/^__dep\d+__$/.test(name)) {
1022
+ return "undefined";
1010
1023
  } else {
1011
- return ("global." + name);
1024
+ return "global." + name;
1012
1025
  }
1013
1026
  }
1014
1027
 
1028
+ var annotate = annotateAst;
1015
1029
  /*
1016
1030
  This module traverse a module's AST, attaching scope information
1017
1031
  to nodes as it goes, which is later used to determine which
1018
1032
  identifiers need to be rewritten to avoid collisions
1019
1033
  */
1020
1034
 
1021
- function Scope ( options ) {
1035
+ function Scope(options) {
1022
1036
  options = options || {};
1023
1037
 
1024
1038
  this.parent = options.parent;
@@ -1026,28 +1040,29 @@
1026
1040
  }
1027
1041
 
1028
1042
  Scope.prototype = {
1029
- add: function ( name ) {
1030
- this.names.push( name );
1043
+ add: function (name) {
1044
+ this.names.push(name);
1031
1045
  },
1032
1046
 
1033
- contains: function ( name, ignoreTopLevel ) {
1034
- if ( ignoreTopLevel && !this.parent ) {
1047
+ contains: function (name, ignoreTopLevel) {
1048
+ if (ignoreTopLevel && !this.parent) {
1035
1049
  return false;
1036
1050
  }
1037
1051
 
1038
- if ( ~this.names.indexOf( name ) ) {
1052
+ if (~this.names.indexOf(name)) {
1039
1053
  return true;
1040
1054
  }
1041
1055
 
1042
- if ( this.parent ) {
1043
- return this.parent.contains( name, ignoreTopLevel );
1056
+ if (this.parent) {
1057
+ return this.parent.contains(name, ignoreTopLevel);
1044
1058
  }
1045
1059
 
1046
1060
  return false;
1047
1061
  }
1048
1062
  };
1063
+ function annotateAst(ast, options) {
1064
+ var trackAssignments = options && options.trackAssignments;
1049
1065
 
1050
- function annotateAst ( ast ) {
1051
1066
  var scope = new Scope();
1052
1067
  var blockScope = new Scope();
1053
1068
  var declared = {};
@@ -1056,38 +1071,40 @@
1056
1071
 
1057
1072
  var envDepth = 0;
1058
1073
 
1059
- walk( ast, {
1060
- enter: function ( node ) {
1061
- if ( node.type === 'ImportDeclaration' || node.type === 'ExportSpecifier' ) {
1074
+ ast_walk(ast, {
1075
+ enter: function (node) {
1076
+ if (node.type === 'ImportDeclaration' || node.type === 'ExportSpecifier') {
1062
1077
  node._skip = true;
1063
1078
  }
1064
1079
 
1065
- if ( node._skip ) {
1080
+ if (node._skip) {
1066
1081
  return this.skip();
1067
1082
  }
1068
1083
 
1069
- switch ( node.type ) {
1084
+ switch (node.type) {
1070
1085
  case 'FunctionExpression':
1071
1086
  case 'FunctionDeclaration':
1072
1087
 
1073
1088
  envDepth += 1;
1074
1089
 
1075
- // fallthrough
1090
+ // fallthrough
1076
1091
 
1077
1092
  case 'ArrowFunctionExpression':
1078
- if ( node.id ) {
1079
- addToScope( node );
1093
+ if (node.id) {
1094
+ addToScope(node);
1080
1095
 
1081
1096
  // If this is the root scope, this may need to be
1082
1097
  // exported early, so we make a note of it
1083
- if ( !scope.parent && node.type === 'FunctionDeclaration' ) {
1084
- topLevelFunctionNames.push( node.id.name );
1098
+ if (!scope.parent && node.type === 'FunctionDeclaration') {
1099
+ topLevelFunctionNames.push(node.id.name);
1085
1100
  }
1086
1101
  }
1087
1102
 
1088
- var names = node.params.map( getName );
1103
+ var names = node.params.map(getName);
1089
1104
 
1090
- names.forEach( function(name ) {return declared[ name ] = true} );
1105
+ names.forEach(function (name) {
1106
+ return declared[name] = true;
1107
+ });
1091
1108
 
1092
1109
  scope = node._scope = new Scope({
1093
1110
  parent: scope,
@@ -1104,19 +1121,19 @@
1104
1121
  break;
1105
1122
 
1106
1123
  case 'VariableDeclaration':
1107
- node.declarations.forEach( node.kind === 'let' ? addToBlockScope : addToScope );
1124
+ node.declarations.forEach(node.kind === 'let' ? addToBlockScope : addToScope);
1108
1125
  break;
1109
1126
 
1110
1127
  case 'ClassExpression':
1111
1128
  case 'ClassDeclaration':
1112
- addToScope( node );
1129
+ addToScope(node);
1113
1130
  break;
1114
1131
 
1115
1132
  case 'MemberExpression':
1116
- if ( envDepth === 0 && node.object.type === 'ThisExpression' ) {
1133
+ if (envDepth === 0 && node.object.type === 'ThisExpression') {
1117
1134
  throw new Error('`this` at the top level is undefined');
1118
1135
  }
1119
- !node.computed && ( node.property._skip = true );
1136
+ !node.computed && (node.property._skip = true);
1120
1137
  break;
1121
1138
 
1122
1139
  case 'Property':
@@ -1124,7 +1141,7 @@
1124
1141
  break;
1125
1142
 
1126
1143
  case 'TemplateLiteral':
1127
- templateLiteralRanges.push([ node.start, node.end ]);
1144
+ templateLiteralRanges.push([node.start, node.end]);
1128
1145
  break;
1129
1146
 
1130
1147
  case 'ThisExpression':
@@ -1132,16 +1149,24 @@
1132
1149
  node._topLevel = true;
1133
1150
  }
1134
1151
  break;
1152
+
1153
+ case 'AssignmentExpression':
1154
+ assignTo(node.left);
1155
+ break;
1156
+
1157
+ case 'UpdateExpression':
1158
+ assignTo(node.argument);
1159
+ break;
1135
1160
  }
1136
1161
  },
1137
- leave: function ( node ) {
1138
- switch ( node.type ) {
1162
+ leave: function (node) {
1163
+ switch (node.type) {
1139
1164
  case 'FunctionExpression':
1140
1165
  case 'FunctionDeclaration':
1141
1166
 
1142
1167
  envDepth -= 1;
1143
1168
 
1144
- // fallthrough
1169
+ // fallthrough
1145
1170
 
1146
1171
  case 'ArrowFunctionExpression':
1147
1172
 
@@ -1156,23 +1181,34 @@
1156
1181
  }
1157
1182
  });
1158
1183
 
1159
- function addToScope ( declarator ) {
1184
+ function assignTo(node) {
1185
+ if (trackAssignments && node.type === 'Identifier' && node.name === trackAssignments.name) {
1186
+ // This is possibly somewhat hacky. Open to alternative approaches...
1187
+ // It will yield false positives if `foo` in `export default foo` is shadowed
1188
+ (trackAssignments._assignments || (trackAssignments._assignments = [])).push({
1189
+ scope: scope,
1190
+ node: node
1191
+ });
1192
+ }
1193
+ }
1194
+
1195
+ function addToScope(declarator) {
1160
1196
  var name = declarator.id.name;
1161
1197
 
1162
- scope.add( name );
1163
- declared[ name ] = true;
1198
+ scope.add(name);
1199
+ declared[name] = true;
1164
1200
  }
1165
1201
 
1166
- function addToBlockScope ( declarator ) {
1202
+ function addToBlockScope(declarator) {
1167
1203
  var name = declarator.id.name;
1168
1204
 
1169
- blockScope.add( name );
1170
- declared[ name ] = true;
1205
+ blockScope.add(name);
1206
+ declared[name] = true;
1171
1207
  }
1172
1208
 
1173
1209
  ast._scope = scope;
1174
1210
  ast._blockScope = blockScope;
1175
- ast._topLevelNames = ast._scope.names.concat( ast._blockScope.names );
1211
+ ast._topLevelNames = ast._scope.names.concat(ast._blockScope.names);
1176
1212
  ast._topLevelFunctionNames = topLevelFunctionNames;
1177
1213
  ast._declared = declared;
1178
1214
  ast._templateLiteralRanges = templateLiteralRanges;
@@ -1180,66 +1216,66 @@
1180
1216
 
1181
1217
  /**
1182
1218
  * Inspects a module and discovers/categorises import & export declarations
1183
- * @param {object} mod - the module object
1184
- * @param {string} source - the module's original source code
1185
1219
  * @param {object} ast - the result of parsing `source` with acorn
1186
- * @returns {array} - [ imports, exports ]
1220
+ * @param {string} source - the module's original source code
1221
+ * @returns {object} - { imports, exports, defaultExport }
1187
1222
  */
1188
- function findImportsAndExports ( mod, source, ast ) {
1189
- var imports = [], exports = [], previousDeclaration;
1223
+ var ast_findImportsAndExports = findImportsAndExports;
1190
1224
 
1191
- ast.body.forEach( function(node ) {
1225
+ function findImportsAndExports(ast, source) {
1226
+ var imports = [];
1227
+ var exports = [];
1228
+ var defaultExport = undefined;
1229
+ var previousDeclaration = undefined;
1230
+
1231
+ ast.body.forEach(function (node) {
1192
1232
  var passthrough, declaration;
1193
1233
 
1194
- if ( previousDeclaration ) {
1234
+ if (previousDeclaration) {
1195
1235
  previousDeclaration.next = node.start;
1196
1236
 
1197
- if ( node.type !== 'EmptyStatement' ) {
1237
+ if (node.type !== 'EmptyStatement') {
1198
1238
  previousDeclaration = null;
1199
1239
  }
1200
1240
  }
1201
1241
 
1202
- if ( node.type === 'ImportDeclaration' ) {
1203
- declaration = processImport( node );
1204
- imports.push( declaration );
1205
- }
1242
+ if (node.type === 'ImportDeclaration') {
1243
+ declaration = processImport(node);
1244
+ imports.push(declaration);
1245
+ } else if (node.type === 'ExportDefaultDeclaration') {
1246
+ declaration = processDefaultExport(node, source);
1247
+ exports.push(declaration);
1206
1248
 
1207
- else if ( node.type === 'ExportDefaultDeclaration' ) {
1208
- declaration = processDefaultExport( node, source );
1209
- exports.push( declaration );
1210
-
1211
- if ( mod.defaultExport ) {
1212
- throw new Error( 'Duplicate default exports' );
1249
+ if (defaultExport) {
1250
+ throw new Error('Duplicate default exports');
1213
1251
  }
1214
- mod.defaultExport = declaration;
1215
- }
1252
+ defaultExport = declaration;
1253
+ } else if (node.type === 'ExportNamedDeclaration') {
1254
+ declaration = processExport(node, source);
1255
+ exports.push(declaration);
1216
1256
 
1217
- else if ( node.type === 'ExportNamedDeclaration' ) {
1218
- declaration = processExport( node, source );
1219
- exports.push( declaration );
1220
-
1221
- if ( node.source ) {
1257
+ if (node.source) {
1222
1258
  // it's both an import and an export, e.g.
1223
1259
  // `export { foo } from './bar';
1224
- passthrough = processImport( node, true );
1225
- imports.push( passthrough );
1260
+ passthrough = processImport(node, true);
1261
+ imports.push(passthrough);
1226
1262
 
1227
1263
  declaration.passthrough = passthrough;
1228
1264
  }
1229
1265
  }
1230
1266
 
1231
- if ( declaration ) {
1267
+ if (declaration) {
1232
1268
  previousDeclaration = declaration;
1233
1269
  }
1234
1270
  });
1235
1271
 
1236
1272
  // catch any trailing semicolons
1237
- if ( previousDeclaration ) {
1273
+ if (previousDeclaration) {
1238
1274
  previousDeclaration.next = source.length;
1239
1275
  previousDeclaration.isFinal = true;
1240
1276
  }
1241
1277
 
1242
- return [ imports, exports ];
1278
+ return { imports: imports, exports: exports, defaultExport: defaultExport };
1243
1279
  }
1244
1280
 
1245
1281
  /**
@@ -1248,7 +1284,7 @@
1248
1284
  * @param {boolean} passthrough - `true` if this is an `export { foo } from 'bar'`-style declaration
1249
1285
  * @returns {object}
1250
1286
  */
1251
- function processImport ( node, passthrough ) {
1287
+ function processImport(node, passthrough) {
1252
1288
  var x = {
1253
1289
  module: null, // used by bundler - filled in later
1254
1290
  node: node,
@@ -1257,38 +1293,40 @@
1257
1293
  passthrough: !!passthrough,
1258
1294
 
1259
1295
  path: node.source.value,
1260
- specifiers: node.specifiers.map( function(s ) {
1261
- if ( s.type === 'ImportNamespaceSpecifier' ) {
1296
+ specifiers: node.specifiers.map(function (s) {
1297
+ if (s.type === 'ImportNamespaceSpecifier') {
1262
1298
  return {
1263
1299
  isBatch: true,
1264
1300
  name: s.local.name, // TODO is this line necessary?
1265
- as: s.local.name
1301
+ as: s.local.name,
1302
+ origin: null // filled in later by bundler
1266
1303
  };
1267
1304
  }
1268
1305
 
1269
- if ( s.type === 'ImportDefaultSpecifier' ) {
1306
+ if (s.type === 'ImportDefaultSpecifier') {
1270
1307
  return {
1271
1308
  isDefault: true,
1272
1309
  name: 'default',
1273
- as: s.local.name
1310
+ as: s.local.name,
1311
+ origin: null
1274
1312
  };
1275
1313
  }
1276
1314
 
1277
1315
  return {
1278
- name: ( !!passthrough ? s.exported : s.imported ).name,
1279
- as: s.local.name
1316
+ name: (!!passthrough ? s.exported : s.imported).name,
1317
+ as: s.local.name,
1318
+ origin: null
1280
1319
  };
1281
1320
  })
1282
1321
  };
1283
1322
 
1284
1323
  // TODO have different types of imports - batch, default, named
1285
- if ( x.specifiers.length === 0 ) {
1324
+ if (x.specifiers.length === 0) {
1286
1325
  x.isEmpty = true;
1287
- } else if ( x.specifiers.length === 1 && x.specifiers[0].isDefault ) {
1326
+ } else if (x.specifiers.length === 1 && x.specifiers[0].isDefault) {
1288
1327
  x.isDefault = true;
1289
1328
  x.as = x.specifiers[0].as;
1290
-
1291
- } else if ( x.specifiers.length === 1 && x.specifiers[0].isBatch ) {
1329
+ } else if (x.specifiers.length === 1 && x.specifiers[0].isBatch) {
1292
1330
  x.isBatch = true;
1293
1331
  x.as = x.specifiers[0].name;
1294
1332
  } else {
@@ -1298,50 +1336,43 @@
1298
1336
  return x;
1299
1337
  }
1300
1338
 
1301
- function processDefaultExport ( node, source ) {
1339
+ function processDefaultExport(node, source) {
1340
+ var d = node.declaration;
1341
+
1302
1342
  var result = {
1303
- isDefault: true,
1304
1343
  node: node,
1344
+ isDefault: true,
1305
1345
  start: node.start,
1306
- end: node.end
1346
+ end: node.end,
1347
+ value: source.slice(d.start, d.end),
1348
+ valueStart: d.start,
1349
+ hasDeclaration: null,
1350
+ type: null,
1351
+ name: null
1307
1352
  };
1308
1353
 
1309
- var d = node.declaration;
1310
-
1311
- if ( d.type === 'FunctionExpression' ) {
1312
- // Case 1: `export default function () {...}`
1313
- result.hasDeclaration = true; // TODO remove in favour of result.type
1314
- result.type = 'anonFunction';
1315
- }
1316
-
1317
- else if ( d.type === 'FunctionDeclaration' ) {
1318
- // Case 2: `export default function foo () {...}`
1319
- result.hasDeclaration = true; // TODO remove in favour of result.type
1320
- result.type = 'namedFunction';
1321
- result.name = d.id.name;
1322
- }
1354
+ // possible declaration types:
1355
+ // * FunctionExpression - `export default function () {...}`
1356
+ // * FunctionDeclaration - `export default function foo () {...}`
1357
+ // * ClassExpression - `export default class {...}`
1358
+ // * ClassDeclaration - `export default class Foo {...}`
1359
+ var match = /^(Function|Class)(Declaration)?/.exec(d.type);
1323
1360
 
1324
- else if ( d.type === 'ClassExpression' ) {
1325
- // Case 3: `export default class {...}`
1326
- result.hasDeclaration = true; // TODO remove in favour of result.type
1327
- result.type = 'anonClass';
1328
- }
1361
+ if (match) {
1362
+ result.hasDeclaration = true;
1363
+ result.type = (match[2] ? 'named' : 'anon') + match[1];
1329
1364
 
1330
- else if ( d.type === 'ClassDeclaration' ) {
1331
- // Case 4: `export default class Foo {...}`
1332
- result.hasDeclaration = true; // TODO remove in favour of result.type
1333
- result.type = 'namedClass';
1334
- result.name = d.id.name;
1365
+ if (match[2]) {
1366
+ result.name = d.id.name;
1367
+ }
1335
1368
  }
1336
1369
 
1370
+ // if no match, we have an expression like `export default whatever`
1337
1371
  else {
1338
1372
  result.type = 'expression';
1339
1373
  result.name = 'default';
1340
1374
  }
1341
1375
 
1342
- result.value = source.slice( d.start, d.end );
1343
- result.valueStart = d.start;
1344
-
1345
1376
  return result;
1346
1377
  }
1347
1378
 
@@ -1351,36 +1382,40 @@
1351
1382
  * @param {string} source - the original source code
1352
1383
  * @returns {object}
1353
1384
  */
1354
- function processExport ( node, source ) {
1355
- var result, d;
1356
-
1357
- result = {
1385
+ function processExport(node, source) {
1386
+ var result = {
1358
1387
  node: node,
1359
1388
  start: node.start,
1360
- end: node.end
1389
+ end: node.end,
1390
+ value: null,
1391
+ valueStart: null,
1392
+ hasDeclaration: null,
1393
+ type: null,
1394
+ name: null,
1395
+ specifiers: null
1361
1396
  };
1362
1397
 
1363
- if ( d = node.declaration ) {
1364
- result.value = source.slice( d.start, d.end );
1398
+ var d = node.declaration;
1399
+
1400
+ if (d) {
1401
+ result.hasDeclaration = true;
1402
+ result.value = source.slice(d.start, d.end);
1365
1403
  result.valueStart = d.start;
1366
1404
 
1367
1405
  // Case 1: `export var foo = 'bar'`
1368
- if ( d.type === 'VariableDeclaration' ) {
1369
- result.hasDeclaration = true; // TODO remove in favour of result.type
1406
+ if (d.type === 'VariableDeclaration') {
1370
1407
  result.type = 'varDeclaration';
1371
1408
  result.name = d.declarations[0].id.name;
1372
1409
  }
1373
1410
 
1374
1411
  // Case 2: `export function foo () {...}`
1375
- else if ( d.type === 'FunctionDeclaration' ) {
1376
- result.hasDeclaration = true; // TODO remove in favour of result.type
1412
+ else if (d.type === 'FunctionDeclaration') {
1377
1413
  result.type = 'namedFunction';
1378
1414
  result.name = d.id.name;
1379
1415
  }
1380
1416
 
1381
1417
  // Case 3: `export class Foo {...}`
1382
- else if ( d.type === 'ClassDeclaration' ) {
1383
- result.hasDeclaration = true; // TODO remove in favour of result.type
1418
+ else if (d.type === 'ClassDeclaration') {
1384
1419
  result.type = 'namedClass';
1385
1420
  result.name = d.id.name;
1386
1421
  }
@@ -1389,8 +1424,9 @@
1389
1424
  // Case 9: `export { foo, bar };`
1390
1425
  else {
1391
1426
  result.type = 'named';
1392
- result.specifiers = node.specifiers.map( function(s ) {
1427
+ result.specifiers = node.specifiers.map(function (s) {
1393
1428
  return {
1429
+ origin: null, // filled in later by bundler
1394
1430
  name: s.local.name,
1395
1431
  as: s.exported.name
1396
1432
  };
@@ -1403,44 +1439,44 @@
1403
1439
  var hasOwnProp = Object.prototype.hasOwnProperty;
1404
1440
  var utils_hasOwnProp = hasOwnProp;
1405
1441
 
1406
- function getUnscopedNames ( mod ) {
1407
- var unscoped = [], importedNames, scope;
1442
+ var ast_getUnscopedNames = getUnscopedNames;
1443
+ function getUnscopedNames(mod) {
1444
+ var unscoped = [],
1445
+ importedNames,
1446
+ scope;
1408
1447
 
1409
- function imported ( name ) {
1410
- if ( !importedNames ) {
1448
+ function imported(name) {
1449
+ if (!importedNames) {
1411
1450
  importedNames = {};
1412
- mod.imports.forEach( function(i ) {
1413
- !i.passthrough && i.specifiers.forEach( function(s ) {
1414
- importedNames[ s.as ] = true;
1451
+ mod.imports.forEach(function (i) {
1452
+ !i.passthrough && i.specifiers.forEach(function (s) {
1453
+ importedNames[s.as] = true;
1415
1454
  });
1416
1455
  });
1417
1456
  }
1418
- return utils_hasOwnProp.call( importedNames, name );
1457
+ return utils_hasOwnProp.call(importedNames, name);
1419
1458
  }
1420
1459
 
1421
- walk( mod.ast, {
1422
- enter: function ( node ) {
1460
+ ast_walk(mod.ast, {
1461
+ enter: function (node) {
1423
1462
  // we're only interested in references, not property names etc
1424
- if ( node._skip ) return this.skip();
1463
+ if (node._skip) return this.skip();
1425
1464
 
1426
- if ( node._scope ) {
1465
+ if (node._scope) {
1427
1466
  scope = node._scope;
1428
1467
  }
1429
1468
 
1430
- if ( node.type === 'Identifier' &&
1431
- !scope.contains( node.name ) &&
1432
- !imported( node.name ) &&
1433
- !~unscoped.indexOf( node.name ) ) {
1434
- unscoped.push( node.name );
1469
+ if (node.type === 'Identifier' && !scope.contains(node.name) && !imported(node.name) && ! ~unscoped.indexOf(node.name)) {
1470
+ unscoped.push(node.name);
1435
1471
  }
1436
1472
  },
1437
1473
 
1438
- leave: function ( node ) {
1439
- if ( node.type === 'Program' ) {
1474
+ leave: function (node) {
1475
+ if (node.type === 'Program') {
1440
1476
  return;
1441
1477
  }
1442
1478
 
1443
- if ( node._scope ) {
1479
+ if (node._scope) {
1444
1480
  scope = scope.parent;
1445
1481
  }
1446
1482
  }
@@ -1449,62 +1485,66 @@
1449
1485
  return unscoped;
1450
1486
  }
1451
1487
 
1452
- function disallowConflictingImports ( imports ) {
1488
+ var utils_disallowConflictingImports = disallowConflictingImports;
1489
+ function disallowConflictingImports(imports) {
1453
1490
  var usedNames = {};
1454
1491
 
1455
- imports.forEach( function(x ) {
1456
- if ( x.passthrough ) return;
1492
+ imports.forEach(function (x) {
1493
+ if (x.passthrough) return;
1457
1494
 
1458
- if ( x.as ) {
1459
- checkName( x.as );
1495
+ if (x.as) {
1496
+ checkName(x.as);
1460
1497
  } else {
1461
- x.specifiers.forEach( checkSpecifier );
1498
+ x.specifiers.forEach(checkSpecifier);
1462
1499
  }
1463
1500
  });
1464
1501
 
1465
- function checkSpecifier ( s ) {
1466
- checkName( s.as );
1502
+ function checkSpecifier(s) {
1503
+ checkName(s.as);
1467
1504
  }
1468
1505
 
1469
- function checkName ( name ) {
1470
- if ( utils_hasOwnProp.call( usedNames, name ) ) {
1471
- throw new SyntaxError( (("Duplicated import ('" + name) + "')") );
1506
+ function checkName(name) {
1507
+ if (utils_hasOwnProp.call(usedNames, name)) {
1508
+ throw new SyntaxError('Duplicated import (\'' + name + '\')');
1472
1509
  }
1473
1510
 
1474
- usedNames[ name ] = true;
1511
+ usedNames[name] = true;
1475
1512
  }
1476
1513
  }
1477
1514
 
1478
- 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( ' ' );
1479
- var INVALID_CHAR = /[^a-zA-Z0-9_$]/g;
1480
- var INVALID_LEADING_CHAR = /[^a-zA-Z_$]/;
1481
-
1482
1515
  /**
1483
1516
  * Generates a sanitized (i.e. valid identifier) name from a module ID
1484
1517
  * @param {string} id - a module ID, or part thereof
1485
1518
  * @returns {string}
1486
1519
  */
1487
- function sanitize ( name ) {
1488
- name = name.replace( INVALID_CHAR, '_' );
1520
+ var utils_sanitize = sanitize;
1489
1521
 
1490
- if ( INVALID_LEADING_CHAR.test( name[0] ) || ~RESERVED.indexOf( name ) ) {
1491
- name = ("_" + name);
1522
+ 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(' ');
1523
+ var INVALID_CHAR = /[^a-zA-Z0-9_$]/g;
1524
+ var INVALID_LEADING_CHAR = /[^a-zA-Z_$]/;
1525
+ function sanitize(name) {
1526
+ name = name.replace(INVALID_CHAR, '_');
1527
+
1528
+ if (INVALID_LEADING_CHAR.test(name[0]) || ~RESERVED.indexOf(name)) {
1529
+ name = '_' + name;
1492
1530
  }
1493
1531
 
1494
1532
  return name;
1495
1533
  }
1496
1534
 
1497
1535
  var pathSplitRE = /\/|\\/;
1498
- function splitPath ( path ) {
1499
- return path.split( pathSplitRE );
1536
+ function splitPath(path) {
1537
+ return path.split(pathSplitRE);
1500
1538
  }
1501
1539
 
1502
- var SOURCEMAPPINGURL_REGEX = /^# sourceMappingURL=/;
1540
+ var getModule = getStandaloneModule;
1503
1541
 
1504
- function getStandaloneModule ( options ) {
1505
- var code, ast;
1542
+ var SOURCEMAPPINGURL_REGEX = /^# sourceMappingURL=/;
1543
+ function getStandaloneModule(options) {
1544
+ var code = undefined,
1545
+ ast = undefined;
1506
1546
 
1507
- if ( typeof options.source === 'object' ) {
1547
+ if (typeof options.source === 'object') {
1508
1548
  code = options.source.code;
1509
1549
  ast = options.source.ast;
1510
1550
  } else {
@@ -1514,199 +1554,211 @@
1514
1554
  var toRemove = [];
1515
1555
 
1516
1556
  var mod = {
1517
- body: new magic_string( code ),
1518
- ast: ast || ( acorn.parse( code, {
1557
+ body: new magic_string(code),
1558
+ ast: ast || acorn.parse(code, {
1519
1559
  ecmaVersion: 6,
1520
1560
  sourceType: 'module',
1521
- onComment: function ( block, text, start, end ) {
1561
+ onComment: function (block, text, start, end) {
1522
1562
  // sourceMappingURL comments should be removed
1523
- if ( !block && SOURCEMAPPINGURL_REGEX.test( text ) ) {
1563
+ if (!block && SOURCEMAPPINGURL_REGEX.test(text)) {
1524
1564
  toRemove.push({ start: start, end: end });
1525
1565
  }
1526
1566
  }
1527
- }))
1567
+ })
1528
1568
  };
1529
1569
 
1530
- toRemove.forEach( function(end) {var start = end.start, end = end.end;return mod.body.remove( start, end )} );
1570
+ toRemove.forEach(function (_ref) {
1571
+ var start = _ref.start;
1572
+ var end = _ref.end;
1573
+ return mod.body.remove(start, end);
1574
+ });
1531
1575
 
1532
- var imports = (exports = findImportsAndExports( mod, code, mod.ast ))[0], exports = exports[1];
1576
+ var _findImportsAndExports = ast_findImportsAndExports(mod.ast, code);
1533
1577
 
1534
- disallowConflictingImports( imports );
1578
+ var imports = _findImportsAndExports.imports;
1579
+ var exports = _findImportsAndExports.exports;
1580
+ var defaultExport = _findImportsAndExports.defaultExport;
1581
+
1582
+ utils_disallowConflictingImports(imports);
1535
1583
 
1536
1584
  mod.imports = imports;
1537
1585
  mod.exports = exports;
1586
+ mod.defaultExport = defaultExport;
1538
1587
 
1539
1588
  var conflicts = {};
1540
1589
 
1541
- if ( options.strict ) {
1542
- annotateAst( mod.ast );
1590
+ if (options.strict) {
1591
+ annotate(mod.ast, {
1592
+ trackAssignments: null
1593
+ });
1543
1594
 
1544
1595
  // TODO there's probably an easier way to get this array
1545
- Object.keys( mod.ast._declared ).concat( getUnscopedNames( mod ) ).forEach( function(n ) {
1596
+ Object.keys(mod.ast._declared).concat(ast_getUnscopedNames(mod)).forEach(function (n) {
1546
1597
  conflicts[n] = true;
1547
1598
  });
1548
1599
  }
1549
1600
 
1550
- determineImportNames( imports, options.getModuleName, conflicts );
1601
+ determineImportNames(imports, options.getModuleName, conflicts);
1551
1602
 
1552
1603
  return mod;
1553
1604
  }
1554
1605
 
1555
- function determineImportNames ( imports, userFn, usedNames ) {
1606
+ function determineImportNames(imports, userFn, usedNames) {
1556
1607
  var nameById = {};
1557
1608
  var inferredNames = {};
1558
1609
 
1559
- imports.forEach( function(x ) {
1610
+ imports.forEach(function (x) {
1560
1611
  var moduleId = x.path;
1561
- var name;
1612
+ var name = undefined;
1562
1613
 
1563
1614
  moduleId = x.path;
1564
1615
 
1565
1616
  // use existing value
1566
- if ( utils_hasOwnProp.call( nameById, moduleId ) ) {
1567
- x.name = nameById[ moduleId ];
1617
+ if (utils_hasOwnProp.call(nameById, moduleId)) {
1618
+ x.name = nameById[moduleId];
1568
1619
  return;
1569
1620
  }
1570
1621
 
1571
1622
  // if user supplied a function, defer to it
1572
- if ( userFn && ( name = userFn( moduleId ) ) ) {
1573
- name = sanitize( name );
1623
+ if (userFn && (name = userFn(moduleId))) {
1624
+ name = utils_sanitize(name);
1574
1625
 
1575
- if ( utils_hasOwnProp.call( usedNames, name ) ) {
1626
+ if (utils_hasOwnProp.call(usedNames, name)) {
1576
1627
  // TODO write a test for this
1577
- throw new Error( (("Naming collision: module " + moduleId) + (" cannot be called " + name) + "") );
1628
+ throw new Error('Naming collision: module ' + moduleId + ' cannot be called ' + name);
1578
1629
  }
1579
- }
1580
-
1581
- else {
1582
- var parts = splitPath( moduleId );
1583
- var i;
1630
+ } else {
1631
+ var parts = splitPath(moduleId);
1632
+ var i = undefined;
1584
1633
  var prefix = '';
1585
- var candidate;
1634
+ var candidate = undefined;
1586
1635
 
1587
1636
  do {
1588
1637
  i = parts.length;
1589
- while ( i-- > 0 ) {
1590
- candidate = prefix + sanitize( parts.slice( i ).join( '__' ) );
1638
+ while (i-- > 0) {
1639
+ candidate = prefix + utils_sanitize(parts.slice(i).join('__'));
1591
1640
 
1592
- if ( !utils_hasOwnProp.call( usedNames, candidate ) ) {
1641
+ if (!utils_hasOwnProp.call(usedNames, candidate)) {
1593
1642
  name = candidate;
1594
1643
  break;
1595
1644
  }
1596
1645
  }
1597
1646
 
1598
1647
  prefix += '_';
1599
- } while ( !name );
1648
+ } while (!name);
1600
1649
  }
1601
1650
 
1602
- usedNames[ name ] = true;
1603
- nameById[ moduleId ] = name;
1651
+ usedNames[name] = true;
1652
+ nameById[moduleId] = name;
1604
1653
 
1605
1654
  x.name = name;
1606
1655
  });
1607
1656
 
1608
1657
  // use inferred names for default imports, wherever they
1609
1658
  // don't clash with path-based names
1610
- imports.forEach( function(x ) {
1611
- if ( x.as && !utils_hasOwnProp.call( usedNames, x.as ) ) {
1612
- inferredNames[ x.path ] = x.as;
1659
+ imports.forEach(function (x) {
1660
+ if (x.as && !utils_hasOwnProp.call(usedNames, x.as)) {
1661
+ inferredNames[x.path] = x.as;
1613
1662
  }
1614
1663
  });
1615
1664
 
1616
- imports.forEach( function(x ) {
1617
- if ( utils_hasOwnProp.call( inferredNames, x.path ) ) {
1618
- x.name = inferredNames[ x.path ];
1665
+ imports.forEach(function (x) {
1666
+ if (utils_hasOwnProp.call(inferredNames, x.path)) {
1667
+ x.name = inferredNames[x.path];
1619
1668
  }
1620
1669
  });
1621
1670
  }
1622
1671
 
1623
- function transformExportDeclaration ( declaration, body ) {
1624
- if ( !declaration ) {
1672
+ var utils_transformExportDeclaration = transformExportDeclaration;
1673
+
1674
+ function transformExportDeclaration(declaration, body) {
1675
+ if (!declaration) {
1625
1676
  return;
1626
1677
  }
1627
1678
 
1628
- var exportedValue;
1679
+ var exportedValue = undefined;
1629
1680
 
1630
- switch ( declaration.type ) {
1681
+ switch (declaration.type) {
1631
1682
  case 'namedFunction':
1632
1683
  case 'namedClass':
1633
- body.remove( declaration.start, declaration.valueStart );
1684
+ body.remove(declaration.start, declaration.valueStart);
1634
1685
  exportedValue = declaration.name;
1635
1686
  break;
1636
1687
 
1637
1688
  case 'anonFunction':
1638
1689
  case 'anonClass':
1639
- if ( declaration.isFinal ) {
1640
- body.replace( declaration.start, declaration.valueStart, 'return ' );
1690
+ if (declaration.isFinal) {
1691
+ body.replace(declaration.start, declaration.valueStart, 'return ');
1641
1692
  } else {
1642
- body.replace( declaration.start, declaration.valueStart, 'var __export = ' );
1693
+ body.replace(declaration.start, declaration.valueStart, 'var __export = ');
1643
1694
  exportedValue = '__export';
1644
1695
  }
1645
1696
 
1646
1697
  // add semi-colon, if necessary
1647
1698
  // TODO body.original is an implementation detail of magic-string - there
1648
1699
  // should probably be an API for this sort of thing
1649
- if ( body.original[ declaration.end - 1 ] !== ';' ) {
1650
- body.insert( declaration.end, ';' );
1700
+ if (body.original[declaration.end - 1] !== ';') {
1701
+ body.insert(declaration.end, ';');
1651
1702
  }
1652
1703
 
1653
1704
  break;
1654
1705
 
1655
1706
  case 'expression':
1656
- body.remove( declaration.start, declaration.next );
1707
+ body.remove(declaration.start, declaration.next);
1657
1708
  exportedValue = declaration.value;
1658
1709
  break;
1659
1710
 
1660
1711
  default:
1661
- throw new Error( (("Unexpected export type '" + (declaration.type)) + "'") );
1712
+ throw new Error('Unexpected export type \'' + declaration.type + '\'');
1662
1713
  }
1663
1714
 
1664
- if ( exportedValue ) {
1665
- body.append( (("\nreturn " + exportedValue) + ";") );
1715
+ if (exportedValue) {
1716
+ body.append('\nreturn ' + exportedValue + ';');
1666
1717
  }
1667
1718
  }
1668
1719
 
1669
- var ABSOLUTE_PATH = /^(?:[A-Z]:)?[\/\\]/i;
1720
+ var utils_packageResult = packageResult;
1670
1721
 
1671
- var utils_packageResult__warned = {};
1722
+ var ABSOLUTE_PATH = /^(?:[A-Z]:)?[\/\\]/i;
1672
1723
 
1673
- function packageResult ( bundleOrModule, body, options, methodName, isBundle ) {
1724
+ var warned = {};
1725
+ function packageResult(bundleOrModule, body, options, methodName, isBundle) {
1674
1726
  // wrap output
1675
- if ( options.banner ) body.prepend( options.banner );
1676
- if ( options.footer ) body.append( options.footer );
1727
+ if (options.banner) body.prepend(options.banner);
1728
+ if (options.footer) body.append(options.footer);
1677
1729
 
1678
1730
  var code = body.toString();
1679
- var map;
1731
+ var map = undefined;
1680
1732
 
1681
- if ( !!options.sourceMap ) {
1682
- if ( options.sourceMap !== 'inline' && !options.sourceMapFile ) {
1683
- throw new Error( 'You must provide `sourceMapFile` option' );
1733
+ if (!!options.sourceMap) {
1734
+ if (options.sourceMap !== 'inline' && !options.sourceMapFile) {
1735
+ throw new Error('You must provide `sourceMapFile` option');
1684
1736
  }
1685
1737
 
1686
- if ( !isBundle && !options.sourceMapSource ) {
1687
- throw new Error( 'You must provide `sourceMapSource` option' );
1738
+ if (!isBundle && !options.sourceMapSource) {
1739
+ throw new Error('You must provide `sourceMapSource` option');
1688
1740
  }
1689
1741
 
1690
- var sourceMapFile;
1691
- if ( options.sourceMap === 'inline' ) {
1742
+ var sourceMapFile = undefined;
1743
+ if (options.sourceMap === 'inline') {
1692
1744
  sourceMapFile = null;
1693
1745
  } else {
1694
- sourceMapFile = ABSOLUTE_PATH.test( options.sourceMapFile ) ? options.sourceMapFile : './' + splitPath( options.sourceMapFile ).pop();
1746
+ sourceMapFile = ABSOLUTE_PATH.test(options.sourceMapFile) ? options.sourceMapFile : './' + splitPath(options.sourceMapFile).pop();
1695
1747
  }
1696
1748
 
1697
- if ( isBundle ) {
1698
- markBundleSourcemapLocations( bundleOrModule );
1749
+ if (isBundle) {
1750
+ markBundleSourcemapLocations(bundleOrModule);
1699
1751
  } else {
1700
- markModuleSourcemapLocations( bundleOrModule );
1752
+ markModuleSourcemapLocations(bundleOrModule);
1701
1753
  }
1702
1754
 
1703
1755
  map = body.generateMap({
1704
1756
  includeContent: true,
1705
1757
  file: sourceMapFile,
1706
- source: ( sourceMapFile && !isBundle ) ? utils_packageResult__getRelativePath( sourceMapFile, options.sourceMapSource ) : null
1758
+ source: sourceMapFile && !isBundle ? utils_packageResult__getRelativePath(sourceMapFile, options.sourceMapSource) : null
1707
1759
  });
1708
1760
 
1709
- if ( options.sourceMap === 'inline' ) {
1761
+ if (options.sourceMap === 'inline') {
1710
1762
  code += '\n//# sourceMa' + 'ppingURL=' + map.toUrl();
1711
1763
  map = null;
1712
1764
  } else {
@@ -1720,9 +1772,9 @@
1720
1772
  code: code,
1721
1773
  map: map,
1722
1774
  toString: function () {
1723
- if ( !utils_packageResult__warned[ methodName ] ) {
1724
- console.log( (("Warning: esperanto." + methodName) + "() returns an object with a 'code' property. You should use this instead of using the returned value directly") );
1725
- utils_packageResult__warned[ methodName ] = true;
1775
+ if (!warned[methodName]) {
1776
+ console.log('Warning: esperanto.' + methodName + '() returns an object with a \'code\' property. You should use this instead of using the returned value directly');
1777
+ warned[methodName] = true;
1726
1778
  }
1727
1779
 
1728
1780
  return code;
@@ -1730,157 +1782,183 @@
1730
1782
  };
1731
1783
  }
1732
1784
 
1733
- function utils_packageResult__getRelativePath ( from, to ) {
1785
+ function utils_packageResult__getRelativePath(from, to) {
1734
1786
  var fromParts, toParts, i;
1735
1787
 
1736
- fromParts = splitPath( from );
1737
- toParts = splitPath( to );
1788
+ fromParts = splitPath(from);
1789
+ toParts = splitPath(to);
1738
1790
 
1739
1791
  fromParts.pop(); // get dirname
1740
1792
 
1741
- while ( fromParts[0] === '.' ) {
1793
+ while (fromParts[0] === '.') {
1742
1794
  fromParts.shift();
1743
1795
  }
1744
1796
 
1745
- while ( fromParts[0] === toParts[0] ) {
1797
+ while (fromParts[0] === toParts[0]) {
1746
1798
  fromParts.shift();
1747
1799
  toParts.shift();
1748
1800
  }
1749
1801
 
1750
- if ( fromParts.length ) {
1802
+ if (fromParts.length) {
1751
1803
  i = fromParts.length;
1752
- while ( i-- ) fromParts[i] = '..';
1804
+ while (i--) fromParts[i] = '..';
1753
1805
 
1754
- return fromParts.concat( toParts ).join( '/' );
1806
+ return fromParts.concat(toParts).join('/');
1755
1807
  } else {
1756
- toParts.unshift( '.' );
1757
- return toParts.join( '/' );
1808
+ toParts.unshift('.');
1809
+ return toParts.join('/');
1758
1810
  }
1759
1811
  }
1760
1812
 
1761
- function markBundleSourcemapLocations ( bundle ) {
1762
- bundle.modules.forEach( function(mod ) {
1763
- walk( mod.ast, {
1764
- enter: function(node ) {
1765
- mod.body.addSourcemapLocation( node.start );
1813
+ function markBundleSourcemapLocations(bundle) {
1814
+ bundle.modules.forEach(function (mod) {
1815
+ ast_walk(mod.ast, {
1816
+ enter: function (node) {
1817
+ mod.body.addSourcemapLocation(node.start);
1766
1818
  }
1767
1819
  });
1768
1820
  });
1769
1821
  }
1770
1822
 
1771
- function markModuleSourcemapLocations ( mod ) {
1772
- walk( mod.ast, {
1773
- enter: function(node ) {
1774
- mod.body.addSourcemapLocation( node.start );
1823
+ function markModuleSourcemapLocations(mod) {
1824
+ ast_walk(mod.ast, {
1825
+ enter: function (node) {
1826
+ mod.body.addSourcemapLocation(node.start);
1775
1827
  }
1776
1828
  });
1777
1829
  }
1778
1830
 
1779
- function resolveId ( importPath, importerPath ) {
1831
+ /**
1832
+ * Resolves an importPath relative to the module that is importing it
1833
+ * @param {string} importPath - the (possibly relative) path of an imported module
1834
+ * @param {string} importerPath - the (relative to `base`) path of the importing module
1835
+ * @returns {string}
1836
+ */
1837
+ var utils_resolveId = resolveId;
1838
+
1839
+ function resolveId(importPath, importerPath) {
1780
1840
  var resolved, importerParts, importParts;
1781
1841
 
1782
- if ( importPath[0] !== '.' ) {
1842
+ if (importPath[0] !== '.') {
1783
1843
  resolved = importPath;
1784
1844
  } else {
1785
- importerParts = splitPath( importerPath );
1786
- importParts = splitPath( importPath );
1845
+ importerParts = splitPath(importerPath);
1846
+ importParts = splitPath(importPath);
1787
1847
 
1788
- if ( importParts[0] === '.' ) {
1848
+ if (importParts[0] === '.') {
1789
1849
  importParts.shift();
1790
1850
  }
1791
1851
 
1792
1852
  importerParts.pop(); // get dirname
1793
- while ( importParts[0] === '..' ) {
1853
+ while (importParts[0] === '..') {
1794
1854
  importParts.shift();
1795
1855
  importerParts.pop();
1796
1856
  }
1797
1857
 
1798
- while ( importParts[0] === '.' ) {
1858
+ while (importParts[0] === '.') {
1799
1859
  importParts.shift();
1800
1860
  }
1801
1861
 
1802
- resolved = importerParts.concat( importParts ).join( '/' );
1862
+ resolved = importerParts.concat(importParts).join('/');
1803
1863
  }
1804
1864
 
1805
1865
  return resolved;
1806
1866
  }
1807
1867
 
1808
- function resolveAgainst ( importerPath ) {
1809
- return function ( importPath ) {
1810
- return resolveId( importPath, importerPath );
1868
+ function resolveAgainst(importerPath) {
1869
+ return function (importPath) {
1870
+ return resolveId(importPath, importerPath);
1811
1871
  };
1812
1872
  }
1813
1873
 
1814
- function getImportSummary (name) {var imports = name.imports, absolutePaths = name.absolutePaths, name = name.name;
1874
+ var amd_getImportSummary = getImportSummary;
1875
+ function getImportSummary(_ref) {
1876
+ var imports = _ref.imports;
1877
+ var absolutePaths = _ref.absolutePaths;
1878
+ var name = _ref.name;
1879
+
1815
1880
  var paths = [];
1816
1881
  var names = [];
1817
1882
  var seen = {};
1818
1883
  var placeholders = 0;
1819
1884
 
1820
- imports.forEach( function(x ) {
1885
+ imports.forEach(function (x) {
1821
1886
  var path = x.id || x.path; // TODO unify these
1822
1887
 
1823
- if ( !seen[ path ] ) {
1824
- seen[ path ] = true;
1888
+ if (!seen[path]) {
1889
+ seen[path] = true;
1825
1890
 
1826
- paths.push( path );
1891
+ paths.push(path);
1827
1892
 
1828
1893
  // TODO x could be an external module, or an internal one.
1829
1894
  // they have different shapes, resulting in the confusing
1830
1895
  // code below
1831
- if ( ( x.needsDefault || x.needsNamed ) || ( x.specifiers && x.specifiers.length ) ) {
1832
- while ( placeholders ) {
1833
- names.push( (("__dep" + (names.length)) + "__") );
1896
+ if (x.needsDefault || x.needsNamed || x.specifiers && x.specifiers.length) {
1897
+ while (placeholders) {
1898
+ names.push('__dep' + names.length + '__');
1834
1899
  placeholders--;
1835
1900
  }
1836
- names.push( x.name );
1901
+ names.push(x.name);
1837
1902
  } else {
1838
1903
  placeholders++;
1839
1904
  }
1840
1905
  }
1841
1906
  });
1842
1907
 
1843
- var ids = absolutePaths ? paths.map( function(relativePath ) {return resolveId( relativePath, name )} ) : paths.slice();
1908
+ var ids = absolutePaths ? paths.map(function (relativePath) {
1909
+ return utils_resolveId(relativePath, name);
1910
+ }) : paths.slice();
1844
1911
 
1845
1912
  return { ids: ids, paths: paths, names: names };
1846
1913
  }
1847
1914
 
1848
- function processName ( name ) {
1849
- return name ? quote( name ) + ', ' : '';
1915
+ var amd_processName = processName;
1916
+ function processName(name) {
1917
+ return name ? quote(name) + ', ' : '';
1850
1918
  }
1851
1919
 
1852
- function processIds ( ids ) {
1853
- return ids.length ? '[' + ids.map( quote ).join( ', ' ) + '], ' : '';
1920
+ var amd_processIds = processIds;
1921
+ function processIds(ids) {
1922
+ return ids.length ? '[' + ids.map(quote).join(', ') + '], ' : '';
1854
1923
  }
1855
1924
 
1856
- function amdIntro (useStrict) {var name = useStrict.name, imports = useStrict.imports, hasExports = useStrict.hasExports, indentStr = useStrict.indentStr, absolutePaths = useStrict.absolutePaths, useStrict = useStrict.useStrict;
1857
- var ids = (names = getImportSummary({ name: name, imports: imports, absolutePaths: absolutePaths })).ids, names = names.names;
1925
+ var amd_amdIntro = amdIntro;
1926
+ function amdIntro(_ref) {
1927
+ var name = _ref.name;
1928
+ var imports = _ref.imports;
1929
+ var hasExports = _ref.hasExports;
1930
+ var indentStr = _ref.indentStr;
1931
+ var absolutePaths = _ref.absolutePaths;
1932
+ var useStrict = _ref.useStrict;
1933
+
1934
+ var _getImportSummary = amd_getImportSummary({ name: name, imports: imports, absolutePaths: absolutePaths });
1935
+
1936
+ var ids = _getImportSummary.ids;
1937
+ var names = _getImportSummary.names;
1858
1938
 
1859
- if ( hasExports ) {
1860
- ids.unshift( 'exports' );
1861
- names.unshift( 'exports' );
1939
+ if (hasExports) {
1940
+ ids.unshift('exports');
1941
+ names.unshift('exports');
1862
1942
  }
1863
1943
 
1864
- var intro = (("\
1865
- \ndefine(" + (processName(name))) + ("" + (processIds(ids))) + ("function (" + (names.join( ', ' ))) + ") {\
1866
- \n\
1867
- \n");
1944
+ var intro = '\ndefine(' + amd_processName(name) + '' + amd_processIds(ids) + 'function (' + names.join(', ') + ') {\n\n';
1868
1945
 
1869
- if ( useStrict ) {
1870
- intro += (("" + indentStr) + "'use strict';\n\n");
1946
+ if (useStrict) {
1947
+ intro += '' + indentStr + '\'use strict\';\n\n';
1871
1948
  }
1872
1949
 
1873
1950
  return intro;
1874
1951
  }
1875
1952
 
1876
- function defaultsMode_amd__amd ( mod, options ) {
1877
- mod.imports.forEach( function(x ) {
1878
- mod.body.remove( x.start, x.next );
1953
+ var defaultsMode_amd = defaultsMode_amd__amd;
1954
+ function defaultsMode_amd__amd(mod, options) {
1955
+ mod.imports.forEach(function (x) {
1956
+ mod.body.remove(x.start, x.next);
1879
1957
  });
1880
1958
 
1881
- transformExportDeclaration( mod.exports[0], mod.body );
1959
+ utils_transformExportDeclaration(mod.exports[0], mod.body);
1882
1960
 
1883
- var intro = amdIntro({
1961
+ var intro = amd_amdIntro({
1884
1962
  name: options.amdName,
1885
1963
  imports: mod.imports,
1886
1964
  absolutePaths: options.absolutePaths,
@@ -1888,121 +1966,118 @@
1888
1966
  useStrict: options.useStrict !== false
1889
1967
  });
1890
1968
 
1891
- mod.body.trim()
1892
- .indent()
1893
- .prepend( intro )
1894
- .trim()
1895
- .append( '\n\n});' );
1969
+ mod.body.trim().indent().prepend(intro).trim().append('\n\n});');
1896
1970
 
1897
- return packageResult( mod, mod.body, options, 'toAmd' );
1971
+ return utils_packageResult(mod, mod.body, options, 'toAmd');
1898
1972
  }
1899
1973
 
1900
- function defaultsMode_cjs__cjs ( mod, options ) {
1974
+ var defaultsMode_cjs = defaultsMode_cjs__cjs;
1975
+ function defaultsMode_cjs__cjs(mod, options) {
1901
1976
  var seen = {};
1902
1977
 
1903
- mod.imports.forEach( function(x ) {
1904
- if ( !utils_hasOwnProp.call( seen, x.path ) ) {
1905
- var replacement = x.isEmpty ? (("" + (req(x.path))) + ";") : (("var " + (x.as)) + (" = " + (req(x.path))) + ";");
1906
- mod.body.replace( x.start, x.end, replacement );
1978
+ mod.imports.forEach(function (x) {
1979
+ if (!utils_hasOwnProp.call(seen, x.path)) {
1980
+ var replacement = x.isEmpty ? '' + req(x.path) + ';' : 'var ' + x.as + ' = ' + req(x.path) + ';';
1981
+ mod.body.replace(x.start, x.end, replacement);
1907
1982
 
1908
- seen[ x.path ] = true;
1983
+ seen[x.path] = true;
1909
1984
  } else {
1910
- mod.body.remove( x.start, x.next );
1985
+ mod.body.remove(x.start, x.next);
1911
1986
  }
1912
1987
  });
1913
1988
 
1914
1989
  var exportDeclaration = mod.exports[0];
1915
1990
 
1916
- if ( exportDeclaration ) {
1917
- switch ( exportDeclaration.type ) {
1991
+ if (exportDeclaration) {
1992
+ switch (exportDeclaration.type) {
1918
1993
  case 'namedFunction':
1919
1994
  case 'namedClass':
1920
- mod.body.remove( exportDeclaration.start, exportDeclaration.valueStart );
1921
- mod.body.replace( exportDeclaration.end, exportDeclaration.end, (("\nmodule.exports = " + (exportDeclaration.node.declaration.id.name)) + ";") );
1995
+ mod.body.remove(exportDeclaration.start, exportDeclaration.valueStart);
1996
+ mod.body.replace(exportDeclaration.end, exportDeclaration.end, '\nmodule.exports = ' + exportDeclaration.name + ';');
1922
1997
  break;
1923
1998
 
1924
1999
  default:
1925
- mod.body.replace( exportDeclaration.start, exportDeclaration.valueStart, 'module.exports = ' );
2000
+ mod.body.replace(exportDeclaration.start, exportDeclaration.valueStart, 'module.exports = ');
1926
2001
  break;
1927
2002
  }
1928
2003
  }
1929
2004
 
1930
- if ( options.useStrict !== false ) {
1931
- mod.body.prepend( "'use strict';\n\n" ).trimLines();
2005
+ if (options.useStrict !== false) {
2006
+ mod.body.prepend('\'use strict\';\n\n').trimLines();
1932
2007
  }
1933
2008
 
1934
- return packageResult( mod, mod.body, options, 'toCjs' );
2009
+ return utils_packageResult(mod, mod.body, options, 'toCjs');
1935
2010
  }
1936
2011
 
1937
- function umdIntro (useStrict) {var amdName = useStrict.amdName, name = useStrict.name, hasExports = useStrict.hasExports, imports = useStrict.imports, absolutePaths = useStrict.absolutePaths, externalDefaults = useStrict.externalDefaults, indentStr = useStrict.indentStr, strict = useStrict.strict, useStrict = useStrict.useStrict;
1938
- var useStrictPragma = useStrict ? (" 'use strict';") : '';
1939
- var intro;
2012
+ var umd_umdIntro = umdIntro;
2013
+ function umdIntro(_ref) {
2014
+ var amdName = _ref.amdName;
2015
+ var name = _ref.name;
2016
+ var hasExports = _ref.hasExports;
2017
+ var imports = _ref.imports;
2018
+ var absolutePaths = _ref.absolutePaths;
2019
+ var externalDefaults = _ref.externalDefaults;
2020
+ var indentStr = _ref.indentStr;
2021
+ var strict = _ref.strict;
2022
+ var useStrict = _ref.useStrict;
1940
2023
 
1941
- if ( !hasExports && !imports.length ) {
1942
- intro =
1943
- (("(function (factory) {\
1944
- \n !(typeof exports === 'object' && typeof module !== 'undefined') &&\
1945
- \n typeof define === 'function' && define.amd ? define(" + (processName(amdName))) + ("factory) :\
1946
- \n factory()\
1947
- \n }(function () {" + useStrictPragma) + "\
1948
- \n\
1949
- \n ");
1950
- }
2024
+ var useStrictPragma = useStrict ? ' \'use strict\';' : '';
2025
+ var intro = undefined;
1951
2026
 
1952
- else {
1953
- var ids = (names = getImportSummary({ imports: imports, name: amdName, absolutePaths: absolutePaths })).ids, paths = names.paths, names = names.names;
2027
+ if (!hasExports && !imports.length) {
2028
+ intro = '(function (factory) {\n\t\t\t\t!(typeof exports === \'object\' && typeof module !== \'undefined\') &&\n\t\t\t\ttypeof define === \'function\' && define.amd ? define(' + amd_processName(amdName) + 'factory) :\n\t\t\t\tfactory()\n\t\t\t}(function () {' + useStrictPragma + '\n\n\t\t\t';
2029
+ } else {
2030
+ var _getImportSummary = amd_getImportSummary({ imports: imports, name: amdName, absolutePaths: absolutePaths });
2031
+
2032
+ var ids = _getImportSummary.ids;
2033
+ var paths = _getImportSummary.paths;
2034
+ var names = _getImportSummary.names;
1954
2035
 
1955
- var amdExport, cjsExport, globalExport, defaultsBlock;
2036
+ var amdExport = undefined,
2037
+ cjsExport = undefined,
2038
+ globalExport = undefined,
2039
+ defaultsBlock = undefined;
1956
2040
 
1957
- if ( strict ) {
1958
- cjsExport = (("factory(" + (( hasExports ? [ 'exports' ] : [] ).concat( paths.map( req ) ).join( ', ' ))) + ")");
1959
- var globalDeps = ( hasExports ? [ (("(global." + name) + " = {})") ] : [] ).concat( names.map( globalify ) ).join( ', ' );
1960
- globalExport = (("factory(" + globalDeps) + ")");
2041
+ if (strict) {
2042
+ cjsExport = 'factory(' + (hasExports ? ['exports'] : []).concat(paths.map(req)).join(', ') + ')';
2043
+ var globalDeps = (hasExports ? ['(global.' + name + ' = {})'] : []).concat(names.map(globalify)).join(', ');
2044
+ globalExport = 'factory(' + globalDeps + ')';
1961
2045
 
1962
- if ( hasExports ) {
1963
- ids.unshift( 'exports' );
1964
- names.unshift( 'exports' );
2046
+ if (hasExports) {
2047
+ ids.unshift('exports');
2048
+ names.unshift('exports');
1965
2049
  }
1966
2050
 
1967
- amdExport = (("define(" + (processName(amdName))) + ("" + (processIds(ids))) + "factory)");
2051
+ amdExport = 'define(' + amd_processName(amdName) + '' + amd_processIds(ids) + 'factory)';
1968
2052
  defaultsBlock = '';
1969
- if ( externalDefaults && externalDefaults.length > 0 ) {
1970
- defaultsBlock = externalDefaults.map( function(x )
1971
- {return '\t' + ( x.needsNamed ? (("var " + (x.name)) + "__default") : x.name ) +
1972
- ((" = ('default' in " + (x.name)) + (" ? " + (x.name)) + ("['default'] : " + (x.name)) + ");")}
1973
- ).join('\n') + '\n\n';
2053
+ if (externalDefaults && externalDefaults.length > 0) {
2054
+ defaultsBlock = externalDefaults.map(function (x) {
2055
+ return '\t' + (x.needsNamed ? 'var ' + x.name + '__default' : x.name) + (' = (\'default\' in ' + x.name + ' ? ' + x.name + '[\'default\'] : ' + x.name + ');');
2056
+ }).join('\n') + '\n\n';
1974
2057
  }
1975
2058
  } else {
1976
- amdExport = (("define(" + (processName(amdName))) + ("" + (processIds(ids))) + "factory)");
1977
- cjsExport = ( hasExports ? 'module.exports = ' : '' ) + (("factory(" + (paths.map( req ).join( ', ' ))) + ")");
1978
- globalExport = ( hasExports ? (("global." + name) + " = ") : '' ) + (("factory(" + (names.map( globalify ).join( ', ' ))) + ")");
2059
+ amdExport = 'define(' + amd_processName(amdName) + '' + amd_processIds(ids) + 'factory)';
2060
+ cjsExport = (hasExports ? 'module.exports = ' : '') + ('factory(' + paths.map(req).join(', ') + ')');
2061
+ globalExport = (hasExports ? 'global.' + name + ' = ' : '') + ('factory(' + names.map(globalify).join(', ') + ')');
1979
2062
 
1980
2063
  defaultsBlock = '';
1981
2064
  }
1982
2065
 
1983
- intro =
1984
- (("(function (global, factory) {\
1985
- \n typeof exports === 'object' && typeof module !== 'undefined' ? " + cjsExport) + (" :\
1986
- \n typeof define === 'function' && define.amd ? " + amdExport) + (" :\
1987
- \n " + globalExport) + ("\
1988
- \n }(this, function (" + (names.join( ', ' ))) + (") {" + useStrictPragma) + ("\
1989
- \n\
1990
- \n " + defaultsBlock) + "");
1991
-
2066
+ intro = '(function (global, factory) {\n\t\t\t\ttypeof exports === \'object\' && typeof module !== \'undefined\' ? ' + cjsExport + ' :\n\t\t\t\ttypeof define === \'function\' && define.amd ? ' + amdExport + ' :\n\t\t\t\t' + globalExport + '\n\t\t\t}(this, function (' + names.join(', ') + ') {' + useStrictPragma + '\n\n\t\t\t' + defaultsBlock;
1992
2067
  }
1993
2068
 
1994
- return intro.replace( /^\t\t\t/gm, '' ).replace( /\t/g, indentStr );
2069
+ return intro.replace(/^\t\t\t/gm, '').replace(/\t/g, indentStr);
1995
2070
  }
1996
2071
 
1997
- var EsperantoError = function ( message, data ) {
2072
+ var EsperantoError = function (message, data) {
1998
2073
  var prop;
1999
2074
 
2000
2075
  this.message = message;
2001
- this.stack = (new Error()).stack;
2076
+ this.stack = new Error().stack;
2002
2077
 
2003
- for ( prop in data ) {
2004
- if ( data.hasOwnProperty( prop ) ) {
2005
- this[ prop ] = data[ prop ];
2078
+ for (prop in data) {
2079
+ if (data.hasOwnProperty(prop)) {
2080
+ this[prop] = data[prop];
2006
2081
  }
2007
2082
  }
2008
2083
  };
@@ -2013,22 +2088,24 @@
2013
2088
 
2014
2089
  var utils_EsperantoError = EsperantoError;
2015
2090
 
2016
- function requireName ( options ) {
2017
- if ( !options.name ) {
2018
- throw new utils_EsperantoError( 'You must supply a `name` option for UMD modules', {
2091
+ var umd_requireName = requireName;
2092
+ function requireName(options) {
2093
+ if (!options.name) {
2094
+ throw new utils_EsperantoError('You must supply a `name` option for UMD modules', {
2019
2095
  code: 'MISSING_NAME'
2020
2096
  });
2021
2097
  }
2022
2098
  }
2023
2099
 
2024
- function defaultsMode_umd__umd ( mod, options ) {
2025
- requireName( options );
2100
+ var defaultsMode_umd = defaultsMode_umd__umd;
2101
+ function defaultsMode_umd__umd(mod, options) {
2102
+ umd_requireName(options);
2026
2103
 
2027
- mod.imports.forEach( function(x ) {
2028
- mod.body.remove( x.start, x.next );
2104
+ mod.imports.forEach(function (x) {
2105
+ mod.body.remove(x.start, x.next);
2029
2106
  });
2030
2107
 
2031
- var intro = umdIntro({
2108
+ var intro = umd_umdIntro({
2032
2109
  hasExports: mod.exports.length > 0,
2033
2110
  imports: mod.imports,
2034
2111
  amdName: options.amdName,
@@ -2038,56 +2115,60 @@
2038
2115
  useStrict: options.useStrict !== false
2039
2116
  });
2040
2117
 
2041
- transformExportDeclaration( mod.exports[0], mod.body );
2118
+ utils_transformExportDeclaration(mod.exports[0], mod.body);
2042
2119
 
2043
- mod.body.indent().prepend( intro ).trimLines().append( '\n\n}));' );
2120
+ mod.body.indent().prepend(intro).trimLines().append('\n\n}));');
2044
2121
 
2045
- return packageResult( mod, mod.body, options, 'toUmd' );
2122
+ return utils_packageResult(mod, mod.body, options, 'toUmd');
2046
2123
  }
2047
2124
 
2048
2125
  var defaultsMode = {
2049
- amd: defaultsMode_amd__amd,
2050
- cjs: defaultsMode_cjs__cjs,
2051
- umd: defaultsMode_umd__umd
2126
+ amd: defaultsMode_amd,
2127
+ cjs: defaultsMode_cjs,
2128
+ umd: defaultsMode_umd
2052
2129
  };
2053
2130
 
2054
- function gatherImports ( imports ) {
2131
+ var utils_gatherImports = gatherImports;
2132
+
2133
+ function gatherImports(imports) {
2055
2134
  var chains = {};
2056
2135
  var identifierReplacements = {};
2057
2136
 
2058
- imports.forEach( function(x ) {
2059
- x.specifiers.forEach( function(s ) {
2060
- if ( s.isBatch ) {
2137
+ imports.forEach(function (x) {
2138
+ x.specifiers.forEach(function (s) {
2139
+ if (s.isBatch) {
2061
2140
  return;
2062
2141
  }
2063
2142
 
2064
2143
  var name = s.as;
2065
- var replacement = x.name + ( s.isDefault ? ("['default']") : ("." + (s.name)) );
2144
+ var replacement = x.name + (s.isDefault ? "['default']" : "." + s.name);
2066
2145
 
2067
- if ( !x.passthrough ) {
2068
- identifierReplacements[ name ] = replacement;
2146
+ if (!x.passthrough) {
2147
+ identifierReplacements[name] = replacement;
2069
2148
  }
2070
2149
 
2071
- chains[ name ] = replacement;
2150
+ chains[name] = replacement;
2072
2151
  });
2073
2152
  });
2074
2153
 
2075
- return [ chains, identifierReplacements ];
2154
+ return [chains, identifierReplacements];
2076
2155
  }
2077
2156
 
2078
- function getExportNames ( exports ) {
2157
+ var utils_getExportNames = getExportNames;
2158
+
2159
+ function getExportNames(exports) {
2079
2160
  var result = {};
2080
2161
 
2081
- exports.forEach( function(x ) {
2082
- if ( x.isDefault ) return;
2162
+ exports.forEach(function (x) {
2163
+ if (x.isDefault) return;
2083
2164
 
2084
- if ( x.hasDeclaration ) {
2085
- result[ x.name ] = x.name;
2165
+ if (x.hasDeclaration) {
2166
+ result[x.name] = x.name;
2086
2167
  return;
2087
2168
  }
2088
2169
 
2089
- x.specifiers.forEach( function(s ) {
2090
- result[ s.name ] = s.as;
2170
+ x.specifiers.forEach(function (s) {
2171
+ result[s.name] = s.as;
2091
2172
  });
2092
2173
  });
2093
2174
 
@@ -2102,128 +2183,136 @@
2102
2183
  * @param {array} imports - the array of imports
2103
2184
  * @returns {array} [ importedBindings, importedNamespaces ]
2104
2185
  */
2105
- function getReadOnlyIdentifiers ( imports ) {
2106
- var importedBindings = {}, importedNamespaces = {};
2186
+ var utils_getReadOnlyIdentifiers = getReadOnlyIdentifiers;
2187
+
2188
+ function getReadOnlyIdentifiers(imports) {
2189
+ var importedBindings = {},
2190
+ importedNamespaces = {};
2107
2191
 
2108
- imports.forEach( function(x ) {
2109
- if ( x.passthrough ) return;
2192
+ imports.forEach(function (x) {
2193
+ if (x.passthrough) return;
2110
2194
 
2111
- x.specifiers.forEach( function(s ) {
2112
- if ( s.isBatch ) {
2113
- importedNamespaces[ s.as ] = true;
2195
+ x.specifiers.forEach(function (s) {
2196
+ if (s.isBatch) {
2197
+ importedNamespaces[s.as] = true;
2114
2198
  } else {
2115
- importedBindings[ s.as ] = true;
2199
+ importedBindings[s.as] = true;
2116
2200
  }
2117
2201
  });
2118
2202
  });
2119
2203
 
2120
- return [ importedBindings, importedNamespaces ];
2204
+ return [importedBindings, importedNamespaces];
2121
2205
  }
2122
2206
 
2207
+ var ast_disallowIllegalReassignment = disallowIllegalReassignment;
2123
2208
  var bindingMessage = 'Cannot reassign imported binding ',
2124
- namespaceMessage = 'Cannot reassign imported binding of namespace ';
2209
+ namespaceMessage = 'Cannot reassign imported binding of namespace ';
2210
+ function disallowIllegalReassignment(node, importedBindings, importedNamespaces, scope) {
2211
+ var assignee = undefined,
2212
+ isNamespaceAssignment = undefined;
2125
2213
 
2126
- function disallowIllegalReassignment ( node, importedBindings, importedNamespaces, scope ) {
2127
- var assignee, isNamespaceAssignment;
2128
-
2129
- if ( node.type === 'AssignmentExpression' ) {
2214
+ if (node.type === 'AssignmentExpression') {
2130
2215
  assignee = node.left;
2131
- } else if ( node.type === 'UpdateExpression' ) {
2216
+ } else if (node.type === 'UpdateExpression') {
2132
2217
  assignee = node.argument;
2133
2218
  } else {
2134
2219
  return; // not an assignment
2135
2220
  }
2136
2221
 
2137
- if ( assignee.type === 'MemberExpression' ) {
2222
+ if (assignee.type === 'MemberExpression') {
2138
2223
  assignee = assignee.object;
2139
2224
  isNamespaceAssignment = true;
2140
2225
  }
2141
2226
 
2142
- if ( assignee.type !== 'Identifier' ) {
2227
+ if (assignee.type !== 'Identifier') {
2143
2228
  return; // not assigning to a binding
2144
2229
  }
2145
2230
 
2146
2231
  var name = assignee.name;
2147
2232
 
2148
- if ( utils_hasOwnProp.call( isNamespaceAssignment ? importedNamespaces : importedBindings, name ) && !scope.contains( name ) ) {
2149
- throw new Error( ( isNamespaceAssignment ? namespaceMessage : bindingMessage ) + '`' + name + '`' );
2233
+ if (utils_hasOwnProp.call(isNamespaceAssignment ? importedNamespaces : importedBindings, name) && !scope.contains(name)) {
2234
+ throw new Error((isNamespaceAssignment ? namespaceMessage : bindingMessage) + '`' + name + '`');
2150
2235
  }
2151
2236
  }
2152
2237
 
2153
- function replaceIdentifiers ( body, node, identifierReplacements, scope ) {
2238
+ var ast_replaceIdentifiers = replaceIdentifiers;
2239
+ function replaceIdentifiers(body, node, identifierReplacements, scope) {
2154
2240
  var name = node.name;
2155
- var replacement = utils_hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
2241
+ var replacement = utils_hasOwnProp.call(identifierReplacements, name) && identifierReplacements[name];
2156
2242
 
2157
2243
  // TODO unchanged identifiers shouldn't have got this far -
2158
2244
  // remove the `replacement !== name` safeguard once that's the case
2159
- if ( replacement && replacement !== name && !scope.contains( name, true ) ) {
2245
+ if (replacement && replacement !== name && !scope.contains(name, true)) {
2160
2246
  // rewrite
2161
- body.replace( node.start, node.end, replacement );
2247
+ body.replace(node.start, node.end, replacement);
2162
2248
  }
2163
2249
  }
2164
2250
 
2165
- function rewriteExportAssignments ( body, node, parent, exports, scope, capturedUpdates ) {
2166
- var assignee;
2251
+ var ast_rewriteExportAssignments = rewriteExportAssignments;
2252
+ function rewriteExportAssignments(body, node, parent, exports, scope, capturedUpdates) {
2253
+ var assignee = undefined;
2167
2254
 
2168
- if ( node.type === 'AssignmentExpression' ) {
2255
+ if (node.type === 'AssignmentExpression') {
2169
2256
  assignee = node.left;
2170
- } else if ( node.type === 'UpdateExpression' ) {
2257
+ } else if (node.type === 'UpdateExpression') {
2171
2258
  assignee = node.argument;
2172
2259
  } else {
2173
2260
  return; // not an assignment
2174
2261
  }
2175
2262
 
2176
- if ( assignee.type !== 'Identifier' ) {
2263
+ if (assignee.type !== 'Identifier') {
2177
2264
  return;
2178
2265
  }
2179
2266
 
2180
2267
  var name = assignee.name;
2181
2268
 
2182
- if ( scope.contains( name, true ) ) {
2269
+ if (scope.contains(name, true)) {
2183
2270
  return; // shadows an export
2184
2271
  }
2185
2272
 
2186
- if ( exports && utils_hasOwnProp.call( exports, name ) ) {
2187
- var exportAs = exports[ name ];
2273
+ if (exports && utils_hasOwnProp.call(exports, name)) {
2274
+ var exportAs = exports[name];
2188
2275
 
2189
- if ( !!capturedUpdates ) {
2276
+ if (!!capturedUpdates) {
2190
2277
  capturedUpdates.push({ name: name, exportAs: exportAs });
2191
2278
  return;
2192
2279
  }
2193
2280
 
2194
2281
  // special case - increment/decrement operators
2195
- if ( node.operator === '++' || node.operator === '--' ) {
2196
- var prefix = ("");
2197
- var suffix = ((", exports." + exportAs) + (" = " + name) + "");
2198
- if ( parent.type !== 'ExpressionStatement' ) {
2199
- if ( !node.prefix ) {
2200
- suffix += ((", " + name) + (" " + (node.operator === '++' ? '-' : '+')) + " 1");
2282
+ if (node.operator === '++' || node.operator === '--') {
2283
+ var prefix = '';
2284
+ var suffix = ', exports.' + exportAs + ' = ' + name;
2285
+ if (parent.type !== 'ExpressionStatement') {
2286
+ if (!node.prefix) {
2287
+ suffix += ', ' + name + ' ' + (node.operator === '++' ? '-' : '+') + ' 1';
2201
2288
  }
2202
- prefix += ("( ");
2203
- suffix += (" )");
2289
+ prefix += '( ';
2290
+ suffix += ' )';
2204
2291
  }
2205
- body.insert( node.start, prefix );
2206
- body.insert( node.end, suffix );
2292
+ body.insert(node.start, prefix);
2293
+ body.insert(node.end, suffix);
2207
2294
  } else {
2208
- body.insert( node.start, (("exports." + exportAs) + " = ") );
2295
+ body.insert(node.start, 'exports.' + exportAs + ' = ');
2209
2296
  }
2210
2297
  }
2211
2298
  }
2212
2299
 
2213
- function traverseAst ( ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames ) {
2300
+ var traverse = traverseAst;
2301
+
2302
+ function traverseAst(ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames) {
2214
2303
  var scope = ast._scope;
2215
2304
  var blockScope = ast._blockScope;
2216
2305
  var capturedUpdates = null;
2217
2306
  var previousCapturedUpdates = null;
2218
2307
 
2219
- walk( ast, {
2220
- enter: function ( node, parent ) {
2308
+ ast_walk(ast, {
2309
+ enter: function (node, parent) {
2221
2310
  // we're only interested in references, not property names etc
2222
- if ( node._skip ) return this.skip();
2311
+ if (node._skip) return this.skip();
2223
2312
 
2224
- if ( node._scope ) {
2313
+ if (node._scope) {
2225
2314
  scope = node._scope;
2226
- } else if ( node._blockScope ) {
2315
+ } else if (node._blockScope) {
2227
2316
  blockScope = node._blockScope;
2228
2317
  }
2229
2318
 
@@ -2233,101 +2322,110 @@
2233
2322
  // normally would) because that would be syntactically invalid. Instead,
2234
2323
  // we capture the change and update the export (and any others) after the
2235
2324
  // variable declaration
2236
- if ( node.type === 'VariableDeclaration' ) {
2325
+ if (node.type === 'VariableDeclaration') {
2237
2326
  previousCapturedUpdates = capturedUpdates;
2238
2327
  capturedUpdates = [];
2239
2328
  return;
2240
2329
  }
2241
2330
 
2242
- disallowIllegalReassignment( node, importedBindings, importedNamespaces, scope );
2331
+ ast_disallowIllegalReassignment(node, importedBindings, importedNamespaces, scope);
2243
2332
 
2244
2333
  // Rewrite assignments to exports inside functions, to keep bindings live.
2245
2334
  // This call may mutate `capturedUpdates`, which is used elsewhere
2246
- if ( scope !== ast._scope ) {
2247
- rewriteExportAssignments( body, node, parent, exportNames, scope, capturedUpdates );
2335
+ if (scope !== ast._scope) {
2336
+ ast_rewriteExportAssignments(body, node, parent, exportNames, scope, capturedUpdates);
2248
2337
  }
2249
2338
 
2250
- if ( node.type === 'Identifier' && parent.type !== 'FunctionExpression' ) {
2251
- replaceIdentifiers( body, node, identifierReplacements, scope );
2339
+ if (node.type === 'Identifier' && parent.type !== 'FunctionExpression') {
2340
+ ast_replaceIdentifiers(body, node, identifierReplacements, scope);
2252
2341
  }
2253
2342
 
2254
2343
  // Replace top-level this with undefined ES6 8.1.1.5.4
2255
- if ( node.type === 'ThisExpression' && node._topLevel ) {
2256
- body.replace( node.start, node.end, 'undefined' );
2344
+ if (node.type === 'ThisExpression' && node._topLevel) {
2345
+ body.replace(node.start, node.end, 'undefined');
2257
2346
  }
2258
2347
  },
2259
2348
 
2260
- leave: function ( node ) {
2349
+ leave: function (node) {
2261
2350
  // Special case - see above
2262
- if ( node.type === 'VariableDeclaration' ) {
2263
- if ( capturedUpdates.length ) {
2264
- body.insert( node.end, capturedUpdates.map( exportCapturedUpdate ).join( '' ) );
2351
+ if (node.type === 'VariableDeclaration') {
2352
+ if (capturedUpdates.length) {
2353
+ body.insert(node.end, capturedUpdates.map(exportCapturedUpdate).join(''));
2265
2354
  }
2266
2355
 
2267
2356
  capturedUpdates = previousCapturedUpdates;
2268
2357
  }
2269
2358
 
2270
- if ( node._scope ) {
2359
+ if (node._scope) {
2271
2360
  scope = scope.parent;
2272
- } else if ( node._blockScope ) {
2361
+ } else if (node._blockScope) {
2273
2362
  blockScope = blockScope.parent;
2274
2363
  }
2275
2364
  }
2276
2365
  });
2277
2366
  }
2278
2367
 
2279
- function exportCapturedUpdate ( c ) {
2280
- return ((" exports." + (c.exportAs)) + (" = " + (c.name)) + ";");
2368
+ function exportCapturedUpdate(c) {
2369
+ return ' exports.' + c.exportAs + ' = ' + c.name + ';';
2281
2370
  }
2282
2371
 
2283
- function transformBody ( mod, body, options ) {
2284
- var chains = (identifierReplacements = gatherImports( mod.imports ))[0], identifierReplacements = identifierReplacements[1];
2285
- var exportNames = getExportNames( mod.exports );
2372
+ var utils_transformBody = transformBody;
2373
+
2374
+ function transformBody(mod, body, options) {
2375
+ var _gatherImports = utils_gatherImports(mod.imports);
2376
+
2377
+ var chains = _gatherImports[0];
2378
+ var identifierReplacements = _gatherImports[1];
2379
+
2380
+ var exportNames = utils_getExportNames(mod.exports);
2381
+
2382
+ var _getReadOnlyIdentifiers = utils_getReadOnlyIdentifiers(mod.imports);
2286
2383
 
2287
- var importedBindings = (importedNamespaces = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = importedNamespaces[1];
2384
+ var importedBindings = _getReadOnlyIdentifiers[0];
2385
+ var importedNamespaces = _getReadOnlyIdentifiers[1];
2288
2386
 
2289
2387
  // ensure no conflict with `exports`
2290
- identifierReplacements.exports = deconflict( 'exports', mod.ast._declared );
2388
+ identifierReplacements.exports = deconflict('exports', mod.ast._declared);
2291
2389
 
2292
- traverseAst( mod.ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames );
2390
+ traverse(mod.ast, body, identifierReplacements, importedBindings, importedNamespaces, exportNames);
2293
2391
 
2294
2392
  // Remove import statements from the body of the module
2295
- mod.imports.forEach( function(x ) {
2296
- body.remove( x.start, x.next );
2393
+ mod.imports.forEach(function (x) {
2394
+ body.remove(x.start, x.next);
2297
2395
  });
2298
2396
 
2299
2397
  // Prepend require() statements (CommonJS output only)
2300
- if ( options.header ) {
2301
- body.prepend( options.header + '\n\n' );
2398
+ if (options.header) {
2399
+ body.prepend(options.header + '\n\n');
2302
2400
  }
2303
2401
 
2304
2402
  // Remove export statements (but keep declarations)
2305
- mod.exports.forEach( function(x ) {
2306
- if ( x.isDefault ) {
2307
- if ( /^named/.test( x.type ) ) {
2403
+ mod.exports.forEach(function (x) {
2404
+ if (x.isDefault) {
2405
+ if (/^named/.test(x.type)) {
2308
2406
  // export default function answer () { return 42; }
2309
- body.remove( x.start, x.valueStart );
2310
- body.insert( x.end, (("\nexports['default'] = " + (x.name)) + ";") );
2407
+ body.remove(x.start, x.valueStart);
2408
+ body.insert(x.end, '\nexports[\'default\'] = ' + x.name + ';');
2311
2409
  } else {
2312
2410
  // everything else
2313
- body.replace( x.start, x.valueStart, 'exports[\'default\'] = ' );
2411
+ body.replace(x.start, x.valueStart, 'exports[\'default\'] = ');
2314
2412
  }
2315
- }
2316
-
2317
- else {
2318
- switch ( x.type ) {
2413
+ } else {
2414
+ switch (x.type) {
2319
2415
  case 'varDeclaration': // export var answer = 42; (or let)
2320
- case 'namedFunction': // export function answer () {...}
2321
- case 'namedClass': // export class answer {...}
2322
- body.remove( x.start, x.valueStart );
2416
+ case 'namedFunction': // export function answer () {...}
2417
+ case 'namedClass':
2418
+ // export class answer {...}
2419
+ body.remove(x.start, x.valueStart);
2323
2420
  break;
2324
2421
 
2325
- case 'named': // export { foo, bar };
2326
- body.remove( x.start, x.next );
2422
+ case 'named':
2423
+ // export { foo, bar };
2424
+ body.remove(x.start, x.next);
2327
2425
  break;
2328
2426
 
2329
2427
  default:
2330
- body.replace( x.start, x.valueStart, 'exports[\'default\'] = ' );
2428
+ body.replace(x.start, x.valueStart, 'exports[\'default\'] = ');
2331
2429
  }
2332
2430
  }
2333
2431
  });
@@ -2336,50 +2434,51 @@
2336
2434
  var earlyExports = [];
2337
2435
  var lateExports = [];
2338
2436
 
2339
- Object.keys( exportNames ).forEach( function(name ) {
2340
- var exportAs = exportNames[ name ];
2437
+ Object.keys(exportNames).forEach(function (name) {
2438
+ var exportAs = exportNames[name];
2341
2439
 
2342
- if ( chains.hasOwnProperty( name ) ) {
2440
+ if (chains.hasOwnProperty(name)) {
2343
2441
  // special case - a binding from another module
2344
- if ( !options._evilES3SafeReExports ) {
2345
- earlyExports.push( (("Object.defineProperty(exports, '" + exportAs) + ("', { enumerable: true, get: function () { return " + (chains[name])) + "; }});") );
2442
+ if (!options._evilES3SafeReExports) {
2443
+ earlyExports.push('Object.defineProperty(exports, \'' + exportAs + '\', { enumerable: true, get: function () { return ' + chains[name] + '; }});');
2346
2444
  } else {
2347
- lateExports.push( (("exports." + exportAs) + (" = " + (chains[name])) + ";") );
2445
+ lateExports.push('exports.' + exportAs + ' = ' + chains[name] + ';');
2348
2446
  }
2349
- } else if ( ~mod.ast._topLevelFunctionNames.indexOf( name ) ) {
2447
+ } else if (~mod.ast._topLevelFunctionNames.indexOf(name)) {
2350
2448
  // functions should be exported early, in
2351
2449
  // case of cyclic dependencies
2352
- earlyExports.push( (("exports." + exportAs) + (" = " + name) + ";") );
2450
+ earlyExports.push('exports.' + exportAs + ' = ' + name + ';');
2353
2451
  } else {
2354
- lateExports.push( (("exports." + exportAs) + (" = " + name) + ";") );
2452
+ lateExports.push('exports.' + exportAs + ' = ' + name + ';');
2355
2453
  }
2356
2454
  });
2357
2455
 
2358
2456
  // Function exports should be exported immediately after 'use strict'
2359
- if ( earlyExports.length ) {
2360
- body.trim().prepend( earlyExports.join( '\n' ) + '\n\n' );
2457
+ if (earlyExports.length) {
2458
+ body.trim().prepend(earlyExports.join('\n') + '\n\n');
2361
2459
  }
2362
2460
 
2363
2461
  // Everything else should be exported at the end
2364
- if ( lateExports.length ) {
2365
- body.trim().append( '\n\n' + lateExports.join( '\n' ) );
2462
+ if (lateExports.length) {
2463
+ body.trim().append('\n\n' + lateExports.join('\n'));
2366
2464
  }
2367
2465
 
2368
- if ( options.intro && options.outro ) {
2369
- body.indent().prepend( options.intro ).trimLines().append( options.outro );
2466
+ if (options.intro && options.outro) {
2467
+ body.indent().prepend(options.intro).trimLines().append(options.outro);
2370
2468
  }
2371
2469
  }
2372
2470
 
2373
- function deconflict ( name, declared ) {
2374
- while ( utils_hasOwnProp.call( declared, name ) ) {
2471
+ function deconflict(name, declared) {
2472
+ while (utils_hasOwnProp.call(declared, name)) {
2375
2473
  name = '_' + name;
2376
2474
  }
2377
2475
 
2378
2476
  return name;
2379
2477
  }
2380
2478
 
2381
- function strictMode_amd__amd ( mod, options ) {
2382
- var intro = amdIntro({
2479
+ var strictMode_amd = strictMode_amd__amd;
2480
+ function strictMode_amd__amd(mod, options) {
2481
+ var intro = amd_amdIntro({
2383
2482
  name: options.amdName,
2384
2483
  absolutePaths: options.absolutePaths,
2385
2484
  imports: mod.imports,
@@ -2388,47 +2487,49 @@
2388
2487
  useStrict: options.useStrict !== false
2389
2488
  });
2390
2489
 
2391
- transformBody( mod, mod.body, {
2490
+ utils_transformBody(mod, mod.body, {
2392
2491
  intro: intro,
2393
2492
  outro: '\n\n});',
2394
2493
  _evilES3SafeReExports: options._evilES3SafeReExports
2395
2494
  });
2396
2495
 
2397
- return packageResult( mod, mod.body, options, 'toAmd' );
2496
+ return utils_packageResult(mod, mod.body, options, 'toAmd');
2398
2497
  }
2399
2498
 
2400
- function strictMode_cjs__cjs ( mod, options ) {
2499
+ var strictMode_cjs = strictMode_cjs__cjs;
2500
+ function strictMode_cjs__cjs(mod, options) {
2401
2501
  var seen = {};
2402
2502
 
2403
2503
  // Create block of require statements
2404
- var importBlock = mod.imports.map( function(x ) {
2405
- if ( !utils_hasOwnProp.call( seen, x.path ) ) {
2406
- seen[ x.path ] = true;
2504
+ var importBlock = mod.imports.map(function (x) {
2505
+ if (!utils_hasOwnProp.call(seen, x.path)) {
2506
+ seen[x.path] = true;
2407
2507
 
2408
- if ( x.isEmpty ) {
2409
- return (("" + (req(x.path))) + ";");
2508
+ if (x.isEmpty) {
2509
+ return '' + req(x.path) + ';';
2410
2510
  }
2411
2511
 
2412
- return (("var " + (x.name)) + (" = " + (req(x.path))) + ";");
2512
+ return 'var ' + x.name + ' = ' + req(x.path) + ';';
2413
2513
  }
2414
- }).filter( Boolean ).join( '\n' );
2514
+ }).filter(Boolean).join('\n');
2415
2515
 
2416
- transformBody( mod, mod.body, {
2516
+ utils_transformBody(mod, mod.body, {
2417
2517
  header: importBlock,
2418
2518
  _evilES3SafeReExports: options._evilES3SafeReExports
2419
2519
  });
2420
2520
 
2421
- if ( options.useStrict !== false ) {
2422
- mod.body.prepend( "'use strict';\n\n" ).trimLines();
2521
+ if (options.useStrict !== false) {
2522
+ mod.body.prepend('\'use strict\';\n\n').trimLines();
2423
2523
  }
2424
2524
 
2425
- return packageResult( mod, mod.body, options, 'toCjs' );
2525
+ return utils_packageResult(mod, mod.body, options, 'toCjs');
2426
2526
  }
2427
2527
 
2428
- function strictMode_umd__umd ( mod, options ) {
2429
- requireName( options );
2528
+ var strictMode_umd = strictMode_umd__umd;
2529
+ function strictMode_umd__umd(mod, options) {
2530
+ umd_requireName(options);
2430
2531
 
2431
- var intro = umdIntro({
2532
+ var intro = umd_umdIntro({
2432
2533
  hasExports: mod.exports.length > 0,
2433
2534
  imports: mod.imports,
2434
2535
  amdName: options.amdName,
@@ -2439,19 +2540,19 @@
2439
2540
  useStrict: options.useStrict !== false
2440
2541
  });
2441
2542
 
2442
- transformBody( mod, mod.body, {
2543
+ utils_transformBody(mod, mod.body, {
2443
2544
  intro: intro,
2444
2545
  outro: '\n\n}));',
2445
2546
  _evilES3SafeReExports: options._evilES3SafeReExports
2446
2547
  });
2447
2548
 
2448
- return packageResult( mod, mod.body, options, 'toUmd' );
2549
+ return utils_packageResult(mod, mod.body, options, 'toUmd');
2449
2550
  }
2450
2551
 
2451
2552
  var strictMode = {
2452
- amd: strictMode_amd__amd,
2453
- cjs: strictMode_cjs__cjs,
2454
- umd: strictMode_umd__umd
2553
+ amd: strictMode_amd,
2554
+ cjs: strictMode_cjs,
2555
+ umd: strictMode_umd
2455
2556
  };
2456
2557
 
2457
2558
  // TODO rewrite with named imports/exports
@@ -2460,50 +2561,53 @@
2460
2561
  strictMode: strictMode
2461
2562
  };
2462
2563
 
2463
- function builders_defaultsMode_amd__amd ( bundle, options ) {
2464
- var defaultName = bundle.entryModule.identifierReplacements.default;
2465
- if ( defaultName ) {
2466
- bundle.body.append( (("\n\nreturn " + defaultName) + ";") );
2564
+ var builders_defaultsMode_amd = builders_defaultsMode_amd__amd;
2565
+ function builders_defaultsMode_amd__amd(bundle, options) {
2566
+ var defaultName = bundle.entryModule.identifierReplacements['default'];
2567
+ if (defaultName) {
2568
+ bundle.body.append('\n\nreturn ' + defaultName + ';');
2467
2569
  }
2468
2570
 
2469
- var intro = amdIntro({
2571
+ var intro = amd_amdIntro({
2470
2572
  name: options.amdName,
2471
2573
  imports: bundle.externalModules,
2472
2574
  indentStr: bundle.body.getIndentString(),
2473
2575
  useStrict: options.useStrict !== false
2474
2576
  });
2475
2577
 
2476
- bundle.body.indent().prepend( intro ).trimLines().append( '\n\n});' );
2477
- return packageResult( bundle, bundle.body, options, 'toAmd', true );
2578
+ bundle.body.indent().prepend(intro).trimLines().append('\n\n});');
2579
+ return utils_packageResult(bundle, bundle.body, options, 'toAmd', true);
2478
2580
  }
2479
2581
 
2480
- function builders_defaultsMode_cjs__cjs ( bundle, options ) {
2481
- var importBlock = bundle.externalModules.map( function(x ) {
2482
- return (("var " + (x.name)) + (" = " + (req(x.id))) + ";");
2483
- }).join( '\n' );
2582
+ var builders_defaultsMode_cjs = builders_defaultsMode_cjs__cjs;
2583
+ function builders_defaultsMode_cjs__cjs(bundle, options) {
2584
+ var importBlock = bundle.externalModules.map(function (x) {
2585
+ return 'var ' + x.name + ' = ' + req(x.id) + ';';
2586
+ }).join('\n');
2484
2587
 
2485
- if ( importBlock ) {
2486
- bundle.body.prepend( importBlock + '\n\n' );
2588
+ if (importBlock) {
2589
+ bundle.body.prepend(importBlock + '\n\n');
2487
2590
  }
2488
2591
 
2489
- var defaultName = bundle.entryModule.identifierReplacements.default;
2490
- if ( defaultName ) {
2491
- bundle.body.append( (("\n\nmodule.exports = " + defaultName) + ";") );
2592
+ var defaultName = bundle.entryModule.identifierReplacements['default'];
2593
+ if (defaultName) {
2594
+ bundle.body.append('\n\nmodule.exports = ' + defaultName + ';');
2492
2595
  }
2493
2596
 
2494
- if ( options.useStrict !== false ) {
2495
- bundle.body.prepend("'use strict';\n\n").trimLines();
2597
+ if (options.useStrict !== false) {
2598
+ bundle.body.prepend('\'use strict\';\n\n').trimLines();
2496
2599
  }
2497
2600
 
2498
- return packageResult( bundle, bundle.body, options, 'toCjs', true );
2601
+ return utils_packageResult(bundle, bundle.body, options, 'toCjs', true);
2499
2602
  }
2500
2603
 
2501
- function builders_defaultsMode_umd__umd ( bundle, options ) {
2502
- requireName( options );
2604
+ var builders_defaultsMode_umd = builders_defaultsMode_umd__umd;
2605
+ function builders_defaultsMode_umd__umd(bundle, options) {
2606
+ umd_requireName(options);
2503
2607
 
2504
2608
  var entry = bundle.entryModule;
2505
2609
 
2506
- var intro = umdIntro({
2610
+ var intro = umd_umdIntro({
2507
2611
  hasExports: entry.exports.length > 0,
2508
2612
  imports: bundle.externalModules,
2509
2613
  amdName: options.amdName,
@@ -2512,49 +2616,53 @@
2512
2616
  useStrict: options.useStrict !== false
2513
2617
  });
2514
2618
 
2515
- if ( entry.defaultExport ) {
2516
- bundle.body.append( (("\n\nreturn " + (entry.identifierReplacements.default)) + ";") );
2619
+ if (entry.defaultExport) {
2620
+ bundle.body.append('\n\nreturn ' + entry.identifierReplacements['default'] + ';');
2517
2621
  }
2518
2622
 
2519
- bundle.body.indent().prepend( intro ).trimLines().append('\n\n}));');
2623
+ bundle.body.indent().prepend(intro).trimLines().append('\n\n}));');
2520
2624
 
2521
- return packageResult( bundle, bundle.body, options, 'toUmd', true );
2625
+ return utils_packageResult(bundle, bundle.body, options, 'toUmd', true);
2522
2626
  }
2523
2627
 
2524
2628
  var builders_defaultsMode = {
2525
- amd: builders_defaultsMode_amd__amd,
2526
- cjs: builders_defaultsMode_cjs__cjs,
2527
- umd: builders_defaultsMode_umd__umd
2629
+ amd: builders_defaultsMode_amd,
2630
+ cjs: builders_defaultsMode_cjs,
2631
+ umd: builders_defaultsMode_umd
2528
2632
  };
2529
2633
 
2530
- function getExportBlock ( entry ) {
2531
- var name = entry.identifierReplacements.default;
2532
- return (("exports['default'] = " + name) + ";");
2634
+ var utils_getExportBlock = getExportBlock;
2635
+
2636
+ function getExportBlock(entry) {
2637
+ var name = entry.identifierReplacements["default"];
2638
+ return "exports['default'] = " + name + ";";
2533
2639
  }
2534
2640
 
2535
- function builders_strictMode_amd__amd ( bundle, options ) {
2536
- var externalDefaults = bundle.externalModules.filter( builders_strictMode_amd__needsDefault );
2641
+ var builders_strictMode_amd = builders_strictMode_amd__amd;
2642
+
2643
+ function builders_strictMode_amd__amd(bundle, options) {
2644
+ var externalDefaults = bundle.externalModules.filter(builders_strictMode_amd__needsDefault);
2537
2645
  var entry = bundle.entryModule;
2538
2646
 
2539
- if ( externalDefaults.length ) {
2540
- var defaultsBlock = externalDefaults.map( function(x ) {
2647
+ if (externalDefaults.length) {
2648
+ var defaultsBlock = externalDefaults.map(function (x) {
2541
2649
  // Case 1: default is used, and named is not
2542
- if ( !x.needsNamed ) {
2543
- return (("" + (x.name)) + (" = ('default' in " + (x.name)) + (" ? " + (x.name)) + ("['default'] : " + (x.name)) + ");");
2650
+ if (!x.needsNamed) {
2651
+ return '' + x.name + ' = (\'default\' in ' + x.name + ' ? ' + x.name + '[\'default\'] : ' + x.name + ');';
2544
2652
  }
2545
2653
 
2546
2654
  // Case 2: both default and named are used
2547
- return (("var " + (x.name)) + ("__default = ('default' in " + (x.name)) + (" ? " + (x.name)) + ("['default'] : " + (x.name)) + ");");
2548
- }).join( '\n' );
2655
+ return 'var ' + x.name + '__default = (\'default\' in ' + x.name + ' ? ' + x.name + '[\'default\'] : ' + x.name + ');';
2656
+ }).join('\n');
2549
2657
 
2550
- bundle.body.prepend( defaultsBlock + '\n\n' );
2658
+ bundle.body.prepend(defaultsBlock + '\n\n');
2551
2659
  }
2552
2660
 
2553
- if ( entry.defaultExport ) {
2554
- bundle.body.append( '\n\n' + getExportBlock( entry ) );
2661
+ if (entry.defaultExport) {
2662
+ bundle.body.append('\n\n' + utils_getExportBlock(entry));
2555
2663
  }
2556
2664
 
2557
- var intro = amdIntro({
2665
+ var intro = amd_amdIntro({
2558
2666
  name: options.amdName,
2559
2667
  imports: bundle.externalModules,
2560
2668
  hasExports: entry.exports.length,
@@ -2562,53 +2670,54 @@
2562
2670
  useStrict: options.useStrict !== false
2563
2671
  });
2564
2672
 
2565
- bundle.body.indent().prepend( intro ).trimLines().append( '\n\n});' );
2566
- return packageResult( bundle, bundle.body, options, 'toAmd', true );
2673
+ bundle.body.indent().prepend(intro).trimLines().append('\n\n});');
2674
+ return utils_packageResult(bundle, bundle.body, options, 'toAmd', true);
2567
2675
  }
2568
2676
 
2569
- function builders_strictMode_amd__needsDefault ( externalModule ) {
2677
+ function builders_strictMode_amd__needsDefault(externalModule) {
2570
2678
  return externalModule.needsDefault;
2571
2679
  }
2572
2680
 
2573
- function builders_strictMode_cjs__cjs ( bundle, options ) {
2681
+ var builders_strictMode_cjs = builders_strictMode_cjs__cjs;
2682
+ function builders_strictMode_cjs__cjs(bundle, options) {
2574
2683
  var entry = bundle.entryModule;
2575
2684
 
2576
- var importBlock = bundle.externalModules.map( function(x ) {
2577
- var statement = (("var " + (x.name)) + (" = " + (req(x.id))) + ";");
2685
+ var importBlock = bundle.externalModules.map(function (x) {
2686
+ var statement = 'var ' + x.name + ' = ' + req(x.id) + ';';
2578
2687
 
2579
- if ( x.needsDefault ) {
2580
- statement += '\n' +
2581
- ( x.needsNamed ? (("var " + (x.name)) + "__default") : x.name ) +
2582
- ((" = ('default' in " + (x.name)) + (" ? " + (x.name)) + ("['default'] : " + (x.name)) + ");");
2688
+ if (x.needsDefault) {
2689
+ statement += '\n' + (x.needsNamed ? 'var ' + x.name + '__default' : x.name) + (' = (\'default\' in ' + x.name + ' ? ' + x.name + '[\'default\'] : ' + x.name + ');');
2583
2690
  }
2584
2691
 
2585
2692
  return statement;
2586
- }).join( '\n' );
2693
+ }).join('\n');
2587
2694
 
2588
- if ( importBlock ) {
2589
- bundle.body.prepend( importBlock + '\n\n' );
2695
+ if (importBlock) {
2696
+ bundle.body.prepend(importBlock + '\n\n');
2590
2697
  }
2591
2698
 
2592
- if ( entry.defaultExport ) {
2593
- bundle.body.append( '\n\n' + getExportBlock( entry ) );
2699
+ if (entry.defaultExport) {
2700
+ bundle.body.append('\n\n' + utils_getExportBlock(entry));
2594
2701
  }
2595
2702
 
2596
- if ( options.useStrict !== false ) {
2597
- bundle.body.prepend("'use strict';\n\n").trimLines();
2703
+ if (options.useStrict !== false) {
2704
+ bundle.body.prepend('\'use strict\';\n\n').trimLines();
2598
2705
  }
2599
2706
 
2600
- return packageResult( bundle, bundle.body, options, 'toCjs', true );
2707
+ return utils_packageResult(bundle, bundle.body, options, 'toCjs', true);
2601
2708
  }
2602
2709
 
2603
- function builders_strictMode_umd__umd ( bundle, options ) {
2604
- requireName( options );
2710
+ var builders_strictMode_umd = builders_strictMode_umd__umd;
2711
+
2712
+ function builders_strictMode_umd__umd(bundle, options) {
2713
+ umd_requireName(options);
2605
2714
 
2606
2715
  var entry = bundle.entryModule;
2607
2716
 
2608
- var intro = umdIntro({
2717
+ var intro = umd_umdIntro({
2609
2718
  hasExports: entry.exports.length > 0,
2610
2719
  imports: bundle.externalModules,
2611
- externalDefaults: bundle.externalModules.filter( builders_strictMode_umd__needsDefault ),
2720
+ externalDefaults: bundle.externalModules.filter(builders_strictMode_umd__needsDefault),
2612
2721
  amdName: options.amdName,
2613
2722
  name: options.name,
2614
2723
  indentStr: bundle.body.getIndentString(),
@@ -2616,23 +2725,23 @@
2616
2725
  useStrict: options.useStrict !== false
2617
2726
  });
2618
2727
 
2619
- if ( entry.defaultExport ) {
2620
- bundle.body.append( '\n\n' + getExportBlock( entry ) );
2728
+ if (entry.defaultExport) {
2729
+ bundle.body.append('\n\n' + utils_getExportBlock(entry));
2621
2730
  }
2622
2731
 
2623
- bundle.body.indent().prepend( intro ).trimLines().append('\n\n}));');
2732
+ bundle.body.indent().prepend(intro).trimLines().append('\n\n}));');
2624
2733
 
2625
- return packageResult( bundle, bundle.body, options, 'toUmd', true );
2734
+ return utils_packageResult(bundle, bundle.body, options, 'toUmd', true);
2626
2735
  }
2627
2736
 
2628
- function builders_strictMode_umd__needsDefault ( externalModule ) {
2737
+ function builders_strictMode_umd__needsDefault(externalModule) {
2629
2738
  return externalModule.needsDefault;
2630
2739
  }
2631
2740
 
2632
2741
  var builders_strictMode = {
2633
- amd: builders_strictMode_amd__amd,
2634
- cjs: builders_strictMode_cjs__cjs,
2635
- umd: builders_strictMode_umd__umd
2742
+ amd: builders_strictMode_amd,
2743
+ cjs: builders_strictMode_cjs,
2744
+ umd: builders_strictMode_umd
2636
2745
  };
2637
2746
 
2638
2747
  // TODO rewrite with named imports/exports
@@ -2641,139 +2750,151 @@
2641
2750
  strictMode: builders_strictMode
2642
2751
  };
2643
2752
 
2644
- function concat ( bundle, options ) {
2753
+ var builders_concat = concat;
2754
+ function concat(bundle, options) {
2645
2755
  // This bundle must be self-contained - no imports or exports
2646
- if ( bundle.externalModules.length || bundle.entryModule.exports.length ) {
2647
- 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(', '))) + "])") );
2756
+ if (bundle.externalModules.length || bundle.entryModule.exports.length) {
2757
+ throw new Error('bundle.concat() can only be used with bundles that have no imports/exports (imports: [' + bundle.externalModules.map(function (x) {
2758
+ return x.id;
2759
+ }).join(', ') + '], exports: [' + bundle.entryModule.exports.join(', ') + '])');
2648
2760
  }
2649
2761
 
2650
2762
  // TODO test these options
2651
- var intro = 'intro' in options ? options.intro : ("(function () { 'use strict';\n\n");
2763
+ var intro = 'intro' in options ? options.intro : '(function () { \'use strict\';\n\n';
2652
2764
  var outro = 'outro' in options ? options.outro : '\n\n})();';
2653
- var indent;
2765
+ var indent = undefined;
2654
2766
 
2655
- if ( !( 'indent' in options ) || options.indent === true ) {
2767
+ if (!('indent' in options) || options.indent === true) {
2656
2768
  indent = bundle.body.getIndentString();
2657
2769
  } else {
2658
2770
  indent = options.indent || '';
2659
2771
  }
2660
2772
 
2661
- bundle.body.trimLines().indent( indent ).prepend( intro ).append( outro );
2773
+ bundle.body.trimLines().indent(indent).prepend(intro).append(outro);
2662
2774
 
2663
- return packageResult( bundle, bundle.body, options, 'toString', true );
2775
+ return utils_packageResult(bundle, bundle.body, options, 'toString', true);
2664
2776
  }
2665
2777
 
2666
- var esperanto__deprecateMessage = 'options.defaultOnly has been deprecated, and is now standard behaviour. To use named imports/exports, pass `strict: true`.';
2667
- var esperanto__alreadyWarned = false;
2778
+ var deprecateMessage = 'options.defaultOnly has been deprecated, and is now standard behaviour. To use named imports/exports, pass `strict: true`.';
2779
+ var alreadyWarned = false;
2668
2780
 
2669
- function transpileMethod ( format ) {
2670
- return function ( source ) {var options = arguments[1];if(options === void 0)options = {};
2671
- var mod = getStandaloneModule({
2781
+ function transpileMethod(format) {
2782
+ return function (source) {
2783
+ var options = arguments[1] === undefined ? {} : arguments[1];
2784
+
2785
+ var mod = getModule({
2672
2786
  source: source,
2673
2787
  getModuleName: options.getModuleName,
2674
2788
  strict: options.strict
2675
2789
  });
2676
2790
 
2677
- if ( 'defaultOnly' in options && !esperanto__alreadyWarned ) {
2791
+ if ('defaultOnly' in options && !alreadyWarned) {
2678
2792
  // TODO link to a wiki page explaining this, or something
2679
- console.log( esperanto__deprecateMessage );
2680
- esperanto__alreadyWarned = true;
2793
+ console.log(deprecateMessage);
2794
+ alreadyWarned = true;
2681
2795
  }
2682
2796
 
2683
- if ( options.absolutePaths && !options.amdName ) {
2684
- throw new Error( 'You must specify an `amdName` in order to use the `absolutePaths` option' );
2797
+ if (options.absolutePaths && !options.amdName) {
2798
+ throw new Error('You must specify an `amdName` in order to use the `absolutePaths` option');
2685
2799
  }
2686
2800
 
2687
- var builder;
2801
+ var builder = undefined;
2688
2802
 
2689
- if ( !options.strict ) {
2803
+ if (!options.strict) {
2690
2804
  // ensure there are no named imports/exports. TODO link to a wiki page...
2691
- if ( hasNamedImports( mod ) || hasNamedExports( mod ) ) {
2692
- throw new Error( 'You must be in strict mode (pass `strict: true`) to use named imports or exports' );
2805
+ if (utils_hasNamedImports(mod) || utils_hasNamedExports(mod)) {
2806
+ throw new Error('You must be in strict mode (pass `strict: true`) to use named imports or exports');
2693
2807
  }
2694
2808
 
2695
- builder = moduleBuilders.defaultsMode[ format ];
2809
+ builder = moduleBuilders.defaultsMode[format];
2696
2810
  } else {
2697
- builder = moduleBuilders.strictMode[ format ];
2811
+ builder = moduleBuilders.strictMode[format];
2698
2812
  }
2699
2813
 
2700
- return builder( mod, options );
2814
+ return builder(mod, options);
2701
2815
  };
2702
2816
  }
2703
2817
 
2704
- var esperanto = {
2705
- toAmd: transpileMethod( 'amd' ),
2706
- toCjs: transpileMethod( 'cjs' ),
2707
- toUmd: transpileMethod( 'umd' ),
2818
+ var toAmd = transpileMethod('amd');
2819
+ var toCjs = transpileMethod('cjs');
2820
+ var toUmd = transpileMethod('umd');function bundle(options) {
2821
+ return getBundle(options).then(function (bundle) {
2822
+ return {
2823
+ imports: bundle.externalModules.map(function (mod) {
2824
+ return mod.id;
2825
+ }),
2826
+ exports: flattenExports(bundle.entryModule.exports),
2827
+
2828
+ toAmd: function (options) {
2829
+ return transpile('amd', options);
2830
+ },
2831
+ toCjs: function (options) {
2832
+ return transpile('cjs', options);
2833
+ },
2834
+ toUmd: function (options) {
2835
+ return transpile('umd', options);
2836
+ },
2837
+
2838
+ concat: function (options) {
2839
+ return builders_concat(bundle, options || {});
2840
+ }
2841
+ };
2708
2842
 
2709
- bundle: function ( options ) {
2710
- return getBundle( options ).then( function ( bundle ) {
2711
- return {
2712
- imports: bundle.externalModules.map( function(mod ) {return mod.id} ),
2713
- exports: flattenExports( bundle.entryModule.exports ),
2843
+ function transpile(format) {
2844
+ var options = arguments[1] === undefined ? {} : arguments[1];
2714
2845
 
2715
- toAmd: function(options ) {return transpile( 'amd', options )},
2716
- toCjs: function(options ) {return transpile( 'cjs', options )},
2717
- toUmd: function(options ) {return transpile( 'umd', options )},
2846
+ if ('defaultOnly' in options && !alreadyWarned) {
2847
+ // TODO link to a wiki page explaining this, or something
2848
+ console.log(deprecateMessage);
2849
+ alreadyWarned = true;
2850
+ }
2718
2851
 
2719
- concat: function(options ) {return concat( bundle, options || {} )}
2720
- };
2852
+ var builder = undefined;
2721
2853
 
2722
- function transpile ( format ) {var options = arguments[1];if(options === void 0)options = {};
2723
- if ( 'defaultOnly' in options && !esperanto__alreadyWarned ) {
2724
- // TODO link to a wiki page explaining this, or something
2725
- console.log( esperanto__deprecateMessage );
2726
- esperanto__alreadyWarned = true;
2854
+ if (!options.strict) {
2855
+ // ensure there are no named imports/exports
2856
+ if (utils_hasNamedExports(bundle.entryModule)) {
2857
+ throw new Error('Entry module can only have named exports in strict mode (pass `strict: true`)');
2727
2858
  }
2728
2859
 
2729
- var builder;
2730
-
2731
- if ( !options.strict ) {
2732
- // ensure there are no named imports/exports
2733
- if ( hasNamedExports( bundle.entryModule ) ) {
2734
- throw new Error( 'Entry module can only have named exports in strict mode (pass `strict: true`)' );
2735
- }
2736
-
2737
- bundle.modules.forEach( function(mod ) {
2738
- mod.imports.forEach( function(x ) {
2739
- if ( x.module.isExternal && ( !x.isDefault && !x.isBatch ) ) {
2740
- throw new Error( 'You can only have named external imports in strict mode (pass `strict: true`)' );
2741
- }
2742
- });
2860
+ bundle.modules.forEach(function (mod) {
2861
+ mod.imports.forEach(function (x) {
2862
+ if (x.module.isExternal && (!x.isDefault && !x.isBatch)) {
2863
+ throw new Error('You can only have named external imports in strict mode (pass `strict: true`)');
2864
+ }
2743
2865
  });
2866
+ });
2744
2867
 
2745
- builder = bundleBuilders.defaultsMode[ format ];
2746
- } else {
2747
- builder = bundleBuilders.strictMode[ format ];
2748
- }
2749
-
2750
- return builder( bundle, options );
2868
+ builder = bundleBuilders.defaultsMode[format];
2869
+ } else {
2870
+ builder = bundleBuilders.strictMode[format];
2751
2871
  }
2752
- });
2753
- }
2754
- };
2755
-
2756
- function flattenExports ( exports ) {
2757
- var flattened = [];
2758
2872
 
2759
- exports.forEach( function(x ) {
2760
- if ( x.isDefault ) {
2761
- flattened.push( 'default' );
2873
+ return builder(bundle, options);
2762
2874
  }
2875
+ });
2876
+ }
2763
2877
 
2764
- else if ( x.name ) {
2765
- flattened.push( x.name );
2766
- }
2878
+ function flattenExports(exports) {
2879
+ var flattened = [];
2767
2880
 
2768
- else if ( x.specifiers ) {
2769
- flattened.push.apply( flattened, x.specifiers.map( getName ) );
2881
+ exports.forEach(function (x) {
2882
+ if (x.isDefault) {
2883
+ flattened.push('default');
2884
+ } else if (x.name) {
2885
+ flattened.push(x.name);
2886
+ } else if (x.specifiers) {
2887
+ flattened.push.apply(flattened, x.specifiers.map(getName));
2770
2888
  }
2771
2889
  });
2772
2890
 
2773
2891
  return flattened;
2774
2892
  }
2775
2893
 
2776
- return esperanto;
2894
+ exports.bundle = bundle;
2895
+ exports.toAmd = toAmd;
2896
+ exports.toCjs = toCjs;
2897
+ exports.toUmd = toUmd;
2777
2898
 
2778
2899
  }));
2779
- //# sourceMappingURL=/Users/tricknotes/src/github.com/esperantojs/esperanto/test/.gobble-build/02-esperantoBundle/1/esperanto.browser.js.map
2900
+ //# sourceMappingURL=/Users/tricknotes/src/github.com/esperantojs/esperanto/.gobble-build/03-esperantoBundle/1/esperanto.browser.js.map