esperanto-source 0.6.17.3 → 0.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecd2bf61c210c71df7894596a99f4c52c4ac4dc2
4
- data.tar.gz: 87b8156755993f74fb3fda718e5e831e740b8521
3
+ metadata.gz: 5eed9288fc9bb2887d6c21a1c181b38df7f33238
4
+ data.tar.gz: 0c66bb5c87139cf500b514f208c53bd167324284
5
5
  SHA512:
6
- metadata.gz: b5387f60e65537808181490ab8f5ae47bc91c7721198ea73f3d607866afad5110814a832ae66f390ceb8b2d5c3c7fd59644e5b0cac43750bfdd49318a3a70654
7
- data.tar.gz: fa197e602ec49f6292292c8c710a3449e406675e464275cfbce7100a6ff5fff325a0ff4c6ad0662cceee8a206ad5f265b2eb0ea25ce06b2cf7b139bcc9948279
6
+ metadata.gz: be6b159bcf781c1e36cfc0a687cb215a1cecaf6342c9d2ebf225bd8cf0748f650b3bd809374927da128a8ccbf179421acdff482b388fa856ab9e5620dd2956a6
7
+ data.tar.gz: 0b8ea823e8f5af10c02d21fcc866b8d59cf4c9027892687c4387aadb449d1be05dafba8d586170b0c7f35c7495a17ac9715f3b262873b80d7b7df976c1e8c557
@@ -1,5 +1,5 @@
1
1
  module Esperanto
2
2
  module Source
3
- VERSION = '0.6.17.3'
3
+ VERSION = '0.6.18'
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  /*
2
- esperanto.js v0.6.17 - 2015-03-01
2
+ esperanto.js v0.6.18 - 2015-03-30
3
3
  http://esperantojs.org
4
4
 
5
5
  Released under the MIT License.
@@ -42,7 +42,7 @@
42
42
  return new Buffer( str ).toString( 'base64' );
43
43
  };
44
44
  } else {
45
- throw new Error( 'Unsupported environment' );
45
+ throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
46
46
  }
47
47
 
48
48
  var btoa = _btoa;
@@ -529,6 +529,10 @@
529
529
  },
530
530
 
531
531
  append: function ( content ) {
532
+ if ( typeof content !== 'string' ) {
533
+ throw new TypeError( 'appended content must be a string' );
534
+ }
535
+
532
536
  this.str += content;
533
537
  return this;
534
538
  },
@@ -675,6 +679,10 @@
675
679
  },
676
680
 
677
681
  insert: function ( index, content ) {
682
+ if ( typeof content !== 'string' ) {
683
+ throw new TypeError( 'inserted content must be a string' );
684
+ }
685
+
678
686
  if ( index === 0 ) {
679
687
  this.prepend( content );
680
688
  } else if ( index === this.original.length ) {
@@ -729,11 +737,41 @@
729
737
  },
730
738
 
731
739
  remove: function ( start, end ) {
732
- this.replace( start, end, '' );
740
+ var loc, d, i, currentStart, currentEnd;
741
+
742
+ if ( start < 0 || end > this.mappings.length ) {
743
+ throw new Error( 'Character is out of bounds' );
744
+ }
745
+
746
+ d = 0;
747
+ currentStart = -1;
748
+ currentEnd = -1;
749
+ for ( i = start; i < end; i += 1 ) {
750
+ loc = this.mappings[i];
751
+
752
+ if ( loc !== -1 ) {
753
+ if ( !~currentStart ) {
754
+ currentStart = loc;
755
+ }
756
+
757
+ currentEnd = loc + 1;
758
+
759
+ this.mappings[i] = -1;
760
+ d += 1;
761
+ }
762
+ }
763
+
764
+ this.str = this.str.slice( 0, currentStart ) + this.str.slice( currentEnd );
765
+
766
+ adjust( this.mappings, end, this.mappings.length, -d );
733
767
  return this;
734
768
  },
735
769
 
736
770
  replace: function ( start, end, content ) {
771
+ if ( typeof content !== 'string' ) {
772
+ throw new TypeError( 'replacement content must be a string' );
773
+ }
774
+
737
775
  var firstChar, lastChar, d;
738
776
 
739
777
  firstChar = this.locate( start );
@@ -934,7 +972,7 @@
934
972
 
935
973
  estraverse.traverse( ast, {
936
974
  enter: function ( node ) {
937
- if ( node.type === 'ImportDeclaration' ) {
975
+ if ( node.type === 'ImportDeclaration' || node.type === 'ExportSpecifier' ) {
938
976
  node._skip = true;
939
977
  }
940
978
 
@@ -1076,16 +1114,19 @@
1076
1114
  imports.push( declaration );
1077
1115
  }
1078
1116
 
1079
- else if ( node.type === 'ExportDeclaration' ) {
1080
- declaration = processExport( node, source );
1117
+ else if ( node.type === 'ExportDefaultDeclaration' ) {
1118
+ declaration = processDefaultExport( node, source );
1081
1119
  exports.push( declaration );
1082
1120
 
1083
- if ( declaration.isDefault ) {
1084
- if ( mod.defaultExport ) {
1085
- throw new Error( 'Duplicate default exports' );
1086
- }
1087
- mod.defaultExport = declaration;
1121
+ if ( mod.defaultExport ) {
1122
+ throw new Error( 'Duplicate default exports' );
1088
1123
  }
1124
+ mod.defaultExport = declaration;
1125
+ }
1126
+
1127
+ else if ( node.type === 'ExportNamedDeclaration' ) {
1128
+ declaration = processExport( node, source );
1129
+ exports.push( declaration );
1089
1130
 
1090
1131
  if ( node.source ) {
1091
1132
  // it's both an import and an export, e.g.
@@ -1129,20 +1170,25 @@
1129
1170
  specifiers: node.specifiers.map( function(s ) {
1130
1171
  var id;
1131
1172
 
1132
- if ( s.type === 'ImportBatchSpecifier' ) {
1173
+ if ( s.type === 'ImportNamespaceSpecifier' ) {
1133
1174
  return {
1134
1175
  isBatch: true,
1135
- name: s.name.name,
1136
- as: s.name.name
1176
+ name: s.local.name, // TODO is this line necessary?
1177
+ as: s.local.name
1137
1178
  };
1138
1179
  }
1139
1180
 
1140
- id = s.id.name;
1181
+ if ( s.type === 'ImportDefaultSpecifier' ) {
1182
+ return {
1183
+ isDefault: true,
1184
+ name: 'default',
1185
+ as: s.local.name
1186
+ }
1187
+ }
1141
1188
 
1142
1189
  return {
1143
- isDefault: !!s.default,
1144
- name: s.default ? 'default' : id,
1145
- as: s.name ? s.name.name : id
1190
+ name: ( !!passthrough ? s.exported : s.imported ).name,
1191
+ as: s.local.name
1146
1192
  };
1147
1193
  })
1148
1194
  };
@@ -1164,6 +1210,53 @@
1164
1210
  return x;
1165
1211
  }
1166
1212
 
1213
+ function processDefaultExport ( node, source ) {
1214
+ var result = {
1215
+ isDefault: true,
1216
+ node: node,
1217
+ start: node.start,
1218
+ end: node.end
1219
+ };
1220
+
1221
+ var d = node.declaration;
1222
+
1223
+ if ( d.type === 'FunctionExpression' ) {
1224
+ // Case 1: `export default function () {...}`
1225
+ result.hasDeclaration = true; // TODO remove in favour of result.type
1226
+ result.type = 'anonFunction';
1227
+ }
1228
+
1229
+ else if ( d.type === 'FunctionDeclaration' ) {
1230
+ // Case 2: `export default function foo () {...}`
1231
+ result.hasDeclaration = true; // TODO remove in favour of result.type
1232
+ result.type = 'namedFunction';
1233
+ result.name = d.id.name;
1234
+ }
1235
+
1236
+ else if ( d.type === 'ClassExpression' ) {
1237
+ // Case 3: `export default class {...}`
1238
+ result.hasDeclaration = true; // TODO remove in favour of result.type
1239
+ result.type = 'anonClass';
1240
+ }
1241
+
1242
+ else if ( d.type === 'ClassDeclaration' ) {
1243
+ // Case 4: `export default class Foo {...}`
1244
+ result.hasDeclaration = true; // TODO remove in favour of result.type
1245
+ result.type = 'namedClass';
1246
+ result.name = d.id.name;
1247
+ }
1248
+
1249
+ else {
1250
+ result.type = 'expression';
1251
+ result.name = 'default';
1252
+ }
1253
+
1254
+ result.value = source.slice( d.start, d.end );
1255
+ result.valueStart = d.start;
1256
+
1257
+ return result;
1258
+ }
1259
+
1167
1260
  /**
1168
1261
  * Generates a representation of an export declaration
1169
1262
  * @param {object} node - the original AST node
@@ -1194,62 +1287,23 @@
1194
1287
  else if ( d.type === 'FunctionDeclaration' ) {
1195
1288
  result.hasDeclaration = true; // TODO remove in favour of result.type
1196
1289
  result.type = 'namedFunction';
1197
- result.isDefault = !!node.default;
1198
1290
  result.name = d.id.name;
1199
1291
  }
1200
1292
 
1201
- else if ( d.type === 'FunctionExpression' ) {
1202
- result.hasDeclaration = true; // TODO remove in favour of result.type
1203
- result.isDefault = true;
1204
-
1205
- // Case 3: `export default function foo () {...}`
1206
- if ( d.id ) {
1207
- result.type = 'namedFunction';
1208
- result.name = d.id.name;
1209
- }
1210
-
1211
- // Case 4: `export default function () {...}`
1212
- else {
1213
- result.type = 'anonFunction';
1214
- }
1215
- }
1216
-
1217
- // Case 5: `export class Foo {...}`
1293
+ // Case 3: `export class Foo {...}`
1218
1294
  else if ( d.type === 'ClassDeclaration' ) {
1219
1295
  result.hasDeclaration = true; // TODO remove in favour of result.type
1220
1296
  result.type = 'namedClass';
1221
- result.isDefault = !!node.default;
1222
1297
  result.name = d.id.name;
1223
1298
  }
1224
-
1225
- else if ( d.type === 'ClassExpression' ) {
1226
- result.hasDeclaration = true; // TODO remove in favour of result.type
1227
- result.isDefault = true;
1228
-
1229
- // Case 6: `export default class Foo {...}`
1230
- if ( d.id ) {
1231
- result.type = 'namedClass';
1232
- result.name = d.id.name;
1233
- }
1234
-
1235
- // Case 7: `export default class {...}`
1236
- else {
1237
- result.type = 'anonClass';
1238
- }
1239
- }
1240
-
1241
- // Case 8: `export default 1 + 2`
1242
- else {
1243
- result.type = 'expression';
1244
- result.isDefault = true;
1245
- result.name = 'default';
1246
- }
1247
1299
  }
1248
1300
 
1249
1301
  // Case 9: `export { foo, bar };`
1250
1302
  else {
1251
1303
  result.type = 'named';
1252
- result.specifiers = node.specifiers.map( function(s ) {return { name: s.id.name }} ); // TODO as?
1304
+ result.specifiers = node.specifiers.map( function(s ) {
1305
+ return { name: s.local.name };
1306
+ }); // TODO as?
1253
1307
  }
1254
1308
 
1255
1309
  return result;
@@ -1352,24 +1406,36 @@
1352
1406
  return path.split( pathSplitRE );
1353
1407
  }
1354
1408
 
1355
- function getStandaloneModule ( options ) {var $D$0;
1356
- var mod, imports, exports, conflicts = {};
1409
+ var SOURCEMAPPINGURL_REGEX = /^# sourceMappingURL=/;
1410
+
1411
+ function getStandaloneModule ( options ) {
1412
+ var toRemove = [];
1357
1413
 
1358
- mod = {
1414
+ var mod = {
1359
1415
  body: new MagicString( options.source ),
1360
1416
  ast: acorn.parse( options.source, {
1361
1417
  ecmaVersion: 6,
1362
- locations: true
1418
+ sourceType: 'module',
1419
+ onComment: function ( block, text, start, end ) {
1420
+ // sourceMappingURL comments should be removed
1421
+ if ( !block && /^# sourceMappingURL=/.test( text ) ) {
1422
+ toRemove.push({ start: start, end: end });
1423
+ }
1424
+ }
1363
1425
  })
1364
1426
  };
1365
1427
 
1366
- imports = ($D$0 = findImportsAndExports( mod, options.source, mod.ast ))[0], exports = $D$0[1], $D$0;
1428
+ toRemove.forEach( function(end) {var start = end.start, end = end.end;return mod.body.remove( start, end )} );
1429
+
1430
+ var imports = (exports = findImportsAndExports( mod, options.source, mod.ast ))[0], exports = exports[1];
1367
1431
 
1368
1432
  disallowConflictingImports( imports );
1369
1433
 
1370
1434
  mod.imports = imports;
1371
1435
  mod.exports = exports;
1372
1436
 
1437
+ var conflicts = {};
1438
+
1373
1439
  if ( options.strict ) {
1374
1440
  annotateAst( mod.ast );
1375
1441
 
@@ -1382,7 +1448,7 @@
1382
1448
  determineImportNames( imports, options.getModuleName, conflicts );
1383
1449
 
1384
1450
  return mod;
1385
- ;$D$0 = void 0}
1451
+ }
1386
1452
 
1387
1453
  function determineImportNames ( imports, userFn, usedNames ) {
1388
1454
  var nameById = {}, inferredNames = {};
@@ -1450,44 +1516,48 @@
1450
1516
  }
1451
1517
 
1452
1518
  function transformExportDeclaration ( declaration, body ) {
1453
- var exportedValue;
1519
+ if ( !declaration ) {
1520
+ return;
1521
+ }
1454
1522
 
1455
- if ( declaration ) {
1456
- switch ( declaration.type ) {
1457
- case 'namedFunction':
1458
- case 'namedClass':
1459
- body.remove( declaration.start, declaration.valueStart );
1460
- exportedValue = declaration.name;
1461
- break;
1523
+ var exportedValue;
1462
1524
 
1463
- case 'anonFunction':
1464
- case 'anonClass':
1465
- if ( declaration.isFinal ) {
1466
- body.replace( declaration.start, declaration.valueStart, 'return ' );
1467
- } else {
1468
- body.replace( declaration.start, declaration.valueStart, 'var __export = ' );
1469
- exportedValue = '__export';
1470
- }
1525
+ switch ( declaration.type ) {
1526
+ case 'namedFunction':
1527
+ case 'namedClass':
1528
+ body.remove( declaration.start, declaration.valueStart );
1529
+ exportedValue = declaration.name;
1530
+ break;
1531
+
1532
+ case 'anonFunction':
1533
+ case 'anonClass':
1534
+ if ( declaration.isFinal ) {
1535
+ body.replace( declaration.start, declaration.valueStart, 'return ' );
1536
+ } else {
1537
+ body.replace( declaration.start, declaration.valueStart, 'var __export = ' );
1538
+ exportedValue = '__export';
1539
+ }
1471
1540
 
1472
- // add semi-colon, if necessary
1473
- if ( declaration.value.slice( -1 ) !== ';' ) {
1474
- body.insert( declaration.end, ';' );
1475
- }
1541
+ // add semi-colon, if necessary
1542
+ // TODO body.original is an implementation detail of magic-string - there
1543
+ // should probably be an API for this sort of thing
1544
+ if ( body.original[ declaration.end - 1 ] !== ';' ) {
1545
+ body.insert( declaration.end, ';' );
1546
+ }
1476
1547
 
1477
- break;
1548
+ break;
1478
1549
 
1479
- case 'expression':
1480
- body.remove( declaration.start, declaration.next );
1481
- exportedValue = declaration.value;
1482
- break;
1550
+ case 'expression':
1551
+ body.remove( declaration.start, declaration.next );
1552
+ exportedValue = declaration.value;
1553
+ break;
1483
1554
 
1484
- default:
1485
- throw new Error( 'Unexpected export type' );
1486
- }
1555
+ default:
1556
+ throw new Error( (("Unexpected export type '" + (declaration.type)) + "'") );
1557
+ }
1487
1558
 
1488
- if ( exportedValue ) {
1489
- body.append( '\nreturn ' + exportedValue + ';' );
1490
- }
1559
+ if ( exportedValue ) {
1560
+ body.append( '\nreturn ' + exportedValue + ';' );
1491
1561
  }
1492
1562
  }
1493
1563
 
@@ -1744,18 +1814,13 @@
1744
1814
  switch ( exportDeclaration.type ) {
1745
1815
  case 'namedFunction':
1746
1816
  case 'namedClass':
1747
- mod.body.remove( exportDeclaration.start, exportDeclaration.valueStart );
1817
+ mod.body.remove( exportDeclaration.start, exportDeclaration.node.declaration.start );
1748
1818
  mod.body.replace( exportDeclaration.end, exportDeclaration.end, (("\nmodule.exports = " + (exportDeclaration.node.declaration.id.name)) + ";") );
1749
1819
  break;
1750
1820
 
1751
- case 'anonFunction':
1752
- case 'anonClass':
1753
- case 'expression':
1754
- mod.body.replace( exportDeclaration.start, exportDeclaration.valueStart, 'module.exports = ' );
1755
- break;
1756
-
1757
1821
  default:
1758
- throw new Error( 'Unexpected export type' );
1822
+ mod.body.replace( exportDeclaration.start, exportDeclaration.node.declaration.start, 'module.exports = ' );
1823
+ break;
1759
1824
  }
1760
1825
  }
1761
1826
 
@@ -1771,12 +1836,12 @@
1771
1836
 
1772
1837
  var intro =
1773
1838
  (("(function (factory) {\
1774
- \n !(typeof exports === 'object' && typeof module !== 'undefined') &&\
1775
- \n typeof define === 'function' && define.amd ? define(" + amdName) + "factory) :\
1776
- \n factory()\
1777
- \n }(function () { 'use strict';\
1839
+ \n !(typeof exports === 'object' && typeof module !== 'undefined') &&\
1840
+ \n typeof define === 'function' && define.amd ? define(" + amdName) + "factory) :\
1841
+ \n factory()\
1842
+ \n}(function () { 'use strict';\
1778
1843
  \n\
1779
- \n ");
1844
+ \n");
1780
1845
 
1781
1846
  return intro.replace( /\t/g, indentStr );
1782
1847
  }
@@ -1803,12 +1868,12 @@
1803
1868
 
1804
1869
  var intro =
1805
1870
  (("(function (global, factory) {\
1806
- \n typeof exports === 'object' && typeof module !== 'undefined' ? " + cjsExport) + (" :\
1807
- \n typeof define === 'function' && define.amd ? define(" + amdName) + ("" + amdDeps) + ("factory) :\
1808
- \n " + globalExport) + ("\
1809
- \n }(this, function (" + args) + ") { 'use strict';\
1871
+ \n typeof exports === 'object' && typeof module !== 'undefined' ? " + cjsExport) + (" :\
1872
+ \n typeof define === 'function' && define.amd ? define(" + amdName) + ("" + amdDeps) + ("factory) :\
1873
+ \n " + globalExport) + ("\
1874
+ \n}(this, function (" + args) + ") { 'use strict';\
1810
1875
  \n\
1811
- \n ");
1876
+ \n");
1812
1877
 
1813
1878
  return intro.replace( /\t/g, indentStr );
1814
1879
  }
@@ -1999,19 +2064,15 @@
1999
2064
  }
2000
2065
  }
2001
2066
 
2002
- function rewriteIdentifiers ( body, node, identifierReplacements, scope ) {
2003
- var name, replacement;
2004
-
2005
- if ( node.type === 'Identifier' ) {
2006
- name = node.name;
2007
- replacement = hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
2067
+ function replaceIdentifiers ( body, node, identifierReplacements, scope ) {
2068
+ var name = node.name;
2069
+ var replacement = hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
2008
2070
 
2009
- // TODO unchanged identifiers shouldn't have got this far -
2010
- // remove the `replacement !== name` safeguard once that's the case
2011
- if ( replacement && replacement !== name && !scope.contains( name, true ) ) {
2012
- // rewrite
2013
- body.replace( node.start, node.end, replacement );
2014
- }
2071
+ // TODO unchanged identifiers shouldn't have got this far -
2072
+ // remove the `replacement !== name` safeguard once that's the case
2073
+ if ( replacement && replacement !== name && !scope.contains( name, true ) ) {
2074
+ // rewrite
2075
+ body.replace( node.start, node.end, replacement );
2015
2076
  }
2016
2077
  }
2017
2078
 
@@ -2067,7 +2128,7 @@
2067
2128
  previousCapturedUpdates = null;
2068
2129
 
2069
2130
  estraverse.traverse( ast, {
2070
- enter: function ( node ) {
2131
+ enter: function ( node, parent ) {
2071
2132
  // we're only interested in references, not property names etc
2072
2133
  if ( node._skip ) return this.skip();
2073
2134
 
@@ -2096,8 +2157,9 @@
2096
2157
  // and `capturedUpdates`, which are used elsewhere
2097
2158
  rewriteExportAssignments( body, node, exportNames, scope, alreadyExported, scope === ast._scope, capturedUpdates );
2098
2159
 
2099
- // Replace identifiers
2100
- rewriteIdentifiers( body, node, identifierReplacements, scope );
2160
+ if ( node.type === 'Identifier' && parent.type !== 'FunctionExpression' ) {
2161
+ replaceIdentifiers( body, node, identifierReplacements, scope );
2162
+ }
2101
2163
 
2102
2164
  // Replace top-level this with undefined ES6 8.1.1.5.4
2103
2165
  if ( node.type === 'ThisExpression' && node._topLevel ) {
@@ -2128,7 +2190,7 @@
2128
2190
  return ((" exports." + (c.name)) + (" = " + (c.exportAs)) + ";");
2129
2191
  }
2130
2192
 
2131
- function transformBody ( mod, body, options ) {var $D$1;
2193
+ function transformBody ( mod, body, options ) {var $D$0;
2132
2194
  var chains,
2133
2195
  identifierReplacements,
2134
2196
  importedBindings = {},
@@ -2138,10 +2200,10 @@
2138
2200
  earlyExports,
2139
2201
  lateExports;
2140
2202
 
2141
- chains = ($D$1 = gatherImports( mod.imports ))[0], identifierReplacements = $D$1[1], $D$1;
2203
+ chains = ($D$0 = gatherImports( mod.imports ))[0], identifierReplacements = $D$0[1], $D$0;
2142
2204
  exportNames = getExportNames( mod.exports );
2143
2205
 
2144
- importedBindings = ($D$1 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$1[1], $D$1;
2206
+ importedBindings = ($D$0 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$0[1], $D$0;
2145
2207
 
2146
2208
  // ensure no conflict with `exports`
2147
2209
  identifierReplacements.exports = deconflict( 'exports', mod.ast._declared );
@@ -2166,35 +2228,32 @@
2166
2228
 
2167
2229
  // Remove export statements (but keep declarations)
2168
2230
  mod.exports.forEach( function(x ) {
2169
- switch ( x.type ) {
2170
- case 'varDeclaration': // export var answer = 42;
2231
+ if ( x.isDefault ) {
2232
+ if ( /^named/.test( x.type ) ) {
2233
+ // export default function answer () { return 42; }
2171
2234
  body.remove( x.start, x.valueStart );
2172
- return;
2235
+ body.insert( x.end, (("\nexports['default'] = " + (x.name)) + ";") );
2236
+ } else {
2237
+ // everything else
2238
+ body.replace( x.start, x.valueStart, 'exports[\'default\'] = ' );
2239
+ }
2240
+ }
2173
2241
 
2174
- case 'namedFunction':
2175
- case 'namedClass':
2176
- if ( x.isDefault ) {
2177
- // export default function answer () { return 42; }
2178
- body.remove( x.start, x.valueStart );
2179
- body.insert( x.end, (("\nexports['default'] = " + (x.name)) + ";") );
2180
- } else {
2181
- // export function answer () { return 42; }
2242
+ else {
2243
+ switch ( x.type ) {
2244
+ case 'varDeclaration': // export var answer = 42; (or let)
2245
+ case 'namedFunction': // export function answer () {...}
2246
+ case 'namedClass': // export class answer {...}
2182
2247
  body.remove( x.start, x.valueStart );
2183
- }
2184
- return;
2185
-
2186
- case 'anonFunction': // export default function () {}
2187
- case 'anonClass': // export default class () {}
2188
- case 'expression': // export default 40 + 2;
2189
- body.replace( x.start, x.valueStart, 'exports[\'default\'] = ' );
2190
- return;
2248
+ break;
2191
2249
 
2192
- case 'named': // export { foo, bar };
2193
- body.remove( x.start, x.next );
2194
- break;
2250
+ case 'named': // export { foo, bar };
2251
+ body.remove( x.start, x.next );
2252
+ break;
2195
2253
 
2196
- default:
2197
- throw new Error( 'Unknown export type: ' + x.type );
2254
+ default:
2255
+ body.replace( x.start, x.valueStart, 'exports[\'default\'] = ' );
2256
+ }
2198
2257
  }
2199
2258
  });
2200
2259
 
@@ -2234,7 +2293,7 @@
2234
2293
  if ( options.intro && options.outro ) {
2235
2294
  body.indent().prepend( options.intro ).trimLines().append( options.outro );
2236
2295
  }
2237
- ;$D$1 = void 0}
2296
+ ;$D$0 = void 0}
2238
2297
 
2239
2298
  function deconflict ( name, declared ) {
2240
2299
  while ( hasOwnProp.call( declared, name ) ) {
@@ -2272,12 +2331,12 @@
2272
2331
 
2273
2332
  strictMode_amd__introTemplate = template( 'define(<%= amdName %><%= paths %>function (<%= names %>) {\n\n\t\'use strict\';\n\n' );
2274
2333
 
2275
- function strictMode_amd__amd ( mod, options ) {var $D$2;
2334
+ function strictMode_amd__amd ( mod, options ) {var $D$1;
2276
2335
  var importPaths,
2277
2336
  importNames,
2278
2337
  intro;
2279
2338
 
2280
- importPaths = ($D$2 = getImportSummary( mod ))[0], importNames = $D$2[1], $D$2;
2339
+ importPaths = ($D$1 = getImportSummary( mod ))[0], importNames = $D$1[1], $D$1;
2281
2340
 
2282
2341
  if ( mod.exports.length ) {
2283
2342
  importPaths.unshift( 'exports' );
@@ -2297,7 +2356,7 @@
2297
2356
  });
2298
2357
 
2299
2358
  return packageResult( mod, mod.body, options, 'toAmd' );
2300
- ;$D$2 = void 0}
2359
+ ;$D$1 = void 0}
2301
2360
 
2302
2361
  function strictMode_cjs__cjs ( mod, options ) {
2303
2362
  var importBlock, seen = {};
@@ -2350,17 +2409,17 @@
2350
2409
  defaultsBlock = options.externalDefaults.map( function(x )
2351
2410
  {return '\t' + ( x.needsNamed ? (("var " + (x.name)) + "__default") : x.name ) +
2352
2411
  ((" = ('default' in " + (x.name)) + (" ? " + (x.name)) + ("['default'] : " + (x.name)) + ");")}
2353
- ).join('\n') + '\n\n';
2412
+ ).join('\n') + '\n\n';
2354
2413
  }
2355
2414
 
2356
2415
  var intro =
2357
2416
  (("(function (global, factory) {\
2358
- \n typeof exports === 'object' && typeof module !== 'undefined' ? factory(" + cjsDeps) + (") :\
2359
- \n typeof define === 'function' && define.amd ? define(" + amdName) + ("" + amdDeps) + ("factory) :\
2360
- \n factory(" + globalDeps) + (")\
2361
- \n }(this, function (" + args) + (") { 'use strict';\
2417
+ \n typeof exports === 'object' && typeof module !== 'undefined' ? factory(" + cjsDeps) + (") :\
2418
+ \n typeof define === 'function' && define.amd ? define(" + amdName) + ("" + amdDeps) + ("factory) :\
2419
+ \n factory(" + globalDeps) + (")\
2420
+ \n}(this, function (" + args) + (") { 'use strict';\
2362
2421
  \n\
2363
- \n " + defaultsBlock) + "");
2422
+ \n" + defaultsBlock) + "");
2364
2423
 
2365
2424
  return intro.replace( /\t/g, indentStr );
2366
2425
  }
data/vendor/esperanto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- esperanto.js v0.6.17 - 2015-03-01
2
+ esperanto.js v0.6.18 - 2015-03-30
3
3
  http://esperantojs.org
4
4
 
5
5
  Released under the MIT License.
@@ -77,7 +77,7 @@ function annotateAst ( ast ) {
77
77
 
78
78
  estraverse.traverse( ast, {
79
79
  enter: function ( node ) {
80
- if ( node.type === 'ImportDeclaration' ) {
80
+ if ( node.type === 'ImportDeclaration' || node.type === 'ExportSpecifier' ) {
81
81
  node._skip = true;
82
82
  }
83
83
 
@@ -219,16 +219,19 @@ function findImportsAndExports ( mod, source, ast ) {
219
219
  imports.push( declaration );
220
220
  }
221
221
 
222
- else if ( node.type === 'ExportDeclaration' ) {
223
- declaration = processExport( node, source );
222
+ else if ( node.type === 'ExportDefaultDeclaration' ) {
223
+ declaration = processDefaultExport( node, source );
224
224
  exports.push( declaration );
225
225
 
226
- if ( declaration.isDefault ) {
227
- if ( mod.defaultExport ) {
228
- throw new Error( 'Duplicate default exports' );
229
- }
230
- mod.defaultExport = declaration;
226
+ if ( mod.defaultExport ) {
227
+ throw new Error( 'Duplicate default exports' );
231
228
  }
229
+ mod.defaultExport = declaration;
230
+ }
231
+
232
+ else if ( node.type === 'ExportNamedDeclaration' ) {
233
+ declaration = processExport( node, source );
234
+ exports.push( declaration );
232
235
 
233
236
  if ( node.source ) {
234
237
  // it's both an import and an export, e.g.
@@ -272,20 +275,25 @@ function processImport ( node, passthrough ) {
272
275
  specifiers: node.specifiers.map( function(s ) {
273
276
  var id;
274
277
 
275
- if ( s.type === 'ImportBatchSpecifier' ) {
278
+ if ( s.type === 'ImportNamespaceSpecifier' ) {
276
279
  return {
277
280
  isBatch: true,
278
- name: s.name.name,
279
- as: s.name.name
281
+ name: s.local.name, // TODO is this line necessary?
282
+ as: s.local.name
280
283
  };
281
284
  }
282
285
 
283
- id = s.id.name;
286
+ if ( s.type === 'ImportDefaultSpecifier' ) {
287
+ return {
288
+ isDefault: true,
289
+ name: 'default',
290
+ as: s.local.name
291
+ }
292
+ }
284
293
 
285
294
  return {
286
- isDefault: !!s.default,
287
- name: s.default ? 'default' : id,
288
- as: s.name ? s.name.name : id
295
+ name: ( !!passthrough ? s.exported : s.imported ).name,
296
+ as: s.local.name
289
297
  };
290
298
  })
291
299
  };
@@ -307,6 +315,53 @@ function processImport ( node, passthrough ) {
307
315
  return x;
308
316
  }
309
317
 
318
+ function processDefaultExport ( node, source ) {
319
+ var result = {
320
+ isDefault: true,
321
+ node: node,
322
+ start: node.start,
323
+ end: node.end
324
+ };
325
+
326
+ var d = node.declaration;
327
+
328
+ if ( d.type === 'FunctionExpression' ) {
329
+ // Case 1: `export default function () {...}`
330
+ result.hasDeclaration = true; // TODO remove in favour of result.type
331
+ result.type = 'anonFunction';
332
+ }
333
+
334
+ else if ( d.type === 'FunctionDeclaration' ) {
335
+ // Case 2: `export default function foo () {...}`
336
+ result.hasDeclaration = true; // TODO remove in favour of result.type
337
+ result.type = 'namedFunction';
338
+ result.name = d.id.name;
339
+ }
340
+
341
+ else if ( d.type === 'ClassExpression' ) {
342
+ // Case 3: `export default class {...}`
343
+ result.hasDeclaration = true; // TODO remove in favour of result.type
344
+ result.type = 'anonClass';
345
+ }
346
+
347
+ else if ( d.type === 'ClassDeclaration' ) {
348
+ // Case 4: `export default class Foo {...}`
349
+ result.hasDeclaration = true; // TODO remove in favour of result.type
350
+ result.type = 'namedClass';
351
+ result.name = d.id.name;
352
+ }
353
+
354
+ else {
355
+ result.type = 'expression';
356
+ result.name = 'default';
357
+ }
358
+
359
+ result.value = source.slice( d.start, d.end );
360
+ result.valueStart = d.start;
361
+
362
+ return result;
363
+ }
364
+
310
365
  /**
311
366
  * Generates a representation of an export declaration
312
367
  * @param {object} node - the original AST node
@@ -337,62 +392,23 @@ function processExport ( node, source ) {
337
392
  else if ( d.type === 'FunctionDeclaration' ) {
338
393
  result.hasDeclaration = true; // TODO remove in favour of result.type
339
394
  result.type = 'namedFunction';
340
- result.isDefault = !!node.default;
341
395
  result.name = d.id.name;
342
396
  }
343
397
 
344
- else if ( d.type === 'FunctionExpression' ) {
345
- result.hasDeclaration = true; // TODO remove in favour of result.type
346
- result.isDefault = true;
347
-
348
- // Case 3: `export default function foo () {...}`
349
- if ( d.id ) {
350
- result.type = 'namedFunction';
351
- result.name = d.id.name;
352
- }
353
-
354
- // Case 4: `export default function () {...}`
355
- else {
356
- result.type = 'anonFunction';
357
- }
358
- }
359
-
360
- // Case 5: `export class Foo {...}`
398
+ // Case 3: `export class Foo {...}`
361
399
  else if ( d.type === 'ClassDeclaration' ) {
362
400
  result.hasDeclaration = true; // TODO remove in favour of result.type
363
401
  result.type = 'namedClass';
364
- result.isDefault = !!node.default;
365
402
  result.name = d.id.name;
366
403
  }
367
-
368
- else if ( d.type === 'ClassExpression' ) {
369
- result.hasDeclaration = true; // TODO remove in favour of result.type
370
- result.isDefault = true;
371
-
372
- // Case 6: `export default class Foo {...}`
373
- if ( d.id ) {
374
- result.type = 'namedClass';
375
- result.name = d.id.name;
376
- }
377
-
378
- // Case 7: `export default class {...}`
379
- else {
380
- result.type = 'anonClass';
381
- }
382
- }
383
-
384
- // Case 8: `export default 1 + 2`
385
- else {
386
- result.type = 'expression';
387
- result.isDefault = true;
388
- result.name = 'default';
389
- }
390
404
  }
391
405
 
392
406
  // Case 9: `export { foo, bar };`
393
407
  else {
394
408
  result.type = 'named';
395
- result.specifiers = node.specifiers.map( function(s ) {return { name: s.id.name }} ); // TODO as?
409
+ result.specifiers = node.specifiers.map( function(s ) {
410
+ return { name: s.local.name };
411
+ }); // TODO as?
396
412
  }
397
413
 
398
414
  return result;
@@ -495,24 +511,36 @@ function splitPath ( path ) {
495
511
  return path.split( pathSplitRE );
496
512
  }
497
513
 
498
- function getStandaloneModule ( options ) {var $D$0;
499
- var mod, imports, exports, conflicts = {};
514
+ var SOURCEMAPPINGURL_REGEX = /^# sourceMappingURL=/;
500
515
 
501
- mod = {
516
+ function getStandaloneModule ( options ) {
517
+ var toRemove = [];
518
+
519
+ var mod = {
502
520
  body: new MagicString( options.source ),
503
521
  ast: acorn.parse( options.source, {
504
522
  ecmaVersion: 6,
505
- locations: true
523
+ sourceType: 'module',
524
+ onComment: function ( block, text, start, end ) {
525
+ // sourceMappingURL comments should be removed
526
+ if ( !block && /^# sourceMappingURL=/.test( text ) ) {
527
+ toRemove.push({ start: start, end: end });
528
+ }
529
+ }
506
530
  })
507
531
  };
508
532
 
509
- imports = ($D$0 = findImportsAndExports( mod, options.source, mod.ast ))[0], exports = $D$0[1], $D$0;
533
+ toRemove.forEach( function(end) {var start = end.start, end = end.end;return mod.body.remove( start, end )} );
534
+
535
+ var imports = (exports = findImportsAndExports( mod, options.source, mod.ast ))[0], exports = exports[1];
510
536
 
511
537
  disallowConflictingImports( imports );
512
538
 
513
539
  mod.imports = imports;
514
540
  mod.exports = exports;
515
541
 
542
+ var conflicts = {};
543
+
516
544
  if ( options.strict ) {
517
545
  annotateAst( mod.ast );
518
546
 
@@ -525,7 +553,7 @@ function getStandaloneModule ( options ) {var $D$0;
525
553
  determineImportNames( imports, options.getModuleName, conflicts );
526
554
 
527
555
  return mod;
528
- ;$D$0 = void 0}
556
+ }
529
557
 
530
558
  function determineImportNames ( imports, userFn, usedNames ) {
531
559
  var nameById = {}, inferredNames = {};
@@ -1069,19 +1097,15 @@ function disallowIllegalReassignment ( node, importedBindings, importedNamespace
1069
1097
  }
1070
1098
  }
1071
1099
 
1072
- function rewriteIdentifiers ( body, node, identifierReplacements, scope ) {
1073
- var name, replacement;
1074
-
1075
- if ( node.type === 'Identifier' ) {
1076
- name = node.name;
1077
- replacement = hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
1100
+ function replaceIdentifiers ( body, node, identifierReplacements, scope ) {
1101
+ var name = node.name;
1102
+ var replacement = hasOwnProp.call( identifierReplacements, name ) && identifierReplacements[ name ];
1078
1103
 
1079
- // TODO unchanged identifiers shouldn't have got this far -
1080
- // remove the `replacement !== name` safeguard once that's the case
1081
- if ( replacement && replacement !== name && !scope.contains( name, true ) ) {
1082
- // rewrite
1083
- body.replace( node.start, node.end, replacement );
1084
- }
1104
+ // TODO unchanged identifiers shouldn't have got this far -
1105
+ // remove the `replacement !== name` safeguard once that's the case
1106
+ if ( replacement && replacement !== name && !scope.contains( name, true ) ) {
1107
+ // rewrite
1108
+ body.replace( node.start, node.end, replacement );
1085
1109
  }
1086
1110
  }
1087
1111
 
@@ -1137,7 +1161,7 @@ function traverseAst ( ast, body, identifierReplacements, importedBindings, impo
1137
1161
  previousCapturedUpdates = null;
1138
1162
 
1139
1163
  estraverse.traverse( ast, {
1140
- enter: function ( node ) {
1164
+ enter: function ( node, parent ) {
1141
1165
  // we're only interested in references, not property names etc
1142
1166
  if ( node._skip ) return this.skip();
1143
1167
 
@@ -1166,8 +1190,9 @@ function traverseAst ( ast, body, identifierReplacements, importedBindings, impo
1166
1190
  // and `capturedUpdates`, which are used elsewhere
1167
1191
  rewriteExportAssignments( body, node, exportNames, scope, alreadyExported, scope === ast._scope, capturedUpdates );
1168
1192
 
1169
- // Replace identifiers
1170
- rewriteIdentifiers( body, node, identifierReplacements, scope );
1193
+ if ( node.type === 'Identifier' && parent.type !== 'FunctionExpression' ) {
1194
+ replaceIdentifiers( body, node, identifierReplacements, scope );
1195
+ }
1171
1196
 
1172
1197
  // Replace top-level this with undefined ES6 8.1.1.5.4
1173
1198
  if ( node.type === 'ThisExpression' && node._topLevel ) {
@@ -1198,7 +1223,7 @@ function exportCapturedUpdate ( c ) {
1198
1223
  return ((" exports." + (c.name)) + (" = " + (c.exportAs)) + ";");
1199
1224
  }
1200
1225
 
1201
- function transformBody__transformBody ( bundle, mod, body ) {var $D$1;
1226
+ function transformBody__transformBody ( bundle, mod, body ) {var $D$0;
1202
1227
  var identifierReplacements,
1203
1228
  importedBindings,
1204
1229
  importedNamespaces,
@@ -1208,7 +1233,7 @@ function transformBody__transformBody ( bundle, mod, body ) {var $D$1;
1208
1233
  exportBlock;
1209
1234
 
1210
1235
  identifierReplacements = mod.identifierReplacements;
1211
- importedBindings = ($D$1 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$1[1], $D$1;
1236
+ importedBindings = ($D$0 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$0[1], $D$0;
1212
1237
 
1213
1238
  exportNames = hasOwnProp.call( bundle.exports, mod.id ) && bundle.exports[ mod.id ];
1214
1239
 
@@ -1319,7 +1344,7 @@ function transformBody__transformBody ( bundle, mod, body ) {var $D$1;
1319
1344
  }
1320
1345
 
1321
1346
  return body.trim();
1322
- ;$D$1 = void 0}
1347
+ ;$D$0 = void 0}
1323
1348
 
1324
1349
  function combine ( bundle ) {
1325
1350
  var body;
@@ -1370,7 +1395,7 @@ function combine ( bundle ) {
1370
1395
  bundle.body = body;
1371
1396
  }
1372
1397
 
1373
- function getModule ( mod ) {var $D$2;
1398
+ function getModule ( mod ) {var $D$1;
1374
1399
  var imports, exports;
1375
1400
 
1376
1401
  mod.body = new MagicString( mod.source );
@@ -1378,7 +1403,7 @@ function getModule ( mod ) {var $D$2;
1378
1403
  try {
1379
1404
  mod.ast = acorn.parse( mod.source, {
1380
1405
  ecmaVersion: 6,
1381
- locations: true
1406
+ sourceType: 'module'
1382
1407
  });
1383
1408
 
1384
1409
  annotateAst( mod.ast );
@@ -1392,7 +1417,7 @@ function getModule ( mod ) {var $D$2;
1392
1417
  throw err;
1393
1418
  }
1394
1419
 
1395
- imports = ($D$2 = findImportsAndExports( mod, mod.source, mod.ast ))[0], exports = $D$2[1], $D$2;
1420
+ imports = ($D$1 = findImportsAndExports( mod, mod.source, mod.ast ))[0], exports = $D$1[1], $D$1;
1396
1421
 
1397
1422
  disallowConflictingImports( imports );
1398
1423
 
@@ -1428,7 +1453,7 @@ function getModule ( mod ) {var $D$2;
1428
1453
  });
1429
1454
 
1430
1455
  return mod;
1431
- ;$D$2 = void 0}
1456
+ ;$D$1 = void 0}
1432
1457
 
1433
1458
  var getBundle__Promise = sander.Promise;
1434
1459
 
@@ -1571,44 +1596,48 @@ function isThenable ( obj ) {
1571
1596
  }
1572
1597
 
1573
1598
  function transformExportDeclaration ( declaration, body ) {
1574
- var exportedValue;
1599
+ if ( !declaration ) {
1600
+ return;
1601
+ }
1575
1602
 
1576
- if ( declaration ) {
1577
- switch ( declaration.type ) {
1578
- case 'namedFunction':
1579
- case 'namedClass':
1580
- body.remove( declaration.start, declaration.valueStart );
1581
- exportedValue = declaration.name;
1582
- break;
1603
+ var exportedValue;
1583
1604
 
1584
- case 'anonFunction':
1585
- case 'anonClass':
1586
- if ( declaration.isFinal ) {
1587
- body.replace( declaration.start, declaration.valueStart, 'return ' );
1588
- } else {
1589
- body.replace( declaration.start, declaration.valueStart, 'var __export = ' );
1590
- exportedValue = '__export';
1591
- }
1605
+ switch ( declaration.type ) {
1606
+ case 'namedFunction':
1607
+ case 'namedClass':
1608
+ body.remove( declaration.start, declaration.valueStart );
1609
+ exportedValue = declaration.name;
1610
+ break;
1611
+
1612
+ case 'anonFunction':
1613
+ case 'anonClass':
1614
+ if ( declaration.isFinal ) {
1615
+ body.replace( declaration.start, declaration.valueStart, 'return ' );
1616
+ } else {
1617
+ body.replace( declaration.start, declaration.valueStart, 'var __export = ' );
1618
+ exportedValue = '__export';
1619
+ }
1592
1620
 
1593
- // add semi-colon, if necessary
1594
- if ( declaration.value.slice( -1 ) !== ';' ) {
1595
- body.insert( declaration.end, ';' );
1596
- }
1621
+ // add semi-colon, if necessary
1622
+ // TODO body.original is an implementation detail of magic-string - there
1623
+ // should probably be an API for this sort of thing
1624
+ if ( body.original[ declaration.end - 1 ] !== ';' ) {
1625
+ body.insert( declaration.end, ';' );
1626
+ }
1597
1627
 
1598
- break;
1628
+ break;
1599
1629
 
1600
- case 'expression':
1601
- body.remove( declaration.start, declaration.next );
1602
- exportedValue = declaration.value;
1603
- break;
1630
+ case 'expression':
1631
+ body.remove( declaration.start, declaration.next );
1632
+ exportedValue = declaration.value;
1633
+ break;
1604
1634
 
1605
- default:
1606
- throw new Error( 'Unexpected export type' );
1607
- }
1635
+ default:
1636
+ throw new Error( (("Unexpected export type '" + (declaration.type)) + "'") );
1637
+ }
1608
1638
 
1609
- if ( exportedValue ) {
1610
- body.append( '\nreturn ' + exportedValue + ';' );
1611
- }
1639
+ if ( exportedValue ) {
1640
+ body.append( '\nreturn ' + exportedValue + ';' );
1612
1641
  }
1613
1642
  }
1614
1643
 
@@ -1806,18 +1835,13 @@ function cjs__cjs ( mod, options ) {
1806
1835
  switch ( exportDeclaration.type ) {
1807
1836
  case 'namedFunction':
1808
1837
  case 'namedClass':
1809
- mod.body.remove( exportDeclaration.start, exportDeclaration.valueStart );
1838
+ mod.body.remove( exportDeclaration.start, exportDeclaration.node.declaration.start );
1810
1839
  mod.body.replace( exportDeclaration.end, exportDeclaration.end, (("\nmodule.exports = " + (exportDeclaration.node.declaration.id.name)) + ";") );
1811
1840
  break;
1812
1841
 
1813
- case 'anonFunction':
1814
- case 'anonClass':
1815
- case 'expression':
1816
- mod.body.replace( exportDeclaration.start, exportDeclaration.valueStart, 'module.exports = ' );
1817
- break;
1818
-
1819
1842
  default:
1820
- throw new Error( 'Unexpected export type' );
1843
+ mod.body.replace( exportDeclaration.start, exportDeclaration.node.declaration.start, 'module.exports = ' );
1844
+ break;
1821
1845
  }
1822
1846
  }
1823
1847
 
@@ -2005,7 +2029,7 @@ function getExportNames ( exports ) {
2005
2029
  return result;
2006
2030
  }
2007
2031
 
2008
- function utils_transformBody__transformBody ( mod, body, options ) {var $D$3;
2032
+ function utils_transformBody__transformBody ( mod, body, options ) {var $D$2;
2009
2033
  var chains,
2010
2034
  identifierReplacements,
2011
2035
  importedBindings = {},
@@ -2015,10 +2039,10 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$3;
2015
2039
  earlyExports,
2016
2040
  lateExports;
2017
2041
 
2018
- chains = ($D$3 = gatherImports( mod.imports ))[0], identifierReplacements = $D$3[1], $D$3;
2042
+ chains = ($D$2 = gatherImports( mod.imports ))[0], identifierReplacements = $D$2[1], $D$2;
2019
2043
  exportNames = getExportNames( mod.exports );
2020
2044
 
2021
- importedBindings = ($D$3 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$3[1], $D$3;
2045
+ importedBindings = ($D$2 = getReadOnlyIdentifiers( mod.imports ))[0], importedNamespaces = $D$2[1], $D$2;
2022
2046
 
2023
2047
  // ensure no conflict with `exports`
2024
2048
  identifierReplacements.exports = deconflict( 'exports', mod.ast._declared );
@@ -2043,35 +2067,32 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$3;
2043
2067
 
2044
2068
  // Remove export statements (but keep declarations)
2045
2069
  mod.exports.forEach( function(x ) {
2046
- switch ( x.type ) {
2047
- case 'varDeclaration': // export var answer = 42;
2070
+ if ( x.isDefault ) {
2071
+ if ( /^named/.test( x.type ) ) {
2072
+ // export default function answer () { return 42; }
2048
2073
  body.remove( x.start, x.valueStart );
2049
- return;
2074
+ body.insert( x.end, (("\nexports['default'] = " + (x.name)) + ";") );
2075
+ } else {
2076
+ // everything else
2077
+ body.replace( x.start, x.valueStart, 'exports[\'default\'] = ' );
2078
+ }
2079
+ }
2050
2080
 
2051
- case 'namedFunction':
2052
- case 'namedClass':
2053
- if ( x.isDefault ) {
2054
- // export default function answer () { return 42; }
2055
- body.remove( x.start, x.valueStart );
2056
- body.insert( x.end, (("\nexports['default'] = " + (x.name)) + ";") );
2057
- } else {
2058
- // export function answer () { return 42; }
2081
+ else {
2082
+ switch ( x.type ) {
2083
+ case 'varDeclaration': // export var answer = 42; (or let)
2084
+ case 'namedFunction': // export function answer () {...}
2085
+ case 'namedClass': // export class answer {...}
2059
2086
  body.remove( x.start, x.valueStart );
2060
- }
2061
- return;
2062
-
2063
- case 'anonFunction': // export default function () {}
2064
- case 'anonClass': // export default class () {}
2065
- case 'expression': // export default 40 + 2;
2066
- body.replace( x.start, x.valueStart, 'exports[\'default\'] = ' );
2067
- return;
2087
+ break;
2068
2088
 
2069
- case 'named': // export { foo, bar };
2070
- body.remove( x.start, x.next );
2071
- break;
2089
+ case 'named': // export { foo, bar };
2090
+ body.remove( x.start, x.next );
2091
+ break;
2072
2092
 
2073
- default:
2074
- throw new Error( 'Unknown export type: ' + x.type );
2093
+ default:
2094
+ body.replace( x.start, x.valueStart, 'exports[\'default\'] = ' );
2095
+ }
2075
2096
  }
2076
2097
  });
2077
2098
 
@@ -2111,7 +2132,7 @@ function utils_transformBody__transformBody ( mod, body, options ) {var $D$3;
2111
2132
  if ( options.intro && options.outro ) {
2112
2133
  body.indent().prepend( options.intro ).trimLines().append( options.outro );
2113
2134
  }
2114
- ;$D$3 = void 0}
2135
+ ;$D$2 = void 0}
2115
2136
 
2116
2137
  function deconflict ( name, declared ) {
2117
2138
  while ( hasOwnProp.call( declared, name ) ) {
@@ -2149,12 +2170,12 @@ var strictMode_amd__introTemplate;
2149
2170
 
2150
2171
  strictMode_amd__introTemplate = template( 'define(<%= amdName %><%= paths %>function (<%= names %>) {\n\n\t\'use strict\';\n\n' );
2151
2172
 
2152
- function strictMode_amd__amd ( mod, options ) {var $D$4;
2173
+ function strictMode_amd__amd ( mod, options ) {var $D$3;
2153
2174
  var importPaths,
2154
2175
  importNames,
2155
2176
  intro;
2156
2177
 
2157
- importPaths = ($D$4 = getImportSummary( mod ))[0], importNames = $D$4[1], $D$4;
2178
+ importPaths = ($D$3 = getImportSummary( mod ))[0], importNames = $D$3[1], $D$3;
2158
2179
 
2159
2180
  if ( mod.exports.length ) {
2160
2181
  importPaths.unshift( 'exports' );
@@ -2174,7 +2195,7 @@ function strictMode_amd__amd ( mod, options ) {var $D$4;
2174
2195
  });
2175
2196
 
2176
2197
  return packageResult( mod, mod.body, options, 'toAmd' );
2177
- ;$D$4 = void 0}
2198
+ ;$D$3 = void 0}
2178
2199
 
2179
2200
  function strictMode_cjs__cjs ( mod, options ) {
2180
2201
  var importBlock, seen = {};
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esperanto-source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.17.3
4
+ version: 0.6.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryunosuke SATO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler