diff --git a/package.json b/package.json index 5b10eed..38c4d2a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "eslint": "^2.9.0", "estree-walker": "^0.2.0", "istanbul": "^0.4.0", - "magic-string": "^0.10.1", + "magic-string": "^0.15.1", "mocha": "^2.3.3", "remap-istanbul": "^0.5.1", "rollup": "^0.26.2", diff --git a/src/Bundle.js b/src/Bundle.js index f16d105..9fc7c01 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'; @@ -282,7 +282,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 cde624c..9786374 100644 --- a/src/Module.js +++ b/src/Module.js @@ -488,15 +488,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 } } @@ -527,7 +528,7 @@ export default class Module { } if ( reference.isShorthandProperty ) { - magicString.insert( end, `: ${name}` ); + magicString.insertLeft( end, `: ${name}` ); } else { magicString.overwrite( start, end, name, true ); } diff --git a/test/cli/multiple-targets-shared-config/_expected/cjs.js.map b/test/cli/multiple-targets-shared-config/_expected/cjs.js.map index 7010396..d88316a 100644 --- a/test/cli/multiple-targets-shared-config/_expected/cjs.js.map +++ b/test/cli/multiple-targets-shared-config/_expected/cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"cjs.js","sources":["../main.js"],"sourcesContent":["export default 0;\n"],"names":[],"mappings":";;WAAe,CAAC,CAAC,;;"} \ No newline at end of file +{"version":3,"file":"cjs.js","sources":["../main.js"],"sourcesContent":["export default 0;\n"],"names":[],"mappings":";;AAAA,WAAe,CAAC,CAAC,;;"} diff --git a/test/cli/multiple-targets-shared-config/_expected/es6.js.map b/test/cli/multiple-targets-shared-config/_expected/es6.js.map index ba7fc9c..8b3e60e 100644 --- a/test/cli/multiple-targets-shared-config/_expected/es6.js.map +++ b/test/cli/multiple-targets-shared-config/_expected/es6.js.map @@ -1 +1 @@ -{"version":3,"file":"es6.js","sources":["../main.js"],"sourcesContent":["export default 0;\n"],"names":[],"mappings":"WAAe,CAAC,CAAC,;;"} \ No newline at end of file +{"version":3,"file":"es6.js","sources":["../main.js"],"sourcesContent":["export default 0;\n"],"names":[],"mappings":"AAAA,WAAe,CAAC,CAAC,;;"} diff --git a/test/form/sourcemaps/_config.js b/test/form/sourcemaps-external/_config.js similarity index 100% rename from test/form/sourcemaps/_config.js rename to test/form/sourcemaps-external/_config.js diff --git a/test/form/sourcemaps/_expected/amd.js b/test/form/sourcemaps-external/_expected/amd.js similarity index 100% rename from test/form/sourcemaps/_expected/amd.js rename to test/form/sourcemaps-external/_expected/amd.js diff --git a/test/form/sourcemaps/_expected/amd.js.map b/test/form/sourcemaps-external/_expected/amd.js.map similarity index 100% rename from test/form/sourcemaps/_expected/amd.js.map rename to test/form/sourcemaps-external/_expected/amd.js.map diff --git a/test/form/sourcemaps/_expected/cjs.js b/test/form/sourcemaps-external/_expected/cjs.js similarity index 100% rename from test/form/sourcemaps/_expected/cjs.js rename to test/form/sourcemaps-external/_expected/cjs.js diff --git a/test/form/sourcemaps/_expected/cjs.js.map b/test/form/sourcemaps-external/_expected/cjs.js.map similarity index 100% rename from test/form/sourcemaps/_expected/cjs.js.map rename to test/form/sourcemaps-external/_expected/cjs.js.map diff --git a/test/form/sourcemaps/_expected/es6.js b/test/form/sourcemaps-external/_expected/es6.js similarity index 100% rename from test/form/sourcemaps/_expected/es6.js rename to test/form/sourcemaps-external/_expected/es6.js diff --git a/test/form/sourcemaps/_expected/es6.js.map b/test/form/sourcemaps-external/_expected/es6.js.map similarity index 100% rename from test/form/sourcemaps/_expected/es6.js.map rename to test/form/sourcemaps-external/_expected/es6.js.map diff --git a/test/form/sourcemaps/_expected/iife.js b/test/form/sourcemaps-external/_expected/iife.js similarity index 100% rename from test/form/sourcemaps/_expected/iife.js rename to test/form/sourcemaps-external/_expected/iife.js diff --git a/test/form/sourcemaps/_expected/iife.js.map b/test/form/sourcemaps-external/_expected/iife.js.map similarity index 100% rename from test/form/sourcemaps/_expected/iife.js.map rename to test/form/sourcemaps-external/_expected/iife.js.map diff --git a/test/form/sourcemaps/_expected/umd.js b/test/form/sourcemaps-external/_expected/umd.js similarity index 100% rename from test/form/sourcemaps/_expected/umd.js rename to test/form/sourcemaps-external/_expected/umd.js diff --git a/test/form/sourcemaps/_expected/umd.js.map b/test/form/sourcemaps-external/_expected/umd.js.map similarity index 100% rename from test/form/sourcemaps/_expected/umd.js.map rename to test/form/sourcemaps-external/_expected/umd.js.map diff --git a/test/form/sourcemaps/bar.js b/test/form/sourcemaps-external/bar.js similarity index 100% rename from test/form/sourcemaps/bar.js rename to test/form/sourcemaps-external/bar.js diff --git a/test/form/sourcemaps/foo.js b/test/form/sourcemaps-external/foo.js similarity index 100% rename from test/form/sourcemaps/foo.js rename to test/form/sourcemaps-external/foo.js diff --git a/test/form/sourcemaps/main.js b/test/form/sourcemaps-external/main.js similarity index 100% rename from test/form/sourcemaps/main.js rename to test/form/sourcemaps-external/main.js diff --git a/test/test.js b/test/test.js index af44baa..1df5666 100644 --- a/test/test.js +++ b/test/test.js @@ -13,7 +13,6 @@ var FUNCTION = path.resolve( __dirname, 'function' ); var FORM = path.resolve( __dirname, 'form' ); var SOURCEMAPS = path.resolve( __dirname, 'sourcemaps' ); var CLI = path.resolve( __dirname, 'cli' ); -var INCREMENTAL = path.resolve( __dirname, 'incremental' ); var PROFILES = [ { format: 'amd' },