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/container.js CHANGED
@@ -25,12 +25,24 @@ function markDirtyUp(node) {
25
25
  }
26
26
 
27
27
  class Container extends Node {
28
- push(child) {
29
- child.parent = this
30
- this.proxyOf.nodes.push(child)
28
+ append(...children) {
29
+ for (let child of children) {
30
+ let nodes = this.normalize(child, this.last)
31
+ for (let node of nodes) this.proxyOf.nodes.push(node)
32
+ }
33
+
34
+ this.markDirty()
35
+
31
36
  return this
32
37
  }
33
38
 
39
+ cleanRaws(keepBetween) {
40
+ super.cleanRaws(keepBetween)
41
+ if (this.nodes) {
42
+ for (let node of this.nodes) node.cleanRaws(keepBetween)
43
+ }
44
+ }
45
+
34
46
  each(callback) {
35
47
  if (!this.proxyOf.nodes) return undefined
36
48
  let iterator = this.getIterator()
@@ -48,151 +60,80 @@ class Container extends Node {
48
60
  return result
49
61
  }
50
62
 
51
- walk(callback) {
52
- return this.each((child, i) => {
53
- let result
54
- try {
55
- result = callback(child, i)
56
- } catch (e) {
57
- throw child.addToError(e)
58
- }
59
- if (result !== false && child.walk) {
60
- result = child.walk(callback)
61
- }
62
-
63
- return result
64
- })
63
+ every(condition) {
64
+ return this.nodes.every(condition)
65
65
  }
66
66
 
67
- walkDecls(prop, callback) {
68
- if (!callback) {
69
- callback = prop
70
- return this.walk((child, i) => {
71
- if (child.type === 'decl') {
72
- return callback(child, i)
73
- }
74
- })
75
- }
76
- if (prop instanceof RegExp) {
77
- return this.walk((child, i) => {
78
- if (child.type === 'decl' && prop.test(child.prop)) {
79
- return callback(child, i)
80
- }
81
- })
82
- }
83
- return this.walk((child, i) => {
84
- if (child.type === 'decl' && child.prop === prop) {
85
- return callback(child, i)
86
- }
87
- })
67
+ get first() {
68
+ if (!this.proxyOf.nodes) return undefined
69
+ return this.proxyOf.nodes[0]
88
70
  }
89
71
 
90
- walkRules(selector, callback) {
91
- if (!callback) {
92
- callback = selector
93
-
94
- return this.walk((child, i) => {
95
- if (child.type === 'rule') {
96
- return callback(child, i)
97
- }
98
- })
99
- }
100
- if (selector instanceof RegExp) {
101
- return this.walk((child, i) => {
102
- if (child.type === 'rule' && selector.test(child.selector)) {
103
- return callback(child, i)
104
- }
105
- })
106
- }
107
- return this.walk((child, i) => {
108
- if (child.type === 'rule' && child.selector === selector) {
109
- return callback(child, i)
110
- }
111
- })
112
- }
72
+ getIterator() {
73
+ if (!this.lastEach) this.lastEach = 0
74
+ if (!this.indexes) this.indexes = {}
113
75
 
114
- walkAtRules(name, callback) {
115
- if (!callback) {
116
- callback = name
117
- return this.walk((child, i) => {
118
- if (child.type === 'atrule') {
119
- return callback(child, i)
120
- }
121
- })
122
- }
123
- if (name instanceof RegExp) {
124
- return this.walk((child, i) => {
125
- if (child.type === 'atrule' && name.test(child.name)) {
126
- return callback(child, i)
127
- }
128
- })
129
- }
130
- return this.walk((child, i) => {
131
- if (child.type === 'atrule' && child.name === name) {
132
- return callback(child, i)
133
- }
134
- })
135
- }
76
+ this.lastEach += 1
77
+ let iterator = this.lastEach
78
+ this.indexes[iterator] = 0
136
79
 
137
- walkComments(callback) {
138
- return this.walk((child, i) => {
139
- if (child.type === 'comment') {
140
- return callback(child, i)
141
- }
142
- })
80
+ return iterator
143
81
  }
144
82
 
145
- append(...children) {
146
- for (let child of children) {
147
- let nodes = this.normalize(child, this.last)
148
- for (let node of nodes) this.proxyOf.nodes.push(node)
149
- }
150
-
151
- this.markDirty()
152
-
153
- return this
154
- }
83
+ getProxyProcessor() {
84
+ return {
85
+ get(node, prop) {
86
+ if (prop === 'proxyOf') {
87
+ return node
88
+ } else if (!node[prop]) {
89
+ return node[prop]
90
+ } else if (
91
+ prop === 'each' ||
92
+ (typeof prop === 'string' && prop.startsWith('walk'))
93
+ ) {
94
+ return (...args) => {
95
+ return node[prop](
96
+ ...args.map(i => {
97
+ if (typeof i === 'function') {
98
+ return (child, index) => i(child.toProxy(), index)
99
+ } else {
100
+ return i
101
+ }
102
+ })
103
+ )
104
+ }
105
+ } else if (prop === 'every' || prop === 'some') {
106
+ return cb => {
107
+ return node[prop]((child, ...other) =>
108
+ cb(child.toProxy(), ...other)
109
+ )
110
+ }
111
+ } else if (prop === 'root') {
112
+ return () => node.root().toProxy()
113
+ } else if (prop === 'nodes') {
114
+ return node.nodes.map(i => i.toProxy())
115
+ } else if (prop === 'first' || prop === 'last') {
116
+ return node[prop].toProxy()
117
+ } else {
118
+ return node[prop]
119
+ }
120
+ },
155
121
 
156
- prepend(...children) {
157
- children = children.reverse()
158
- for (let child of children) {
159
- let nodes = this.normalize(child, this.first, 'prepend').reverse()
160
- for (let node of nodes) this.proxyOf.nodes.unshift(node)
161
- for (let id in this.indexes) {
162
- this.indexes[id] = this.indexes[id] + nodes.length
122
+ set(node, prop, value) {
123
+ if (node[prop] === value) return true
124
+ node[prop] = value
125
+ if (prop === 'name' || prop === 'params' || prop === 'selector') {
126
+ node.markDirty()
127
+ }
128
+ return true
163
129
  }
164
130
  }
165
-
166
- this.markDirty()
167
-
168
- return this
169
131
  }
170
132
 
171
- cleanRaws(keepBetween) {
172
- super.cleanRaws(keepBetween)
173
- if (this.nodes) {
174
- for (let node of this.nodes) node.cleanRaws(keepBetween)
175
- }
176
- }
177
-
178
- insertBefore(exist, add) {
179
- let existIndex = this.index(exist)
180
- let type = existIndex === 0 ? 'prepend' : false
181
- let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse()
182
- existIndex = this.index(exist)
183
- for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
184
-
185
- let index
186
- for (let id in this.indexes) {
187
- index = this.indexes[id]
188
- if (existIndex <= index) {
189
- this.indexes[id] = index + nodes.length
190
- }
191
- }
192
-
193
- this.markDirty()
194
-
195
- return this
133
+ index(child) {
134
+ if (typeof child === 'number') return child
135
+ if (child.proxyOf) child = child.proxyOf
136
+ return this.proxyOf.nodes.indexOf(child)
196
137
  }
197
138
 
198
139
  insertAfter(exist, add) {
@@ -214,16 +155,18 @@ class Container extends Node {
214
155
  return this
215
156
  }
216
157
 
217
- removeChild(child) {
218
- child = this.index(child)
219
- this.proxyOf.nodes[child].parent = undefined
220
- this.proxyOf.nodes.splice(child, 1)
158
+ insertBefore(exist, add) {
159
+ let existIndex = this.index(exist)
160
+ let type = existIndex === 0 ? 'prepend' : false
161
+ let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse()
162
+ existIndex = this.index(exist)
163
+ for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
221
164
 
222
165
  let index
223
166
  for (let id in this.indexes) {
224
167
  index = this.indexes[id]
225
- if (index >= child) {
226
- this.indexes[id] = index - 1
168
+ if (existIndex <= index) {
169
+ this.indexes[id] = index + nodes.length
227
170
  }
228
171
  }
229
172
 
@@ -232,52 +175,6 @@ class Container extends Node {
232
175
  return this
233
176
  }
234
177
 
235
- removeAll() {
236
- for (let node of this.proxyOf.nodes) node.parent = undefined
237
- this.proxyOf.nodes = []
238
-
239
- this.markDirty()
240
-
241
- return this
242
- }
243
-
244
- replaceValues(pattern, opts, callback) {
245
- if (!callback) {
246
- callback = opts
247
- opts = {}
248
- }
249
-
250
- this.walkDecls(decl => {
251
- if (opts.props && !opts.props.includes(decl.prop)) return
252
- if (opts.fast && !decl.value.includes(opts.fast)) return
253
-
254
- decl.value = decl.value.replace(pattern, callback)
255
- })
256
-
257
- this.markDirty()
258
-
259
- return this
260
- }
261
-
262
- every(condition) {
263
- return this.nodes.every(condition)
264
- }
265
-
266
- some(condition) {
267
- return this.nodes.some(condition)
268
- }
269
-
270
- index(child) {
271
- if (typeof child === 'number') return child
272
- if (child.proxyOf) child = child.proxyOf
273
- return this.proxyOf.nodes.indexOf(child)
274
- }
275
-
276
- get first() {
277
- if (!this.proxyOf.nodes) return undefined
278
- return this.proxyOf.nodes[0]
279
- }
280
-
281
178
  get last() {
282
179
  if (!this.proxyOf.nodes) return undefined
283
180
  return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
@@ -333,65 +230,168 @@ class Container extends Node {
333
230
  return processed
334
231
  }
335
232
 
336
- getProxyProcessor() {
337
- return {
338
- set(node, prop, value) {
339
- if (node[prop] === value) return true
340
- node[prop] = value
341
- if (prop === 'name' || prop === 'params' || prop === 'selector') {
342
- node.markDirty()
343
- }
344
- return true
345
- },
233
+ prepend(...children) {
234
+ children = children.reverse()
235
+ for (let child of children) {
236
+ let nodes = this.normalize(child, this.first, 'prepend').reverse()
237
+ for (let node of nodes) this.proxyOf.nodes.unshift(node)
238
+ for (let id in this.indexes) {
239
+ this.indexes[id] = this.indexes[id] + nodes.length
240
+ }
241
+ }
346
242
 
347
- get(node, prop) {
348
- if (prop === 'proxyOf') {
349
- return node
350
- } else if (!node[prop]) {
351
- return node[prop]
352
- } else if (
353
- prop === 'each' ||
354
- (typeof prop === 'string' && prop.startsWith('walk'))
355
- ) {
356
- return (...args) => {
357
- return node[prop](
358
- ...args.map(i => {
359
- if (typeof i === 'function') {
360
- return (child, index) => i(child.toProxy(), index)
361
- } else {
362
- return i
363
- }
364
- })
365
- )
366
- }
367
- } else if (prop === 'every' || prop === 'some') {
368
- return cb => {
369
- return node[prop]((child, ...other) =>
370
- cb(child.toProxy(), ...other)
371
- )
372
- }
373
- } else if (prop === 'root') {
374
- return () => node.root().toProxy()
375
- } else if (prop === 'nodes') {
376
- return node.nodes.map(i => i.toProxy())
377
- } else if (prop === 'first' || prop === 'last') {
378
- return node[prop].toProxy()
379
- } else {
380
- return node[prop]
381
- }
243
+ this.markDirty()
244
+
245
+ return this
246
+ }
247
+
248
+ push(child) {
249
+ child.parent = this
250
+ this.proxyOf.nodes.push(child)
251
+ return this
252
+ }
253
+
254
+ removeAll() {
255
+ for (let node of this.proxyOf.nodes) node.parent = undefined
256
+ this.proxyOf.nodes = []
257
+
258
+ this.markDirty()
259
+
260
+ return this
261
+ }
262
+
263
+ removeChild(child) {
264
+ child = this.index(child)
265
+ this.proxyOf.nodes[child].parent = undefined
266
+ this.proxyOf.nodes.splice(child, 1)
267
+
268
+ let index
269
+ for (let id in this.indexes) {
270
+ index = this.indexes[id]
271
+ if (index >= child) {
272
+ this.indexes[id] = index - 1
382
273
  }
383
274
  }
275
+
276
+ this.markDirty()
277
+
278
+ return this
384
279
  }
385
280
 
386
- getIterator() {
387
- if (!this.lastEach) this.lastEach = 0
388
- if (!this.indexes) this.indexes = {}
281
+ replaceValues(pattern, opts, callback) {
282
+ if (!callback) {
283
+ callback = opts
284
+ opts = {}
285
+ }
389
286
 
390
- this.lastEach += 1
391
- let iterator = this.lastEach
392
- this.indexes[iterator] = 0
287
+ this.walkDecls(decl => {
288
+ if (opts.props && !opts.props.includes(decl.prop)) return
289
+ if (opts.fast && !decl.value.includes(opts.fast)) return
393
290
 
394
- return iterator
291
+ decl.value = decl.value.replace(pattern, callback)
292
+ })
293
+
294
+ this.markDirty()
295
+
296
+ return this
297
+ }
298
+
299
+ some(condition) {
300
+ return this.nodes.some(condition)
301
+ }
302
+
303
+ walk(callback) {
304
+ return this.each((child, i) => {
305
+ let result
306
+ try {
307
+ result = callback(child, i)
308
+ } catch (e) {
309
+ throw child.addToError(e)
310
+ }
311
+ if (result !== false && child.walk) {
312
+ result = child.walk(callback)
313
+ }
314
+
315
+ return result
316
+ })
317
+ }
318
+
319
+ walkAtRules(name, callback) {
320
+ if (!callback) {
321
+ callback = name
322
+ return this.walk((child, i) => {
323
+ if (child.type === 'atrule') {
324
+ return callback(child, i)
325
+ }
326
+ })
327
+ }
328
+ if (name instanceof RegExp) {
329
+ return this.walk((child, i) => {
330
+ if (child.type === 'atrule' && name.test(child.name)) {
331
+ return callback(child, i)
332
+ }
333
+ })
334
+ }
335
+ return this.walk((child, i) => {
336
+ if (child.type === 'atrule' && child.name === name) {
337
+ return callback(child, i)
338
+ }
339
+ })
340
+ }
341
+
342
+ walkComments(callback) {
343
+ return this.walk((child, i) => {
344
+ if (child.type === 'comment') {
345
+ return callback(child, i)
346
+ }
347
+ })
348
+ }
349
+
350
+ walkDecls(prop, callback) {
351
+ if (!callback) {
352
+ callback = prop
353
+ return this.walk((child, i) => {
354
+ if (child.type === 'decl') {
355
+ return callback(child, i)
356
+ }
357
+ })
358
+ }
359
+ if (prop instanceof RegExp) {
360
+ return this.walk((child, i) => {
361
+ if (child.type === 'decl' && prop.test(child.prop)) {
362
+ return callback(child, i)
363
+ }
364
+ })
365
+ }
366
+ return this.walk((child, i) => {
367
+ if (child.type === 'decl' && child.prop === prop) {
368
+ return callback(child, i)
369
+ }
370
+ })
371
+ }
372
+
373
+ walkRules(selector, callback) {
374
+ if (!callback) {
375
+ callback = selector
376
+
377
+ return this.walk((child, i) => {
378
+ if (child.type === 'rule') {
379
+ return callback(child, i)
380
+ }
381
+ })
382
+ }
383
+ if (selector instanceof RegExp) {
384
+ return this.walk((child, i) => {
385
+ if (child.type === 'rule' && selector.test(child.selector)) {
386
+ return callback(child, i)
387
+ }
388
+ })
389
+ }
390
+ return this.walk((child, i) => {
391
+ if (child.type === 'rule' && child.selector === selector) {
392
+ return callback(child, i)
393
+ }
394
+ })
395
395
  }
396
396
  }
397
397