magic-string
Advanced tools
Comparing version 0.5.0 to 0.5.1
# changelog | ||
## 0.5.1 | ||
* Allow bundle separator to be the empty string | ||
* Indenting is handled correctly with empty string separator | ||
## 0.5.0 | ||
@@ -4,0 +9,0 @@ |
@@ -78,3 +78,3 @@ (function (global, factory) { | ||
this.outro = options.outro || ''; | ||
this.separator = options.separator || '\n'; | ||
this.separator = options.separator !== undefined ? options.separator : '\n'; | ||
@@ -172,2 +172,4 @@ this.sources = []; | ||
Bundle.prototype.indent = function indent(indentStr) { | ||
var _this = this; | ||
if (!indentStr) { | ||
@@ -177,7 +179,19 @@ indentStr = this.getIndentString(); | ||
this.sources.forEach(function (source) { | ||
source.content.indent(indentStr, { exclude: source.indentExclusionRanges }); | ||
var trailingNewline = !this.intro || this.intro.slice(0, -1) === '\n'; | ||
this.sources.forEach(function (source, i) { | ||
var separator = source.separator !== undefined ? source.separator : _this.separator; | ||
var indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator); | ||
source.content.indent(indentStr, { | ||
exclude: source.indentExclusionRanges, | ||
indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator ) | ||
}); | ||
trailingNewline = source.content.str.slice(0, -1) === '\n'; | ||
}); | ||
this.intro = this.intro.replace(/^[^\n]/gm, indentStr + '$&'); | ||
this.intro = this.intro.replace(/^[^\n]/gm, function (match, index) { | ||
return index > 0 ? indentStr + match : match; | ||
}); | ||
this.outro = this.outro.replace(/^[^\n]/gm, indentStr + '$&'); | ||
@@ -194,6 +208,6 @@ | ||
Bundle.prototype.toString = function toString() { | ||
var _this = this; | ||
var _this2 = this; | ||
var body = this.sources.map(function (source, i) { | ||
var separator = source.separator !== undefined ? source.separator : _this.separator; | ||
var separator = source.separator !== undefined ? source.separator : _this2.separator; | ||
var str = (i > 0 ? separator : '') + source.content.toString(); | ||
@@ -204,3 +218,3 @@ | ||
return this.intro + body; | ||
return this.intro + body + this.outro; | ||
}; | ||
@@ -636,17 +650,21 @@ | ||
var indentStart = options.indentStart !== false; | ||
if (!exclusions) { | ||
while (match = pattern.exec(this.str)) { | ||
inserts.push(match.index); | ||
} | ||
this.str = this.str.replace(pattern, function (match, index) { | ||
if (!indentStart && index === 0) { | ||
return match; | ||
} | ||
this.str = this.str.replace(pattern, indentStr + '$&'); | ||
inserts.push(index); | ||
return indentStr + match; | ||
}); | ||
} else { | ||
while (match = pattern.exec(this.str)) { | ||
if (!isExcluded(match.index - 1)) { | ||
inserts.push(match.index); | ||
this.str = this.str.replace(pattern, function (match, index) { | ||
if (!indentStart && index === 0 || isExcluded(index - 1)) { | ||
return match; | ||
} | ||
} | ||
this.str = this.str.replace(pattern, function (match, index) { | ||
return isExcluded(index - 1) ? match : indentStr + match; | ||
inserts.push(index); | ||
return indentStr + match; | ||
}); | ||
@@ -653,0 +671,0 @@ } |
@@ -78,3 +78,3 @@ (function (global, factory) { | ||
this.outro = options.outro || ''; | ||
this.separator = options.separator || '\n'; | ||
this.separator = options.separator !== undefined ? options.separator : '\n'; | ||
@@ -172,2 +172,4 @@ this.sources = []; | ||
Bundle.prototype.indent = function indent(indentStr) { | ||
var _this = this; | ||
if (!indentStr) { | ||
@@ -177,7 +179,19 @@ indentStr = this.getIndentString(); | ||
this.sources.forEach(function (source) { | ||
source.content.indent(indentStr, { exclude: source.indentExclusionRanges }); | ||
var trailingNewline = !this.intro || this.intro.slice(0, -1) === '\n'; | ||
this.sources.forEach(function (source, i) { | ||
var separator = source.separator !== undefined ? source.separator : _this.separator; | ||
var indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator); | ||
source.content.indent(indentStr, { | ||
exclude: source.indentExclusionRanges, | ||
indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator ) | ||
}); | ||
trailingNewline = source.content.str.slice(0, -1) === '\n'; | ||
}); | ||
this.intro = this.intro.replace(/^[^\n]/gm, indentStr + '$&'); | ||
this.intro = this.intro.replace(/^[^\n]/gm, function (match, index) { | ||
return index > 0 ? indentStr + match : match; | ||
}); | ||
this.outro = this.outro.replace(/^[^\n]/gm, indentStr + '$&'); | ||
@@ -194,6 +208,6 @@ | ||
Bundle.prototype.toString = function toString() { | ||
var _this = this; | ||
var _this2 = this; | ||
var body = this.sources.map(function (source, i) { | ||
var separator = source.separator !== undefined ? source.separator : _this.separator; | ||
var separator = source.separator !== undefined ? source.separator : _this2.separator; | ||
var str = (i > 0 ? separator : '') + source.content.toString(); | ||
@@ -204,3 +218,3 @@ | ||
return this.intro + body; | ||
return this.intro + body + this.outro; | ||
}; | ||
@@ -552,17 +566,21 @@ | ||
var indentStart = options.indentStart !== false; | ||
if (!exclusions) { | ||
while (match = pattern.exec(this.str)) { | ||
inserts.push(match.index); | ||
} | ||
this.str = this.str.replace(pattern, function (match, index) { | ||
if (!indentStart && index === 0) { | ||
return match; | ||
} | ||
this.str = this.str.replace(pattern, indentStr + '$&'); | ||
inserts.push(index); | ||
return indentStr + match; | ||
}); | ||
} else { | ||
while (match = pattern.exec(this.str)) { | ||
if (!isExcluded(match.index - 1)) { | ||
inserts.push(match.index); | ||
this.str = this.str.replace(pattern, function (match, index) { | ||
if (!indentStart && index === 0 || isExcluded(index - 1)) { | ||
return match; | ||
} | ||
} | ||
this.str = this.str.replace(pattern, function (match, index) { | ||
return isExcluded(index - 1) ? match : indentStr + match; | ||
inserts.push(index); | ||
return indentStr + match; | ||
}); | ||
@@ -569,0 +587,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Rich Harris", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"repository": "https://github.com/rich-harris/magic-string", | ||
@@ -8,0 +8,0 @@ "main": "dist/magic-string.js", |
@@ -10,3 +10,3 @@ import MagicString from '../MagicString/index'; | ||
this.outro = options.outro || ''; | ||
this.separator = options.separator || '\n'; | ||
this.separator = options.separator !== undefined ? options.separator : '\n'; | ||
@@ -112,7 +112,19 @@ this.sources = []; | ||
this.sources.forEach( source => { | ||
source.content.indent( indentStr, { exclude: source.indentExclusionRanges }); | ||
let trailingNewline = !this.intro || ( this.intro.slice( 0, -1 ) === '\n' ); | ||
this.sources.forEach( ( source, i ) => { | ||
const separator = source.separator !== undefined ? source.separator : this.separator; | ||
const indentStart = trailingNewline || ( i > 0 && /\r?\n$/.test( separator ) ); | ||
source.content.indent( indentStr, { | ||
exclude: source.indentExclusionRanges, | ||
indentStart//: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator ) | ||
}); | ||
trailingNewline = source.content.str.slice( 0, -1 ) === '\n'; | ||
}); | ||
this.intro = this.intro.replace( /^[^\n]/gm, indentStr + '$&' ); | ||
this.intro = this.intro.replace( /^[^\n]/gm, ( match, index ) => { | ||
return index > 0 ? indentStr + match : match; | ||
}); | ||
this.outro = this.outro.replace( /^[^\n]/gm, indentStr + '$&' ); | ||
@@ -136,3 +148,3 @@ | ||
return this.intro + body; | ||
return this.intro + body + this.outro; | ||
} | ||
@@ -139,0 +151,0 @@ |
@@ -122,17 +122,21 @@ import Bundle from '../Bundle'; | ||
const indentStart = options.indentStart !== false; | ||
if ( !exclusions ) { | ||
while ( match = pattern.exec( this.str ) ) { | ||
inserts.push( match.index ); | ||
} | ||
this.str = this.str.replace( pattern, ( match, index ) => { | ||
if ( !indentStart && index === 0 ) { | ||
return match; | ||
} | ||
this.str = this.str.replace( pattern, indentStr + '$&' ); | ||
inserts.push( index ); | ||
return indentStr + match; | ||
}); | ||
} else { | ||
while ( match = pattern.exec( this.str ) ) { | ||
if ( !isExcluded( match.index - 1 ) ) { | ||
inserts.push( match.index ); | ||
this.str = this.str.replace( pattern, ( match, index ) => { | ||
if ( ( !indentStart && index === 0 ) || isExcluded( index - 1 ) ) { | ||
return match; | ||
} | ||
} | ||
this.str = this.str.replace( pattern, function ( match, index ) { | ||
return isExcluded( index - 1 ) ? match : indentStr + match; | ||
inserts.push( index ); | ||
return indentStr + match; | ||
}); | ||
@@ -139,0 +143,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157021
2077