Comparing version 8.2.15 to 8.3.0
@@ -40,4 +40,7 @@ import Container, { ContainerProps } from './container.js' | ||
export interface AtRuleProps extends ContainerProps { | ||
/** Name of the at-rule. */ | ||
name: string | ||
/** Parameters following the name of the at-rule. */ | ||
params?: string | number | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: AtRuleRaws | ||
@@ -73,2 +76,3 @@ } | ||
type: 'atrule' | ||
parent: Container | undefined | ||
raws: AtRuleRaws | ||
@@ -100,2 +104,3 @@ | ||
constructor(defaults?: AtRuleProps) | ||
assign(overrides: object | AtRuleProps): this | ||
clone(overrides?: Partial<AtRuleProps>): this | ||
@@ -102,0 +107,0 @@ cloneBefore(overrides?: Partial<AtRuleProps>): this |
@@ -0,1 +1,2 @@ | ||
import Container from './container.js' | ||
import Node, { NodeProps } from './node.js' | ||
@@ -21,3 +22,5 @@ | ||
export interface CommentProps extends NodeProps { | ||
/** Content of the comment. */ | ||
text: string | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: CommentRaws | ||
@@ -41,2 +44,3 @@ } | ||
type: 'comment' | ||
parent: Container | undefined | ||
raws: CommentRaws | ||
@@ -50,2 +54,3 @@ | ||
constructor(defaults?: CommentProps) | ||
assign(overrides: object | CommentProps): this | ||
clone(overrides?: Partial<CommentProps>): this | ||
@@ -52,0 +57,0 @@ cloneBefore(overrides?: Partial<CommentProps>): this |
@@ -30,3 +30,5 @@ import Node, { ChildNode, NodeProps, ChildProps } from './node.js' | ||
*/ | ||
export default abstract class Container extends Node { | ||
export default abstract class Container< | ||
Child extends Node = ChildNode | ||
> extends Node { | ||
/** | ||
@@ -42,3 +44,3 @@ * An array containing the container’s children. | ||
*/ | ||
nodes: ChildNode[] | ||
nodes: Child[] | ||
@@ -52,3 +54,3 @@ /** | ||
*/ | ||
get first(): ChildNode | undefined | ||
get first(): Child | undefined | ||
@@ -62,3 +64,3 @@ /** | ||
*/ | ||
get last(): ChildNode | undefined | ||
get last(): Child | undefined | ||
@@ -99,3 +101,3 @@ /** | ||
each( | ||
callback: (node: ChildNode, index: number) => false | void | ||
callback: (node: Child, index: number) => false | void | ||
): false | undefined | ||
@@ -312,3 +314,3 @@ | ||
*/ | ||
push(child: ChildNode): this | ||
push(child: Child): this | ||
@@ -327,10 +329,4 @@ /** | ||
insertBefore( | ||
oldNode: ChildNode | number, | ||
newNode: | ||
| ChildNode | ||
| ChildProps | ||
| string | ||
| ChildNode[] | ||
| ChildProps[] | ||
| string[] | ||
oldNode: Child | number, | ||
newNode: Child | ChildProps | string | Child[] | ChildProps[] | string[] | ||
): this | ||
@@ -346,10 +342,4 @@ | ||
insertAfter( | ||
oldNode: ChildNode | number, | ||
newNode: | ||
| ChildNode | ||
| ChildProps | ||
| string | ||
| ChildNode[] | ||
| ChildProps[] | ||
| string[] | ||
oldNode: Child | number, | ||
newNode: Child | ChildProps | string | Child[] | ChildProps[] | string[] | ||
): this | ||
@@ -371,3 +361,3 @@ | ||
*/ | ||
removeChild(child: ChildNode | number): this | ||
removeChild(child: Child | number): this | ||
@@ -432,3 +422,3 @@ /** | ||
every( | ||
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean | ||
condition: (node: Child, index: number, nodes: Child[]) => boolean | ||
): boolean | ||
@@ -448,3 +438,3 @@ | ||
some( | ||
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean | ||
condition: (node: Child, index: number, nodes: Child[]) => boolean | ||
): boolean | ||
@@ -462,3 +452,3 @@ | ||
*/ | ||
index(child: ChildNode | number): number | ||
index(child: Child | number): number | ||
} |
@@ -313,3 +313,3 @@ 'use strict' | ||
} | ||
} else if (nodes.type === 'root') { | ||
} else if (nodes.type === 'root' && this.type !== 'document') { | ||
nodes = nodes.nodes.slice(0) | ||
@@ -316,0 +316,0 @@ for (let i of nodes) { |
@@ -0,1 +1,2 @@ | ||
import Container from './container.js' | ||
import Node from './node.js' | ||
@@ -30,4 +31,9 @@ | ||
export interface DeclarationProps { | ||
/** Name of the declaration. */ | ||
prop: string | ||
/** Value of the declaration. */ | ||
value: string | ||
/** Whether the declaration has an `!important` annotation. */ | ||
important?: boolean | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: DeclarationRaws | ||
@@ -55,2 +61,3 @@ } | ||
type: 'decl' | ||
parent: Container | undefined | ||
raws: DeclarationRaws | ||
@@ -115,2 +122,3 @@ | ||
constructor(defaults?: DeclarationProps) | ||
assign(overrides: object | DeclarationProps): this | ||
clone(overrides?: Partial<DeclarationProps>): this | ||
@@ -117,0 +125,0 @@ cloneBefore(overrides?: Partial<DeclarationProps>): this |
'use strict' | ||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js') | ||
let { fileURLToPath, pathToFileURL } = require('url') | ||
let { resolve, isAbsolute } = require('path') | ||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map') | ||
let { nanoid } = require('nanoid/non-secure') | ||
@@ -7,0 +7,0 @@ |
@@ -10,4 +10,6 @@ 'use strict' | ||
let Root = require('./root') | ||
let Document = require('./document') | ||
const TYPE_TO_CLASS_NAME = { | ||
document: 'Document', | ||
root: 'Root', | ||
@@ -24,2 +26,3 @@ atrule: 'AtRule', | ||
Once: true, | ||
Document: true, | ||
Root: true, | ||
@@ -35,2 +38,3 @@ Declaration: true, | ||
RootExit: true, | ||
DocumentExit: true, | ||
OnceExit: true | ||
@@ -79,3 +83,5 @@ } | ||
let events | ||
if (node.type === 'root') { | ||
if (node.type === 'document') { | ||
events = ['Document', CHILDREN, 'DocumentExit'] | ||
} else if (node.type === 'root') { | ||
events = ['Root', CHILDREN, 'RootExit'] | ||
@@ -110,3 +116,7 @@ } else { | ||
let root | ||
if (typeof css === 'object' && css !== null && css.type === 'root') { | ||
if ( | ||
typeof css === 'object' && | ||
css !== null && | ||
(css.type === 'root' || css.type === 'document') | ||
) { | ||
root = cleanMarks(css) | ||
@@ -239,3 +249,9 @@ } else if (css instanceof LazyResult || css instanceof Result) { | ||
if (this.listeners.OnceExit) { | ||
this.visitSync(this.listeners.OnceExit, root) | ||
if (root.type === 'document') { | ||
for (let subRoot of root.nodes) { | ||
this.visitSync(this.listeners.OnceExit, subRoot) | ||
} | ||
} else { | ||
this.visitSync(this.listeners.OnceExit, root) | ||
} | ||
} | ||
@@ -296,3 +312,5 @@ } | ||
} | ||
if (node.type !== 'root' && !node.parent) return true | ||
if (node.type !== 'root' && node.type !== 'document' && !node.parent) { | ||
return true | ||
} | ||
if (isPromise(promise)) { | ||
@@ -308,2 +326,14 @@ throw this.getAsyncError() | ||
if (typeof plugin === 'object' && plugin.Once) { | ||
if (this.result.root.type === 'document') { | ||
let roots = this.result.root.nodes.map(root => | ||
plugin.Once(root, this.helpers) | ||
) | ||
if (isPromise(roots[0])) { | ||
return Promise.all(roots) | ||
} | ||
return roots | ||
} | ||
return plugin.Once(this.result.root, this.helpers) | ||
@@ -396,3 +426,11 @@ } else if (typeof plugin === 'function') { | ||
try { | ||
await visitor(root, this.helpers) | ||
if (root.type === 'document') { | ||
let roots = root.nodes.map(subRoot => | ||
visitor(subRoot, this.helpers) | ||
) | ||
await Promise.all(roots) | ||
} else { | ||
await visitor(root, this.helpers) | ||
} | ||
} catch (e) { | ||
@@ -451,3 +489,3 @@ throw this.handleError(e) | ||
if (node.type !== 'root' && !node.parent) { | ||
if (node.type !== 'root' && node.type !== 'document' && !node.parent) { | ||
stack.pop() | ||
@@ -514,1 +552,2 @@ return | ||
Root.registerLazyResult(LazyResult) | ||
Document.registerLazyResult(LazyResult) |
'use strict' | ||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js') | ||
let { dirname, resolve, relative, sep } = require('path') | ||
let { pathToFileURL } = require('url') | ||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map') | ||
@@ -7,0 +7,0 @@ let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator) |
@@ -8,10 +8,11 @@ import Declaration, { DeclarationProps } from './declaration.js' | ||
import CssSyntaxError from './css-syntax-error.js' | ||
import Container from './container.js' | ||
import Result from './result.js' | ||
import Input from './input.js' | ||
import Root from './root.js' | ||
import Document from './document.js' | ||
import Container from './container.js' | ||
export type ChildNode = AtRule | Rule | Declaration | Comment | ||
export type AnyNode = AtRule | Rule | Declaration | Comment | Root | ||
export type AnyNode = AtRule | Rule | Declaration | Comment | Root | Document | ||
@@ -101,3 +102,3 @@ export type ChildProps = | ||
*/ | ||
parent: Container | undefined | ||
parent: Document | Container | undefined | ||
@@ -257,2 +258,14 @@ /** | ||
/** | ||
* Assigns properties to the current node. | ||
* | ||
* ```js | ||
* decl.assign({ prop: 'word-wrap', value: 'break-word' }) | ||
* ``` | ||
* | ||
* @param overrides New properties to override the node. | ||
* @return Current node to methods chain. | ||
*/ | ||
assign(overrides: object): this | ||
/** | ||
* Returns an exact clone of the node. | ||
@@ -259,0 +272,0 @@ * |
@@ -87,2 +87,9 @@ 'use strict' | ||
assign(overrides = {}) { | ||
for (let name in overrides) { | ||
this[name] = overrides[name] | ||
} | ||
return this | ||
} | ||
clone(overrides = {}) { | ||
@@ -155,3 +162,5 @@ let cloned = cloneNode(this) | ||
let result = this | ||
while (result.parent) result = result.parent | ||
while (result.parent && result.parent.type !== 'document') { | ||
result = result.parent | ||
} | ||
return result | ||
@@ -158,0 +167,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { SourceMapGenerator, RawSourceMap } from 'source-map' | ||
import { SourceMapGenerator, RawSourceMap } from 'source-map-js' | ||
@@ -14,2 +14,3 @@ import Node, { | ||
import Root, { RootProps } from './root.js' | ||
import Document, { DocumentProps } from './document.js' | ||
import Comment, { CommentProps } from './comment.js' | ||
@@ -44,2 +45,3 @@ import AtRule, { AtRuleProps } from './at-rule.js' | ||
RootProps, | ||
DocumentProps, | ||
Warning, | ||
@@ -55,2 +57,3 @@ CssSyntaxError, | ||
Root, | ||
Document, | ||
Result, | ||
@@ -67,2 +70,6 @@ LazyResult, | ||
type DocumentProcessor = ( | ||
document: Document, | ||
helper: Helpers | ||
) => Promise<void> | void | ||
type RootProcessor = (root: Root, helper: Helpers) => Promise<void> | void | ||
@@ -82,2 +89,16 @@ type DeclarationProcessor = ( | ||
/** | ||
* Will be called on `Document` node. | ||
* | ||
* Will be called again on children changes. | ||
*/ | ||
Document?: DocumentProcessor | ||
/** | ||
* Will be called on `Document` node, when all children will be processed. | ||
* | ||
* Will be called again on children changes. | ||
*/ | ||
DocumentExit?: DocumentProcessor | ||
/** | ||
* Will be called on `Root` node once. | ||
@@ -208,7 +229,7 @@ */ | ||
export interface Parser { | ||
export interface Parser<RootNode = Root> { | ||
( | ||
css: string | { toString(): string }, | ||
opts?: Pick<ProcessOptions, 'map' | 'from'> | ||
): Root | ||
): RootNode | ||
} | ||
@@ -233,3 +254,3 @@ | ||
*/ | ||
parse?: Parser | ||
parse?: Parser<Root | Document> | ||
@@ -357,3 +378,3 @@ /** | ||
/** | ||
* Parses source css and returns a new `Root` node, | ||
* Parses source css and returns a new `Root` or `Document` node, | ||
* which contains the source CSS nodes. | ||
@@ -426,2 +447,10 @@ * | ||
/** | ||
* Creates a new `Document` node. | ||
* | ||
* @param defaults Properties for the new node. | ||
* @return New document node. | ||
*/ | ||
document(defaults?: DocumentProps): Document | ||
CssSyntaxError: typeof CssSyntaxError | ||
@@ -428,0 +457,0 @@ Declaration: typeof Declaration |
@@ -10,2 +10,3 @@ 'use strict' | ||
let fromJSON = require('./fromJSON') | ||
let Document = require('./document') | ||
let Warning = require('./warning') | ||
@@ -77,2 +78,3 @@ let Comment = require('./comment') | ||
postcss.root = defaults => new Root(defaults) | ||
postcss.document = defaults => new Document(defaults) | ||
@@ -82,2 +84,3 @@ postcss.CssSyntaxError = CssSyntaxError | ||
postcss.Container = Container | ||
postcss.Document = Document | ||
postcss.Comment = Comment | ||
@@ -84,0 +87,0 @@ postcss.Warning = Warning |
@@ -1,2 +0,2 @@ | ||
import { SourceMapConsumer } from 'source-map' | ||
import { SourceMapConsumer } from 'source-map-js' | ||
@@ -3,0 +3,0 @@ import { ProcessOptions } from './postcss.js' |
@@ -5,3 +5,3 @@ 'use strict' | ||
let { dirname, join } = require('path') | ||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map') | ||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js') | ||
@@ -8,0 +8,0 @@ function fromBase64(str) { |
@@ -5,6 +5,7 @@ 'use strict' | ||
let Root = require('./root') | ||
let Document = require('./document') | ||
class Processor { | ||
constructor(plugins = []) { | ||
this.version = '8.2.15' | ||
this.version = '8.3.0' | ||
this.plugins = this.normalize(plugins) | ||
@@ -72,1 +73,2 @@ } | ||
Root.registerProcessor(Processor) | ||
Document.registerProcessor(Processor) |
import Container, { ContainerProps } from './container.js' | ||
import Document from './document.js' | ||
import { ProcessOptions } from './postcss.js' | ||
import Result from './result.js' | ||
interface RootRaws { | ||
interface RootRaws extends Record<string, any> { | ||
/** | ||
@@ -12,2 +13,18 @@ * The space symbols after the last child to the end of file. | ||
/** | ||
* Non-CSS code before `Root`, when `Root` is inside `Document`. | ||
* | ||
* **Experimental:** some aspects of this node could change within minor | ||
* or patch version releases. | ||
*/ | ||
codeBefore?: string | ||
/** | ||
* Non-CSS code after `Root`, when `Root` is inside `Document`. | ||
* | ||
* **Experimental:** some aspects of this node could change within minor | ||
* or patch version releases. | ||
*/ | ||
codeAfter?: string | ||
/** | ||
* Is the last child has an (optional) semicolon. | ||
@@ -19,2 +36,6 @@ */ | ||
export interface RootProps extends ContainerProps { | ||
/** | ||
* Information used to generate byte-to-byte equal node string | ||
* as it was in the origin input. | ||
* */ | ||
raws?: RootRaws | ||
@@ -34,7 +55,5 @@ } | ||
type: 'root' | ||
parent: undefined | ||
parent: Document | undefined | ||
raws: RootRaws | ||
constructor(defaults?: RootProps) | ||
/** | ||
@@ -54,2 +73,5 @@ * Returns a `Result` instance representing the root’s CSS. | ||
toResult(options?: ProcessOptions): Result | ||
constructor(defaults?: RootProps) | ||
assign(overrides: object | RootProps): this | ||
} |
@@ -40,4 +40,7 @@ import Container, { ContainerProps } from './container.js' | ||
export interface RuleProps extends ContainerProps { | ||
/** Selector or selectors of the rule. */ | ||
selector?: string | ||
/** Selectors of the rule represented as an array of strings. */ | ||
selectors?: string[] | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: RuleRaws | ||
@@ -66,2 +69,3 @@ } | ||
type: 'rule' | ||
parent: Container | undefined | ||
raws: RuleRaws | ||
@@ -98,2 +102,3 @@ | ||
constructor(defaults?: RuleProps) | ||
assign(overrides: object | RuleProps): this | ||
clone(overrides?: Partial<RuleProps>): this | ||
@@ -100,0 +105,0 @@ cloneBefore(overrides?: Partial<RuleProps>): this |
@@ -40,2 +40,6 @@ 'use strict' | ||
document(node) { | ||
this.body(node) | ||
} | ||
root(node) { | ||
@@ -133,7 +137,12 @@ this.body(node) | ||
// Hack for first rule in CSS | ||
if (detect === 'before') { | ||
// Hack for first rule in CSS | ||
if (!parent || (parent.type === 'root' && parent.first === node)) { | ||
return '' | ||
} | ||
// `root` nodes in `document` should use only their own raws | ||
if (parent && parent.type === 'document') { | ||
return '' | ||
} | ||
} | ||
@@ -140,0 +149,0 @@ |
{ | ||
"name": "postcss", | ||
"version": "8.2.15", | ||
"version": "8.3.0", | ||
"description": "Tool for transforming styles with JS plugins", | ||
@@ -66,12 +66,12 @@ "engines": { | ||
"nanoid": "^3.1.23", | ||
"source-map": "^0.6.1" | ||
"source-map-js": "^0.6.2" | ||
}, | ||
"browser": { | ||
"./lib/terminal-highlight": false, | ||
"source-map-js": false, | ||
"colorette": false, | ||
"fs": false, | ||
"path": false, | ||
"url": false, | ||
"source-map": false | ||
"fs": false | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
188482
51
6024
+ Addedsource-map-js@^0.6.2
+ Addedsource-map-js@0.6.2(transitive)
- Removedsource-map@^0.6.1
- Removedsource-map@0.6.1(transitive)