Comparing version 0.3.9 to 0.3.10
@@ -18,2 +18,2 @@ var transform = require('./transform'); | ||
} | ||
} | ||
}; |
@@ -24,2 +24,7 @@ var __export; | ||
// Remove empty imports from the end of the array | ||
while ( imports.length && imports[ imports.length - 1 ].empty ) { | ||
imports.pop(); | ||
} | ||
importNames = ( | ||
@@ -26,0 +31,0 @@ options.defaultOnly || !hasExports ? |
@@ -10,4 +10,4 @@ module.exports = function ( parsed, options ) { | ||
result[0] = imports.map( function ( x ) { | ||
return 'var ' + x.name + ' = require(\'' + x.path + '\');'; | ||
}).join( '\n' ); | ||
return ( !x.empty ? 'var ' + x.name + ' = ' : '' ) + 'require(\'' + x.path + '\');'; | ||
}).join( '\n' ) + '\n'; | ||
} | ||
@@ -25,3 +25,3 @@ | ||
return result.join( '\n' ); | ||
return result.join( '\n' ).trim(); | ||
}; |
@@ -69,8 +69,20 @@ var acorn = require('acorn'); | ||
function replaceImport ( node ) { | ||
var _import, result = [], indent; | ||
var _import, result = [], indent, specifier0; | ||
indent = getIndent( node.start, source ); | ||
// empty imports, e.g. `import 'polyfills'` | ||
specifier0 = node.specifiers[0]; | ||
if ( !specifier0 ) { | ||
imports.push({ | ||
path: node.source.value, | ||
name: '__imports_' + imports.length, | ||
empty: true | ||
}); | ||
return SKIP; | ||
} | ||
// batch imports, e.g. `import * as fs from 'fs';` | ||
if ( node.specifiers[0].type === 'ImportBatchSpecifier' ) { | ||
if ( specifier0 && specifier0.type === 'ImportBatchSpecifier' ) { | ||
// this is (as far as AMD/CJS are concerned) functionally | ||
@@ -80,3 +92,3 @@ // equivalent to `import fs from 'fs'` | ||
path: node.source.value, | ||
name: node.specifiers[0].name.name | ||
name: specifier0.name.name | ||
}); | ||
@@ -83,0 +95,0 @@ |
{ | ||
"name": "esperanto", | ||
"description": "An easier way to convert ES6 modules to AMD and CommonJS", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"author": "Rich Harris", | ||
@@ -15,3 +15,3 @@ "dependencies": { | ||
"mkdirp": "~0.5.0", | ||
"gobble": "~0.1.2", | ||
"gobble": "~0.2.0", | ||
"gobble-requirejs": "~0.1.0", | ||
@@ -22,3 +22,4 @@ "gobble-amdclean": "~0.1.0", | ||
"promise-map-series": "~0.2.0", | ||
"colors": "~0.6.2" | ||
"colors": "~0.6.2", | ||
"gobble-uglifyjs": "^0.1.0" | ||
}, | ||
@@ -25,0 +26,0 @@ "files": [ |
14425
282
12