()
| 135 | } |
| 136 | |
| 137 | generateString() { |
| 138 | this.css = '' |
| 139 | this.map = new SourceMapGenerator({ |
| 140 | file: this.outputFile(), |
| 141 | ignoreInvalidMapping: true |
| 142 | }) |
| 143 | |
| 144 | let line = 1 |
| 145 | let column = 1 |
| 146 | |
| 147 | let noSource = '<no source>' |
| 148 | let mapping = { |
| 149 | generated: { column: 0, line: 0 }, |
| 150 | original: { column: 0, line: 0 }, |
| 151 | source: '' |
| 152 | } |
| 153 | |
| 154 | let last, lines |
| 155 | this.stringify(this.root, (str, node, type) => { |
| 156 | this.css += str |
| 157 | |
| 158 | if (node && type !== 'end') { |
| 159 | mapping.generated.line = line |
| 160 | mapping.generated.column = column - 1 |
| 161 | if (node.source && node.source.start) { |
| 162 | mapping.source = this.sourcePath(node) |
| 163 | mapping.original.line = node.source.start.line |
| 164 | mapping.original.column = node.source.start.column - 1 |
| 165 | this.map.addMapping(mapping) |
| 166 | } else { |
| 167 | mapping.source = noSource |
| 168 | mapping.original.line = 1 |
| 169 | mapping.original.column = 0 |
| 170 | this.map.addMapping(mapping) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | lines = str.match(/\n/g) |
| 175 | if (lines) { |
| 176 | line += lines.length |
| 177 | last = str.lastIndexOf('\n') |
| 178 | column = str.length - last |
| 179 | } else { |
| 180 | column += str.length |
| 181 | } |
| 182 | |
| 183 | if (node && type !== 'start') { |
| 184 | let p = node.parent || { raws: {} } |
| 185 | let childless = |
| 186 | node.type === 'decl' || (node.type === 'atrule' && !node.nodes) |
| 187 | if (!childless || node !== p.last || p.raws.semicolon) { |
| 188 | if (node.source && node.source.end) { |
| 189 | mapping.source = this.sourcePath(node) |
| 190 | mapping.original.line = node.source.end.line |
| 191 | mapping.original.column = node.source.end.column - 1 |
| 192 | mapping.generated.line = line |
| 193 | mapping.generated.column = column - 2 |
| 194 | this.map.addMapping(mapping) |
no test coverage detected