postcss 8.3.9 → 8.4.31
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.
- package/README.md +7 -23
- package/lib/at-rule.d.ts +58 -49
- package/lib/comment.d.ts +43 -32
- package/lib/container.d.ts +233 -223
- package/lib/container.js +251 -244
- package/lib/css-syntax-error.d.ts +117 -61
- package/lib/css-syntax-error.js +10 -3
- package/lib/declaration.d.ts +85 -61
- package/lib/document.d.ts +27 -16
- package/lib/fromJSON.d.ts +6 -2
- package/lib/input.d.ts +118 -54
- package/lib/input.js +87 -55
- package/lib/lazy-result.d.ts +82 -67
- package/lib/lazy-result.js +234 -232
- package/lib/list.d.ts +53 -47
- package/lib/list.js +16 -14
- package/lib/map-generator.js +231 -172
- package/lib/no-work-result.d.ts +46 -0
- package/lib/no-work-result.js +135 -0
- package/lib/node.d.ts +345 -253
- package/lib/node.js +200 -139
- package/lib/parse.d.ts +6 -2
- package/lib/parser.js +354 -309
- package/lib/postcss.d.mts +72 -0
- package/lib/postcss.d.ts +288 -319
- package/lib/postcss.js +18 -12
- package/lib/postcss.mjs +1 -0
- package/lib/previous-map.d.ts +23 -14
- package/lib/previous-map.js +37 -40
- package/lib/processor.d.ts +55 -41
- package/lib/processor.js +20 -27
- package/lib/result.d.ts +87 -76
- package/lib/root.d.ts +49 -36
- package/lib/root.js +12 -10
- package/lib/rule.d.ts +54 -45
- package/lib/stringifier.d.ts +46 -0
- package/lib/stringifier.js +140 -138
- package/lib/stringify.d.ts +6 -2
- package/lib/terminal-highlight.js +11 -11
- package/lib/tokenize.js +2 -2
- package/lib/warn-once.js +1 -0
- package/lib/warning.d.ts +79 -36
- package/lib/warning.js +6 -4
- package/package.json +20 -10
package/lib/root.d.ts
CHANGED
@@ -3,40 +3,45 @@ import Document from './document.js'
|
|
3
3
|
import { ProcessOptions } from './postcss.js'
|
4
4
|
import Result from './result.js'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
declare namespace Root {
|
7
|
+
export interface RootRaws extends Record<string, any> {
|
8
|
+
/**
|
9
|
+
* The space symbols after the last child to the end of file.
|
10
|
+
*/
|
11
|
+
after?: string
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
/**
|
14
|
+
* Non-CSS code after `Root`, when `Root` is inside `Document`.
|
15
|
+
*
|
16
|
+
* **Experimental:** some aspects of this node could change within minor
|
17
|
+
* or patch version releases.
|
18
|
+
*/
|
19
|
+
codeAfter?: string
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
/**
|
22
|
+
* Non-CSS code before `Root`, when `Root` is inside `Document`.
|
23
|
+
*
|
24
|
+
* **Experimental:** some aspects of this node could change within minor
|
25
|
+
* or patch version releases.
|
26
|
+
*/
|
27
|
+
codeBefore?: string
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
29
|
+
/**
|
30
|
+
* Is the last child has an (optional) semicolon.
|
31
|
+
*/
|
32
|
+
semicolon?: boolean
|
33
|
+
}
|
33
34
|
|
34
|
-
export interface RootProps extends ContainerProps {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
export interface RootProps extends ContainerProps {
|
36
|
+
/**
|
37
|
+
* Information used to generate byte-to-byte equal node string
|
38
|
+
* as it was in the origin input.
|
39
|
+
* */
|
40
|
+
raws?: RootRaws
|
41
|
+
}
|
42
|
+
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
44
|
+
export { Root_ as default }
|
40
45
|
}
|
41
46
|
|
42
47
|
/**
|
@@ -48,10 +53,17 @@ export interface RootProps extends ContainerProps {
|
|
48
53
|
* root.nodes.length //=> 2
|
49
54
|
* ```
|
50
55
|
*/
|
51
|
-
|
52
|
-
type: 'root'
|
56
|
+
declare class Root_ extends Container {
|
53
57
|
parent: Document | undefined
|
54
|
-
raws: RootRaws
|
58
|
+
raws: Root.RootRaws
|
59
|
+
type: 'root'
|
60
|
+
|
61
|
+
constructor(defaults?: Root.RootProps)
|
62
|
+
|
63
|
+
assign(overrides: object | Root.RootProps): this
|
64
|
+
clone(overrides?: Partial<Root.RootProps>): Root
|
65
|
+
cloneAfter(overrides?: Partial<Root.RootProps>): Root
|
66
|
+
cloneBefore(overrides?: Partial<Root.RootProps>): Root
|
55
67
|
|
56
68
|
/**
|
57
69
|
* Returns a `Result` instance representing the root’s CSS.
|
@@ -67,7 +79,8 @@ export default class Root extends Container {
|
|
67
79
|
* @return Result with current root’s CSS.
|
68
80
|
*/
|
69
81
|
toResult(options?: ProcessOptions): Result
|
70
|
-
|
71
|
-
constructor(defaults?: RootProps)
|
72
|
-
assign(overrides: object | RootProps): this
|
73
82
|
}
|
83
|
+
|
84
|
+
declare class Root extends Root_ {}
|
85
|
+
|
86
|
+
export = Root
|
package/lib/root.js
CHANGED
@@ -11,16 +11,6 @@ class Root extends Container {
|
|
11
11
|
if (!this.nodes) this.nodes = []
|
12
12
|
}
|
13
13
|
|
14
|
-
removeChild(child, ignore) {
|
15
|
-
let index = this.index(child)
|
16
|
-
|
17
|
-
if (!ignore && index === 0 && this.nodes.length > 1) {
|
18
|
-
this.nodes[1].raws.before = this.nodes[index].raws.before
|
19
|
-
}
|
20
|
-
|
21
|
-
return super.removeChild(child)
|
22
|
-
}
|
23
|
-
|
24
14
|
normalize(child, sample, type) {
|
25
15
|
let nodes = super.normalize(child)
|
26
16
|
|
@@ -41,6 +31,16 @@ class Root extends Container {
|
|
41
31
|
return nodes
|
42
32
|
}
|
43
33
|
|
34
|
+
removeChild(child, ignore) {
|
35
|
+
let index = this.index(child)
|
36
|
+
|
37
|
+
if (!ignore && index === 0 && this.nodes.length > 1) {
|
38
|
+
this.nodes[1].raws.before = this.nodes[index].raws.before
|
39
|
+
}
|
40
|
+
|
41
|
+
return super.removeChild(child)
|
42
|
+
}
|
43
|
+
|
44
44
|
toResult(opts = {}) {
|
45
45
|
let lazy = new LazyResult(new Processor(), this, opts)
|
46
46
|
return lazy.stringify()
|
@@ -57,3 +57,5 @@ Root.registerProcessor = dependant => {
|
|
57
57
|
|
58
58
|
module.exports = Root
|
59
59
|
Root.default = Root
|
60
|
+
|
61
|
+
Container.registerRoot(Root)
|
package/lib/rule.d.ts
CHANGED
@@ -1,48 +1,53 @@
|
|
1
1
|
import Container, { ContainerProps } from './container.js'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
declare namespace Rule {
|
4
|
+
export interface RuleRaws extends Record<string, unknown> {
|
5
|
+
/**
|
6
|
+
* The space symbols after the last child of the node to the end of the node.
|
7
|
+
*/
|
8
|
+
after?: string
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
/**
|
11
|
+
* The space symbols before the node. It also stores `*`
|
12
|
+
* and `_` symbols before the declaration (IE hack).
|
13
|
+
*/
|
14
|
+
before?: string
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
/**
|
17
|
+
* The symbols between the selector and `{` for rules.
|
18
|
+
*/
|
19
|
+
between?: string
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
/**
|
22
|
+
* Contains `true` if there is semicolon after rule.
|
23
|
+
*/
|
24
|
+
ownSemicolon?: string
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
/**
|
27
|
+
* The rule’s selector with comments.
|
28
|
+
*/
|
29
|
+
selector?: {
|
30
|
+
raw: string
|
31
|
+
value: string
|
32
|
+
}
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
value: string
|
35
|
-
raw: string
|
34
|
+
/**
|
35
|
+
* Contains `true` if the last child has an (optional) semicolon.
|
36
|
+
*/
|
37
|
+
semicolon?: boolean
|
36
38
|
}
|
37
|
-
}
|
38
39
|
|
39
|
-
export interface RuleProps extends ContainerProps {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
export interface RuleProps extends ContainerProps {
|
41
|
+
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
|
42
|
+
raws?: RuleRaws
|
43
|
+
/** Selector or selectors of the rule. */
|
44
|
+
selector?: string
|
45
|
+
/** Selectors of the rule represented as an array of strings. */
|
46
|
+
selectors?: string[]
|
47
|
+
}
|
48
|
+
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
50
|
+
export { Rule_ as default }
|
46
51
|
}
|
47
52
|
|
48
53
|
/**
|
@@ -63,11 +68,9 @@ export interface RuleProps extends ContainerProps {
|
|
63
68
|
* rule.toString() //=> 'a{}'
|
64
69
|
* ```
|
65
70
|
*/
|
66
|
-
|
67
|
-
type: 'rule'
|
71
|
+
declare class Rule_ extends Container {
|
68
72
|
parent: Container | undefined
|
69
|
-
raws: RuleRaws
|
70
|
-
|
73
|
+
raws: Rule.RuleRaws
|
71
74
|
/**
|
72
75
|
* The rule’s full selector represented as a string.
|
73
76
|
*
|
@@ -96,9 +99,15 @@ export default class Rule extends Container {
|
|
96
99
|
*/
|
97
100
|
selectors: string[]
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
type: 'rule'
|
103
|
+
|
104
|
+
constructor(defaults?: Rule.RuleProps)
|
105
|
+
assign(overrides: object | Rule.RuleProps): this
|
106
|
+
clone(overrides?: Partial<Rule.RuleProps>): Rule
|
107
|
+
cloneAfter(overrides?: Partial<Rule.RuleProps>): Rule
|
108
|
+
cloneBefore(overrides?: Partial<Rule.RuleProps>): Rule
|
104
109
|
}
|
110
|
+
|
111
|
+
declare class Rule extends Rule_ {}
|
112
|
+
|
113
|
+
export = Rule
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import {
|
2
|
+
AnyNode,
|
3
|
+
AtRule,
|
4
|
+
Builder,
|
5
|
+
Comment,
|
6
|
+
Container,
|
7
|
+
Declaration,
|
8
|
+
Document,
|
9
|
+
Root,
|
10
|
+
Rule
|
11
|
+
} from './postcss.js'
|
12
|
+
|
13
|
+
declare namespace Stringifier {
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
15
|
+
export { Stringifier_ as default }
|
16
|
+
}
|
17
|
+
|
18
|
+
declare class Stringifier_ {
|
19
|
+
builder: Builder
|
20
|
+
constructor(builder: Builder)
|
21
|
+
atrule(node: AtRule, semicolon?: boolean): void
|
22
|
+
beforeAfter(node: AnyNode, detect: 'after' | 'before'): string
|
23
|
+
block(node: AnyNode, start: string): void
|
24
|
+
body(node: Container): void
|
25
|
+
comment(node: Comment): void
|
26
|
+
decl(node: Declaration, semicolon?: boolean): void
|
27
|
+
document(node: Document): void
|
28
|
+
raw(node: AnyNode, own: null | string, detect?: string): string
|
29
|
+
rawBeforeClose(root: Root): string | undefined
|
30
|
+
rawBeforeComment(root: Root, node: Comment): string | undefined
|
31
|
+
rawBeforeDecl(root: Root, node: Declaration): string | undefined
|
32
|
+
rawBeforeOpen(root: Root): string | undefined
|
33
|
+
rawBeforeRule(root: Root): string | undefined
|
34
|
+
rawColon(root: Root): string | undefined
|
35
|
+
rawEmptyBody(root: Root): string | undefined
|
36
|
+
rawIndent(root: Root): string | undefined
|
37
|
+
rawSemicolon(root: Root): boolean | undefined
|
38
|
+
rawValue(node: AnyNode, prop: string): string
|
39
|
+
root(node: Root): void
|
40
|
+
rule(node: Rule): void
|
41
|
+
stringify(node: AnyNode, semicolon?: boolean): void
|
42
|
+
}
|
43
|
+
|
44
|
+
declare class Stringifier extends Stringifier_ {}
|
45
|
+
|
46
|
+
export = Stringifier
|
package/lib/stringifier.js
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
3
|
const DEFAULT_RAW = {
|
4
|
-
|
5
|
-
indent: ' ',
|
6
|
-
beforeDecl: '\n',
|
7
|
-
beforeRule: '\n',
|
8
|
-
beforeOpen: ' ',
|
4
|
+
after: '\n',
|
9
5
|
beforeClose: '\n',
|
10
6
|
beforeComment: '\n',
|
11
|
-
|
12
|
-
|
7
|
+
beforeDecl: '\n',
|
8
|
+
beforeOpen: ' ',
|
9
|
+
beforeRule: '\n',
|
10
|
+
colon: ': ',
|
13
11
|
commentLeft: ' ',
|
14
12
|
commentRight: ' ',
|
13
|
+
emptyBody: '',
|
14
|
+
indent: ' ',
|
15
15
|
semicolon: false
|
16
16
|
}
|
17
17
|
|
@@ -24,53 +24,6 @@ class Stringifier {
|
|
24
24
|
this.builder = builder
|
25
25
|
}
|
26
26
|
|
27
|
-
stringify(node, semicolon) {
|
28
|
-
/* istanbul ignore if */
|
29
|
-
if (!this[node.type]) {
|
30
|
-
throw new Error(
|
31
|
-
'Unknown AST node type ' +
|
32
|
-
node.type +
|
33
|
-
'. ' +
|
34
|
-
'Maybe you need to change PostCSS stringifier.'
|
35
|
-
)
|
36
|
-
}
|
37
|
-
this[node.type](node, semicolon)
|
38
|
-
}
|
39
|
-
|
40
|
-
document(node) {
|
41
|
-
this.body(node)
|
42
|
-
}
|
43
|
-
|
44
|
-
root(node) {
|
45
|
-
this.body(node)
|
46
|
-
if (node.raws.after) this.builder(node.raws.after)
|
47
|
-
}
|
48
|
-
|
49
|
-
comment(node) {
|
50
|
-
let left = this.raw(node, 'left', 'commentLeft')
|
51
|
-
let right = this.raw(node, 'right', 'commentRight')
|
52
|
-
this.builder('/*' + left + node.text + right + '*/', node)
|
53
|
-
}
|
54
|
-
|
55
|
-
decl(node, semicolon) {
|
56
|
-
let between = this.raw(node, 'between', 'colon')
|
57
|
-
let string = node.prop + between + this.rawValue(node, 'value')
|
58
|
-
|
59
|
-
if (node.important) {
|
60
|
-
string += node.raws.important || ' !important'
|
61
|
-
}
|
62
|
-
|
63
|
-
if (semicolon) string += ';'
|
64
|
-
this.builder(string, node)
|
65
|
-
}
|
66
|
-
|
67
|
-
rule(node) {
|
68
|
-
this.block(node, this.rawValue(node, 'selector'))
|
69
|
-
if (node.raws.ownSemicolon) {
|
70
|
-
this.builder(node.raws.ownSemicolon, node, 'end')
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
27
|
atrule(node, semicolon) {
|
75
28
|
let name = '@' + node.name
|
76
29
|
let params = node.params ? this.rawValue(node, 'params') : ''
|
@@ -89,20 +42,33 @@ class Stringifier {
|
|
89
42
|
}
|
90
43
|
}
|
91
44
|
|
92
|
-
|
93
|
-
let
|
94
|
-
|
95
|
-
|
96
|
-
|
45
|
+
beforeAfter(node, detect) {
|
46
|
+
let value
|
47
|
+
if (node.type === 'decl') {
|
48
|
+
value = this.raw(node, null, 'beforeDecl')
|
49
|
+
} else if (node.type === 'comment') {
|
50
|
+
value = this.raw(node, null, 'beforeComment')
|
51
|
+
} else if (detect === 'before') {
|
52
|
+
value = this.raw(node, null, 'beforeRule')
|
53
|
+
} else {
|
54
|
+
value = this.raw(node, null, 'beforeClose')
|
97
55
|
}
|
98
56
|
|
99
|
-
let
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
this.stringify(child, last !== i || semicolon)
|
57
|
+
let buf = node.parent
|
58
|
+
let depth = 0
|
59
|
+
while (buf && buf.type !== 'root') {
|
60
|
+
depth += 1
|
61
|
+
buf = buf.parent
|
105
62
|
}
|
63
|
+
|
64
|
+
if (value.includes('\n')) {
|
65
|
+
let indent = this.raw(node, null, 'indent')
|
66
|
+
if (indent.length) {
|
67
|
+
for (let step = 0; step < depth; step++) value += indent
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
return value
|
106
72
|
}
|
107
73
|
|
108
74
|
block(node, start) {
|
@@ -121,6 +87,44 @@ class Stringifier {
|
|
121
87
|
this.builder('}', node, 'end')
|
122
88
|
}
|
123
89
|
|
90
|
+
body(node) {
|
91
|
+
let last = node.nodes.length - 1
|
92
|
+
while (last > 0) {
|
93
|
+
if (node.nodes[last].type !== 'comment') break
|
94
|
+
last -= 1
|
95
|
+
}
|
96
|
+
|
97
|
+
let semicolon = this.raw(node, 'semicolon')
|
98
|
+
for (let i = 0; i < node.nodes.length; i++) {
|
99
|
+
let child = node.nodes[i]
|
100
|
+
let before = this.raw(child, 'before')
|
101
|
+
if (before) this.builder(before)
|
102
|
+
this.stringify(child, last !== i || semicolon)
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
comment(node) {
|
107
|
+
let left = this.raw(node, 'left', 'commentLeft')
|
108
|
+
let right = this.raw(node, 'right', 'commentRight')
|
109
|
+
this.builder('/*' + left + node.text + right + '*/', node)
|
110
|
+
}
|
111
|
+
|
112
|
+
decl(node, semicolon) {
|
113
|
+
let between = this.raw(node, 'between', 'colon')
|
114
|
+
let string = node.prop + between + this.rawValue(node, 'value')
|
115
|
+
|
116
|
+
if (node.important) {
|
117
|
+
string += node.raws.important || ' !important'
|
118
|
+
}
|
119
|
+
|
120
|
+
if (semicolon) string += ';'
|
121
|
+
this.builder(string, node)
|
122
|
+
}
|
123
|
+
|
124
|
+
document(node) {
|
125
|
+
this.body(node)
|
126
|
+
}
|
127
|
+
|
124
128
|
raw(node, own, detect) {
|
125
129
|
let value
|
126
130
|
if (!detect) detect = own
|
@@ -175,42 +179,20 @@ class Stringifier {
|
|
175
179
|
return value
|
176
180
|
}
|
177
181
|
|
178
|
-
|
179
|
-
let value
|
180
|
-
root.walk(i => {
|
181
|
-
if (i.nodes && i.nodes.length && i.last.type === 'decl') {
|
182
|
-
value = i.raws.semicolon
|
183
|
-
if (typeof value !== 'undefined') return false
|
184
|
-
}
|
185
|
-
})
|
186
|
-
return value
|
187
|
-
}
|
188
|
-
|
189
|
-
rawEmptyBody(root) {
|
190
|
-
let value
|
191
|
-
root.walk(i => {
|
192
|
-
if (i.nodes && i.nodes.length === 0) {
|
193
|
-
value = i.raws.after
|
194
|
-
if (typeof value !== 'undefined') return false
|
195
|
-
}
|
196
|
-
})
|
197
|
-
return value
|
198
|
-
}
|
199
|
-
|
200
|
-
rawIndent(root) {
|
201
|
-
if (root.raws.indent) return root.raws.indent
|
182
|
+
rawBeforeClose(root) {
|
202
183
|
let value
|
203
184
|
root.walk(i => {
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
185
|
+
if (i.nodes && i.nodes.length > 0) {
|
186
|
+
if (typeof i.raws.after !== 'undefined') {
|
187
|
+
value = i.raws.after
|
188
|
+
if (value.includes('\n')) {
|
189
|
+
value = value.replace(/[^\n]+$/, '')
|
190
|
+
}
|
210
191
|
return false
|
211
192
|
}
|
212
193
|
}
|
213
194
|
})
|
195
|
+
if (value) value = value.replace(/\S/g, '')
|
214
196
|
return value
|
215
197
|
}
|
216
198
|
|
@@ -252,6 +234,17 @@ class Stringifier {
|
|
252
234
|
return value
|
253
235
|
}
|
254
236
|
|
237
|
+
rawBeforeOpen(root) {
|
238
|
+
let value
|
239
|
+
root.walk(i => {
|
240
|
+
if (i.type !== 'decl') {
|
241
|
+
value = i.raws.between
|
242
|
+
if (typeof value !== 'undefined') return false
|
243
|
+
}
|
244
|
+
})
|
245
|
+
return value
|
246
|
+
}
|
247
|
+
|
255
248
|
rawBeforeRule(root) {
|
256
249
|
let value
|
257
250
|
root.walk(i => {
|
@@ -269,71 +262,53 @@ class Stringifier {
|
|
269
262
|
return value
|
270
263
|
}
|
271
264
|
|
272
|
-
|
265
|
+
rawColon(root) {
|
273
266
|
let value
|
274
|
-
root.
|
275
|
-
if (
|
276
|
-
|
277
|
-
|
278
|
-
if (value.includes('\n')) {
|
279
|
-
value = value.replace(/[^\n]+$/, '')
|
280
|
-
}
|
281
|
-
return false
|
282
|
-
}
|
267
|
+
root.walkDecls(i => {
|
268
|
+
if (typeof i.raws.between !== 'undefined') {
|
269
|
+
value = i.raws.between.replace(/[^\s:]/g, '')
|
270
|
+
return false
|
283
271
|
}
|
284
272
|
})
|
285
|
-
if (value) value = value.replace(/\S/g, '')
|
286
273
|
return value
|
287
274
|
}
|
288
275
|
|
289
|
-
|
276
|
+
rawEmptyBody(root) {
|
290
277
|
let value
|
291
278
|
root.walk(i => {
|
292
|
-
if (i.
|
293
|
-
value = i.raws.
|
279
|
+
if (i.nodes && i.nodes.length === 0) {
|
280
|
+
value = i.raws.after
|
294
281
|
if (typeof value !== 'undefined') return false
|
295
282
|
}
|
296
283
|
})
|
297
284
|
return value
|
298
285
|
}
|
299
286
|
|
300
|
-
|
287
|
+
rawIndent(root) {
|
288
|
+
if (root.raws.indent) return root.raws.indent
|
301
289
|
let value
|
302
|
-
root.
|
303
|
-
|
304
|
-
|
305
|
-
|
290
|
+
root.walk(i => {
|
291
|
+
let p = i.parent
|
292
|
+
if (p && p !== root && p.parent && p.parent === root) {
|
293
|
+
if (typeof i.raws.before !== 'undefined') {
|
294
|
+
let parts = i.raws.before.split('\n')
|
295
|
+
value = parts[parts.length - 1]
|
296
|
+
value = value.replace(/\S/g, '')
|
297
|
+
return false
|
298
|
+
}
|
306
299
|
}
|
307
300
|
})
|
308
301
|
return value
|
309
302
|
}
|
310
303
|
|
311
|
-
|
304
|
+
rawSemicolon(root) {
|
312
305
|
let value
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
} else if (detect === 'before') {
|
318
|
-
value = this.raw(node, null, 'beforeRule')
|
319
|
-
} else {
|
320
|
-
value = this.raw(node, null, 'beforeClose')
|
321
|
-
}
|
322
|
-
|
323
|
-
let buf = node.parent
|
324
|
-
let depth = 0
|
325
|
-
while (buf && buf.type !== 'root') {
|
326
|
-
depth += 1
|
327
|
-
buf = buf.parent
|
328
|
-
}
|
329
|
-
|
330
|
-
if (value.includes('\n')) {
|
331
|
-
let indent = this.raw(node, null, 'indent')
|
332
|
-
if (indent.length) {
|
333
|
-
for (let step = 0; step < depth; step++) value += indent
|
306
|
+
root.walk(i => {
|
307
|
+
if (i.nodes && i.nodes.length && i.last.type === 'decl') {
|
308
|
+
value = i.raws.semicolon
|
309
|
+
if (typeof value !== 'undefined') return false
|
334
310
|
}
|
335
|
-
}
|
336
|
-
|
311
|
+
})
|
337
312
|
return value
|
338
313
|
}
|
339
314
|
|
@@ -346,6 +321,33 @@ class Stringifier {
|
|
346
321
|
|
347
322
|
return value
|
348
323
|
}
|
324
|
+
|
325
|
+
root(node) {
|
326
|
+
this.body(node)
|
327
|
+
if (node.raws.after) this.builder(node.raws.after)
|
328
|
+
}
|
329
|
+
|
330
|
+
rule(node) {
|
331
|
+
this.block(node, this.rawValue(node, 'selector'))
|
332
|
+
if (node.raws.ownSemicolon) {
|
333
|
+
this.builder(node.raws.ownSemicolon, node, 'end')
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
stringify(node, semicolon) {
|
338
|
+
/* c8 ignore start */
|
339
|
+
if (!this[node.type]) {
|
340
|
+
throw new Error(
|
341
|
+
'Unknown AST node type ' +
|
342
|
+
node.type +
|
343
|
+
'. ' +
|
344
|
+
'Maybe you need to change PostCSS stringifier.'
|
345
|
+
)
|
346
|
+
}
|
347
|
+
/* c8 ignore stop */
|
348
|
+
this[node.type](node, semicolon)
|
349
|
+
}
|
349
350
|
}
|
350
351
|
|
351
352
|
module.exports = Stringifier
|
353
|
+
Stringifier.default = Stringifier
|