diff --git a/src/Module.js b/src/Module.js index 442c349..5bd4b9b 100644 --- a/src/Module.js +++ b/src/Module.js @@ -140,7 +140,8 @@ export default class Module { // By default, `id` is the filename. Custom resolvers and loaders // can change that, but it makes sense to use it for the source filename this.magicString = new MagicString( source, { - filename: id + filename: id, + indentExclusionRanges: [] }); // remove existing sourceMappingURL comments @@ -501,6 +502,8 @@ export default class Module { return; } + statement.stringLiteralRanges.forEach( range => magicString.indentExclusionRanges.push( range ) ); + // skip `export { foo, bar, baz }` if ( statement.node.type === 'ExportNamedDeclaration' ) { // skip `export { foo, bar, baz }` diff --git a/src/Statement.js b/src/Statement.js index ae83957..4aa3c63 100644 --- a/src/Statement.js +++ b/src/Statement.js @@ -67,6 +67,7 @@ export default class Statement { this.scope = new Scope(); this.references = []; + this.stringLiteralRanges = []; this.isIncluded = false; @@ -88,11 +89,14 @@ export default class Statement { }); // find references - let { module, references, scope } = this; + let { module, references, scope, stringLiteralRanges } = this; let readDepth = 0; walk( this.node, { enter ( node, parent ) { + const isStringLiteral = node.type === 'TemplateElement' || ( node.type === 'Literal' && typeof node.value === 'string' ); + if ( isStringLiteral ) stringLiteralRanges.push([ node.start, node.end ]); + if ( node._scope ) scope = node._scope; if ( /Function/.test( node.type ) && !isIife( node, parent ) ) readDepth += 1;