(indentStr, options)
| 205 | } |
| 206 | |
| 207 | indent(indentStr, options) { |
| 208 | const pattern = /^[^\r\n]/gm; |
| 209 | |
| 210 | if (isObject(indentStr)) { |
| 211 | options = indentStr; |
| 212 | indentStr = undefined; |
| 213 | } |
| 214 | |
| 215 | if (indentStr === undefined) { |
| 216 | this._ensureindentStr(); |
| 217 | indentStr = this.indentStr || '\t'; |
| 218 | } |
| 219 | |
| 220 | if (indentStr === '') return this; // noop |
| 221 | |
| 222 | options = options || {}; |
| 223 | |
| 224 | // Process exclusion ranges |
| 225 | const isExcluded = {}; |
| 226 | |
| 227 | if (options.exclude) { |
| 228 | const exclusions = |
| 229 | typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude; |
| 230 | exclusions.forEach((exclusion) => { |
| 231 | for (let i = exclusion[0]; i < exclusion[1]; i += 1) { |
| 232 | isExcluded[i] = true; |
| 233 | } |
| 234 | }); |
| 235 | } |
| 236 | |
| 237 | let shouldIndentNextCharacter = options.indentStart !== false; |
| 238 | const replacer = (match) => { |
| 239 | if (shouldIndentNextCharacter) return `${indentStr}${match}`; |
| 240 | shouldIndentNextCharacter = true; |
| 241 | return match; |
| 242 | }; |
| 243 | |
| 244 | this.intro = this.intro.replace(pattern, replacer); |
| 245 | |
| 246 | let charIndex = 0; |
| 247 | let chunk = this.firstChunk; |
| 248 | |
| 249 | while (chunk) { |
| 250 | const end = chunk.end; |
| 251 | |
| 252 | if (chunk.edited) { |
| 253 | if (!isExcluded[charIndex]) { |
| 254 | chunk.content = chunk.content.replace(pattern, replacer); |
| 255 | |
| 256 | if (chunk.content.length) { |
| 257 | shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n'; |
| 258 | } |
| 259 | } |
| 260 | } else { |
| 261 | charIndex = chunk.start; |
| 262 | |
| 263 | while (charIndex < end) { |
| 264 | if (!isExcluded[charIndex]) { |
nothing calls this directly
no test coverage detected