diff --git a/package.json b/package.json index cb726fa..2d13811 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ }, "dependencies": { "chalk": "^1.1.1", + "magic-string": "^0.15.0", "minimist": "^1.2.0", "source-map-support": "^0.4.0" }, diff --git a/src/Bundle.js b/src/Bundle.js index 95248b1..65bf133 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -1,4 +1,4 @@ -import MagicString from 'magic-string'; +import { Bundle as MagicStringBundle } from 'magic-string'; import first from './utils/first.js'; import { blank, forOwn, keys } from './utils/object.js'; import Module from './Module.js'; @@ -268,7 +268,7 @@ export default class Bundle { // Determine export mode - 'default', 'named', 'none' const exportMode = getExportMode( this, options.exports, options.moduleName ); - let magicString = new MagicString.Bundle({ separator: '\n\n' }); + let magicString = new MagicStringBundle({ separator: '\n\n' }); let usedModules = []; this.orderedModules.forEach( module => { diff --git a/src/Module.js b/src/Module.js index e222b3a..e05f04c 100644 --- a/src/Module.js +++ b/src/Module.js @@ -491,15 +491,16 @@ export default class Module { const declaration = this.declarations[ name ]; if ( declaration.exportName && declaration.isReassigned ) { - magicString.insert( statement.end, `;\nexports.${name} = ${declaration.render( es6 )}` ); + magicString.insertLeft( statement.end, `;\nexports.${name} = ${declaration.render( es6 )}` ); } }); } if ( statement.node.isSynthetic ) { // insert `var/let/const` if necessary - magicString.insert( statement.start, `${statement.node.kind} ` ); - magicString.overwrite( statement.end, statement.next, ';\n' ); // TODO account for trailing newlines + magicString.insertRight( statement.start, `${statement.node.kind} ` ); + magicString.insertLeft( statement.end, ';' ); + magicString.overwrite( statement.end, statement.next, '\n' ); // TODO account for trailing newlines } } @@ -530,7 +531,7 @@ export default class Module { } if ( reference.isShorthandProperty ) { - magicString.insert( end, `: ${name}` ); + magicString.insertLeft( end, `: ${name}` ); } else { magicString.overwrite( start, end, name, true ); }