MCPcopy
hub / github.com/postcss/postcss / origin

Method origin

lib/input.js:205–252  ·  view source on GitHub ↗
(line, column, endLine, endColumn)

Source from the content-addressed store, hash-verified

203 }
204
205 origin(line, column, endLine, endColumn) {
206 if (!this.map) return false
207 let consumer = this.map.consumer()
208
209 let from = consumer.originalPositionFor({ column: column - 1, line })
210 if (!from.source) return false
211
212 let to
213 if (typeof endLine === 'number') {
214 to = consumer.originalPositionFor({
215 column: endColumn - 1,
216 line: endLine
217 })
218 }
219
220 let fromUrl
221
222 if (isAbsolute(from.source)) {
223 fromUrl = pathToFileURL(from.source)
224 } else {
225 fromUrl = new URL(
226 from.source,
227 this.map.consumer().sourceRoot || pathToFileURL(this.map.mapFile)
228 )
229 }
230
231 let result = {
232 column: from.column + 1,
233 endColumn: to && to.column + 1,
234 endLine: to && to.line,
235 line: from.line,
236 url: fromUrl.toString()
237 }
238
239 if (fromUrl.protocol === 'file:') {
240 if (fileURLToPath) {
241 result.file = fileURLToPath(fromUrl)
242 } else {
243 /* c8 ignore next 2 */
244 throw new Error(`file: protocol is not available in this PostCSS build`)
245 }
246 }
247
248 let source = consumer.sourceContentFor(from.source)
249 if (source) result.source = source
250
251 return result
252 }
253
254 toJSON() {
255 let json = {}

Callers 4

errorMethod · 0.95
input.test.tsFile · 0.80
map.test.tsFile · 0.80

Calls 2

consumerMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected