mirror of
https://github.com/hanzoai/postcss.git
synced 2026-09-24 17:01:56 +00:00
235 lines
20 KiB
HTML
235 lines
20 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>input.es6 - Documentation</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"></script>
|
|
<script src="scripts/prettify/lang-css.js"></script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
</head>
|
|
<body>
|
|
|
|
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
<label for="nav-trigger" class="navicon-button x">
|
|
<div class="navicon"></div>
|
|
</label>
|
|
|
|
<label for="nav-trigger" class="overlay"></label>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AtRule.html">AtRule</a><ul class='methods'><li data-type='method'><a href="AtRule.html#append">append</a></li><li data-type='method'><a href="AtRule.html#each">each</a></li><li data-type='method'><a href="AtRule.html#every">every</a></li><li data-type='method'><a href="AtRule.html#index">index</a></li><li data-type='method'><a href="AtRule.html#insertAfter">insertAfter</a></li><li data-type='method'><a href="AtRule.html#insertBefore">insertBefore</a></li><li data-type='method'><a href="AtRule.html#prepend">prepend</a></li><li data-type='method'><a href="AtRule.html#removeAll">removeAll</a></li><li data-type='method'><a href="AtRule.html#removeChild">removeChild</a></li><li data-type='method'><a href="AtRule.html#replaceValues">replaceValues</a></li><li data-type='method'><a href="AtRule.html#some">some</a></li><li data-type='method'><a href="AtRule.html#walk">walk</a></li><li data-type='method'><a href="AtRule.html#walkAtRules">walkAtRules</a></li><li data-type='method'><a href="AtRule.html#walkComments">walkComments</a></li><li data-type='method'><a href="AtRule.html#walkDecls">walkDecls</a></li><li data-type='method'><a href="AtRule.html#walkRules">walkRules</a></li></ul></li><li><a href="Comment.html">Comment</a><ul class='methods'><li data-type='method'><a href="Comment.html#after">after</a></li><li data-type='method'><a href="Comment.html#before">before</a></li><li data-type='method'><a href="Comment.html#cleanRaws">cleanRaws</a></li><li data-type='method'><a href="Comment.html#clone">clone</a></li><li data-type='method'><a href="Comment.html#cloneAfter">cloneAfter</a></li><li data-type='method'><a href="Comment.html#cloneBefore">cloneBefore</a></li><li data-type='method'><a href="Comment.html#error">error</a></li><li data-type='method'><a href="Comment.html#next">next</a></li><li data-type='method'><a href="Comment.html#prev">prev</a></li><li data-type='method'><a href="Comment.html#raw">raw</a></li><li data-type='method'><a href="Comment.html#remove">remove</a></li><li data-type='method'><a href="Comment.html#replaceWith">replaceWith</a></li><li data-type='method'><a href="Comment.html#root">root</a></li><li data-type='method'><a href="Comment.html#toString">toString</a></li><li data-type='method'><a href="Comment.html#warn">warn</a></li></ul></li><li><a href="Container.html">Container</a><ul class='methods'><li data-type='method'><a href="Container.html#after">after</a></li><li data-type='method'><a href="Container.html#append">append</a></li><li data-type='method'><a href="Container.html#before">before</a></li><li data-type='method'><a href="Container.html#cleanRaws">cleanRaws</a></li><li data-type='method'><a href="Container.html#clone">clone</a></li><li data-type='method'><a href="Container.html#cloneAfter">cloneAfter</a></li><li data-type='method'><a href="Container.html#cloneBefore">cloneBefore</a></li><li data-type='method'><a href="Container.html#each">each</a></li><li data-type='method'><a href="Container.html#error">error</a></li><li data-type='method'><a href="Container.html#every">every</a></li><li data-type='method'><a href="Container.html#index">index</a></li><li data-type='method'><a href="Container.html#insertAfter">insertAfter</a></li><li data-type='method'><a href="Container.html#insertBefore">insertBefore</a></li><li data-type='method'><a href="Container.html#next">next</a></li><li data-type='method'><a href="Container.html#prepend">prepend</a></li><li data-type='method'><a href="Container.html#prev">prev</a></li><li data-type='method'><a href="Container.html#raw">raw</a></li><li data-type='method'><a href="Container.html#remove">remove</a></li><li data-type='method'><a href="Container.html#removeAll">removeAll</a></li><li data-type='method'><a href="Container.html#removeChild">removeChild</a></li><li data-type='method'><a href="Container.html#replaceValues">replaceValues</a></li><li data-type='method'><a href="Container.html#replaceWith">replaceWith</a></li><li data-type='method'><a href="Container.html#root">root</a></li><li data-type='method'><a href="Container.html#some">some</a></li><li data-type='method'><a href="Container.html#toString">toString</a></li><li data-type='method'><a href="Container.html#walk">walk</a></li><li data-type='method'><a href="Container.html#walkAtRules">walkAtRules</a></li><li data-type='method'><a href="Container.html#walkComments">walkComments</a></li><li data-type='method'><a href="Container.html#walkDecls">walkDecls</a></li><li data-type='method'><a href="Container.html#walkRules">walkRules</a></li><li data-type='method'><a href="Container.html#warn">warn</a></li></ul></li><li><a href="CssSyntaxError.html">CssSyntaxError</a><ul class='methods'><li data-type='method'><a href="CssSyntaxError.html#showSourceCode">showSourceCode</a></li><li data-type='method'><a href="CssSyntaxError.html#toString">toString</a></li></ul></li><li><a href="Declaration.html">Declaration</a><ul class='methods'><li data-type='method'><a href="Declaration.html#after">after</a></li><li data-type='method'><a href="Declaration.html#before">before</a></li><li data-type='method'><a href="Declaration.html#cleanRaws">cleanRaws</a></li><li data-type='method'><a href="Declaration.html#clone">clone</a></li><li data-type='method'><a href="Declaration.html#cloneAfter">cloneAfter</a></li><li data-type='method'><a href="Declaration.html#cloneBefore">cloneBefore</a></li><li data-type='method'><a href="Declaration.html#error">error</a></li><li data-type='method'><a href="Declaration.html#next">next</a></li><li data-type='method'><a href="Declaration.html#prev">prev</a></li><li data-type='method'><a href="Declaration.html#raw">raw</a></li><li data-type='method'><a href="Declaration.html#remove">remove</a></li><li data-type='method'><a href="Declaration.html#replaceWith">replaceWith</a></li><li data-type='method'><a href="Declaration.html#root">root</a></li><li data-type='method'><a href="Declaration.html#toString">toString</a></li><li data-type='method'><a href="Declaration.html#warn">warn</a></li></ul></li><li><a href="Input.html">Input</a><ul class='methods'><li data-type='method'><a href="Input.html#origin">origin</a></li></ul></li><li><a href="LazyResult.html">LazyResult</a><ul class='methods'><li data-type='method'><a href="LazyResult.html#catch">catch</a></li><li data-type='method'><a href="LazyResult.html#finally">finally</a></li><li data-type='method'><a href="LazyResult.html#then">then</a></li><li data-type='method'><a href="LazyResult.html#toString">toString</a></li><li data-type='method'><a href="LazyResult.html#warnings">warnings</a></li></ul></li><li><a href="Node.html">Node</a><ul class='methods'><li data-type='method'><a href="Node.html#after">after</a></li><li data-type='method'><a href="Node.html#before">before</a></li><li data-type='method'><a href="Node.html#cleanRaws">cleanRaws</a></li><li data-type='method'><a href="Node.html#clone">clone</a></li><li data-type='method'><a href="Node.html#cloneAfter">cloneAfter</a></li><li data-type='method'><a href="Node.html#cloneBefore">cloneBefore</a></li><li data-type='method'><a href="Node.html#error">error</a></li><li data-type='method'><a href="Node.html#next">next</a></li><li data-type='method'><a href="Node.html#prev">prev</a></li><li data-type='method'><a href="Node.html#raw">raw</a></li><li data-type='method'><a href="Node.html#remove">remove</a></li><li data-type='method'><a href="Node.html#replaceWith">replaceWith</a></li><li data-type='method'><a href="Node.html#root">root</a></li><li data-type='method'><a href="Node.html#toString">toString</a></li><li data-type='method'><a href="Node.html#warn">warn</a></li></ul></li><li><a href="PreviousMap.html">PreviousMap</a><ul class='methods'><li data-type='method'><a href="PreviousMap.html#consumer">consumer</a></li><li data-type='method'><a href="PreviousMap.html#withContent">withContent</a></li></ul></li><li><a href="Processor.html">Processor</a><ul class='methods'><li data-type='method'><a href="Processor.html#process">process</a></li><li data-type='method'><a href="Processor.html#use">use</a></li></ul></li><li><a href="Result.html">Result</a><ul class='methods'><li data-type='method'><a href="Result.html#toString">toString</a></li><li data-type='method'><a href="Result.html#warn">warn</a></li><li data-type='method'><a href="Result.html#warnings">warnings</a></li></ul></li><li><a href="Root.html">Root</a><ul class='methods'><li data-type='method'><a href="Root.html#after">after</a></li><li data-type='method'><a href="Root.html#append">append</a></li><li data-type='method'><a href="Root.html#before">before</a></li><li data-type='method'><a href="Root.html#cleanRaws">cleanRaws</a></li><li data-type='method'><a href="Root.html#clone">clone</a></li><li data-type='method'><a href="Root.html#cloneAfter">cloneAfter</a></li><li data-type='method'><a href="Root.html#cloneBefore">cloneBefore</a></li><li data-type='method'><a href="Root.html#each">each</a></li><li data-type='method'><a href="Root.html#error">error</a></li><li data-type='method'><a href="Root.html#every">every</a></li><li data-type='method'><a href="Root.html#index">index</a></li><li data-type='method'><a href="Root.html#insertAfter">insertAfter</a></li><li data-type='method'><a href="Root.html#insertBefore">insertBefore</a></li><li data-type='method'><a href="Root.html#next">next</a></li><li data-type='method'><a href="Root.html#prepend">prepend</a></li><li data-type='method'><a href="Root.html#prev">prev</a></li><li data-type='method'><a href="Root.html#raw">raw</a></li><li data-type='method'><a href="Root.html#remove">remove</a></li><li data-type='method'><a href="Root.html#removeAll">removeAll</a></li><li data-type='method'><a href="Root.html#removeChild">removeChild</a></li><li data-type='method'><a href="Root.html#replaceValues">replaceValues</a></li><li data-type='method'><a href="Root.html#replaceWith">replaceWith</a></li><li data-type='method'><a href="Root.html#root">root</a></li><li data-type='method'><a href="Root.html#some">some</a></li><li data-type='method'><a href="Root.html#toResult">toResult</a></li><li data-type='method'><a href="Root.html#toString">toString</a></li><li data-type='method'><a href="Root.html#walk">walk</a></li><li data-type='method'><a href="Root.html#walkAtRules">walkAtRules</a></li><li data-type='method'><a href="Root.html#walkComments">walkComments</a></li><li data-type='method'><a href="Root.html#walkDecls">walkDecls</a></li><li data-type='method'><a href="Root.html#walkRules">walkRules</a></li><li data-type='method'><a href="Root.html#warn">warn</a></li></ul></li><li><a href="Rule.html">Rule</a><ul class='methods'><li data-type='method'><a href="Rule.html#after">after</a></li><li data-type='method'><a href="Rule.html#append">append</a></li><li data-type='method'><a href="Rule.html#before">before</a></li><li data-type='method'><a href="Rule.html#cleanRaws">cleanRaws</a></li><li data-type='method'><a href="Rule.html#clone">clone</a></li><li data-type='method'><a href="Rule.html#cloneAfter">cloneAfter</a></li><li data-type='method'><a href="Rule.html#cloneBefore">cloneBefore</a></li><li data-type='method'><a href="Rule.html#each">each</a></li><li data-type='method'><a href="Rule.html#error">error</a></li><li data-type='method'><a href="Rule.html#every">every</a></li><li data-type='method'><a href="Rule.html#index">index</a></li><li data-type='method'><a href="Rule.html#insertAfter">insertAfter</a></li><li data-type='method'><a href="Rule.html#insertBefore">insertBefore</a></li><li data-type='method'><a href="Rule.html#next">next</a></li><li data-type='method'><a href="Rule.html#prepend">prepend</a></li><li data-type='method'><a href="Rule.html#prev">prev</a></li><li data-type='method'><a href="Rule.html#raw">raw</a></li><li data-type='method'><a href="Rule.html#remove">remove</a></li><li data-type='method'><a href="Rule.html#removeAll">removeAll</a></li><li data-type='method'><a href="Rule.html#removeChild">removeChild</a></li><li data-type='method'><a href="Rule.html#replaceValues">replaceValues</a></li><li data-type='method'><a href="Rule.html#replaceWith">replaceWith</a></li><li data-type='method'><a href="Rule.html#root">root</a></li><li data-type='method'><a href="Rule.html#some">some</a></li><li data-type='method'><a href="Rule.html#toString">toString</a></li><li data-type='method'><a href="Rule.html#walk">walk</a></li><li data-type='method'><a href="Rule.html#walkAtRules">walkAtRules</a></li><li data-type='method'><a href="Rule.html#walkComments">walkComments</a></li><li data-type='method'><a href="Rule.html#walkDecls">walkDecls</a></li><li data-type='method'><a href="Rule.html#walkRules">walkRules</a></li><li data-type='method'><a href="Rule.html#warn">warn</a></li></ul></li><li><a href="Warning.html">Warning</a><ul class='methods'><li data-type='method'><a href="Warning.html#toString">toString</a></li></ul></li></ul><h3>Namespaces</h3><ul><li><a href="list.html">list</a><ul class='methods'><li data-type='method'><a href="list.html#.comma">comma</a></li><li data-type='method'><a href="list.html#.space">space</a></li></ul></li><li><a href="postcss.html">postcss</a><ul class='methods'><li data-type='method'><a href="postcss.html#.atRule">atRule</a></li><li data-type='method'><a href="postcss.html#.comment">comment</a></li><li data-type='method'><a href="postcss.html#.decl">decl</a></li><li data-type='method'><a href="postcss.html#.parse">parse</a></li><li data-type='method'><a href="postcss.html#.plugin">plugin</a></li><li data-type='method'><a href="postcss.html#.root">root</a></li><li data-type='method'><a href="postcss.html#.rule">rule</a></li><li data-type='method'><a href="postcss.html#.stringify">stringify</a></li></ul></li><li><a href="vendor.html">vendor</a><ul class='methods'><li data-type='method'><a href="vendor.html#.prefix">prefix</a></li><li data-type='method'><a href="vendor.html#.unprefixed">unprefixed</a></li></ul></li></ul><h3><a href="global.html">Global</a></h3>
|
|
</nav>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">input.es6</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>import CssSyntaxError from './css-syntax-error'
|
|
import PreviousMap from './previous-map'
|
|
|
|
import path from 'path'
|
|
|
|
let sequence = 0
|
|
|
|
/**
|
|
* Represents the source CSS.
|
|
*
|
|
* @example
|
|
* const root = postcss.parse(css, { from: file })
|
|
* const input = root.source.input
|
|
*/
|
|
class Input {
|
|
/**
|
|
* @param {string} css Input CSS source.
|
|
* @param {object} [opts] {@link Processor#process} options.
|
|
*/
|
|
constructor (css, opts = { }) {
|
|
if (css === null || (typeof css === 'object' && !css.toString)) {
|
|
throw new Error(`PostCSS received ${ css } instead of CSS string`)
|
|
}
|
|
|
|
/**
|
|
* Input CSS source
|
|
*
|
|
* @type {string}
|
|
*
|
|
* @example
|
|
* const input = postcss.parse('a{}', { from: file }).input
|
|
* input.css //=> "a{}"
|
|
*/
|
|
this.css = css.toString()
|
|
|
|
if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
|
|
this.css = this.css.slice(1)
|
|
}
|
|
|
|
if (opts.from) {
|
|
if (/^\w+:\/\//.test(opts.from)) {
|
|
/**
|
|
* The absolute path to the CSS source file defined
|
|
* with the `from` option.
|
|
*
|
|
* @type {string}
|
|
*
|
|
* @example
|
|
* const root = postcss.parse(css, { from: 'a.css' })
|
|
* root.source.input.file //=> '/home/ai/a.css'
|
|
*/
|
|
this.file = opts.from
|
|
} else {
|
|
this.file = path.resolve(opts.from)
|
|
}
|
|
}
|
|
|
|
const map = new PreviousMap(this.css, opts)
|
|
if (map.text) {
|
|
/**
|
|
* The input source map passed from a compilation step before PostCSS
|
|
* (for example, from Sass compiler).
|
|
*
|
|
* @type {PreviousMap}
|
|
*
|
|
* @example
|
|
* root.source.input.map.consumer().sources //=> ['a.sass']
|
|
*/
|
|
this.map = map
|
|
const file = map.consumer().file
|
|
if (!this.file && file) this.file = this.mapResolve(file)
|
|
}
|
|
|
|
if (!this.file) {
|
|
sequence += 1
|
|
/**
|
|
* The unique ID of the CSS source. It will be created if `from` option
|
|
* is not provided (because PostCSS does not know the file path).
|
|
*
|
|
* @type {string}
|
|
*
|
|
* @example
|
|
* const root = postcss.parse(css)
|
|
* root.source.input.file //=> undefined
|
|
* root.source.input.id //=> "<input css 1>"
|
|
*/
|
|
this.id = '<input css ' + sequence + '>'
|
|
}
|
|
if (this.map) this.map.file = this.from
|
|
}
|
|
|
|
error (message, line, column, opts = { }) {
|
|
let result
|
|
const origin = this.origin(line, column)
|
|
if (origin) {
|
|
result = new CssSyntaxError(
|
|
message, origin.line, origin.column,
|
|
origin.source, origin.file, opts.plugin
|
|
)
|
|
} else {
|
|
result = new CssSyntaxError(
|
|
message, line, column, this.css, this.file, opts.plugin)
|
|
}
|
|
|
|
result.input = { line, column, source: this.css }
|
|
if (this.file) result.input.file = this.file
|
|
|
|
return result
|
|
}
|
|
|
|
/**
|
|
* Reads the input source map and returns a symbol position
|
|
* in the input source (e.g., in a Sass file that was compiled
|
|
* to CSS before being passed to PostCSS).
|
|
*
|
|
* @param {number} line Line in input CSS.
|
|
* @param {number} column Column in input CSS.
|
|
*
|
|
* @return {filePosition} Position in input source.
|
|
*
|
|
* @example
|
|
* root.source.input.origin(1, 1) //=> { file: 'a.css', line: 3, column: 1 }
|
|
*/
|
|
origin (line, column) {
|
|
if (!this.map) return false
|
|
const consumer = this.map.consumer()
|
|
|
|
const from = consumer.originalPositionFor({ line, column })
|
|
if (!from.source) return false
|
|
|
|
const result = {
|
|
file: this.mapResolve(from.source),
|
|
line: from.line,
|
|
column: from.column
|
|
}
|
|
|
|
const source = consumer.sourceContentFor(from.source)
|
|
if (source) result.source = source
|
|
|
|
return result
|
|
}
|
|
|
|
mapResolve (file) {
|
|
if (/^\w+:\/\//.test(file)) {
|
|
return file
|
|
} else {
|
|
return path.resolve(this.map.consumer().sourceRoot || '.', file)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The CSS source identifier. Contains {@link Input#file} if the user
|
|
* set the `from` option, or {@link Input#id} if they did not.
|
|
*
|
|
* @type {string}
|
|
*
|
|
* @example
|
|
* const root = postcss.parse(css, { from: 'a.css' })
|
|
* root.source.input.from //=> "/home/ai/a.css"
|
|
*
|
|
* const root = postcss.parse(css)
|
|
* root.source.input.from //=> "<input css 1>"
|
|
*/
|
|
get from () {
|
|
return this.file || this.id
|
|
}
|
|
}
|
|
|
|
export default Input
|
|
|
|
/**
|
|
* @typedef {object} filePosition
|
|
* @property {string} file Path to file.
|
|
* @property {number} line Source line in file.
|
|
* @property {number} column Source column in file.
|
|
*/
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
</footer>
|
|
|
|
<script>prettyPrint();</script>
|
|
<script src="scripts/linenumber.js"></script>
|
|
</body>
|
|
</html>
|