full site update
This commit is contained in:
58
node_modules/postcss/lib/input.js
generated
vendored
58
node_modules/postcss/lib/input.js
generated
vendored
@@ -9,11 +9,26 @@ let CssSyntaxError = require('./css-syntax-error')
|
||||
let PreviousMap = require('./previous-map')
|
||||
let terminalHighlight = require('./terminal-highlight')
|
||||
|
||||
let fromOffsetCache = Symbol('fromOffsetCache')
|
||||
let lineToIndexCache = Symbol('lineToIndexCache')
|
||||
|
||||
let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
|
||||
let pathAvailable = Boolean(resolve && isAbsolute)
|
||||
|
||||
function getLineToIndex(input) {
|
||||
if (input[lineToIndexCache]) return input[lineToIndexCache]
|
||||
let lines = input.css.split('\n')
|
||||
let lineToIndex = new Array(lines.length)
|
||||
let prevIndex = 0
|
||||
|
||||
for (let i = 0, l = lines.length; i < l; i++) {
|
||||
lineToIndex[i] = prevIndex
|
||||
prevIndex += lines[i].length + 1
|
||||
}
|
||||
|
||||
input[lineToIndexCache] = lineToIndex
|
||||
return lineToIndex
|
||||
}
|
||||
|
||||
class Input {
|
||||
get from() {
|
||||
return this.file || this.id
|
||||
@@ -68,31 +83,38 @@ class Input {
|
||||
}
|
||||
|
||||
error(message, line, column, opts = {}) {
|
||||
let endColumn, endLine, result
|
||||
let endColumn, endLine, endOffset, offset, result
|
||||
|
||||
if (line && typeof line === 'object') {
|
||||
let start = line
|
||||
let end = column
|
||||
if (typeof start.offset === 'number') {
|
||||
let pos = this.fromOffset(start.offset)
|
||||
offset = start.offset
|
||||
let pos = this.fromOffset(offset)
|
||||
line = pos.line
|
||||
column = pos.col
|
||||
} else {
|
||||
line = start.line
|
||||
column = start.column
|
||||
offset = this.fromLineAndColumn(line, column)
|
||||
}
|
||||
if (typeof end.offset === 'number') {
|
||||
let pos = this.fromOffset(end.offset)
|
||||
endOffset = end.offset
|
||||
let pos = this.fromOffset(endOffset)
|
||||
endLine = pos.line
|
||||
endColumn = pos.col
|
||||
} else {
|
||||
endLine = end.line
|
||||
endColumn = end.column
|
||||
endOffset = this.fromLineAndColumn(end.line, end.column)
|
||||
}
|
||||
} else if (!column) {
|
||||
let pos = this.fromOffset(line)
|
||||
offset = line
|
||||
let pos = this.fromOffset(offset)
|
||||
line = pos.line
|
||||
column = pos.col
|
||||
} else {
|
||||
offset = this.fromLineAndColumn(line, column)
|
||||
}
|
||||
|
||||
let origin = this.origin(line, column, endLine, endColumn)
|
||||
@@ -120,7 +142,7 @@ class Input {
|
||||
)
|
||||
}
|
||||
|
||||
result.input = { column, endColumn, endLine, line, source: this.css }
|
||||
result.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css }
|
||||
if (this.file) {
|
||||
if (pathToFileURL) {
|
||||
result.input.url = pathToFileURL(this.file).toString()
|
||||
@@ -131,23 +153,15 @@ class Input {
|
||||
return result
|
||||
}
|
||||
|
||||
fromLineAndColumn(line, column) {
|
||||
let lineToIndex = getLineToIndex(this)
|
||||
let index = lineToIndex[line - 1]
|
||||
return index + column - 1
|
||||
}
|
||||
|
||||
fromOffset(offset) {
|
||||
let lastLine, lineToIndex
|
||||
if (!this[fromOffsetCache]) {
|
||||
let lines = this.css.split('\n')
|
||||
lineToIndex = new Array(lines.length)
|
||||
let prevIndex = 0
|
||||
|
||||
for (let i = 0, l = lines.length; i < l; i++) {
|
||||
lineToIndex[i] = prevIndex
|
||||
prevIndex += lines[i].length + 1
|
||||
}
|
||||
|
||||
this[fromOffsetCache] = lineToIndex
|
||||
} else {
|
||||
lineToIndex = this[fromOffsetCache]
|
||||
}
|
||||
lastLine = lineToIndex[lineToIndex.length - 1]
|
||||
let lineToIndex = getLineToIndex(this)
|
||||
let lastLine = lineToIndex[lineToIndex.length - 1]
|
||||
|
||||
let min = 0
|
||||
if (offset >= lastLine) {
|
||||
|
Reference in New Issue
Block a user