Browse Source

prevent multiline strings being indented (#164)

better-aggressive
Rich Harris 9 years ago
parent
commit
4fcbba63e0
  1. 5
      src/Module.js
  2. 6
      src/Statement.js

5
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 }`

6
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;

Loading…
Cancel
Save