(chunk, fileInfo, index, mapLines)
| 46 | } |
| 47 | |
| 48 | add(chunk, fileInfo, index, mapLines) { |
| 49 | |
| 50 | // ignore adding empty strings |
| 51 | if (!chunk) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | let lines, sourceLines, columns, sourceColumns, i; |
| 56 | |
| 57 | if (fileInfo && fileInfo.filename) { |
| 58 | let inputSource = this._contentsMap[fileInfo.filename]; |
| 59 | |
| 60 | // remove vars/banner added to the top of the file |
| 61 | if (this._contentsIgnoredCharsMap[fileInfo.filename]) { |
| 62 | // adjust the index |
| 63 | index -= this._contentsIgnoredCharsMap[fileInfo.filename]; |
| 64 | if (index < 0) { index = 0; } |
| 65 | // adjust the source |
| 66 | inputSource = inputSource.slice(this._contentsIgnoredCharsMap[fileInfo.filename]); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * ignore empty content, or failsafe |
| 71 | * if contents map is incorrect |
| 72 | */ |
| 73 | if (inputSource === undefined) { |
| 74 | this._css.push(chunk); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | inputSource = inputSource.substring(0, index); |
| 79 | sourceLines = inputSource.split('\n'); |
| 80 | sourceColumns = sourceLines[sourceLines.length - 1]; |
| 81 | } |
| 82 | |
| 83 | lines = chunk.split('\n'); |
| 84 | columns = lines[lines.length - 1]; |
| 85 | |
| 86 | if (fileInfo && fileInfo.filename) { |
| 87 | if (!mapLines) { |
| 88 | this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column}, |
| 89 | original: { line: sourceLines.length, column: sourceColumns.length}, |
| 90 | source: this.normalizeFilename(fileInfo.filename)}); |
| 91 | } else { |
| 92 | for (i = 0; i < lines.length; i++) { |
| 93 | this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + i + 1, column: i === 0 ? this._column : 0}, |
| 94 | original: { line: sourceLines.length + i, column: i === 0 ? sourceColumns.length : 0}, |
| 95 | source: this.normalizeFilename(fileInfo.filename)}); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (lines.length === 1) { |
| 101 | this._column += columns.length; |
| 102 | } else { |
| 103 | this._lineNumber += lines.length - 1; |
| 104 | this._column = columns.length; |
| 105 | } |
no test coverage detected