Comparing version 8.4.27 to 8.4.30
@@ -129,11 +129,2 @@ import AtRule from './at-rule.js' | ||
/** | ||
* The container’s first child. | ||
* | ||
* ```js | ||
* rule.first === rules.nodes[0] | ||
* ``` | ||
*/ | ||
get first(): Child | undefined | ||
/** | ||
* Returns a `child`’s index within the `Container#nodes` array. | ||
@@ -149,2 +140,3 @@ * | ||
index(child: Child | number): number | ||
/** | ||
@@ -161,21 +153,3 @@ * Insert new node after old node within the container. | ||
): this | ||
/** | ||
* Traverses the container’s descendant nodes, calling callback | ||
* for each comment node. | ||
* | ||
* Like `Container#each`, this method is safe | ||
* to use if you are mutating arrays during iteration. | ||
* | ||
* ```js | ||
* root.walkComments(comment => { | ||
* comment.remove() | ||
* }) | ||
* ``` | ||
* | ||
* @param callback Iterator receives each node and index. | ||
* @return Returns `false` if iteration was broke. | ||
*/ | ||
/** | ||
* Insert new node before old node within the container. | ||
@@ -195,10 +169,19 @@ * | ||
): this | ||
/** | ||
* The container’s last child. | ||
* Traverses the container’s descendant nodes, calling callback | ||
* for each comment node. | ||
* | ||
* Like `Container#each`, this method is safe | ||
* to use if you are mutating arrays during iteration. | ||
* | ||
* ```js | ||
* rule.last === rule.nodes[rule.nodes.length - 1] | ||
* root.walkComments(comment => { | ||
* comment.remove() | ||
* }) | ||
* ``` | ||
* | ||
* @param callback Iterator receives each node and index. | ||
* @return Returns `false` if iteration was broke. | ||
*/ | ||
get last(): Child | undefined | ||
@@ -228,3 +211,2 @@ /** | ||
): this | ||
/** | ||
@@ -342,2 +324,3 @@ * Add child to the end of the node. | ||
): false | undefined | ||
/** | ||
@@ -380,3 +363,2 @@ * Traverses the container’s descendant nodes, calling callback | ||
): false | undefined | ||
walkComments( | ||
@@ -423,5 +405,7 @@ callback: (comment: Comment, indexed: number) => false | void | ||
): false | undefined | ||
walkDecls( | ||
callback: (decl: Declaration, index: number) => false | void | ||
): false | undefined | ||
/** | ||
@@ -456,2 +440,18 @@ * Traverses the container’s descendant nodes, calling callback | ||
): false | undefined | ||
/** | ||
* The container’s first child. | ||
* | ||
* ```js | ||
* rule.first === rules.nodes[0] | ||
* ``` | ||
*/ | ||
get first(): Child | undefined | ||
/** | ||
* The container’s last child. | ||
* | ||
* ```js | ||
* rule.last === rule.nodes[rule.nodes.length - 1] | ||
* ``` | ||
*/ | ||
get last(): Child | undefined | ||
} | ||
@@ -458,0 +458,0 @@ |
@@ -67,7 +67,2 @@ 'use strict' | ||
get first() { | ||
if (!this.proxyOf.nodes) return undefined | ||
return this.proxyOf.nodes[0] | ||
} | ||
getIterator() { | ||
@@ -179,7 +174,2 @@ if (!this.lastEach) this.lastEach = 0 | ||
get last() { | ||
if (!this.proxyOf.nodes) return undefined | ||
return this.proxyOf.nodes[this.proxyOf.nodes.length - 1] | ||
} | ||
normalize(nodes, sample) { | ||
@@ -398,2 +388,12 @@ if (typeof nodes === 'string') { | ||
} | ||
get first() { | ||
if (!this.proxyOf.nodes) return undefined | ||
return this.proxyOf.nodes[0] | ||
} | ||
get last() { | ||
if (!this.proxyOf.nodes) return undefined | ||
return this.proxyOf.nodes[this.proxyOf.nodes.length - 1] | ||
} | ||
} | ||
@@ -400,0 +400,0 @@ |
@@ -147,15 +147,2 @@ import { CssSyntaxError, ProcessOptions } from './postcss.js' | ||
/** | ||
* The CSS source identifier. Contains `Input#file` if the user | ||
* set the `from` option, or `Input#id` if they did not. | ||
* | ||
* ```js | ||
* 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(): string | ||
/** | ||
* Converts source offset to line and column. | ||
@@ -191,2 +178,15 @@ * | ||
): false | Input.FilePosition | ||
/** | ||
* The CSS source identifier. Contains `Input#file` if the user | ||
* set the `from` option, or `Input#id` if they did not. | ||
* | ||
* ```js | ||
* 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(): string | ||
} | ||
@@ -193,0 +193,0 @@ |
@@ -127,6 +127,2 @@ 'use strict' | ||
get from() { | ||
return this.file || this.id | ||
} | ||
fromOffset(offset) { | ||
@@ -242,2 +238,6 @@ let lastLine, lineToIndex | ||
} | ||
get from() { | ||
return this.file || this.id | ||
} | ||
} | ||
@@ -244,0 +244,0 @@ |
@@ -0,1 +1,2 @@ | ||
import Document from './document.js' | ||
import { SourceMap } from './postcss.js' | ||
@@ -21,3 +22,5 @@ import Processor from './processor.js' | ||
*/ | ||
declare class LazyResult_ implements PromiseLike<Result> { | ||
declare class LazyResult_<RootNode = Document | Root> | ||
implements PromiseLike<Result<RootNode>> | ||
{ | ||
/** | ||
@@ -37,3 +40,3 @@ * Processes input CSS through synchronous and asynchronous plugins | ||
*/ | ||
catch: Promise<Result>['catch'] | ||
catch: Promise<Result<RootNode>>['catch'] | ||
@@ -52,3 +55,3 @@ /** | ||
*/ | ||
finally: Promise<Result>['finally'] | ||
finally: Promise<Result<RootNode>>['finally'] | ||
@@ -68,3 +71,3 @@ /** | ||
*/ | ||
then: Promise<Result>['then'] | ||
then: Promise<Result<RootNode>>['then'] | ||
@@ -83,5 +86,31 @@ /** | ||
*/ | ||
async(): Promise<Result> | ||
async(): Promise<Result<RootNode>> | ||
/** | ||
* Run plugin in sync way and return `Result`. | ||
* | ||
* @return Result with output content. | ||
*/ | ||
sync(): Result<RootNode> | ||
/** | ||
* Alias for the `LazyResult#css` property. | ||
* | ||
* ```js | ||
* lazy + '' === lazy.css | ||
* ``` | ||
* | ||
* @return Output CSS. | ||
*/ | ||
toString(): string | ||
/** | ||
* Processes input CSS through synchronous plugins | ||
* and calls `Result#warnings`. | ||
* | ||
* @return Warnings from plugins. | ||
*/ | ||
warnings(): Warning[] | ||
/** | ||
* An alias for the `css` property. Use it with syntaxes | ||
@@ -153,3 +182,3 @@ * that generate non-CSS output. | ||
*/ | ||
get root(): Root | ||
get root(): RootNode | ||
@@ -161,32 +190,8 @@ /** | ||
get [Symbol.toStringTag](): string | ||
/** | ||
* Run plugin in sync way and return `Result`. | ||
* | ||
* @return Result with output content. | ||
*/ | ||
sync(): Result | ||
/** | ||
* Alias for the `LazyResult#css` property. | ||
* | ||
* ```js | ||
* lazy + '' === lazy.css | ||
* ``` | ||
* | ||
* @return Output CSS. | ||
*/ | ||
toString(): string | ||
/** | ||
* Processes input CSS through synchronous plugins | ||
* and calls `Result#warnings`. | ||
* | ||
* @return Warnings from plugins. | ||
*/ | ||
warnings(): Warning[] | ||
} | ||
declare class LazyResult extends LazyResult_ {} | ||
declare class LazyResult< | ||
RootNode = Document | Root | ||
> extends LazyResult_<RootNode> {} | ||
export = LazyResult |
@@ -169,10 +169,2 @@ 'use strict' | ||
get content() { | ||
return this.stringify().content | ||
} | ||
get css() { | ||
return this.stringify().css | ||
} | ||
finally(onFinally) { | ||
@@ -225,14 +217,2 @@ return this.async().then(onFinally, onFinally) | ||
get map() { | ||
return this.stringify().map | ||
} | ||
get messages() { | ||
return this.sync().messages | ||
} | ||
get opts() { | ||
return this.result.opts | ||
} | ||
prepareVisitors() { | ||
@@ -276,10 +256,2 @@ this.listeners = {} | ||
get processor() { | ||
return this.result.processor | ||
} | ||
get root() { | ||
return this.sync().root | ||
} | ||
async runAsync() { | ||
@@ -388,6 +360,2 @@ this.plugin = 0 | ||
get [Symbol.toStringTag]() { | ||
return 'LazyResult' | ||
} | ||
sync() { | ||
@@ -544,2 +512,34 @@ if (this.error) throw this.error | ||
} | ||
get content() { | ||
return this.stringify().content | ||
} | ||
get css() { | ||
return this.stringify().css | ||
} | ||
get map() { | ||
return this.stringify().map | ||
} | ||
get messages() { | ||
return this.sync().messages | ||
} | ||
get opts() { | ||
return this.result.opts | ||
} | ||
get processor() { | ||
return this.result.processor | ||
} | ||
get root() { | ||
return this.sync().root | ||
} | ||
get [Symbol.toStringTag]() { | ||
return 'LazyResult' | ||
} | ||
} | ||
@@ -546,0 +546,0 @@ |
@@ -20,2 +20,6 @@ 'use strict' | ||
this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute | ||
this.memoizedFileURLs = new Map() | ||
this.memoizedPaths = new Map() | ||
this.memoizedURLs = new Map() | ||
} | ||
@@ -245,5 +249,7 @@ | ||
path(file) { | ||
if (file.indexOf('<') === 0) return file | ||
if (this.mapOpts.absolute) return file | ||
if (file.charCodeAt(0) === 60 /* `<` */) return file | ||
if (/^\w+:\/\//.test(file)) return file | ||
if (this.mapOpts.absolute) return file | ||
let cached = this.memoizedPaths.get(file) | ||
if (cached) return cached | ||
@@ -256,4 +262,6 @@ let from = this.opts.to ? dirname(this.opts.to) : '.' | ||
file = relative(from, file) | ||
return file | ||
let path = relative(from, file) | ||
this.memoizedPaths.set(file, path) | ||
return path | ||
} | ||
@@ -324,4 +332,10 @@ | ||
toFileUrl(path) { | ||
let cached = this.memoizedFileURLs.get(path) | ||
if (cached) return cached | ||
if (pathToFileURL) { | ||
return pathToFileURL(path).toString() | ||
let fileURL = pathToFileURL(path).toString() | ||
this.memoizedFileURLs.set(path, fileURL) | ||
return fileURL | ||
} else { | ||
@@ -335,6 +349,13 @@ throw new Error( | ||
toUrl(path) { | ||
let cached = this.memoizedURLs.get(path) | ||
if (cached) return cached | ||
if (sep === '\\') { | ||
path = path.replace(/\\/g, '/') | ||
} | ||
return encodeURI(path).replace(/[#?]/g, encodeURIComponent) | ||
let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent) | ||
this.memoizedURLs.set(path, url) | ||
return url | ||
} | ||
@@ -341,0 +362,0 @@ } |
@@ -25,8 +25,11 @@ import LazyResult from './lazy-result.js' | ||
*/ | ||
declare class NoWorkResult_ implements LazyResult { | ||
catch: Promise<Result>['catch'] | ||
finally: Promise<Result>['finally'] | ||
then: Promise<Result>['then'] | ||
declare class NoWorkResult_ implements LazyResult<Root> { | ||
catch: Promise<Result<Root>>['catch'] | ||
finally: Promise<Result<Root>>['finally'] | ||
then: Promise<Result<Root>>['then'] | ||
constructor(processor: Processor, css: string, opts: ResultOptions) | ||
async(): Promise<Result> | ||
async(): Promise<Result<Root>> | ||
sync(): Result<Root> | ||
toString(): string | ||
warnings(): Warning[] | ||
get content(): string | ||
@@ -40,5 +43,2 @@ get css(): string | ||
get [Symbol.toStringTag](): string | ||
sync(): Result | ||
toString(): string | ||
warnings(): Warning[] | ||
} | ||
@@ -45,0 +45,0 @@ |
@@ -52,2 +52,33 @@ 'use strict' | ||
finally(onFinally) { | ||
return this.async().then(onFinally, onFinally) | ||
} | ||
sync() { | ||
if (this.error) throw this.error | ||
return this.result | ||
} | ||
then(onFulfilled, onRejected) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!('from' in this._opts)) { | ||
warnOnce( | ||
'Without `from` option PostCSS could generate wrong source map ' + | ||
'and will not find Browserslist config. Set it to CSS file path ' + | ||
'or to `undefined` to prevent this warning.' | ||
) | ||
} | ||
} | ||
return this.async().then(onFulfilled, onRejected) | ||
} | ||
toString() { | ||
return this._css | ||
} | ||
warnings() { | ||
return [] | ||
} | ||
get content() { | ||
@@ -61,6 +92,2 @@ return this.result.css | ||
finally(onFinally) { | ||
return this.async().then(onFinally, onFinally) | ||
} | ||
get map() { | ||
@@ -107,29 +134,2 @@ return this.result.map | ||
} | ||
sync() { | ||
if (this.error) throw this.error | ||
return this.result | ||
} | ||
then(onFulfilled, onRejected) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!('from' in this._opts)) { | ||
warnOnce( | ||
'Without `from` option PostCSS could generate wrong source map ' + | ||
'and will not find Browserslist config. Set it to CSS file path ' + | ||
'or to `undefined` to prevent this warning.' | ||
) | ||
} | ||
} | ||
return this.async().then(onFulfilled, onRejected) | ||
} | ||
toString() { | ||
return this._css | ||
} | ||
warnings() { | ||
return [] | ||
} | ||
} | ||
@@ -136,0 +136,0 @@ |
@@ -207,6 +207,2 @@ 'use strict' | ||
get proxyOf() { | ||
return this | ||
} | ||
rangeBy(opts) { | ||
@@ -379,2 +375,6 @@ let start = { | ||
} | ||
get proxyOf() { | ||
return this | ||
} | ||
} | ||
@@ -381,0 +381,0 @@ |
@@ -68,2 +68,3 @@ 'use strict' | ||
node.source.end = this.getPosition(token[2]) | ||
node.source.end.offset++ | ||
this.semicolon = true | ||
@@ -83,2 +84,3 @@ break | ||
node.source.end = this.getPosition(prev[3] || prev[2]) | ||
node.source.end.offset++ | ||
} | ||
@@ -108,2 +110,3 @@ } | ||
node.source.end = this.getPosition(token[3] || token[2]) | ||
node.source.end.offset++ | ||
this.spaces = node.raws.between | ||
@@ -177,2 +180,3 @@ node.raws.between = '' | ||
node.source.end = this.getPosition(token[3] || token[2]) | ||
node.source.end.offset++ | ||
@@ -209,2 +213,3 @@ let text = token[1].slice(2, -2) | ||
) | ||
node.source.end.offset++ | ||
@@ -328,2 +333,3 @@ while (tokens[0][0] !== 'word') { | ||
this.current.source.end = this.getPosition(token[2]) | ||
this.current.source.end.offset++ | ||
this.current = this.current.parent | ||
@@ -341,2 +347,3 @@ } else { | ||
this.current.raws.after = (this.current.raws.after || '') + this.spaces | ||
this.root.source.end = this.getPosition(this.tokenizer.position()) | ||
} | ||
@@ -343,0 +350,0 @@ |
@@ -239,7 +239,7 @@ import { RawSourceMap, SourceMapGenerator } from 'source-map-js' | ||
export interface Syntax { | ||
export interface Syntax<RootNode = Document | Root> { | ||
/** | ||
* Function to generate AST by string. | ||
*/ | ||
parse?: Parser | ||
parse?: Parser<RootNode> | ||
@@ -308,3 +308,3 @@ /** | ||
export interface ProcessOptions { | ||
export interface ProcessOptions<RootNode = Document | Root> { | ||
/** | ||
@@ -324,3 +324,3 @@ * The path of the CSS source file. You should always set `from`, | ||
*/ | ||
parser?: Parser | Syntax | ||
parser?: Parser<RootNode> | Syntax<RootNode> | ||
@@ -330,3 +330,3 @@ /** | ||
*/ | ||
stringifier?: Stringifier | Syntax | ||
stringifier?: Stringifier | Syntax<RootNode> | ||
@@ -336,3 +336,3 @@ /** | ||
*/ | ||
syntax?: Syntax | ||
syntax?: Syntax<RootNode> | ||
@@ -339,0 +339,0 @@ /** |
@@ -0,1 +1,2 @@ | ||
import Document from './document.js' | ||
import LazyResult from './lazy-result.js' | ||
@@ -75,5 +76,8 @@ import NoWorkResult from './no-work-result.js' | ||
process( | ||
css: { toString(): string } | LazyResult | Result | Root | string | ||
): LazyResult | NoWorkResult | ||
process<RootNode extends Document | Root = Root>( | ||
css: { toString(): string } | LazyResult | Result | Root | string, | ||
options?: ProcessOptions | ||
): LazyResult | NoWorkResult | ||
options: ProcessOptions<RootNode> | ||
): LazyResult<RootNode> | ||
@@ -80,0 +84,0 @@ /** |
@@ -10,3 +10,3 @@ 'use strict' | ||
constructor(plugins = []) { | ||
this.version = '8.4.27' | ||
this.version = '8.4.30' | ||
this.plugins = this.normalize(plugins) | ||
@@ -13,0 +13,0 @@ } |
@@ -63,3 +63,3 @@ import { | ||
*/ | ||
declare class Result_ { | ||
declare class Result_<RootNode = Document | Root> { | ||
/** | ||
@@ -145,3 +145,3 @@ * A CSS string representing of `Result#root`. | ||
*/ | ||
root: Document | Root | ||
root: RootNode | ||
@@ -153,15 +153,5 @@ /** | ||
*/ | ||
constructor(processor: Processor, root: Document | Root, opts: Result.ResultOptions) | ||
constructor(processor: Processor, root: RootNode, opts: Result.ResultOptions) | ||
/** | ||
* An alias for the `Result#css` property. | ||
* Use it with syntaxes that generate non-CSS output. | ||
* | ||
* ```js | ||
* result.css === result.content | ||
* ``` | ||
*/ | ||
get content(): string | ||
/** | ||
* Returns for `Result#css` content. | ||
@@ -205,6 +195,16 @@ * | ||
warnings(): Warning[] | ||
/** | ||
* An alias for the `Result#css` property. | ||
* Use it with syntaxes that generate non-CSS output. | ||
* | ||
* ```js | ||
* result.css === result.content | ||
* ``` | ||
*/ | ||
get content(): string | ||
} | ||
declare class Result extends Result_ {} | ||
declare class Result<RootNode = Document | Root> extends Result_<RootNode> {} | ||
export = Result |
@@ -15,6 +15,2 @@ 'use strict' | ||
get content() { | ||
return this.css | ||
} | ||
toString() { | ||
@@ -40,2 +36,6 @@ return this.css | ||
} | ||
get content() { | ||
return this.css | ||
} | ||
} | ||
@@ -42,0 +42,0 @@ |
{ | ||
"name": "postcss", | ||
"version": "8.4.27", | ||
"version": "8.4.30", | ||
"description": "Tool for transforming styles with JS plugins", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -12,16 +12,9 @@ # PostCSS | ||
PostCSS is used by industry leaders including Wikipedia, Twitter, Alibaba, | ||
and JetBrains. The [Autoprefixer] PostCSS plugin is one of the most popular | ||
CSS processors. | ||
and JetBrains. The [Autoprefixer] and [Stylelint] PostCSS plugins is one of the most popular CSS tools. | ||
PostCSS takes a CSS file and provides an API to analyze and modify its rules | ||
(by transforming them into an [Abstract Syntax Tree]). | ||
This API can then be used by [plugins] to do a lot of useful things, | ||
e.g., to find errors automatically, or to insert vendor prefixes. | ||
--- | ||
**Twitter account:** [@postcss](https://twitter.com/postcss)<br> | ||
**中文翻译**: [`docs/README-cn.md`](./docs/README-cn.md) | ||
<img src="https://cdn.evilmartians.com/badges/logo-no-label.svg" alt="" width="22" height="16" /> Made in <b><a href="https://evilmartians.com/?utm_source=postcss&utm_campaign=devtools-button&utm_medium=github">Evil Martians</a></b>, product consulting for <b>developer tools</b>. | ||
For PostCSS commercial support (consulting, improving the front-end culture | ||
of your company, PostCSS plugins), contact [Evil Martians] | ||
at <postcss@evilmartians.com>. | ||
--- | ||
@@ -31,11 +24,7 @@ [Abstract Syntax Tree]: https://en.wikipedia.org/wiki/Abstract_syntax_tree | ||
[Autoprefixer]: https://github.com/postcss/autoprefixer | ||
[Stylelint]: https://stylelint.io/ | ||
[plugins]: https://github.com/postcss/postcss#plugins | ||
<a href="https://evilmartians.com/?utm_source=postcss"> | ||
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" | ||
alt="Sponsored by Evil Martians" width="236" height="54"> | ||
</a> | ||
## Docs | ||
Read full docs **[here](https://postcss.org/)**. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
196515
6745
29