postcss 8.4.24 → 8.4.25
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 +19 -19
- package/lib/comment.d.ts +12 -10
- package/lib/container.d.ts +212 -212
- package/lib/container.js +239 -239
- package/lib/css-syntax-error.d.ts +95 -95
- package/lib/css-syntax-error.js +1 -1
- package/lib/declaration.d.ts +55 -42
- package/lib/document.d.ts +1 -1
- package/lib/input.d.ts +70 -70
- package/lib/input.js +64 -64
- package/lib/lazy-result.d.ts +54 -54
- package/lib/lazy-result.js +226 -226
- package/lib/list.d.ts +14 -14
- package/lib/list.js +9 -9
- package/lib/map-generator.js +188 -188
- package/lib/no-work-result.d.ts +12 -12
- package/lib/no-work-result.js +30 -30
- package/lib/node.d.ts +277 -230
- package/lib/node.js +201 -199
- package/lib/parser.js +286 -286
- package/lib/postcss.d.ts +124 -124
- package/lib/previous-map.d.ts +13 -13
- package/lib/previous-map.js +33 -33
- package/lib/processor.d.ts +37 -37
- package/lib/processor.js +19 -19
- package/lib/result.d.ts +44 -44
- package/lib/result.js +4 -4
- package/lib/root.d.ts +8 -8
- package/lib/root.js +10 -10
- package/lib/rule.d.ts +16 -16
- package/lib/stringifier.d.ts +21 -21
- package/lib/stringifier.js +139 -139
- package/lib/terminal-highlight.js +11 -11
- package/lib/tokenize.js +1 -1
- package/lib/warning.d.ts +38 -38
- package/lib/warning.js +1 -1
- package/package.json +1 -1
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,54 +24,6 @@ class Stringifier {
|
|
24
24
|
this.builder = builder
|
25
25
|
}
|
26
26
|
|
27
|
-
stringify(node, semicolon) {
|
28
|
-
/* c8 ignore start */
|
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
|
-
/* c8 ignore stop */
|
38
|
-
this[node.type](node, semicolon)
|
39
|
-
}
|
40
|
-
|
41
|
-
document(node) {
|
42
|
-
this.body(node)
|
43
|
-
}
|
44
|
-
|
45
|
-
root(node) {
|
46
|
-
this.body(node)
|
47
|
-
if (node.raws.after) this.builder(node.raws.after)
|
48
|
-
}
|
49
|
-
|
50
|
-
comment(node) {
|
51
|
-
let left = this.raw(node, 'left', 'commentLeft')
|
52
|
-
let right = this.raw(node, 'right', 'commentRight')
|
53
|
-
this.builder('/*' + left + node.text + right + '*/', node)
|
54
|
-
}
|
55
|
-
|
56
|
-
decl(node, semicolon) {
|
57
|
-
let between = this.raw(node, 'between', 'colon')
|
58
|
-
let string = node.prop + between + this.rawValue(node, 'value')
|
59
|
-
|
60
|
-
if (node.important) {
|
61
|
-
string += node.raws.important || ' !important'
|
62
|
-
}
|
63
|
-
|
64
|
-
if (semicolon) string += ';'
|
65
|
-
this.builder(string, node)
|
66
|
-
}
|
67
|
-
|
68
|
-
rule(node) {
|
69
|
-
this.block(node, this.rawValue(node, 'selector'))
|
70
|
-
if (node.raws.ownSemicolon) {
|
71
|
-
this.builder(node.raws.ownSemicolon, node, 'end')
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
27
|
atrule(node, semicolon) {
|
76
28
|
let name = '@' + node.name
|
77
29
|
let params = node.params ? this.rawValue(node, 'params') : ''
|
@@ -90,20 +42,33 @@ class Stringifier {
|
|
90
42
|
}
|
91
43
|
}
|
92
44
|
|
93
|
-
|
94
|
-
let
|
95
|
-
|
96
|
-
|
97
|
-
|
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')
|
98
55
|
}
|
99
56
|
|
100
|
-
let
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
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
|
106
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
|
107
72
|
}
|
108
73
|
|
109
74
|
block(node, start) {
|
@@ -122,6 +87,44 @@ class Stringifier {
|
|
122
87
|
this.builder('}', node, 'end')
|
123
88
|
}
|
124
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
|
+
|
125
128
|
raw(node, own, detect) {
|
126
129
|
let value
|
127
130
|
if (!detect) detect = own
|
@@ -176,42 +179,20 @@ class Stringifier {
|
|
176
179
|
return value
|
177
180
|
}
|
178
181
|
|
179
|
-
|
180
|
-
let value
|
181
|
-
root.walk(i => {
|
182
|
-
if (i.nodes && i.nodes.length && i.last.type === 'decl') {
|
183
|
-
value = i.raws.semicolon
|
184
|
-
if (typeof value !== 'undefined') return false
|
185
|
-
}
|
186
|
-
})
|
187
|
-
return value
|
188
|
-
}
|
189
|
-
|
190
|
-
rawEmptyBody(root) {
|
191
|
-
let value
|
192
|
-
root.walk(i => {
|
193
|
-
if (i.nodes && i.nodes.length === 0) {
|
194
|
-
value = i.raws.after
|
195
|
-
if (typeof value !== 'undefined') return false
|
196
|
-
}
|
197
|
-
})
|
198
|
-
return value
|
199
|
-
}
|
200
|
-
|
201
|
-
rawIndent(root) {
|
202
|
-
if (root.raws.indent) return root.raws.indent
|
182
|
+
rawBeforeClose(root) {
|
203
183
|
let value
|
204
184
|
root.walk(i => {
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
+
}
|
211
191
|
return false
|
212
192
|
}
|
213
193
|
}
|
214
194
|
})
|
195
|
+
if (value) value = value.replace(/\S/g, '')
|
215
196
|
return value
|
216
197
|
}
|
217
198
|
|
@@ -253,6 +234,17 @@ class Stringifier {
|
|
253
234
|
return value
|
254
235
|
}
|
255
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
|
+
|
256
248
|
rawBeforeRule(root) {
|
257
249
|
let value
|
258
250
|
root.walk(i => {
|
@@ -270,71 +262,53 @@ class Stringifier {
|
|
270
262
|
return value
|
271
263
|
}
|
272
264
|
|
273
|
-
|
265
|
+
rawColon(root) {
|
274
266
|
let value
|
275
|
-
root.
|
276
|
-
if (
|
277
|
-
|
278
|
-
|
279
|
-
if (value.includes('\n')) {
|
280
|
-
value = value.replace(/[^\n]+$/, '')
|
281
|
-
}
|
282
|
-
return false
|
283
|
-
}
|
267
|
+
root.walkDecls(i => {
|
268
|
+
if (typeof i.raws.between !== 'undefined') {
|
269
|
+
value = i.raws.between.replace(/[^\s:]/g, '')
|
270
|
+
return false
|
284
271
|
}
|
285
272
|
})
|
286
|
-
if (value) value = value.replace(/\S/g, '')
|
287
273
|
return value
|
288
274
|
}
|
289
275
|
|
290
|
-
|
276
|
+
rawEmptyBody(root) {
|
291
277
|
let value
|
292
278
|
root.walk(i => {
|
293
|
-
if (i.
|
294
|
-
value = i.raws.
|
279
|
+
if (i.nodes && i.nodes.length === 0) {
|
280
|
+
value = i.raws.after
|
295
281
|
if (typeof value !== 'undefined') return false
|
296
282
|
}
|
297
283
|
})
|
298
284
|
return value
|
299
285
|
}
|
300
286
|
|
301
|
-
|
287
|
+
rawIndent(root) {
|
288
|
+
if (root.raws.indent) return root.raws.indent
|
302
289
|
let value
|
303
|
-
root.
|
304
|
-
|
305
|
-
|
306
|
-
|
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
|
+
}
|
307
299
|
}
|
308
300
|
})
|
309
301
|
return value
|
310
302
|
}
|
311
303
|
|
312
|
-
|
304
|
+
rawSemicolon(root) {
|
313
305
|
let value
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
} else if (detect === 'before') {
|
319
|
-
value = this.raw(node, null, 'beforeRule')
|
320
|
-
} else {
|
321
|
-
value = this.raw(node, null, 'beforeClose')
|
322
|
-
}
|
323
|
-
|
324
|
-
let buf = node.parent
|
325
|
-
let depth = 0
|
326
|
-
while (buf && buf.type !== 'root') {
|
327
|
-
depth += 1
|
328
|
-
buf = buf.parent
|
329
|
-
}
|
330
|
-
|
331
|
-
if (value.includes('\n')) {
|
332
|
-
let indent = this.raw(node, null, 'indent')
|
333
|
-
if (indent.length) {
|
334
|
-
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
|
335
310
|
}
|
336
|
-
}
|
337
|
-
|
311
|
+
})
|
338
312
|
return value
|
339
313
|
}
|
340
314
|
|
@@ -347,6 +321,32 @@ class Stringifier {
|
|
347
321
|
|
348
322
|
return value
|
349
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
|
+
}
|
350
350
|
}
|
351
351
|
|
352
352
|
module.exports = Stringifier
|
@@ -11,21 +11,21 @@ function registerInput(dependant) {
|
|
11
11
|
}
|
12
12
|
|
13
13
|
const HIGHLIGHT_THEME = {
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'comment': pico.gray,
|
17
|
-
'string': pico.green,
|
18
|
-
'class': pico.yellow,
|
19
|
-
'hash': pico.magenta,
|
20
|
-
'call': pico.cyan,
|
14
|
+
';': pico.yellow,
|
15
|
+
':': pico.yellow,
|
21
16
|
'(': pico.cyan,
|
22
17
|
')': pico.cyan,
|
23
|
-
'{': pico.yellow,
|
24
|
-
'}': pico.yellow,
|
25
18
|
'[': pico.yellow,
|
26
19
|
']': pico.yellow,
|
27
|
-
'
|
28
|
-
'
|
20
|
+
'{': pico.yellow,
|
21
|
+
'}': pico.yellow,
|
22
|
+
'at-word': pico.cyan,
|
23
|
+
'brackets': pico.cyan,
|
24
|
+
'call': pico.cyan,
|
25
|
+
'class': pico.yellow,
|
26
|
+
'comment': pico.gray,
|
27
|
+
'hash': pico.magenta,
|
28
|
+
'string': pico.green
|
29
29
|
}
|
30
30
|
|
31
31
|
function getTokenType([type, value], processor) {
|
package/lib/tokenize.js
CHANGED
package/lib/warning.d.ts
CHANGED
@@ -4,14 +4,14 @@ import Node from './node.js'
|
|
4
4
|
declare namespace Warning {
|
5
5
|
export interface WarningOptions {
|
6
6
|
/**
|
7
|
-
* CSS node that caused the warning.
|
7
|
+
* End position, exclusive, in CSS node string that caused the warning.
|
8
8
|
*/
|
9
|
-
|
9
|
+
end?: RangePosition
|
10
10
|
|
11
11
|
/**
|
12
|
-
*
|
12
|
+
* End index, exclusive, in CSS node string that caused the warning.
|
13
13
|
*/
|
14
|
-
|
14
|
+
endIndex?: number
|
15
15
|
|
16
16
|
/**
|
17
17
|
* Start index, inclusive, in CSS node string that caused the warning.
|
@@ -19,25 +19,25 @@ declare namespace Warning {
|
|
19
19
|
index?: number
|
20
20
|
|
21
21
|
/**
|
22
|
-
*
|
22
|
+
* CSS node that caused the warning.
|
23
23
|
*/
|
24
|
-
|
24
|
+
node?: Node
|
25
25
|
|
26
26
|
/**
|
27
|
-
*
|
27
|
+
* Name of the plugin that created this warning. `Result#warn` fills
|
28
|
+
* this property automatically.
|
28
29
|
*/
|
29
|
-
|
30
|
+
plugin?: string
|
30
31
|
|
31
32
|
/**
|
32
|
-
*
|
33
|
+
* Start position, inclusive, in CSS node string that caused the warning.
|
33
34
|
*/
|
34
|
-
|
35
|
+
start?: RangePosition
|
35
36
|
|
36
37
|
/**
|
37
|
-
*
|
38
|
-
* this property automatically.
|
38
|
+
* Word in CSS source that caused the warning.
|
39
39
|
*/
|
40
|
-
|
40
|
+
word?: string
|
41
41
|
}
|
42
42
|
|
43
43
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
@@ -55,38 +55,31 @@ declare namespace Warning {
|
|
55
55
|
*/
|
56
56
|
declare class Warning_ {
|
57
57
|
/**
|
58
|
-
*
|
59
|
-
* Always equal to `"warning"`.
|
60
|
-
*/
|
61
|
-
type: 'warning'
|
62
|
-
|
63
|
-
/**
|
64
|
-
* The warning message.
|
58
|
+
* Column for inclusive start position in the input file with this warning’s source.
|
65
59
|
*
|
66
60
|
* ```js
|
67
|
-
* warning.
|
61
|
+
* warning.column //=> 6
|
68
62
|
* ```
|
69
63
|
*/
|
70
|
-
|
64
|
+
column: number
|
71
65
|
|
72
66
|
/**
|
73
|
-
*
|
74
|
-
* When you call `Node#warn` it will fill this property automatically.
|
67
|
+
* Column for exclusive end position in the input file with this warning’s source.
|
75
68
|
*
|
76
69
|
* ```js
|
77
|
-
* warning.
|
70
|
+
* warning.endColumn //=> 4
|
78
71
|
* ```
|
79
72
|
*/
|
80
|
-
|
73
|
+
endColumn?: number
|
81
74
|
|
82
75
|
/**
|
83
|
-
*
|
76
|
+
* Line for exclusive end position in the input file with this warning’s source.
|
84
77
|
*
|
85
78
|
* ```js
|
86
|
-
* warning.
|
79
|
+
* warning.endLine //=> 6
|
87
80
|
* ```
|
88
81
|
*/
|
89
|
-
|
82
|
+
endLine?: number
|
90
83
|
|
91
84
|
/**
|
92
85
|
* Line for inclusive start position in the input file with this warning’s source.
|
@@ -98,31 +91,38 @@ declare class Warning_ {
|
|
98
91
|
line: number
|
99
92
|
|
100
93
|
/**
|
101
|
-
*
|
94
|
+
* Contains the CSS node that caused the warning.
|
102
95
|
*
|
103
96
|
* ```js
|
104
|
-
* warning.
|
97
|
+
* warning.node.toString() //=> 'color: white !important'
|
105
98
|
* ```
|
106
99
|
*/
|
107
|
-
|
100
|
+
node: Node
|
108
101
|
|
109
102
|
/**
|
110
|
-
*
|
103
|
+
* The name of the plugin that created this warning.
|
104
|
+
* When you call `Node#warn` it will fill this property automatically.
|
111
105
|
*
|
112
106
|
* ```js
|
113
|
-
* warning.
|
107
|
+
* warning.plugin //=> 'postcss-important'
|
114
108
|
* ```
|
115
109
|
*/
|
116
|
-
|
110
|
+
plugin: string
|
117
111
|
|
118
112
|
/**
|
119
|
-
*
|
113
|
+
* The warning message.
|
120
114
|
*
|
121
115
|
* ```js
|
122
|
-
* warning.
|
116
|
+
* warning.text //=> 'Try to avoid !important'
|
123
117
|
* ```
|
124
118
|
*/
|
125
|
-
|
119
|
+
text: string
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Type to filter warnings from `Result#messages`.
|
123
|
+
* Always equal to `"warning"`.
|
124
|
+
*/
|
125
|
+
type: 'warning'
|
126
126
|
|
127
127
|
/**
|
128
128
|
* @param text Warning message.
|
package/lib/warning.js
CHANGED