postcss 8.4.23 → 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.

@@ -11,37 +11,37 @@ let parse = require('./parse')
11
11
  let Root = require('./root')
12
12
 
13
13
  const TYPE_TO_CLASS_NAME = {
14
- document: 'Document',
15
- root: 'Root',
16
14
  atrule: 'AtRule',
17
- rule: 'Rule',
15
+ comment: 'Comment',
18
16
  decl: 'Declaration',
19
- comment: 'Comment'
17
+ document: 'Document',
18
+ root: 'Root',
19
+ rule: 'Rule'
20
20
  }
21
21
 
22
22
  const PLUGIN_PROPS = {
23
- postcssPlugin: true,
24
- prepare: true,
25
- Once: true,
26
- Document: true,
27
- Root: true,
28
- Declaration: true,
29
- Rule: true,
30
23
  AtRule: true,
31
- Comment: true,
32
- DeclarationExit: true,
33
- RuleExit: true,
34
24
  AtRuleExit: true,
25
+ Comment: true,
35
26
  CommentExit: true,
36
- RootExit: true,
27
+ Declaration: true,
28
+ DeclarationExit: true,
29
+ Document: true,
37
30
  DocumentExit: true,
38
- OnceExit: true
31
+ Once: true,
32
+ OnceExit: true,
33
+ postcssPlugin: true,
34
+ prepare: true,
35
+ Root: true,
36
+ RootExit: true,
37
+ Rule: true,
38
+ RuleExit: true
39
39
  }
40
40
 
41
41
  const NOT_VISITORS = {
42
+ Once: true,
42
43
  postcssPlugin: true,
43
- prepare: true,
44
- Once: true
44
+ prepare: true
45
45
  }
46
46
 
47
47
  const CHILDREN = 0
@@ -87,12 +87,12 @@ function toStack(node) {
87
87
  }
88
88
 
89
89
  return {
90
- node,
91
- events,
92
90
  eventIndex: 0,
93
- visitors: [],
91
+ events,
92
+ iterator: 0,
93
+ node,
94
94
  visitorIndex: 0,
95
- iterator: 0
95
+ visitors: []
96
96
  }
97
97
  }
98
98
 
@@ -143,7 +143,7 @@ class LazyResult {
143
143
  }
144
144
 
145
145
  this.result = new Result(processor, root, opts)
146
- this.helpers = { ...postcss, result: this.result, postcss }
146
+ this.helpers = { ...postcss, postcss, result: this.result }
147
147
  this.plugins = this.processor.plugins.map(plugin => {
148
148
  if (typeof plugin === 'object' && plugin.prepare) {
149
149
  return { ...plugin, ...plugin.prepare(this.result) }
@@ -153,67 +153,6 @@ class LazyResult {
153
153
  })
154
154
  }
155
155
 
156
- get [Symbol.toStringTag]() {
157
- return 'LazyResult'
158
- }
159
-
160
- get processor() {
161
- return this.result.processor
162
- }
163
-
164
- get opts() {
165
- return this.result.opts
166
- }
167
-
168
- get css() {
169
- return this.stringify().css
170
- }
171
-
172
- get content() {
173
- return this.stringify().content
174
- }
175
-
176
- get map() {
177
- return this.stringify().map
178
- }
179
-
180
- get root() {
181
- return this.sync().root
182
- }
183
-
184
- get messages() {
185
- return this.sync().messages
186
- }
187
-
188
- warnings() {
189
- return this.sync().warnings()
190
- }
191
-
192
- toString() {
193
- return this.css
194
- }
195
-
196
- then(onFulfilled, onRejected) {
197
- if (process.env.NODE_ENV !== 'production') {
198
- if (!('from' in this.opts)) {
199
- warnOnce(
200
- 'Without `from` option PostCSS could generate wrong source map ' +
201
- 'and will not find Browserslist config. Set it to CSS file path ' +
202
- 'or to `undefined` to prevent this warning.'
203
- )
204
- }
205
- }
206
- return this.async().then(onFulfilled, onRejected)
207
- }
208
-
209
- catch(onRejected) {
210
- return this.async().catch(onRejected)
211
- }
212
-
213
- finally(onFinally) {
214
- return this.async().then(onFinally, onFinally)
215
- }
216
-
217
156
  async() {
218
157
  if (this.error) return Promise.reject(this.error)
219
158
  if (this.processed) return Promise.resolve(this.result)
@@ -223,124 +162,20 @@ class LazyResult {
223
162
  return this.processing
224
163
  }
225
164
 
226
- sync() {
227
- if (this.error) throw this.error
228
- if (this.processed) return this.result
229
- this.processed = true
230
-
231
- if (this.processing) {
232
- throw this.getAsyncError()
233
- }
234
-
235
- for (let plugin of this.plugins) {
236
- let promise = this.runOnRoot(plugin)
237
- if (isPromise(promise)) {
238
- throw this.getAsyncError()
239
- }
240
- }
241
-
242
- this.prepareVisitors()
243
- if (this.hasListener) {
244
- let root = this.result.root
245
- while (!root[isClean]) {
246
- root[isClean] = true
247
- this.walkSync(root)
248
- }
249
- if (this.listeners.OnceExit) {
250
- if (root.type === 'document') {
251
- for (let subRoot of root.nodes) {
252
- this.visitSync(this.listeners.OnceExit, subRoot)
253
- }
254
- } else {
255
- this.visitSync(this.listeners.OnceExit, root)
256
- }
257
- }
258
- }
259
-
260
- return this.result
261
- }
262
-
263
- stringify() {
264
- if (this.error) throw this.error
265
- if (this.stringified) return this.result
266
- this.stringified = true
267
-
268
- this.sync()
269
-
270
- let opts = this.result.opts
271
- let str = stringify
272
- if (opts.syntax) str = opts.syntax.stringify
273
- if (opts.stringifier) str = opts.stringifier
274
- if (str.stringify) str = str.stringify
275
-
276
- let map = new MapGenerator(str, this.result.root, this.result.opts)
277
- let data = map.generate()
278
- this.result.css = data[0]
279
- this.result.map = data[1]
280
-
281
- return this.result
165
+ catch(onRejected) {
166
+ return this.async().catch(onRejected)
282
167
  }
283
168
 
284
- walkSync(node) {
285
- node[isClean] = true
286
- let events = getEvents(node)
287
- for (let event of events) {
288
- if (event === CHILDREN) {
289
- if (node.nodes) {
290
- node.each(child => {
291
- if (!child[isClean]) this.walkSync(child)
292
- })
293
- }
294
- } else {
295
- let visitors = this.listeners[event]
296
- if (visitors) {
297
- if (this.visitSync(visitors, node.toProxy())) return
298
- }
299
- }
300
- }
169
+ get content() {
170
+ return this.stringify().content
301
171
  }
302
172
 
303
- visitSync(visitors, node) {
304
- for (let [plugin, visitor] of visitors) {
305
- this.result.lastPlugin = plugin
306
- let promise
307
- try {
308
- promise = visitor(node, this.helpers)
309
- } catch (e) {
310
- throw this.handleError(e, node.proxyOf)
311
- }
312
- if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
313
- return true
314
- }
315
- if (isPromise(promise)) {
316
- throw this.getAsyncError()
317
- }
318
- }
173
+ get css() {
174
+ return this.stringify().css
319
175
  }
320
176
 
321
- runOnRoot(plugin) {
322
- this.result.lastPlugin = plugin
323
- try {
324
- if (typeof plugin === 'object' && plugin.Once) {
325
- if (this.result.root.type === 'document') {
326
- let roots = this.result.root.nodes.map(root =>
327
- plugin.Once(root, this.helpers)
328
- )
329
-
330
- if (isPromise(roots[0])) {
331
- return Promise.all(roots)
332
- }
333
-
334
- return roots
335
- }
336
-
337
- return plugin.Once(this.result.root, this.helpers)
338
- } else if (typeof plugin === 'function') {
339
- return plugin(this.result.root, this.result)
340
- }
341
- } catch (error) {
342
- throw this.handleError(error)
343
- }
177
+ finally(onFinally) {
178
+ return this.async().then(onFinally, onFinally)
344
179
  }
345
180
 
346
181
  getAsyncError() {
@@ -386,6 +221,64 @@ class LazyResult {
386
221
  return error
387
222
  }
388
223
 
224
+ get map() {
225
+ return this.stringify().map
226
+ }
227
+
228
+ get messages() {
229
+ return this.sync().messages
230
+ }
231
+
232
+ get opts() {
233
+ return this.result.opts
234
+ }
235
+
236
+ prepareVisitors() {
237
+ this.listeners = {}
238
+ let add = (plugin, type, cb) => {
239
+ if (!this.listeners[type]) this.listeners[type] = []
240
+ this.listeners[type].push([plugin, cb])
241
+ }
242
+ for (let plugin of this.plugins) {
243
+ if (typeof plugin === 'object') {
244
+ for (let event in plugin) {
245
+ if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
246
+ throw new Error(
247
+ `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
248
+ `Try to update PostCSS (${this.processor.version} now).`
249
+ )
250
+ }
251
+ if (!NOT_VISITORS[event]) {
252
+ if (typeof plugin[event] === 'object') {
253
+ for (let filter in plugin[event]) {
254
+ if (filter === '*') {
255
+ add(plugin, event, plugin[event][filter])
256
+ } else {
257
+ add(
258
+ plugin,
259
+ event + '-' + filter.toLowerCase(),
260
+ plugin[event][filter]
261
+ )
262
+ }
263
+ }
264
+ } else if (typeof plugin[event] === 'function') {
265
+ add(plugin, event, plugin[event])
266
+ }
267
+ }
268
+ }
269
+ }
270
+ }
271
+ this.hasListener = Object.keys(this.listeners).length > 0
272
+ }
273
+
274
+ get processor() {
275
+ return this.result.processor
276
+ }
277
+
278
+ get root() {
279
+ return this.sync().root
280
+ }
281
+
389
282
  async runAsync() {
390
283
  this.plugin = 0
391
284
  for (let i = 0; i < this.plugins.length; i++) {
@@ -443,42 +336,126 @@ class LazyResult {
443
336
  return this.stringify()
444
337
  }
445
338
 
446
- prepareVisitors() {
447
- this.listeners = {}
448
- let add = (plugin, type, cb) => {
449
- if (!this.listeners[type]) this.listeners[type] = []
450
- this.listeners[type].push([plugin, cb])
339
+ runOnRoot(plugin) {
340
+ this.result.lastPlugin = plugin
341
+ try {
342
+ if (typeof plugin === 'object' && plugin.Once) {
343
+ if (this.result.root.type === 'document') {
344
+ let roots = this.result.root.nodes.map(root =>
345
+ plugin.Once(root, this.helpers)
346
+ )
347
+
348
+ if (isPromise(roots[0])) {
349
+ return Promise.all(roots)
350
+ }
351
+
352
+ return roots
353
+ }
354
+
355
+ return plugin.Once(this.result.root, this.helpers)
356
+ } else if (typeof plugin === 'function') {
357
+ return plugin(this.result.root, this.result)
358
+ }
359
+ } catch (error) {
360
+ throw this.handleError(error)
361
+ }
362
+ }
363
+
364
+ stringify() {
365
+ if (this.error) throw this.error
366
+ if (this.stringified) return this.result
367
+ this.stringified = true
368
+
369
+ this.sync()
370
+
371
+ let opts = this.result.opts
372
+ let str = stringify
373
+ if (opts.syntax) str = opts.syntax.stringify
374
+ if (opts.stringifier) str = opts.stringifier
375
+ if (str.stringify) str = str.stringify
376
+
377
+ let map = new MapGenerator(str, this.result.root, this.result.opts)
378
+ let data = map.generate()
379
+ this.result.css = data[0]
380
+ this.result.map = data[1]
381
+
382
+ return this.result
383
+ }
384
+
385
+ get [Symbol.toStringTag]() {
386
+ return 'LazyResult'
387
+ }
388
+
389
+ sync() {
390
+ if (this.error) throw this.error
391
+ if (this.processed) return this.result
392
+ this.processed = true
393
+
394
+ if (this.processing) {
395
+ throw this.getAsyncError()
451
396
  }
397
+
452
398
  for (let plugin of this.plugins) {
453
- if (typeof plugin === 'object') {
454
- for (let event in plugin) {
455
- if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
456
- throw new Error(
457
- `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
458
- `Try to update PostCSS (${this.processor.version} now).`
459
- )
460
- }
461
- if (!NOT_VISITORS[event]) {
462
- if (typeof plugin[event] === 'object') {
463
- for (let filter in plugin[event]) {
464
- if (filter === '*') {
465
- add(plugin, event, plugin[event][filter])
466
- } else {
467
- add(
468
- plugin,
469
- event + '-' + filter.toLowerCase(),
470
- plugin[event][filter]
471
- )
472
- }
473
- }
474
- } else if (typeof plugin[event] === 'function') {
475
- add(plugin, event, plugin[event])
476
- }
399
+ let promise = this.runOnRoot(plugin)
400
+ if (isPromise(promise)) {
401
+ throw this.getAsyncError()
402
+ }
403
+ }
404
+
405
+ this.prepareVisitors()
406
+ if (this.hasListener) {
407
+ let root = this.result.root
408
+ while (!root[isClean]) {
409
+ root[isClean] = true
410
+ this.walkSync(root)
411
+ }
412
+ if (this.listeners.OnceExit) {
413
+ if (root.type === 'document') {
414
+ for (let subRoot of root.nodes) {
415
+ this.visitSync(this.listeners.OnceExit, subRoot)
477
416
  }
417
+ } else {
418
+ this.visitSync(this.listeners.OnceExit, root)
478
419
  }
479
420
  }
480
421
  }
481
- this.hasListener = Object.keys(this.listeners).length > 0
422
+
423
+ return this.result
424
+ }
425
+
426
+ then(onFulfilled, onRejected) {
427
+ if (process.env.NODE_ENV !== 'production') {
428
+ if (!('from' in this.opts)) {
429
+ warnOnce(
430
+ 'Without `from` option PostCSS could generate wrong source map ' +
431
+ 'and will not find Browserslist config. Set it to CSS file path ' +
432
+ 'or to `undefined` to prevent this warning.'
433
+ )
434
+ }
435
+ }
436
+ return this.async().then(onFulfilled, onRejected)
437
+ }
438
+
439
+ toString() {
440
+ return this.css
441
+ }
442
+
443
+ visitSync(visitors, node) {
444
+ for (let [plugin, visitor] of visitors) {
445
+ this.result.lastPlugin = plugin
446
+ let promise
447
+ try {
448
+ promise = visitor(node, this.helpers)
449
+ } catch (e) {
450
+ throw this.handleError(e, node.proxyOf)
451
+ }
452
+ if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
453
+ return true
454
+ }
455
+ if (isPromise(promise)) {
456
+ throw this.getAsyncError()
457
+ }
458
+ }
482
459
  }
483
460
 
484
461
  visitTick(stack) {
@@ -537,6 +514,29 @@ class LazyResult {
537
514
  }
538
515
  stack.pop()
539
516
  }
517
+
518
+ walkSync(node) {
519
+ node[isClean] = true
520
+ let events = getEvents(node)
521
+ for (let event of events) {
522
+ if (event === CHILDREN) {
523
+ if (node.nodes) {
524
+ node.each(child => {
525
+ if (!child[isClean]) this.walkSync(child)
526
+ })
527
+ }
528
+ } else {
529
+ let visitors = this.listeners[event]
530
+ if (visitors) {
531
+ if (this.visitSync(visitors, node.toProxy())) return
532
+ }
533
+ }
534
+ }
535
+ }
536
+
537
+ warnings() {
538
+ return this.sync().warnings()
539
+ }
540
540
  }
541
541
 
542
542
  LazyResult.registerPostcss = dependant => {
package/lib/list.d.ts CHANGED
@@ -1,22 +1,22 @@
1
1
  declare namespace list {
2
2
  type List = {
3
- default: List
4
-
5
3
  /**
6
- * Safely splits values.
4
+ * Safely splits comma-separated values (such as those for `transition-*`
5
+ * and `background` properties).
7
6
  *
8
7
  * ```js
9
8
  * Once (root, { list }) {
10
- * list.split('1px calc(10% + 1px)', [' ', '\n', '\t']) //=> ['1px', 'calc(10% + 1px)']
9
+ * list.comma('black, linear-gradient(white, black)')
10
+ * //=> ['black', 'linear-gradient(white, black)']
11
11
  * }
12
12
  * ```
13
13
  *
14
- * @param string separated values.
15
- * @param separators array of separators.
16
- * @param last boolean indicator.
14
+ * @param str Comma-separated values.
17
15
  * @return Split values.
18
16
  */
19
- split(string: string, separators: string[], last: boolean): string[]
17
+ comma(str: string): string[]
18
+
19
+ default: List
20
20
 
21
21
  /**
22
22
  * Safely splits space-separated values (such as those for `background`,
@@ -34,20 +34,20 @@ declare namespace list {
34
34
  space(str: string): string[]
35
35
 
36
36
  /**
37
- * Safely splits comma-separated values (such as those for `transition-*`
38
- * and `background` properties).
37
+ * Safely splits values.
39
38
  *
40
39
  * ```js
41
40
  * Once (root, { list }) {
42
- * list.comma('black, linear-gradient(white, black)')
43
- * //=> ['black', 'linear-gradient(white, black)']
41
+ * list.split('1px calc(10% + 1px)', [' ', '\n', '\t']) //=> ['1px', 'calc(10% + 1px)']
44
42
  * }
45
43
  * ```
46
44
  *
47
- * @param str Comma-separated values.
45
+ * @param string separated values.
46
+ * @param separators array of separators.
47
+ * @param last boolean indicator.
48
48
  * @return Split values.
49
49
  */
50
- comma(str: string): string[]
50
+ split(string: string, separators: string[], last: boolean): string[]
51
51
  }
52
52
  }
53
53
 
package/lib/list.js CHANGED
@@ -1,6 +1,15 @@
1
1
  'use strict'
2
2
 
3
3
  let list = {
4
+ comma(string) {
5
+ return list.split(string, [','], true)
6
+ },
7
+
8
+ space(string) {
9
+ let spaces = [' ', '\n', '\t']
10
+ return list.split(string, spaces)
11
+ },
12
+
4
13
  split(string, separators, last) {
5
14
  let array = []
6
15
  let current = ''
@@ -42,15 +51,6 @@ let list = {
42
51
 
43
52
  if (last || current !== '') array.push(current.trim())
44
53
  return array
45
- },
46
-
47
- space(string) {
48
- let spaces = [' ', '\n', '\t']
49
- return list.split(string, spaces)
50
- },
51
-
52
- comma(string) {
53
- return list.split(string, [','], true)
54
54
  }
55
55
  }
56
56