PHP 7.4.33
Preview: css-syntax-error.js Size: 2.46 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/next/node_modules/postcss/lib/css-syntax-error.js
'use strict'

let pico = require('picocolors')

let terminalHighlight = require('./terminal-highlight')

class CssSyntaxError extends Error {
  constructor(message, line, column, source, file, plugin) {
    super(message)
    this.name = 'CssSyntaxError'
    this.reason = message

    if (file) {
      this.file = file
    }
    if (source) {
      this.source = source
    }
    if (plugin) {
      this.plugin = plugin
    }
    if (typeof line !== 'undefined' && typeof column !== 'undefined') {
      if (typeof line === 'number') {
        this.line = line
        this.column = column
      } else {
        this.line = line.line
        this.column = line.column
        this.endLine = column.line
        this.endColumn = column.column
      }
    }

    this.setMessage()

    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, CssSyntaxError)
    }
  }

  setMessage() {
    this.message = this.plugin ? this.plugin + ': ' : ''
    this.message += this.file ? this.file : '<css input>'
    if (typeof this.line !== 'undefined') {
      this.message += ':' + this.line + ':' + this.column
    }
    this.message += ': ' + this.reason
  }

  showSourceCode(color) {
    if (!this.source) return ''

    let css = this.source
    if (color == null) color = pico.isColorSupported
    if (terminalHighlight) {
      if (color) css = terminalHighlight(css)
    }

    let lines = css.split(/\r?\n/)
    let start = Math.max(this.line - 3, 0)
    let end = Math.min(this.line + 2, lines.length)

    let maxWidth = String(end).length

    let mark, aside
    if (color) {
      let { bold, gray, red } = pico.createColors(true)
      mark = text => bold(red(text))
      aside = text => gray(text)
    } else {
      mark = aside = str => str
    }

    return lines
      .slice(start, end)
      .map((line, index) => {
        let number = start + 1 + index
        let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | '
        if (number === this.line) {
          let spacing =
            aside(gutter.replace(/\d/g, ' ')) +
            line.slice(0, this.column - 1).replace(/[^\t]/g, ' ')
          return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^')
        }
        return ' ' + aside(gutter) + line
      })
      .join('\n')
  }

  toString() {
    let code = this.showSourceCode()
    if (code) {
      code = '\n\n' + code + '\n'
    }
    return this.name + ': ' + this.message + code
  }
}

module.exports = CssSyntaxError
CssSyntaxError.default = CssSyntaxError

Directory Contents

Dirs: 0 × Files: 52
Name Size Perms Modified Actions
2.75 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
471 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.69 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
203 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
12.85 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
10.26 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
6.35 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.46 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
3.70 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
495 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.90 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
654 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
162 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.47 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
4.32 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
6.04 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
4.89 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
13.24 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.42 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.20 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
9.35 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.54 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.49 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
13.53 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
8.53 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
135 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.12 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
14.41 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.03 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
10.98 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.83 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
980 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.78 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
3.83 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
3.33 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.77 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
4.31 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
745 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.23 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.21 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.62 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
569 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.38 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
8.03 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
165 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
213 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
91 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.37 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
6.38 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
256 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.92 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
739 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).