postcss 8.2.15 → 8.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of postcss might be problematic. Click here for more details.
- package/lib/at-rule.d.ts +5 -0
- package/lib/comment.d.ts +5 -0
- package/lib/container.d.ts +16 -26
- package/lib/container.js +22 -22
- package/lib/declaration.d.ts +8 -0
- package/lib/document.d.ts +57 -0
- package/lib/document.js +33 -0
- package/lib/input.js +2 -2
- package/lib/lazy-result.js +49 -7
- package/lib/map-generator.js +1 -1
- package/lib/node.d.ts +16 -3
- package/lib/node.js +10 -1
- package/lib/postcss.d.ts +34 -5
- package/lib/postcss.js +3 -0
- package/lib/postcss.mjs +2 -0
- package/lib/previous-map.d.ts +1 -1
- package/lib/previous-map.js +1 -1
- package/lib/processor.js +6 -2
- package/lib/root.d.ts +26 -4
- package/lib/rule.d.ts +5 -0
- package/lib/stringifier.js +10 -1
- package/lib/symbols.js +2 -0
- package/package.json +4 -4
package/lib/at-rule.d.ts
CHANGED
@@ -37,8 +37,11 @@ interface AtRuleRaws {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
export interface AtRuleProps extends ContainerProps {
|
40
|
+
/** Name of the at-rule. */
|
40
41
|
name: string
|
42
|
+
/** Parameters following the name of the at-rule. */
|
41
43
|
params?: string | number
|
44
|
+
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
|
42
45
|
raws?: AtRuleRaws
|
43
46
|
}
|
44
47
|
|
@@ -69,6 +72,7 @@ export interface AtRuleProps extends ContainerProps {
|
|
69
72
|
*/
|
70
73
|
export default class AtRule extends Container {
|
71
74
|
type: 'atrule'
|
75
|
+
parent: Container | undefined
|
72
76
|
raws: AtRuleRaws
|
73
77
|
|
74
78
|
/**
|
@@ -95,6 +99,7 @@ export default class AtRule extends Container {
|
|
95
99
|
params: string
|
96
100
|
|
97
101
|
constructor(defaults?: AtRuleProps)
|
102
|
+
assign(overrides: object | AtRuleProps): this
|
98
103
|
clone(overrides?: Partial<AtRuleProps>): this
|
99
104
|
cloneBefore(overrides?: Partial<AtRuleProps>): this
|
100
105
|
cloneAfter(overrides?: Partial<AtRuleProps>): this
|
package/lib/comment.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import Container from './container.js'
|
1
2
|
import Node, { NodeProps } from './node.js'
|
2
3
|
|
3
4
|
interface CommentRaws {
|
@@ -18,7 +19,9 @@ interface CommentRaws {
|
|
18
19
|
}
|
19
20
|
|
20
21
|
export interface CommentProps extends NodeProps {
|
22
|
+
/** Content of the comment. */
|
21
23
|
text: string
|
24
|
+
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
|
22
25
|
raws?: CommentRaws
|
23
26
|
}
|
24
27
|
|
@@ -37,6 +40,7 @@ export interface CommentProps extends NodeProps {
|
|
37
40
|
*/
|
38
41
|
export default class Comment extends Node {
|
39
42
|
type: 'comment'
|
43
|
+
parent: Container | undefined
|
40
44
|
raws: CommentRaws
|
41
45
|
|
42
46
|
/**
|
@@ -45,6 +49,7 @@ export default class Comment extends Node {
|
|
45
49
|
text: string
|
46
50
|
|
47
51
|
constructor(defaults?: CommentProps)
|
52
|
+
assign(overrides: object | CommentProps): this
|
48
53
|
clone(overrides?: Partial<CommentProps>): this
|
49
54
|
cloneBefore(overrides?: Partial<CommentProps>): this
|
50
55
|
cloneAfter(overrides?: Partial<CommentProps>): this
|
package/lib/container.d.ts
CHANGED
@@ -27,7 +27,9 @@ export interface ContainerProps extends NodeProps {
|
|
27
27
|
* Note that all containers can store any content. If you write a rule inside
|
28
28
|
* a rule, PostCSS will parse it.
|
29
29
|
*/
|
30
|
-
export default abstract class Container
|
30
|
+
export default abstract class Container<
|
31
|
+
Child extends Node = ChildNode
|
32
|
+
> extends Node {
|
31
33
|
/**
|
32
34
|
* An array containing the container’s children.
|
33
35
|
*
|
@@ -38,7 +40,7 @@ export default abstract class Container extends Node {
|
|
38
40
|
* root.nodes[0].nodes[0].prop //=> 'color'
|
39
41
|
* ```
|
40
42
|
*/
|
41
|
-
nodes:
|
43
|
+
nodes: Child[]
|
42
44
|
|
43
45
|
/**
|
44
46
|
* The container’s first child.
|
@@ -47,7 +49,7 @@ export default abstract class Container extends Node {
|
|
47
49
|
* rule.first === rules.nodes[0]
|
48
50
|
* ```
|
49
51
|
*/
|
50
|
-
get first():
|
52
|
+
get first(): Child | undefined
|
51
53
|
|
52
54
|
/**
|
53
55
|
* The container’s last child.
|
@@ -56,7 +58,7 @@ export default abstract class Container extends Node {
|
|
56
58
|
* rule.last === rule.nodes[rule.nodes.length - 1]
|
57
59
|
* ```
|
58
60
|
*/
|
59
|
-
get last():
|
61
|
+
get last(): Child | undefined
|
60
62
|
|
61
63
|
/**
|
62
64
|
* Iterates through the container’s immediate children,
|
@@ -92,7 +94,7 @@ export default abstract class Container extends Node {
|
|
92
94
|
* @return Returns `false` if iteration was broke.
|
93
95
|
*/
|
94
96
|
each(
|
95
|
-
callback: (node:
|
97
|
+
callback: (node: Child, index: number) => false | void
|
96
98
|
): false | undefined
|
97
99
|
|
98
100
|
/**
|
@@ -304,7 +306,7 @@ export default abstract class Container extends Node {
|
|
304
306
|
* @param child New node.
|
305
307
|
* @return This node for methods chain.
|
306
308
|
*/
|
307
|
-
push(child:
|
309
|
+
push(child: Child): this
|
308
310
|
|
309
311
|
/**
|
310
312
|
* Insert new node before old node within the container.
|
@@ -318,14 +320,8 @@ export default abstract class Container extends Node {
|
|
318
320
|
* @return This node for methods chain.
|
319
321
|
*/
|
320
322
|
insertBefore(
|
321
|
-
oldNode:
|
322
|
-
newNode:
|
323
|
-
| ChildNode
|
324
|
-
| ChildProps
|
325
|
-
| string
|
326
|
-
| ChildNode[]
|
327
|
-
| ChildProps[]
|
328
|
-
| string[]
|
323
|
+
oldNode: Child | number,
|
324
|
+
newNode: Child | ChildProps | string | Child[] | ChildProps[] | string[]
|
329
325
|
): this
|
330
326
|
|
331
327
|
/**
|
@@ -336,14 +332,8 @@ export default abstract class Container extends Node {
|
|
336
332
|
* @return This node for methods chain.
|
337
333
|
*/
|
338
334
|
insertAfter(
|
339
|
-
oldNode:
|
340
|
-
newNode:
|
341
|
-
| ChildNode
|
342
|
-
| ChildProps
|
343
|
-
| string
|
344
|
-
| ChildNode[]
|
345
|
-
| ChildProps[]
|
346
|
-
| string[]
|
335
|
+
oldNode: Child | number,
|
336
|
+
newNode: Child | ChildProps | string | Child[] | ChildProps[] | string[]
|
347
337
|
): this
|
348
338
|
|
349
339
|
/**
|
@@ -360,7 +350,7 @@ export default abstract class Container extends Node {
|
|
360
350
|
* @param child Child or child’s index.
|
361
351
|
* @return This node for methods chain.
|
362
352
|
*/
|
363
|
-
removeChild(child:
|
353
|
+
removeChild(child: Child | number): this
|
364
354
|
|
365
355
|
/**
|
366
356
|
* Removes all children from the container
|
@@ -420,7 +410,7 @@ export default abstract class Container extends Node {
|
|
420
410
|
* @return Is every child pass condition.
|
421
411
|
*/
|
422
412
|
every(
|
423
|
-
condition: (node:
|
413
|
+
condition: (node: Child, index: number, nodes: Child[]) => boolean
|
424
414
|
): boolean
|
425
415
|
|
426
416
|
/**
|
@@ -435,7 +425,7 @@ export default abstract class Container extends Node {
|
|
435
425
|
* @return Is some child pass condition.
|
436
426
|
*/
|
437
427
|
some(
|
438
|
-
condition: (node:
|
428
|
+
condition: (node: Child, index: number, nodes: Child[]) => boolean
|
439
429
|
): boolean
|
440
430
|
|
441
431
|
/**
|
@@ -448,5 +438,5 @@ export default abstract class Container extends Node {
|
|
448
438
|
* @param child Child of the current container.
|
449
439
|
* @return Child index.
|
450
440
|
*/
|
451
|
-
index(child:
|
441
|
+
index(child: Child | number): number
|
452
442
|
}
|
package/lib/container.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
|
+
let { isClean, my } = require('./symbols')
|
3
4
|
let Declaration = require('./declaration')
|
4
|
-
let { isClean } = require('./symbols')
|
5
5
|
let Comment = require('./comment')
|
6
6
|
let Node = require('./node')
|
7
7
|
|
@@ -24,25 +24,6 @@ function markDirtyUp(node) {
|
|
24
24
|
}
|
25
25
|
}
|
26
26
|
|
27
|
-
// istanbul ignore next
|
28
|
-
function rebuild(node) {
|
29
|
-
if (node.type === 'atrule') {
|
30
|
-
Object.setPrototypeOf(node, AtRule.prototype)
|
31
|
-
} else if (node.type === 'rule') {
|
32
|
-
Object.setPrototypeOf(node, Rule.prototype)
|
33
|
-
} else if (node.type === 'decl') {
|
34
|
-
Object.setPrototypeOf(node, Declaration.prototype)
|
35
|
-
} else if (node.type === 'comment') {
|
36
|
-
Object.setPrototypeOf(node, Comment.prototype)
|
37
|
-
}
|
38
|
-
|
39
|
-
if (node.nodes) {
|
40
|
-
node.nodes.forEach(child => {
|
41
|
-
rebuild(child)
|
42
|
-
})
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
27
|
class Container extends Node {
|
47
28
|
push(child) {
|
48
29
|
child.parent = this
|
@@ -310,7 +291,7 @@ class Container extends Node {
|
|
310
291
|
for (let i of nodes) {
|
311
292
|
if (i.parent) i.parent.removeChild(i, 'ignore')
|
312
293
|
}
|
313
|
-
} else if (nodes.type === 'root') {
|
294
|
+
} else if (nodes.type === 'root' && this.type !== 'document') {
|
314
295
|
nodes = nodes.nodes.slice(0)
|
315
296
|
for (let i of nodes) {
|
316
297
|
if (i.parent) i.parent.removeChild(i, 'ignore')
|
@@ -336,7 +317,7 @@ class Container extends Node {
|
|
336
317
|
|
337
318
|
let processed = nodes.map(i => {
|
338
319
|
// istanbul ignore next
|
339
|
-
if (
|
320
|
+
if (!i[my]) Container.rebuild(i)
|
340
321
|
i = i.proxyOf
|
341
322
|
if (i.parent) i.parent.removeChild(i)
|
342
323
|
if (i[isClean]) markDirtyUp(i)
|
@@ -428,3 +409,22 @@ Container.registerAtRule = dependant => {
|
|
428
409
|
|
429
410
|
module.exports = Container
|
430
411
|
Container.default = Container
|
412
|
+
|
413
|
+
// istanbul ignore next
|
414
|
+
Container.rebuild = node => {
|
415
|
+
if (node.type === 'atrule') {
|
416
|
+
Object.setPrototypeOf(node, AtRule.prototype)
|
417
|
+
} else if (node.type === 'rule') {
|
418
|
+
Object.setPrototypeOf(node, Rule.prototype)
|
419
|
+
} else if (node.type === 'decl') {
|
420
|
+
Object.setPrototypeOf(node, Declaration.prototype)
|
421
|
+
} else if (node.type === 'comment') {
|
422
|
+
Object.setPrototypeOf(node, Comment.prototype)
|
423
|
+
}
|
424
|
+
|
425
|
+
if (node.nodes) {
|
426
|
+
node.nodes.forEach(child => {
|
427
|
+
Container.rebuild(child)
|
428
|
+
})
|
429
|
+
}
|
430
|
+
}
|
package/lib/declaration.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import Container from './container.js'
|
1
2
|
import Node from './node.js'
|
2
3
|
|
3
4
|
interface DeclarationRaws {
|
@@ -27,8 +28,13 @@ interface DeclarationRaws {
|
|
27
28
|
}
|
28
29
|
|
29
30
|
export interface DeclarationProps {
|
31
|
+
/** Name of the declaration. */
|
30
32
|
prop: string
|
33
|
+
/** Value of the declaration. */
|
31
34
|
value: string
|
35
|
+
/** Whether the declaration has an `!important` annotation. */
|
36
|
+
important?: boolean
|
37
|
+
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
|
32
38
|
raws?: DeclarationRaws
|
33
39
|
}
|
34
40
|
|
@@ -51,6 +57,7 @@ export interface DeclarationProps {
|
|
51
57
|
*/
|
52
58
|
export default class Declaration extends Node {
|
53
59
|
type: 'decl'
|
60
|
+
parent: Container | undefined
|
54
61
|
raws: DeclarationRaws
|
55
62
|
|
56
63
|
/**
|
@@ -110,6 +117,7 @@ export default class Declaration extends Node {
|
|
110
117
|
variable: boolean
|
111
118
|
|
112
119
|
constructor(defaults?: DeclarationProps)
|
120
|
+
assign(overrides: object | DeclarationProps): this
|
113
121
|
clone(overrides?: Partial<DeclarationProps>): this
|
114
122
|
cloneBefore(overrides?: Partial<DeclarationProps>): this
|
115
123
|
cloneAfter(overrides?: Partial<DeclarationProps>): this
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import Container, { ContainerProps } from './container.js'
|
2
|
+
import { ProcessOptions } from './postcss.js'
|
3
|
+
import Result from './result.js'
|
4
|
+
import Root, { RootProps } from './root.js'
|
5
|
+
|
6
|
+
export interface DocumentProps extends ContainerProps {
|
7
|
+
nodes?: Root[]
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Information to generate byte-to-byte equal node string as it was
|
11
|
+
* in the origin input.
|
12
|
+
*
|
13
|
+
* Every parser saves its own properties.
|
14
|
+
*/
|
15
|
+
raws?: Record<string, any>
|
16
|
+
}
|
17
|
+
|
18
|
+
type ChildNode = Root
|
19
|
+
type ChildProps = RootProps
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Represents a file and contains all its parsed nodes.
|
23
|
+
*
|
24
|
+
* **Experimental:** some aspects of this node could change within minor
|
25
|
+
* or patch version releases.
|
26
|
+
*
|
27
|
+
* ```js
|
28
|
+
* const document = htmlParser(
|
29
|
+
* '<html><style>a{color:black}</style><style>b{z-index:2}</style>'
|
30
|
+
* )
|
31
|
+
* document.type //=> 'document'
|
32
|
+
* document.nodes.length //=> 2
|
33
|
+
* ```
|
34
|
+
*/
|
35
|
+
export default class Document extends Container<Root> {
|
36
|
+
type: 'document'
|
37
|
+
parent: undefined
|
38
|
+
|
39
|
+
constructor(defaults?: DocumentProps)
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Returns a `Result` instance representing the document’s CSS roots.
|
43
|
+
*
|
44
|
+
* ```js
|
45
|
+
* const root1 = postcss.parse(css1, { from: 'a.css' })
|
46
|
+
* const root2 = postcss.parse(css2, { from: 'b.css' })
|
47
|
+
* const document = postcss.document()
|
48
|
+
* document.append(root1)
|
49
|
+
* document.append(root2)
|
50
|
+
* const result = document.toResult({ to: 'all.css', map: true })
|
51
|
+
* ```
|
52
|
+
*
|
53
|
+
* @param opts Options.
|
54
|
+
* @return Result with current document’s CSS.
|
55
|
+
*/
|
56
|
+
toResult(options?: ProcessOptions): Result
|
57
|
+
}
|
package/lib/document.js
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
let Container = require('./container')
|
4
|
+
|
5
|
+
let LazyResult, Processor
|
6
|
+
|
7
|
+
class Document extends Container {
|
8
|
+
constructor(defaults) {
|
9
|
+
// type needs to be passed to super, otherwise child roots won't be normalized correctly
|
10
|
+
super({ type: 'document', ...defaults })
|
11
|
+
|
12
|
+
if (!this.nodes) {
|
13
|
+
this.nodes = []
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
toResult(opts = {}) {
|
18
|
+
let lazy = new LazyResult(new Processor(), this, opts)
|
19
|
+
|
20
|
+
return lazy.stringify()
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
Document.registerLazyResult = dependant => {
|
25
|
+
LazyResult = dependant
|
26
|
+
}
|
27
|
+
|
28
|
+
Document.registerProcessor = dependant => {
|
29
|
+
Processor = dependant
|
30
|
+
}
|
31
|
+
|
32
|
+
module.exports = Document
|
33
|
+
Document.default = Document
|
package/lib/input.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
|
+
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
3
4
|
let { fileURLToPath, pathToFileURL } = require('url')
|
4
5
|
let { resolve, isAbsolute } = require('path')
|
5
|
-
let { SourceMapConsumer, SourceMapGenerator } = require('source-map')
|
6
6
|
let { nanoid } = require('nanoid/non-secure')
|
7
7
|
|
8
8
|
let terminalHighlight = require('./terminal-highlight')
|
9
9
|
let CssSyntaxError = require('./css-syntax-error')
|
10
10
|
let PreviousMap = require('./previous-map')
|
11
11
|
|
12
|
-
let fromOffsetCache = Symbol('
|
12
|
+
let fromOffsetCache = Symbol('fromOffsetCache')
|
13
13
|
|
14
14
|
let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
|
15
15
|
let pathAvailable = Boolean(resolve && isAbsolute)
|
package/lib/lazy-result.js
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
|
+
let { isClean, my } = require('./symbols')
|
3
4
|
let MapGenerator = require('./map-generator')
|
4
|
-
let { isClean } = require('./symbols')
|
5
5
|
let stringify = require('./stringify')
|
6
|
+
let Container = require('./container')
|
7
|
+
let Document = require('./document')
|
6
8
|
let warnOnce = require('./warn-once')
|
7
9
|
let Result = require('./result')
|
8
10
|
let parse = require('./parse')
|
9
11
|
let Root = require('./root')
|
10
12
|
|
11
13
|
const TYPE_TO_CLASS_NAME = {
|
14
|
+
document: 'Document',
|
12
15
|
root: 'Root',
|
13
16
|
atrule: 'AtRule',
|
14
17
|
rule: 'Rule',
|
@@ -20,6 +23,7 @@ const PLUGIN_PROPS = {
|
|
20
23
|
postcssPlugin: true,
|
21
24
|
prepare: true,
|
22
25
|
Once: true,
|
26
|
+
Document: true,
|
23
27
|
Root: true,
|
24
28
|
Declaration: true,
|
25
29
|
Rule: true,
|
@@ -30,6 +34,7 @@ const PLUGIN_PROPS = {
|
|
30
34
|
AtRuleExit: true,
|
31
35
|
CommentExit: true,
|
32
36
|
RootExit: true,
|
37
|
+
DocumentExit: true,
|
33
38
|
OnceExit: true
|
34
39
|
}
|
35
40
|
|
@@ -73,7 +78,9 @@ function getEvents(node) {
|
|
73
78
|
|
74
79
|
function toStack(node) {
|
75
80
|
let events
|
76
|
-
if (node.type === '
|
81
|
+
if (node.type === 'document') {
|
82
|
+
events = ['Document', CHILDREN, 'DocumentExit']
|
83
|
+
} else if (node.type === 'root') {
|
77
84
|
events = ['Root', CHILDREN, 'RootExit']
|
78
85
|
} else {
|
79
86
|
events = getEvents(node)
|
@@ -103,7 +110,11 @@ class LazyResult {
|
|
103
110
|
this.processed = false
|
104
111
|
|
105
112
|
let root
|
106
|
-
if (
|
113
|
+
if (
|
114
|
+
typeof css === 'object' &&
|
115
|
+
css !== null &&
|
116
|
+
(css.type === 'root' || css.type === 'document')
|
117
|
+
) {
|
107
118
|
root = cleanMarks(css)
|
108
119
|
} else if (css instanceof LazyResult || css instanceof Result) {
|
109
120
|
root = cleanMarks(css.root)
|
@@ -124,6 +135,8 @@ class LazyResult {
|
|
124
135
|
this.processed = true
|
125
136
|
this.error = error
|
126
137
|
}
|
138
|
+
|
139
|
+
if (root && !root[my]) Container.rebuild(root)
|
127
140
|
}
|
128
141
|
|
129
142
|
this.result = new Result(processor, root, opts)
|
@@ -231,7 +244,13 @@ class LazyResult {
|
|
231
244
|
this.walkSync(root)
|
232
245
|
}
|
233
246
|
if (this.listeners.OnceExit) {
|
234
|
-
|
247
|
+
if (root.type === 'document') {
|
248
|
+
for (let subRoot of root.nodes) {
|
249
|
+
this.visitSync(this.listeners.OnceExit, subRoot)
|
250
|
+
}
|
251
|
+
} else {
|
252
|
+
this.visitSync(this.listeners.OnceExit, root)
|
253
|
+
}
|
235
254
|
}
|
236
255
|
}
|
237
256
|
|
@@ -287,7 +306,9 @@ class LazyResult {
|
|
287
306
|
} catch (e) {
|
288
307
|
throw this.handleError(e, node.proxyOf)
|
289
308
|
}
|
290
|
-
if (node.type !== 'root' && !node.parent)
|
309
|
+
if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
|
310
|
+
return true
|
311
|
+
}
|
291
312
|
if (isPromise(promise)) {
|
292
313
|
throw this.getAsyncError()
|
293
314
|
}
|
@@ -298,6 +319,18 @@ class LazyResult {
|
|
298
319
|
this.result.lastPlugin = plugin
|
299
320
|
try {
|
300
321
|
if (typeof plugin === 'object' && plugin.Once) {
|
322
|
+
if (this.result.root.type === 'document') {
|
323
|
+
let roots = this.result.root.nodes.map(root =>
|
324
|
+
plugin.Once(root, this.helpers)
|
325
|
+
)
|
326
|
+
|
327
|
+
if (isPromise(roots[0])) {
|
328
|
+
return Promise.all(roots)
|
329
|
+
}
|
330
|
+
|
331
|
+
return roots
|
332
|
+
}
|
333
|
+
|
301
334
|
return plugin.Once(this.result.root, this.helpers)
|
302
335
|
} else if (typeof plugin === 'function') {
|
303
336
|
return plugin(this.result.root, this.result)
|
@@ -385,7 +418,15 @@ class LazyResult {
|
|
385
418
|
for (let [plugin, visitor] of this.listeners.OnceExit) {
|
386
419
|
this.result.lastPlugin = plugin
|
387
420
|
try {
|
388
|
-
|
421
|
+
if (root.type === 'document') {
|
422
|
+
let roots = root.nodes.map(subRoot =>
|
423
|
+
visitor(subRoot, this.helpers)
|
424
|
+
)
|
425
|
+
|
426
|
+
await Promise.all(roots)
|
427
|
+
} else {
|
428
|
+
await visitor(root, this.helpers)
|
429
|
+
}
|
389
430
|
} catch (e) {
|
390
431
|
throw this.handleError(e)
|
391
432
|
}
|
@@ -439,7 +480,7 @@ class LazyResult {
|
|
439
480
|
let visit = stack[stack.length - 1]
|
440
481
|
let { node, visitors } = visit
|
441
482
|
|
442
|
-
if (node.type !== 'root' && !node.parent) {
|
483
|
+
if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
|
443
484
|
stack.pop()
|
444
485
|
return
|
445
486
|
}
|
@@ -501,3 +542,4 @@ module.exports = LazyResult
|
|
501
542
|
LazyResult.default = LazyResult
|
502
543
|
|
503
544
|
Root.registerLazyResult(LazyResult)
|
545
|
+
Document.registerLazyResult(LazyResult)
|
package/lib/map-generator.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
|
+
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
3
4
|
let { dirname, resolve, relative, sep } = require('path')
|
4
5
|
let { pathToFileURL } = require('url')
|
5
|
-
let { SourceMapConsumer, SourceMapGenerator } = require('source-map')
|
6
6
|
|
7
7
|
let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
|
8
8
|
let pathAvailable = Boolean(dirname && resolve && relative && sep)
|
package/lib/node.d.ts
CHANGED
@@ -5,14 +5,15 @@ import AtRule, { AtRuleProps } from './at-rule.js'
|
|
5
5
|
import Rule, { RuleProps } from './rule.js'
|
6
6
|
import { WarningOptions } from './warning.js'
|
7
7
|
import CssSyntaxError from './css-syntax-error.js'
|
8
|
-
import Container from './container.js'
|
9
8
|
import Result from './result.js'
|
10
9
|
import Input from './input.js'
|
11
10
|
import Root from './root.js'
|
11
|
+
import Document from './document.js'
|
12
|
+
import Container from './container.js'
|
12
13
|
|
13
14
|
export type ChildNode = AtRule | Rule | Declaration | Comment
|
14
15
|
|
15
|
-
export type AnyNode = AtRule | Rule | Declaration | Comment | Root
|
16
|
+
export type AnyNode = AtRule | Rule | Declaration | Comment | Root | Document
|
16
17
|
|
17
18
|
export type ChildProps =
|
18
19
|
| AtRuleProps
|
@@ -97,7 +98,7 @@ export default abstract class Node {
|
|
97
98
|
* root.nodes[0].parent === root
|
98
99
|
* ```
|
99
100
|
*/
|
100
|
-
parent: Container | undefined
|
101
|
+
parent: Document | Container | undefined
|
101
102
|
|
102
103
|
/**
|
103
104
|
* The input source of the node.
|
@@ -251,6 +252,18 @@ export default abstract class Node {
|
|
251
252
|
*/
|
252
253
|
toString(stringifier?: Stringifier | Syntax): string
|
253
254
|
|
255
|
+
/**
|
256
|
+
* Assigns properties to the current node.
|
257
|
+
*
|
258
|
+
* ```js
|
259
|
+
* decl.assign({ prop: 'word-wrap', value: 'break-word' })
|
260
|
+
* ```
|
261
|
+
*
|
262
|
+
* @param overrides New properties to override the node.
|
263
|
+
* @return Current node to methods chain.
|
264
|
+
*/
|
265
|
+
assign(overrides: object): this
|
266
|
+
|
254
267
|
/**
|
255
268
|
* Returns an exact clone of the node.
|
256
269
|
*
|
package/lib/node.js
CHANGED
@@ -84,6 +84,13 @@ class Node {
|
|
84
84
|
return result
|
85
85
|
}
|
86
86
|
|
87
|
+
assign(overrides = {}) {
|
88
|
+
for (let name in overrides) {
|
89
|
+
this[name] = overrides[name]
|
90
|
+
}
|
91
|
+
return this
|
92
|
+
}
|
93
|
+
|
87
94
|
clone(overrides = {}) {
|
88
95
|
let cloned = cloneNode(this)
|
89
96
|
for (let name in overrides) {
|
@@ -151,7 +158,9 @@ class Node {
|
|
151
158
|
|
152
159
|
root() {
|
153
160
|
let result = this
|
154
|
-
while (result.parent
|
161
|
+
while (result.parent && result.parent.type !== 'document') {
|
162
|
+
result = result.parent
|
163
|
+
}
|
155
164
|
return result
|
156
165
|
}
|
157
166
|
|
package/lib/postcss.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SourceMapGenerator, RawSourceMap } from 'source-map'
|
1
|
+
import { SourceMapGenerator, RawSourceMap } from 'source-map-js'
|
2
2
|
|
3
3
|
import Node, {
|
4
4
|
Position,
|
@@ -11,6 +11,7 @@ import Node, {
|
|
11
11
|
} from './node.js'
|
12
12
|
import Declaration, { DeclarationProps } from './declaration.js'
|
13
13
|
import Root, { RootProps } from './root.js'
|
14
|
+
import Document, { DocumentProps } from './document.js'
|
14
15
|
import Comment, { CommentProps } from './comment.js'
|
15
16
|
import AtRule, { AtRuleProps } from './at-rule.js'
|
16
17
|
import Result, { Message } from './result.js'
|
@@ -40,6 +41,7 @@ export {
|
|
40
41
|
ChildProps,
|
41
42
|
AtRuleProps,
|
42
43
|
RootProps,
|
44
|
+
DocumentProps,
|
43
45
|
Warning,
|
44
46
|
CssSyntaxError,
|
45
47
|
Node,
|
@@ -50,6 +52,7 @@ export {
|
|
50
52
|
AtRule,
|
51
53
|
Rule,
|
52
54
|
Root,
|
55
|
+
Document,
|
53
56
|
Result,
|
54
57
|
LazyResult,
|
55
58
|
Input
|
@@ -61,6 +64,10 @@ export type SourceMap = SourceMapGenerator & {
|
|
61
64
|
|
62
65
|
export type Helpers = { result: Result; postcss: Postcss } & Postcss
|
63
66
|
|
67
|
+
type DocumentProcessor = (
|
68
|
+
document: Document,
|
69
|
+
helper: Helpers
|
70
|
+
) => Promise<void> | void
|
64
71
|
type RootProcessor = (root: Root, helper: Helpers) => Promise<void> | void
|
65
72
|
type DeclarationProcessor = (
|
66
73
|
decl: Declaration,
|
@@ -74,6 +81,20 @@ type CommentProcessor = (
|
|
74
81
|
) => Promise<void> | void
|
75
82
|
|
76
83
|
interface Processors {
|
84
|
+
/**
|
85
|
+
* Will be called on `Document` node.
|
86
|
+
*
|
87
|
+
* Will be called again on children changes.
|
88
|
+
*/
|
89
|
+
Document?: DocumentProcessor
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Will be called on `Document` node, when all children will be processed.
|
93
|
+
*
|
94
|
+
* Will be called again on children changes.
|
95
|
+
*/
|
96
|
+
DocumentExit?: DocumentProcessor
|
97
|
+
|
77
98
|
/**
|
78
99
|
* Will be called on `Root` node once.
|
79
100
|
*/
|
@@ -200,11 +221,11 @@ export type AcceptedPlugin =
|
|
200
221
|
}
|
201
222
|
| Processor
|
202
223
|
|
203
|
-
export interface Parser {
|
224
|
+
export interface Parser<RootNode = Root> {
|
204
225
|
(
|
205
226
|
css: string | { toString(): string },
|
206
227
|
opts?: Pick<ProcessOptions, 'map' | 'from'>
|
207
|
-
):
|
228
|
+
): RootNode
|
208
229
|
}
|
209
230
|
|
210
231
|
export interface Builder {
|
@@ -224,7 +245,7 @@ export interface Syntax {
|
|
224
245
|
/**
|
225
246
|
* Function to generate AST by string.
|
226
247
|
*/
|
227
|
-
parse?: Parser
|
248
|
+
parse?: Parser<Root | Document>
|
228
249
|
|
229
250
|
/**
|
230
251
|
* Class to generate string by AST.
|
@@ -347,7 +368,7 @@ export interface Postcss {
|
|
347
368
|
stringify: Stringifier
|
348
369
|
|
349
370
|
/**
|
350
|
-
* Parses source css and returns a new `Root` node,
|
371
|
+
* Parses source css and returns a new `Root` or `Document` node,
|
351
372
|
* which contains the source CSS nodes.
|
352
373
|
*
|
353
374
|
* ```js
|
@@ -415,6 +436,14 @@ export interface Postcss {
|
|
415
436
|
*/
|
416
437
|
root(defaults?: RootProps): Root
|
417
438
|
|
439
|
+
/**
|
440
|
+
* Creates a new `Document` node.
|
441
|
+
*
|
442
|
+
* @param defaults Properties for the new node.
|
443
|
+
* @return New document node.
|
444
|
+
*/
|
445
|
+
document(defaults?: DocumentProps): Document
|
446
|
+
|
418
447
|
CssSyntaxError: typeof CssSyntaxError
|
419
448
|
Declaration: typeof Declaration
|
420
449
|
Container: typeof Container
|
package/lib/postcss.js
CHANGED
@@ -7,6 +7,7 @@ let Container = require('./container')
|
|
7
7
|
let Processor = require('./processor')
|
8
8
|
let stringify = require('./stringify')
|
9
9
|
let fromJSON = require('./fromJSON')
|
10
|
+
let Document = require('./document')
|
10
11
|
let Warning = require('./warning')
|
11
12
|
let Comment = require('./comment')
|
12
13
|
let AtRule = require('./at-rule')
|
@@ -73,10 +74,12 @@ postcss.atRule = defaults => new AtRule(defaults)
|
|
73
74
|
postcss.decl = defaults => new Declaration(defaults)
|
74
75
|
postcss.rule = defaults => new Rule(defaults)
|
75
76
|
postcss.root = defaults => new Root(defaults)
|
77
|
+
postcss.document = defaults => new Document(defaults)
|
76
78
|
|
77
79
|
postcss.CssSyntaxError = CssSyntaxError
|
78
80
|
postcss.Declaration = Declaration
|
79
81
|
postcss.Container = Container
|
82
|
+
postcss.Document = Document
|
80
83
|
postcss.Comment = Comment
|
81
84
|
postcss.Warning = Warning
|
82
85
|
postcss.AtRule = AtRule
|
package/lib/postcss.mjs
CHANGED
@@ -8,6 +8,7 @@ export const plugin = postcss.plugin
|
|
8
8
|
export const parse = postcss.parse
|
9
9
|
export const list = postcss.list
|
10
10
|
|
11
|
+
export const document = postcss.document
|
11
12
|
export const comment = postcss.comment
|
12
13
|
export const atRule = postcss.atRule
|
13
14
|
export const rule = postcss.rule
|
@@ -17,6 +18,7 @@ export const root = postcss.root
|
|
17
18
|
export const CssSyntaxError = postcss.CssSyntaxError
|
18
19
|
export const Declaration = postcss.Declaration
|
19
20
|
export const Container = postcss.Container
|
21
|
+
export const Document = postcss.Document
|
20
22
|
export const Comment = postcss.Comment
|
21
23
|
export const Warning = postcss.Warning
|
22
24
|
export const AtRule = postcss.AtRule
|
package/lib/previous-map.d.ts
CHANGED
package/lib/previous-map.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
|
+
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
3
4
|
let { existsSync, readFileSync } = require('fs')
|
4
5
|
let { dirname, join } = require('path')
|
5
|
-
let { SourceMapConsumer, SourceMapGenerator } = require('source-map')
|
6
6
|
|
7
7
|
function fromBase64(str) {
|
8
8
|
if (Buffer) {
|
package/lib/processor.js
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
3
|
let LazyResult = require('./lazy-result')
|
4
|
+
let Document = require('./document')
|
4
5
|
let Root = require('./root')
|
5
6
|
|
6
7
|
class Processor {
|
7
8
|
constructor(plugins = []) {
|
8
|
-
this.version = '8.
|
9
|
+
this.version = '8.3.3'
|
9
10
|
this.plugins = this.normalize(plugins)
|
10
11
|
}
|
11
12
|
|
@@ -17,7 +18,9 @@ class Processor {
|
|
17
18
|
process(css, opts = {}) {
|
18
19
|
if (
|
19
20
|
this.plugins.length === 0 &&
|
20
|
-
opts.parser ===
|
21
|
+
typeof opts.parser === 'undefined' &&
|
22
|
+
typeof opts.stringifier === 'undefined' &&
|
23
|
+
typeof opts.syntax === 'undefined' &&
|
21
24
|
!opts.hideNothingWarning
|
22
25
|
) {
|
23
26
|
if (process.env.NODE_ENV !== 'production') {
|
@@ -68,3 +71,4 @@ module.exports = Processor
|
|
68
71
|
Processor.default = Processor
|
69
72
|
|
70
73
|
Root.registerProcessor(Processor)
|
74
|
+
Document.registerProcessor(Processor)
|
package/lib/root.d.ts
CHANGED
@@ -1,13 +1,30 @@
|
|
1
1
|
import Container, { ContainerProps } from './container.js'
|
2
|
+
import Document from './document.js'
|
2
3
|
import { ProcessOptions } from './postcss.js'
|
3
4
|
import Result from './result.js'
|
4
5
|
|
5
|
-
interface RootRaws {
|
6
|
+
interface RootRaws extends Record<string, any> {
|
6
7
|
/**
|
7
8
|
* The space symbols after the last child to the end of file.
|
8
9
|
*/
|
9
10
|
after?: string
|
10
11
|
|
12
|
+
/**
|
13
|
+
* Non-CSS code before `Root`, when `Root` is inside `Document`.
|
14
|
+
*
|
15
|
+
* **Experimental:** some aspects of this node could change within minor
|
16
|
+
* or patch version releases.
|
17
|
+
*/
|
18
|
+
codeBefore?: string
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Non-CSS code after `Root`, when `Root` is inside `Document`.
|
22
|
+
*
|
23
|
+
* **Experimental:** some aspects of this node could change within minor
|
24
|
+
* or patch version releases.
|
25
|
+
*/
|
26
|
+
codeAfter?: string
|
27
|
+
|
11
28
|
/**
|
12
29
|
* Is the last child has an (optional) semicolon.
|
13
30
|
*/
|
@@ -15,6 +32,10 @@ interface RootRaws {
|
|
15
32
|
}
|
16
33
|
|
17
34
|
export interface RootProps extends ContainerProps {
|
35
|
+
/**
|
36
|
+
* Information used to generate byte-to-byte equal node string
|
37
|
+
* as it was in the origin input.
|
38
|
+
* */
|
18
39
|
raws?: RootRaws
|
19
40
|
}
|
20
41
|
|
@@ -29,11 +50,9 @@ export interface RootProps extends ContainerProps {
|
|
29
50
|
*/
|
30
51
|
export default class Root extends Container {
|
31
52
|
type: 'root'
|
32
|
-
parent: undefined
|
53
|
+
parent: Document | undefined
|
33
54
|
raws: RootRaws
|
34
55
|
|
35
|
-
constructor(defaults?: RootProps)
|
36
|
-
|
37
56
|
/**
|
38
57
|
* Returns a `Result` instance representing the root’s CSS.
|
39
58
|
*
|
@@ -48,4 +67,7 @@ export default class Root extends Container {
|
|
48
67
|
* @return Result with current root’s CSS.
|
49
68
|
*/
|
50
69
|
toResult(options?: ProcessOptions): Result
|
70
|
+
|
71
|
+
constructor(defaults?: RootProps)
|
72
|
+
assign(overrides: object | RootProps): this
|
51
73
|
}
|
package/lib/rule.d.ts
CHANGED
@@ -37,8 +37,11 @@ interface RuleRaws {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
export interface RuleProps extends ContainerProps {
|
40
|
+
/** Selector or selectors of the rule. */
|
40
41
|
selector?: string
|
42
|
+
/** Selectors of the rule represented as an array of strings. */
|
41
43
|
selectors?: string[]
|
44
|
+
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
|
42
45
|
raws?: RuleRaws
|
43
46
|
}
|
44
47
|
|
@@ -62,6 +65,7 @@ export interface RuleProps extends ContainerProps {
|
|
62
65
|
*/
|
63
66
|
export default class Rule extends Container {
|
64
67
|
type: 'rule'
|
68
|
+
parent: Container | undefined
|
65
69
|
raws: RuleRaws
|
66
70
|
|
67
71
|
/**
|
@@ -93,6 +97,7 @@ export default class Rule extends Container {
|
|
93
97
|
selectors: string[]
|
94
98
|
|
95
99
|
constructor(defaults?: RuleProps)
|
100
|
+
assign(overrides: object | RuleProps): this
|
96
101
|
clone(overrides?: Partial<RuleProps>): this
|
97
102
|
cloneBefore(overrides?: Partial<RuleProps>): this
|
98
103
|
cloneAfter(overrides?: Partial<RuleProps>): this
|
package/lib/stringifier.js
CHANGED
@@ -37,6 +37,10 @@ class Stringifier {
|
|
37
37
|
this[node.type](node, semicolon)
|
38
38
|
}
|
39
39
|
|
40
|
+
document(node) {
|
41
|
+
this.body(node)
|
42
|
+
}
|
43
|
+
|
40
44
|
root(node) {
|
41
45
|
this.body(node)
|
42
46
|
if (node.raws.after) this.builder(node.raws.after)
|
@@ -129,11 +133,16 @@ class Stringifier {
|
|
129
133
|
|
130
134
|
let parent = node.parent
|
131
135
|
|
132
|
-
// Hack for first rule in CSS
|
133
136
|
if (detect === 'before') {
|
137
|
+
// Hack for first rule in CSS
|
134
138
|
if (!parent || (parent.type === 'root' && parent.first === node)) {
|
135
139
|
return ''
|
136
140
|
}
|
141
|
+
|
142
|
+
// `root` nodes in `document` should use only their own raws
|
143
|
+
if (parent && parent.type === 'document') {
|
144
|
+
return ''
|
145
|
+
}
|
137
146
|
}
|
138
147
|
|
139
148
|
// Floating child without parent
|
package/lib/symbols.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "postcss",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.3.3",
|
4
4
|
"description": "Tool for transforming styles with JS plugins",
|
5
5
|
"engines": {
|
6
6
|
"node": "^10 || ^12 || >=14"
|
@@ -63,14 +63,14 @@
|
|
63
63
|
"dependencies": {
|
64
64
|
"colorette": "^1.2.2",
|
65
65
|
"nanoid": "^3.1.23",
|
66
|
-
"source-map": "^0.6.
|
66
|
+
"source-map-js": "^0.6.2"
|
67
67
|
},
|
68
68
|
"browser": {
|
69
69
|
"./lib/terminal-highlight": false,
|
70
|
+
"source-map-js": false,
|
70
71
|
"colorette": false,
|
71
|
-
"fs": false,
|
72
72
|
"path": false,
|
73
73
|
"url": false,
|
74
|
-
"
|
74
|
+
"fs": false
|
75
75
|
}
|
76
76
|
}
|