postcss 8.0.7 → 8.1.1

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/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  # Change Log
2
2
  This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
+ ## 8.1.1
5
+ * Update funding link.
6
+
7
+ ## 8.1 “Duke Gemory”
8
+ * Added `Once` and `OnceExit` events.
9
+ * Fixed `Root` and `RootExit` events re-visiting.
10
+ * Fixed node re-visiting on deep children changes.
11
+ * Added docs for visitor API events.
12
+
13
+ ## 8.0.9
14
+ * Replace prototype in PostCSS 7 nodes instead of recreating them.
15
+ * Added missed `Transformer` to exported types (by Pierre-Marie Dartus).
16
+
17
+ ## 8.0.8
18
+ * Fix `8.0.7` regression on PostCSS 7 nodes converting (by Adam Wathan).
19
+
4
20
  ## 8.0.7
5
21
  * Fixed compatibility issue with mixin AST with PostCSS 7 and 8 nodes.
6
22
  * Added migration guide translation to Chinese to the warning.
@@ -55,6 +71,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55
71
  * Removed docs from npm package.
56
72
  * Replaced `chalk` to `colorette`.
57
73
 
74
+ ## 7.0.35
75
+ * Add migration guide link to PostCSS 8 error text.
76
+
58
77
  ## 7.0.34
59
78
  * Fix compatibility with `postcss-scss` 2.
60
79
 
package/README.md CHANGED
@@ -371,7 +371,7 @@ prefixer({ display: 'flex' }) //=> { display: ['-webkit-box', '-webkit-flex', '-
371
371
 
372
372
  ### Runners
373
373
 
374
- * **Grunt**: [`grunt-postcss`](https://github.com/nDmitry/grunt-postcss)
374
+ * **Grunt**: [`@lodder/grunt-postcss`](https://github.com/C-Lodder/grunt-postcss)
375
375
  * **HTML**: [`posthtml-postcss`](https://github.com/posthtml/posthtml-postcss)
376
376
  * **Stylus**: [`poststylus`](https://github.com/seaneking/poststylus)
377
377
  * **Rollup**: [`rollup-plugin-postcss`](https://github.com/egoist/rollup-plugin-postcss)
package/lib/at-rule.d.ts CHANGED
@@ -46,7 +46,7 @@ export interface AtRuleProps extends ContainerProps {
46
46
  * Represents an at-rule.
47
47
  *
48
48
  * ```js
49
- * Root (root, { AtRule }) {
49
+ * Once (root, { AtRule }) {
50
50
  * let media = new AtRule({ name: 'media', params: 'print' })
51
51
  * media.append(…)
52
52
  * root.append(media)
package/lib/comment.d.ts CHANGED
@@ -26,7 +26,7 @@ export interface CommentProps extends NodeProps {
26
26
  * Represents a comment between declarations or statements (rule and at-rules).
27
27
  *
28
28
  * ```js
29
- * Root (root, { Comment }) {
29
+ * Once (root, { Comment }) {
30
30
  * let note = new Comment({ text: 'Note: …' })
31
31
  * root.append(note)
32
32
  * }
package/lib/container.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- let { isClean, isComplete } = require('./symbols')
3
+ let { isClean } = require('./symbols')
4
4
  let Declaration = require('./declaration')
5
5
  let Comment = require('./comment')
6
6
  let Node = require('./node')
@@ -17,7 +17,6 @@ function cleanSource (nodes) {
17
17
 
18
18
  function markDirtyUp (node) {
19
19
  node[isClean] = false
20
- node[isComplete] = false
21
20
  if (node.proxyOf.nodes) {
22
21
  for (let i of node.proxyOf.nodes) {
23
22
  markDirtyUp(i)
@@ -26,29 +25,22 @@ function markDirtyUp (node) {
26
25
  }
27
26
 
28
27
  // istanbul ignore next
29
- function rebuild (node, parent) {
30
- let fix
28
+ function rebuild (node) {
31
29
  if (node.type === 'atrule') {
32
- fix = new AtRule()
30
+ Object.setPrototypeOf(node, AtRule.prototype)
33
31
  } else if (node.type === 'rule') {
34
- fix = new Rule()
32
+ Object.setPrototypeOf(node, Rule.prototype)
35
33
  } else if (node.type === 'decl') {
36
- fix = new Declaration()
34
+ Object.setPrototypeOf(node, Declaration.prototype)
37
35
  } else if (node.type === 'comment') {
38
- fix = new Comment()
36
+ Object.setPrototypeOf(node, Comment.prototype)
39
37
  }
40
38
 
41
- for (let i in node) {
42
- if (i === 'nodes') {
43
- fix.nodes = node.nodes.map(j => rebuild(j, fix))
44
- } else if (i === 'parent' && parent) {
45
- fix.parent = parent
46
- } else if (Object.prototype.hasOwnProperty.call(i)) {
47
- fix[i] = node[i]
48
- }
39
+ if (node.nodes) {
40
+ node.nodes.forEach(child => {
41
+ rebuild(child)
42
+ })
49
43
  }
50
-
51
- return fix
52
44
  }
53
45
 
54
46
  class Container extends Node {
@@ -344,7 +336,7 @@ class Container extends Node {
344
336
 
345
337
  let processed = nodes.map(i => {
346
338
  // istanbul ignore next
347
- if (typeof i.markDirty !== 'function') i = rebuild(i)
339
+ if (typeof i.markDirty !== 'function') rebuild(i)
348
340
  if (i.parent) i.parent.removeChild(i)
349
341
  if (i[isClean]) markDirtyUp(i)
350
342
  if (typeof i.raws.before === 'undefined') {
@@ -36,7 +36,7 @@ export interface DeclarationProps {
36
36
  * Represents a CSS declaration.
37
37
  *
38
38
  * ```js
39
- * Root (root, { Declaration }) {
39
+ * Once (root, { Declaration }) {
40
40
  * let color = new Declaration({ prop: 'color', value: 'black' })
41
41
  * root.append(color)
42
42
  * }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- let { isComplete, isClean } = require('./symbols')
3
+ let { isClean } = require('./symbols')
4
4
  let MapGenerator = require('./map-generator')
5
5
  let stringify = require('./stringify')
6
6
  let warnOnce = require('./warn-once')
@@ -50,11 +50,9 @@ function getEvents (node) {
50
50
 
51
51
  function toStack (node) {
52
52
  let events
53
- if (node[isClean]) {
54
- events = node.append ? [CHILDREN] : []
53
+ if (node.type === 'root') {
54
+ events = ['Root', CHILDREN, 'RootExit']
55
55
  } else {
56
- node[isComplete] = true
57
- node[isClean] = true
58
56
  events = getEvents(node)
59
57
  }
60
58
 
@@ -70,7 +68,6 @@ function toStack (node) {
70
68
 
71
69
  function cleanMarks (node) {
72
70
  node[isClean] = false
73
- node[isComplete] = false
74
71
  if (node.nodes) node.nodes.forEach(i => cleanMarks(i))
75
72
  return node
76
73
  }
@@ -202,13 +199,12 @@ class LazyResult {
202
199
  this.prepareVisitors()
203
200
  if (this.hasListener) {
204
201
  let root = this.result.root
205
- while (!root[isComplete]) {
206
- root[isComplete] = true
202
+ while (!root[isClean]) {
207
203
  root[isClean] = true
208
204
  this.walkSync(root)
209
205
  }
210
- if (this.listeners.RootExit) {
211
- this.visitSync(this.listeners.RootExit, root)
206
+ if (this.listeners.OnceExit) {
207
+ this.visitSync(this.listeners.OnceExit, root)
212
208
  }
213
209
  }
214
210
 
@@ -237,29 +233,22 @@ class LazyResult {
237
233
  }
238
234
 
239
235
  walkSync (node) {
240
- node.each(child => {
241
- if (child[isComplete]) return
242
- child[isComplete] = true
243
-
244
- if (child[isClean]) {
245
- if (child.nodes) this.walkSync(child)
236
+ node[isClean] = true
237
+ let events = getEvents(node)
238
+ for (let event of events) {
239
+ if (event === CHILDREN) {
240
+ if (node.nodes) {
241
+ node.each(child => {
242
+ if (!child[isClean]) this.walkSync(child)
243
+ })
244
+ }
246
245
  } else {
247
- child[isClean] = true
248
- let events = getEvents(child)
249
- for (let event of events) {
250
- if (event === CHILDREN) {
251
- if (child.nodes) {
252
- this.walkSync(child)
253
- }
254
- } else {
255
- let visitors = this.listeners[event]
256
- if (visitors) {
257
- if (this.visitSync(visitors, child.toProxy())) return
258
- }
259
- }
246
+ let visitors = this.listeners[event]
247
+ if (visitors) {
248
+ if (this.visitSync(visitors, node.toProxy())) return
260
249
  }
261
250
  }
262
- })
251
+ }
263
252
  }
264
253
 
265
254
  visitSync (visitors, node) {
@@ -281,8 +270,8 @@ class LazyResult {
281
270
  runOnRoot (plugin) {
282
271
  this.result.lastPlugin = plugin
283
272
  try {
284
- if (typeof plugin === 'object' && plugin.Root) {
285
- return plugin.Root(this.result.root, this.helpers)
273
+ if (typeof plugin === 'object' && plugin.Once) {
274
+ return plugin.Once(this.result.root, this.helpers)
286
275
  } else if (typeof plugin === 'function') {
287
276
  return plugin(this.result.root, this.result)
288
277
  }
@@ -349,8 +338,7 @@ class LazyResult {
349
338
  this.prepareVisitors()
350
339
  if (this.hasListener) {
351
340
  let root = this.result.root
352
- while (!root[isComplete]) {
353
- root[isComplete] = true
341
+ while (!root[isClean]) {
354
342
  root[isClean] = true
355
343
  let stack = [toStack(root)]
356
344
  while (stack.length > 0) {
@@ -366,8 +354,8 @@ class LazyResult {
366
354
  }
367
355
  }
368
356
 
369
- if (this.listeners.RootExit) {
370
- for (let [plugin, visitor] of this.listeners.RootExit) {
357
+ if (this.listeners.OnceExit) {
358
+ for (let [plugin, visitor] of this.listeners.OnceExit) {
371
359
  this.result.lastPlugin = plugin
372
360
  try {
373
361
  await visitor(root, this.helpers)
@@ -391,6 +379,7 @@ class LazyResult {
391
379
  for (let plugin of this.plugins) {
392
380
  if (typeof plugin === 'object') {
393
381
  for (let type of [
382
+ 'Root',
394
383
  'Declaration',
395
384
  'Rule',
396
385
  'AtRule',
@@ -399,7 +388,8 @@ class LazyResult {
399
388
  'RuleExit',
400
389
  'AtRuleExit',
401
390
  'CommentExit',
402
- 'RootExit'
391
+ 'RootExit',
392
+ 'OnceExit'
403
393
  ]) {
404
394
  if (typeof plugin[type] === 'object') {
405
395
  for (let filter in plugin[type]) {
@@ -451,7 +441,8 @@ class LazyResult {
451
441
  let child
452
442
  while ((child = node.nodes[node.indexes[iterator]])) {
453
443
  node.indexes[iterator] += 1
454
- if (!child[isComplete]) {
444
+ if (!child[isClean]) {
445
+ child[isClean] = true
455
446
  stack.push(toStack(child))
456
447
  return
457
448
  }
@@ -466,7 +457,7 @@ class LazyResult {
466
457
  visit.eventIndex += 1
467
458
  if (event === CHILDREN) {
468
459
  if (node.nodes && node.nodes.length) {
469
- node[isComplete] = true
460
+ node[isClean] = true
470
461
  visit.iterator = node.getIterator()
471
462
  }
472
463
  return
package/lib/list.d.ts CHANGED
@@ -4,7 +4,7 @@ export type List = {
4
4
  * `border-radius`, and other shorthand properties).
5
5
  *
6
6
  * ```js
7
- * Root (root, { list }) {
7
+ * Once (root, { list }) {
8
8
  * list.space('1px calc(10% + 1px)') //=> ['1px', 'calc(10% + 1px)']
9
9
  * }
10
10
  * ```
@@ -19,7 +19,7 @@ export type List = {
19
19
  * and `background` properties).
20
20
  *
21
21
  * ```js
22
- * Root (root, { list }) {
22
+ * Once (root, { list }) {
23
23
  * list.comma('black, linear-gradient(white, black)')
24
24
  * //=> ['black', 'linear-gradient(white, black)']
25
25
  * }
package/lib/node.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict'
2
2
 
3
- let { isClean, isComplete } = require('./symbols')
4
3
  let CssSyntaxError = require('./css-syntax-error')
5
4
  let Stringifier = require('./stringifier')
5
+ let { isClean } = require('./symbols')
6
6
  let stringify = require('./stringify')
7
7
 
8
8
  function cloneNode (obj, parent) {
@@ -35,7 +35,6 @@ function cloneNode (obj, parent) {
35
35
  class Node {
36
36
  constructor (defaults = {}) {
37
37
  this.raws = {}
38
- this[isComplete] = false
39
38
  this[isClean] = false
40
39
 
41
40
  for (let name in defaults) {
@@ -276,17 +275,13 @@ class Node {
276
275
  markDirty () {
277
276
  if (this[isClean]) {
278
277
  this[isClean] = false
279
- this.markIncomplete()
278
+ let next = this
279
+ while ((next = next.parent)) {
280
+ next[isClean] = false
281
+ }
280
282
  }
281
283
  }
282
284
 
283
- markIncomplete () {
284
- let next = this
285
- do {
286
- next[isComplete] = false
287
- } while ((next = next.parent))
288
- }
289
-
290
285
  get proxyOf () {
291
286
  return this
292
287
  }
package/lib/postcss.d.ts CHANGED
@@ -70,18 +70,96 @@ type CommentProcessor = (
70
70
  ) => Promise<void> | void
71
71
 
72
72
  interface Processors {
73
+ /**
74
+ * Will be called on `Root` node once.
75
+ */
76
+ Once?: RootProcessor
77
+
78
+ /**
79
+ * Will be called on `Root` node once, when all children will be processed.
80
+ */
81
+ OnceExit?: RootProcessor
82
+
83
+ /**
84
+ * Will be called on `Root` node.
85
+ *
86
+ * Will be called again on children changes.
87
+ */
73
88
  Root?: RootProcessor
89
+
90
+ /**
91
+ * Will be called on `Root` node, when all children will be processed.
92
+ *
93
+ * Will be called again on children changes.
94
+ */
74
95
  RootExit?: RootProcessor
96
+
97
+ /**
98
+ * Will be called on all `Declaration` nodes after listeners
99
+ * for `Declaration` event.
100
+ *
101
+ * Will be called again on node or children changes.
102
+ */
75
103
  Declaration?: DeclarationProcessor | { [prop: string]: DeclarationProcessor }
104
+
105
+ /**
106
+ * Will be called on all `Declaration` nodes.
107
+ *
108
+ * Will be called again on node or children changes.
109
+ */
76
110
  DeclarationExit?:
77
111
  | DeclarationProcessor
78
112
  | { [prop: string]: DeclarationProcessor }
113
+
114
+ /**
115
+ * Will be called on all `Rule` nodes.
116
+ *
117
+ * Will be called again on node or children changes.
118
+ */
79
119
  Rule?: RuleProcessor
120
+
121
+ /**
122
+ * Will be called on all `Rule` nodes, when all children will be processed.
123
+ *
124
+ * Will be called again on node or children changes.
125
+ */
80
126
  RuleExit?: RuleProcessor
127
+
128
+ /**
129
+ * Will be called on all`AtRule` nodes.
130
+ *
131
+ * Will be called again on node or children changes.
132
+ */
81
133
  AtRule?: AtRuleProcessor | { [name: string]: AtRuleProcessor }
134
+
135
+ /**
136
+ * Will be called on all `AtRule` nodes, when all children will be processed.
137
+ *
138
+ * Will be called again on node or children changes.
139
+ */
82
140
  AtRuleExit?: AtRuleProcessor | { [name: string]: AtRuleProcessor }
141
+
142
+ /**
143
+ * Will be called on all `Comment` nodes.
144
+ *
145
+ * Will be called again on node or children changes.
146
+ */
83
147
  Comment?: CommentProcessor
148
+
149
+ /**
150
+ * Will be called on all `Comment` nodes after listeners
151
+ * for `Comment` event.
152
+ *
153
+ * Will be called again on node or children changes.
154
+ */
84
155
  CommentExit?: CommentProcessor
156
+
157
+ /**
158
+ * Will be called when all other listeners processed the document.
159
+ *
160
+ * This listener will not be called again.
161
+ */
162
+ Exit?: RootProcessor
85
163
  }
86
164
 
87
165
  export interface Plugin extends Processors {
@@ -94,7 +172,7 @@ export interface PluginCreator<PluginOptions> {
94
172
  postcss: true
95
173
  }
96
174
 
97
- interface Transformer extends TransformCallback {
175
+ export interface Transformer extends TransformCallback {
98
176
  postcssPlugin: string
99
177
  postcssVersion: string
100
178
  }
@@ -2,6 +2,7 @@ import {
2
2
  AcceptedPlugin,
3
3
  Plugin,
4
4
  ProcessOptions,
5
+ Transformer,
5
6
  TransformCallback
6
7
  } from './postcss.js'
7
8
  import LazyResult from './lazy-result.js'
package/lib/processor.js CHANGED
@@ -5,7 +5,7 @@ let Root = require('./root')
5
5
 
6
6
  class Processor {
7
7
  constructor (plugins = []) {
8
- this.version = '8.0.7'
8
+ this.version = '8.1.1'
9
9
  this.plugins = this.normalize(plugins)
10
10
  }
11
11
 
package/lib/rule.d.ts CHANGED
@@ -46,7 +46,7 @@ export interface RuleProps extends ContainerProps {
46
46
  * Represents a CSS rule: a selector followed by a declaration block.
47
47
  *
48
48
  * ```js
49
- * Root (root, { Rule }) {
49
+ * Once (root, { Rule }) {
50
50
  * let a = new Rule({ selector: 'a' })
51
51
  * a.append(…)
52
52
  * root.append(a)
package/lib/symbols.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
3
  module.exports = {
4
- isComplete: Symbol('isComplete'),
5
4
  isClean: Symbol('isClean')
6
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss",
3
- "version": "8.0.7",
3
+ "version": "8.1.1",
4
4
  "description": "Tool for transforming styles with JS plugins",
5
5
  "engines": {
6
6
  "node": "^10 || ^12 || >=14"
@@ -25,8 +25,8 @@
25
25
  "transpiler"
26
26
  ],
27
27
  "funding": {
28
- "type": "tidelift",
29
- "url": "https://tidelift.com/funding/github/npm/postcss"
28
+ "type": "opencollective",
29
+ "url": "https://opencollective.com/postcss/"
30
30
  },
31
31
  "author": "Andrey Sitnik <andrey@sitnik.ru>",
32
32
  "license": "MIT",