postcss 8.4.40 → 8.4.42

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/lib/at-rule.d.ts CHANGED
@@ -79,18 +79,6 @@ declare namespace AtRule {
79
79
  * ```
80
80
  */
81
81
  declare class AtRule_ extends Container {
82
- /**
83
- * The at-rule’s name immediately follows the `@`.
84
- *
85
- * ```js
86
- * const root = postcss.parse('@media print {}')
87
- * const media = root.first
88
- * media.name //=> 'media'
89
- * ```
90
- */
91
- get name(): string
92
- set name(value: string)
93
-
94
82
  /**
95
83
  * An array containing the layer’s children.
96
84
  *
@@ -110,6 +98,29 @@ declare class AtRule_ extends Container {
110
98
  * ```
111
99
  */
112
100
  nodes: Container['nodes']
101
+ parent: ContainerWithChildren | undefined
102
+
103
+ raws: AtRule.AtRuleRaws
104
+ type: 'atrule'
105
+ constructor(defaults?: AtRule.AtRuleProps)
106
+ assign(overrides: AtRule.AtRuleProps | object): this
107
+
108
+ clone(overrides?: Partial<AtRule.AtRuleProps>): this
109
+
110
+ cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): this
111
+
112
+ cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): this
113
+ /**
114
+ * The at-rule’s name immediately follows the `@`.
115
+ *
116
+ * ```js
117
+ * const root = postcss.parse('@media print {}')
118
+ * const media = root.first
119
+ * media.name //=> 'media'
120
+ * ```
121
+ */
122
+ get name(): string
123
+ set name(value: string)
113
124
  /**
114
125
  * The at-rule’s parameters, the values that follow the at-rule’s name
115
126
  * but precede any `{}` block.
@@ -122,17 +133,6 @@ declare class AtRule_ extends Container {
122
133
  */
123
134
  get params(): string
124
135
  set params(value: string)
125
- parent: ContainerWithChildren | undefined
126
-
127
- raws: AtRule.AtRuleRaws
128
-
129
- type: 'atrule'
130
-
131
- constructor(defaults?: AtRule.AtRuleProps)
132
- assign(overrides: AtRule.AtRuleProps | object): this
133
- clone(overrides?: Partial<AtRule.AtRuleProps>): AtRule
134
- cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): AtRule
135
- cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): AtRule
136
136
  }
137
137
 
138
138
  declare class AtRule extends AtRule_ {}
package/lib/comment.d.ts CHANGED
@@ -48,19 +48,19 @@ declare namespace Comment {
48
48
  declare class Comment_ extends Node {
49
49
  parent: Container | undefined
50
50
  raws: Comment.CommentRaws
51
+ type: 'comment'
52
+ constructor(defaults?: Comment.CommentProps)
53
+
54
+ assign(overrides: Comment.CommentProps | object): this
55
+
56
+ clone(overrides?: Partial<Comment.CommentProps>): this
57
+ cloneAfter(overrides?: Partial<Comment.CommentProps>): this
58
+ cloneBefore(overrides?: Partial<Comment.CommentProps>): this
51
59
  /**
52
60
  * The comment's text.
53
61
  */
54
62
  get text(): string
55
63
  set text(value: string)
56
-
57
- type: 'comment'
58
-
59
- constructor(defaults?: Comment.CommentProps)
60
- assign(overrides: Comment.CommentProps | object): this
61
- clone(overrides?: Partial<Comment.CommentProps>): Comment
62
- cloneAfter(overrides?: Partial<Comment.CommentProps>): Comment
63
- cloneBefore(overrides?: Partial<Comment.CommentProps>): Comment
64
64
  }
65
65
 
66
66
  declare class Comment extends Comment_ {}
@@ -20,13 +20,26 @@ declare namespace Container {
20
20
  /**
21
21
  * An array of property names.
22
22
  */
23
- props?: string[]
23
+ props?: readonly string[]
24
24
  }
25
25
 
26
26
  export interface ContainerProps extends NodeProps {
27
- nodes?: (ChildNode | ChildProps)[]
27
+ nodes?: readonly (ChildProps | Node)[]
28
28
  }
29
29
 
30
+ /**
31
+ * All types that can be passed into container methods to create or add a new
32
+ * child node.
33
+ */
34
+ export type NewChild =
35
+ | ChildProps
36
+ | Node
37
+ | readonly ChildProps[]
38
+ | readonly Node[]
39
+ | readonly string[]
40
+ | string
41
+ | undefined
42
+
30
43
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
31
44
  export { Container_ as default }
32
45
  }
@@ -51,6 +64,26 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
51
64
  */
52
65
  nodes: Child[] | undefined
53
66
 
67
+ /**
68
+ * An internal method that converts a {@link NewChild} into a list of actual
69
+ * child nodes that can then be added to this container.
70
+ *
71
+ * This ensures that the nodes' parent is set to this container, that they use
72
+ * the correct prototype chain, and that they're marked as dirty.
73
+ *
74
+ * @param mnodes The new node or nodes to add.
75
+ * @param sample A node from whose raws the new node's `before` raw should be
76
+ * taken.
77
+ * @param type This should be set to `'prepend'` if the new nodes will be
78
+ * inserted at the beginning of the container.
79
+ * @hidden
80
+ */
81
+ protected normalize(
82
+ nodes: Container.NewChild,
83
+ sample: Node | undefined,
84
+ type?: 'prepend' | false
85
+ ): Child[]
86
+
54
87
  /**
55
88
  * Inserts new nodes to the end of the container.
56
89
  *
@@ -71,22 +104,12 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
71
104
  * @param nodes New nodes.
72
105
  * @return This node for methods chain.
73
106
  */
74
- append(
75
- ...nodes: (
76
- | ChildProps
77
- | ChildProps[]
78
- | Node
79
- | Node[]
80
- | string
81
- | string[]
82
- | undefined
83
- )[]
84
- ): this
85
-
107
+ append(...nodes: Container.NewChild[]): this
86
108
  assign(overrides: Container.ContainerProps | object): this
87
- clone(overrides?: Partial<Container.ContainerProps>): Container<Child>
88
- cloneAfter(overrides?: Partial<Container.ContainerProps>): Container<Child>
89
- cloneBefore(overrides?: Partial<Container.ContainerProps>): Container<Child>
109
+ clone(overrides?: Partial<Container.ContainerProps>): this
110
+ cloneAfter(overrides?: Partial<Container.ContainerProps>): this
111
+
112
+ cloneBefore(overrides?: Partial<Container.ContainerProps>): this
90
113
 
91
114
  /**
92
115
  * Iterates through the container’s immediate children,
@@ -124,7 +147,6 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
124
147
  each(
125
148
  callback: (node: Child, index: number) => false | void
126
149
  ): false | undefined
127
-
128
150
  /**
129
151
  * Returns `true` if callback returns `true`
130
152
  * for all of the container’s children.
@@ -139,6 +161,7 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
139
161
  every(
140
162
  condition: (node: Child, index: number, nodes: Child[]) => boolean
141
163
  ): boolean
164
+
142
165
  /**
143
166
  * Returns a `child`’s index within the `Container#nodes` array.
144
167
  *
@@ -150,7 +173,6 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
150
173
  * @return Child index.
151
174
  */
152
175
  index(child: Child | number): number
153
-
154
176
  /**
155
177
  * Insert new node after old node within the container.
156
178
  *
@@ -158,17 +180,8 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
158
180
  * @param newNode New node.
159
181
  * @return This node for methods chain.
160
182
  */
161
- insertAfter(
162
- oldNode: Child | number,
163
- newNode:
164
- | Child
165
- | Child[]
166
- | ChildProps
167
- | ChildProps[]
168
- | string
169
- | string[]
170
- | undefined
171
- ): this
183
+ insertAfter(oldNode: Child | number, newNode: Container.NewChild): this
184
+
172
185
  /**
173
186
  * Insert new node before old node within the container.
174
187
  *
@@ -180,17 +193,7 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
180
193
  * @param newNode New node.
181
194
  * @return This node for methods chain.
182
195
  */
183
- insertBefore(
184
- oldNode: Child | number,
185
- newNode:
186
- | Child
187
- | Child[]
188
- | ChildProps
189
- | ChildProps[]
190
- | string
191
- | string[]
192
- | undefined
193
- ): this
196
+ insertBefore(oldNode: Child | number, newNode: Container.NewChild): this
194
197
 
195
198
  /**
196
199
  * Traverses the container’s descendant nodes, calling callback
@@ -229,17 +232,7 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
229
232
  * @param nodes New nodes.
230
233
  * @return This node for methods chain.
231
234
  */
232
- prepend(
233
- ...nodes: (
234
- | ChildProps
235
- | ChildProps[]
236
- | Node
237
- | Node[]
238
- | string
239
- | string[]
240
- | undefined
241
- )[]
242
- ): this
235
+ prepend(...nodes: Container.NewChild[]): this
243
236
  /**
244
237
  * Add child to the end of the node.
245
238
  *
@@ -301,8 +294,8 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
301
294
  * ```
302
295
  *
303
296
  * @param pattern Replace pattern.
304
- * @param {object} opts Options to speed up the search.
305
- * @param callback String to replace pattern or callback
297
+ * @param {object} options Options to speed up the search.
298
+ * @param replaced String to replace pattern or callback
306
299
  * that returns a new value. The callback
307
300
  * will receive the same arguments
308
301
  * as those passed to a function parameter
package/lib/container.js CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict'
2
2
 
3
- let { isClean, my } = require('./symbols')
4
- let Declaration = require('./declaration')
5
3
  let Comment = require('./comment')
4
+ let Declaration = require('./declaration')
6
5
  let Node = require('./node')
6
+ let { isClean, my } = require('./symbols')
7
7
 
8
- let parse, Rule, AtRule, Root
8
+ let AtRule, parse, Root, Rule
9
9
 
10
10
  function cleanSource(nodes) {
11
11
  return nodes.map(i => {
@@ -198,7 +198,7 @@ class Container extends Node {
198
198
  nodes.value = String(nodes.value)
199
199
  }
200
200
  nodes = [new Declaration(nodes)]
201
- } else if (nodes.selector) {
201
+ } else if (nodes.selector || nodes.selectors) {
202
202
  nodes = [new Rule(nodes)]
203
203
  } else if (nodes.name) {
204
204
  nodes = [new AtRule(nodes)]
@@ -52,37 +52,70 @@ class CssSyntaxError extends Error {
52
52
 
53
53
  let css = this.source
54
54
  if (color == null) color = pico.isColorSupported
55
- if (terminalHighlight) {
56
- if (color) css = terminalHighlight(css)
57
- }
58
-
59
- let lines = css.split(/\r?\n/)
60
- let start = Math.max(this.line - 3, 0)
61
- let end = Math.min(this.line + 2, lines.length)
62
55
 
63
- let maxWidth = String(end).length
64
-
65
- let mark, aside
56
+ let aside = text => text
57
+ let mark = text => text
58
+ let highlight = text => text
66
59
  if (color) {
67
60
  let { bold, gray, red } = pico.createColors(true)
68
61
  mark = text => bold(red(text))
69
62
  aside = text => gray(text)
70
- } else {
71
- mark = aside = str => str
63
+ if (terminalHighlight) {
64
+ highlight = text => terminalHighlight(text)
65
+ }
72
66
  }
73
67
 
68
+ let lines = css.split(/\r?\n/)
69
+ let start = Math.max(this.line - 3, 0)
70
+ let end = Math.min(this.line + 2, lines.length)
71
+ let maxWidth = String(end).length
72
+
74
73
  return lines
75
74
  .slice(start, end)
76
75
  .map((line, index) => {
77
76
  let number = start + 1 + index
78
77
  let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | '
79
78
  if (number === this.line) {
79
+ if (line.length > 160) {
80
+ let padding = 20
81
+ let subLineStart = Math.max(0, this.column - padding)
82
+ let subLineEnd = Math.max(
83
+ this.column + padding,
84
+ this.endColumn + padding
85
+ )
86
+ let subLine = line.slice(subLineStart, subLineEnd)
87
+
88
+ let spacing =
89
+ aside(gutter.replace(/\d/g, ' ')) +
90
+ line
91
+ .slice(0, Math.min(this.column - 1, padding - 1))
92
+ .replace(/[^\t]/g, ' ')
93
+
94
+ return (
95
+ mark('>') +
96
+ aside(gutter) +
97
+ highlight(subLine) +
98
+ '\n ' +
99
+ spacing +
100
+ mark('^')
101
+ )
102
+ }
103
+
80
104
  let spacing =
81
105
  aside(gutter.replace(/\d/g, ' ')) +
82
106
  line.slice(0, this.column - 1).replace(/[^\t]/g, ' ')
83
- return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^')
107
+
108
+ return (
109
+ mark('>') +
110
+ aside(gutter) +
111
+ highlight(line) +
112
+ '\n ' +
113
+ spacing +
114
+ mark('^')
115
+ )
84
116
  }
85
- return ' ' + aside(gutter) + line
117
+
118
+ return ' ' + aside(gutter) + highlight(line)
86
119
  })
87
120
  .join('\n')
88
121
  }
@@ -63,6 +63,19 @@ declare namespace Declaration {
63
63
  * ```
64
64
  */
65
65
  declare class Declaration_ extends Node {
66
+ parent: ContainerWithChildren | undefined
67
+ raws: Declaration.DeclarationRaws
68
+
69
+ type: 'decl'
70
+
71
+ constructor(defaults?: Declaration.DeclarationProps)
72
+ assign(overrides: Declaration.DeclarationProps | object): this
73
+
74
+ clone(overrides?: Partial<Declaration.DeclarationProps>): this
75
+
76
+ cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): this
77
+
78
+ cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this
66
79
  /**
67
80
  * It represents a specificity of the declaration.
68
81
  *
@@ -78,10 +91,8 @@ declare class Declaration_ extends Node {
78
91
  * ```
79
92
  */
80
93
  get important(): boolean
81
- set important(value: boolean)
82
-
83
- parent: ContainerWithChildren | undefined
84
94
 
95
+ set important(value: boolean)
85
96
  /**
86
97
  * The property name for a CSS declaration.
87
98
  *
@@ -93,12 +104,8 @@ declare class Declaration_ extends Node {
93
104
  * ```
94
105
  */
95
106
  get prop(): string
96
- set prop(value: string)
97
-
98
- raws: Declaration.DeclarationRaws
99
-
100
- type: 'decl'
101
107
 
108
+ set prop(value: string)
102
109
  /**
103
110
  * The property value for a CSS declaration.
104
111
  *
@@ -118,7 +125,6 @@ declare class Declaration_ extends Node {
118
125
  */
119
126
  get value(): string
120
127
  set value(value: string)
121
-
122
128
  /**
123
129
  * It represents a getter that returns `true` if a declaration starts with
124
130
  * `--` or `$`, which are used to declare variables in CSS and SASS/SCSS.
@@ -138,13 +144,6 @@ declare class Declaration_ extends Node {
138
144
  * ```
139
145
  */
140
146
  get variable(): boolean
141
- set varaible(value: string)
142
-
143
- constructor(defaults?: Declaration.DeclarationProps)
144
- assign(overrides: Declaration.DeclarationProps | object): this
145
- clone(overrides?: Partial<Declaration.DeclarationProps>): Declaration
146
- cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): Declaration
147
- cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): Declaration
148
147
  }
149
148
 
150
149
  declare class Declaration extends Declaration_ {}
package/lib/document.d.ts CHANGED
@@ -5,7 +5,7 @@ import Root from './root.js'
5
5
 
6
6
  declare namespace Document {
7
7
  export interface DocumentProps extends ContainerProps {
8
- nodes?: Root[]
8
+ nodes?: readonly Root[]
9
9
 
10
10
  /**
11
11
  * Information to generate byte-to-byte equal node string as it was
@@ -42,9 +42,9 @@ declare class Document_ extends Container<Root> {
42
42
  constructor(defaults?: Document.DocumentProps)
43
43
 
44
44
  assign(overrides: Document.DocumentProps | object): this
45
- clone(overrides?: Partial<Document.DocumentProps>): Document
46
- cloneAfter(overrides?: Partial<Document.DocumentProps>): Document
47
- cloneBefore(overrides?: Partial<Document.DocumentProps>): Document
45
+ clone(overrides?: Partial<Document.DocumentProps>): this
46
+ cloneAfter(overrides?: Partial<Document.DocumentProps>): this
47
+ cloneBefore(overrides?: Partial<Document.DocumentProps>): this
48
48
 
49
49
  /**
50
50
  * Returns a `Result` instance representing the document’s CSS roots.
package/lib/fromJSON.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
 
3
- let Declaration = require('./declaration')
4
- let PreviousMap = require('./previous-map')
5
- let Comment = require('./comment')
6
3
  let AtRule = require('./at-rule')
4
+ let Comment = require('./comment')
5
+ let Declaration = require('./declaration')
7
6
  let Input = require('./input')
7
+ let PreviousMap = require('./previous-map')
8
8
  let Root = require('./root')
9
9
  let Rule = require('./rule')
10
10
 
package/lib/input.d.ts CHANGED
@@ -174,6 +174,9 @@ declare class Input_ {
174
174
  endLine?: number,
175
175
  endColumn?: number
176
176
  ): false | Input.FilePosition
177
+ /** Converts this to a JSON-friendly object representation. */
178
+ toJSON(): object
179
+
177
180
  /**
178
181
  * The CSS source identifier. Contains `Input#file` if the user
179
182
  * set the `from` option, or `Input#id` if they did not.
package/lib/input.js CHANGED
@@ -1,13 +1,13 @@
1
1
  'use strict'
2
2
 
3
+ let { nanoid } = require('nanoid/non-secure')
4
+ let { isAbsolute, resolve } = require('path')
3
5
  let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
4
6
  let { fileURLToPath, pathToFileURL } = require('url')
5
- let { isAbsolute, resolve } = require('path')
6
- let { nanoid } = require('nanoid/non-secure')
7
7
 
8
- let terminalHighlight = require('./terminal-highlight')
9
8
  let CssSyntaxError = require('./css-syntax-error')
10
9
  let PreviousMap = require('./previous-map')
10
+ let terminalHighlight = require('./terminal-highlight')
11
11
 
12
12
  let fromOffsetCache = Symbol('fromOffsetCache')
13
13
 
@@ -61,7 +61,7 @@ class Input {
61
61
  }
62
62
 
63
63
  error(message, line, column, opts = {}) {
64
- let result, endLine, endColumn
64
+ let endColumn, endLine, result
65
65
 
66
66
  if (line && typeof line === 'object') {
67
67
  let start = line
@@ -1,14 +1,14 @@
1
1
  'use strict'
2
2
 
3
- let { isClean, my } = require('./symbols')
4
- let MapGenerator = require('./map-generator')
5
- let stringify = require('./stringify')
6
3
  let Container = require('./container')
7
4
  let Document = require('./document')
8
- let warnOnce = require('./warn-once')
9
- let Result = require('./result')
5
+ let MapGenerator = require('./map-generator')
10
6
  let parse = require('./parse')
7
+ let Result = require('./result')
11
8
  let Root = require('./root')
9
+ let stringify = require('./stringify')
10
+ let { isClean, my } = require('./symbols')
11
+ let warnOnce = require('./warn-once')
12
12
 
13
13
  const TYPE_TO_CLASS_NAME = {
14
14
  atrule: 'AtRule',
@@ -269,7 +269,7 @@ class LazyResult {
269
269
  if (this.hasListener) {
270
270
  let root = this.result.root
271
271
  while (!root[isClean]) {
272
- root[isClean] = true
272
+ root.markClean()
273
273
  let stack = [toStack(root)]
274
274
  while (stack.length > 0) {
275
275
  let promise = this.visitTick(stack)
@@ -374,7 +374,7 @@ class LazyResult {
374
374
  if (this.hasListener) {
375
375
  let root = this.result.root
376
376
  while (!root[isClean]) {
377
- root[isClean] = true
377
+ root.markClean()
378
378
  this.walkSync(root)
379
379
  }
380
380
  if (this.listeners.OnceExit) {
@@ -456,7 +456,7 @@ class LazyResult {
456
456
  while ((child = node.nodes[node.indexes[iterator]])) {
457
457
  node.indexes[iterator] += 1
458
458
  if (!child[isClean]) {
459
- child[isClean] = true
459
+ child.markClean()
460
460
  stack.push(toStack(child))
461
461
  return
462
462
  }
@@ -471,7 +471,7 @@ class LazyResult {
471
471
  visit.eventIndex += 1
472
472
  if (event === CHILDREN) {
473
473
  if (node.nodes && node.nodes.length) {
474
- node[isClean] = true
474
+ node.markClean()
475
475
  visit.iterator = node.getIterator()
476
476
  }
477
477
  return
@@ -484,7 +484,7 @@ class LazyResult {
484
484
  }
485
485
 
486
486
  walkSync(node) {
487
- node[isClean] = true
487
+ node.markClean()
488
488
  let events = getEvents(node)
489
489
  for (let event of events) {
490
490
  if (event === CHILDREN) {
package/lib/list.d.ts CHANGED
@@ -47,11 +47,14 @@ declare namespace list {
47
47
  * @param last boolean indicator.
48
48
  * @return Split values.
49
49
  */
50
- split(string: string, separators: string[], last: boolean): string[]
50
+ split(
51
+ string: string,
52
+ separators: readonly string[],
53
+ last: boolean
54
+ ): string[]
51
55
  }
52
56
  }
53
57
 
54
- // eslint-disable-next-line @typescript-eslint/no-redeclare
55
58
  declare const list: list.List
56
59
 
57
60
  export = list
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
4
3
  let { dirname, relative, resolve, sep } = require('path')
4
+ let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
5
5
  let { pathToFileURL } = require('url')
6
6
 
7
7
  let Input = require('./input')
@@ -70,12 +70,12 @@ class MapGenerator {
70
70
  for (let i = this.root.nodes.length - 1; i >= 0; i--) {
71
71
  node = this.root.nodes[i]
72
72
  if (node.type !== 'comment') continue
73
- if (node.text.indexOf('# sourceMappingURL=') === 0) {
73
+ if (node.text.startsWith('# sourceMappingURL=')) {
74
74
  this.root.removeChild(i)
75
75
  }
76
76
  }
77
77
  } else if (this.css) {
78
- this.css = this.css.replace(/\n*?\/\*#[\S\s]*?\*\/$/gm, '')
78
+ this.css = this.css.replace(/\n*\/\*#[\S\s]*?\*\/$/gm, '')
79
79
  }
80
80
  }
81
81
 
@@ -143,7 +143,7 @@ class MapGenerator {
143
143
  source: ''
144
144
  }
145
145
 
146
- let lines, last
146
+ let last, lines
147
147
  this.stringify(this.root, (str, node, type) => {
148
148
  this.css += str
149
149
 
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
 
3
3
  let MapGenerator = require('./map-generator')
4
- let stringify = require('./stringify')
5
- let warnOnce = require('./warn-once')
6
4
  let parse = require('./parse')
7
5
  const Result = require('./result')
6
+ let stringify = require('./stringify')
7
+ let warnOnce = require('./warn-once')
8
8
 
9
9
  class NoWorkResult {
10
10
  constructor(processor, css, opts) {
package/lib/node.d.ts CHANGED
@@ -2,7 +2,7 @@ import AtRule = require('./at-rule.js')
2
2
 
3
3
  import { AtRuleProps } from './at-rule.js'
4
4
  import Comment, { CommentProps } from './comment.js'
5
- import Container from './container.js'
5
+ import Container, { NewChild } from './container.js'
6
6
  import CssSyntaxError from './css-syntax-error.js'
7
7
  import Declaration, { DeclarationProps } from './declaration.js'
8
8
  import Document from './document.js'
@@ -234,6 +234,14 @@ declare abstract class Node_ {
234
234
 
235
235
  constructor(defaults?: object)
236
236
 
237
+ /**
238
+ * If this node isn't already dirty, marks it and its ancestors as such. This
239
+ * indicates to the LazyResult processor that the {@link Root} has been
240
+ * modified by the current plugin and may need to be processed again by other
241
+ * plugins.
242
+ */
243
+ protected markDirty(): void
244
+
237
245
  /**
238
246
  * Insert new node after current node to current node’s parent.
239
247
  *
@@ -246,7 +254,9 @@ declare abstract class Node_ {
246
254
  * @param newNode New node.
247
255
  * @return This node for methods chain.
248
256
  */
249
- after(newNode: Node | Node.ChildProps | Node[] | string | undefined): this
257
+ after(
258
+ newNode: Node | Node.ChildProps | readonly Node[] | string | undefined
259
+ ): this
250
260
 
251
261
  /**
252
262
  * It assigns properties to an existing node instance.
@@ -273,7 +283,9 @@ declare abstract class Node_ {
273
283
  * @param newNode New node.
274
284
  * @return This node for methods chain.
275
285
  */
276
- before(newNode: Node | Node.ChildProps | Node[] | string | undefined): this
286
+ before(
287
+ newNode: Node | Node.ChildProps | readonly Node[] | string | undefined
288
+ ): this
277
289
 
278
290
  /**
279
291
  * Clear the code style properties for the node and its children.
@@ -303,7 +315,7 @@ declare abstract class Node_ {
303
315
  *
304
316
  * @return Duplicate of the node instance.
305
317
  */
306
- clone(overrides?: object): Node
318
+ clone(overrides?: object): this
307
319
 
308
320
  /**
309
321
  * Shortcut to clone the node and insert the resulting cloned node
@@ -312,7 +324,7 @@ declare abstract class Node_ {
312
324
  * @param overrides New properties to override in the clone.
313
325
  * @return New node.
314
326
  */
315
- cloneAfter(overrides?: object): Node
327
+ cloneAfter(overrides?: object): this
316
328
 
317
329
  /**
318
330
  * Shortcut to clone the node and insert the resulting cloned node
@@ -326,7 +338,7 @@ declare abstract class Node_ {
326
338
  *
327
339
  * @return New node
328
340
  */
329
- cloneBefore(overrides?: object): Node
341
+ cloneBefore(overrides?: object): this
330
342
 
331
343
  /**
332
344
  * It creates an instance of the class `CssSyntaxError` and parameters passed
@@ -470,14 +482,7 @@ declare abstract class Node_ {
470
482
  * @param nodes Mode(s) to replace current one.
471
483
  * @return Current node to methods chain.
472
484
  */
473
- replaceWith(
474
- ...nodes: (
475
- | Node.ChildNode
476
- | Node.ChildNode[]
477
- | Node.ChildProps
478
- | Node.ChildProps[]
479
- )[]
480
- ): this
485
+ replaceWith(...nodes: NewChild[]): this
481
486
 
482
487
  /**
483
488
  * Finds the Root instance of the node’s tree.
package/lib/node.js CHANGED
@@ -1,9 +1,9 @@
1
1
  'use strict'
2
2
 
3
- let { isClean, my } = require('./symbols')
4
3
  let CssSyntaxError = require('./css-syntax-error')
5
4
  let Stringifier = require('./stringifier')
6
5
  let stringify = require('./stringify')
6
+ let { isClean, my } = require('./symbols')
7
7
 
8
8
  function cloneNode(obj, parent) {
9
9
  let cloned = new obj.constructor()
@@ -153,6 +153,10 @@ class Node {
153
153
  }
154
154
  }
155
155
 
156
+ markClean() {
157
+ this[isClean] = true;
158
+ }
159
+
156
160
  markDirty() {
157
161
  if (this[isClean]) {
158
162
  this[isClean] = false
package/lib/parse.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  let Container = require('./container')
4
- let Parser = require('./parser')
5
4
  let Input = require('./input')
5
+ let Parser = require('./parser')
6
6
 
7
7
  function parse(css, opts) {
8
8
  let input = new Input(css, opts)
package/lib/parser.js CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict'
2
2
 
3
- let Declaration = require('./declaration')
4
- let tokenizer = require('./tokenize')
5
- let Comment = require('./comment')
6
3
  let AtRule = require('./at-rule')
4
+ let Comment = require('./comment')
5
+ let Declaration = require('./declaration')
7
6
  let Root = require('./root')
8
7
  let Rule = require('./rule')
8
+ let tokenizer = require('./tokenize')
9
9
 
10
10
  const SAFE_COMMENT_NEIGHBOR = {
11
11
  empty: true,
@@ -143,7 +143,7 @@ class Parser {
143
143
 
144
144
  colon(tokens) {
145
145
  let brackets = 0
146
- let token, type, prev
146
+ let prev, token, type
147
147
  for (let [i, element] of tokens.entries()) {
148
148
  token = element
149
149
  type = token[0]
@@ -267,12 +267,12 @@ class Parser {
267
267
  let str = ''
268
268
  for (let j = i; j > 0; j--) {
269
269
  let type = cache[j][0]
270
- if (str.trim().indexOf('!') === 0 && type !== 'space') {
270
+ if (str.trim().startsWith('!') && type !== 'space') {
271
271
  break
272
272
  }
273
273
  str = cache.pop()[1] + str
274
274
  }
275
- if (str.trim().indexOf('!') === 0) {
275
+ if (str.trim().startsWith('!')) {
276
276
  node.important = true
277
277
  node.raws.important = str
278
278
  tokens = cache
package/lib/postcss.d.mts CHANGED
@@ -9,14 +9,12 @@ export {
9
9
  plugin,
10
10
  parse,
11
11
  list,
12
-
13
12
  document,
14
13
  comment,
15
14
  atRule,
16
15
  rule,
17
16
  decl,
18
17
  root,
19
-
20
18
  CssSyntaxError,
21
19
  Declaration,
22
20
  Container,
@@ -67,6 +65,5 @@ export {
67
65
  WarningOptions,
68
66
 
69
67
  // This is a class, but it’s not re-exported. That’s why it’s exported as type-only here.
70
- type LazyResult,
71
-
68
+ type LazyResult
72
69
  } from './postcss.js'
package/lib/postcss.d.ts CHANGED
@@ -2,7 +2,7 @@ import { RawSourceMap, SourceMapGenerator } from 'source-map-js'
2
2
 
3
3
  import AtRule, { AtRuleProps } from './at-rule.js'
4
4
  import Comment, { CommentProps } from './comment.js'
5
- import Container, { ContainerProps } from './container.js'
5
+ import Container, { ContainerProps, NewChild } from './container.js'
6
6
  import CssSyntaxError from './css-syntax-error.js'
7
7
  import Declaration, { DeclarationProps } from './declaration.js'
8
8
  import Document, { DocumentProps } from './document.js'
@@ -28,13 +28,22 @@ type DocumentProcessor = (
28
28
  document: Document,
29
29
  helper: postcss.Helpers
30
30
  ) => Promise<void> | void
31
- type RootProcessor = (root: Root, helper: postcss.Helpers) => Promise<void> | void
31
+ type RootProcessor = (
32
+ root: Root,
33
+ helper: postcss.Helpers
34
+ ) => Promise<void> | void
32
35
  type DeclarationProcessor = (
33
36
  decl: Declaration,
34
37
  helper: postcss.Helpers
35
38
  ) => Promise<void> | void
36
- type RuleProcessor = (rule: Rule, helper: postcss.Helpers) => Promise<void> | void
37
- type AtRuleProcessor = (atRule: AtRule, helper: postcss.Helpers) => Promise<void> | void
39
+ type RuleProcessor = (
40
+ rule: Rule,
41
+ helper: postcss.Helpers
42
+ ) => Promise<void> | void
43
+ type AtRuleProcessor = (
44
+ atRule: AtRule,
45
+ helper: postcss.Helpers
46
+ ) => Promise<void> | void
38
47
  type CommentProcessor = (
39
48
  comment: Comment,
40
49
  helper: postcss.Helpers
@@ -161,6 +170,7 @@ declare namespace postcss {
161
170
  LazyResult,
162
171
  list,
163
172
  Message,
173
+ NewChild,
164
174
  Node,
165
175
  NodeErrorOptions,
166
176
  NodeProps,
@@ -176,9 +186,9 @@ declare namespace postcss {
176
186
  WarningOptions
177
187
  }
178
188
 
179
- export type SourceMap = SourceMapGenerator & {
189
+ export type SourceMap = {
180
190
  toJSON(): RawSourceMap
181
- }
191
+ } & SourceMapGenerator
182
192
 
183
193
  export type Helpers = { postcss: Postcss; result: Result } & Postcss
184
194
 
@@ -435,7 +445,9 @@ declare namespace postcss {
435
445
  * @param plugins PostCSS plugins.
436
446
  * @return Processor to process multiple CSS.
437
447
  */
438
- declare function postcss(plugins?: postcss.AcceptedPlugin[]): Processor
448
+ declare function postcss(
449
+ plugins?: readonly postcss.AcceptedPlugin[]
450
+ ): Processor
439
451
  declare function postcss(...plugins: postcss.AcceptedPlugin[]): Processor
440
452
 
441
453
  export = postcss
package/lib/postcss.js CHANGED
@@ -1,23 +1,23 @@
1
1
  'use strict'
2
2
 
3
+ let AtRule = require('./at-rule')
4
+ let Comment = require('./comment')
5
+ let Container = require('./container')
3
6
  let CssSyntaxError = require('./css-syntax-error')
4
7
  let Declaration = require('./declaration')
5
- let LazyResult = require('./lazy-result')
6
- let Container = require('./container')
7
- let Processor = require('./processor')
8
- let stringify = require('./stringify')
9
- let fromJSON = require('./fromJSON')
10
8
  let Document = require('./document')
11
- let Warning = require('./warning')
12
- let Comment = require('./comment')
13
- let AtRule = require('./at-rule')
14
- let Result = require('./result.js')
9
+ let fromJSON = require('./fromJSON')
15
10
  let Input = require('./input')
16
- let parse = require('./parse')
11
+ let LazyResult = require('./lazy-result')
17
12
  let list = require('./list')
18
- let Rule = require('./rule')
19
- let Root = require('./root')
20
13
  let Node = require('./node')
14
+ let parse = require('./parse')
15
+ let Processor = require('./processor')
16
+ let Result = require('./result.js')
17
+ let Root = require('./root')
18
+ let Rule = require('./rule')
19
+ let stringify = require('./stringify')
20
+ let Warning = require('./warning')
21
21
 
22
22
  function postcss(...plugins) {
23
23
  if (plugins.length === 1 && Array.isArray(plugins[0])) {
@@ -1,8 +1,8 @@
1
1
  'use strict'
2
2
 
3
- let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
4
3
  let { existsSync, readFileSync } = require('fs')
5
4
  let { dirname, join } = require('path')
5
+ let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
6
6
 
7
7
  function fromBase64(str) {
8
8
  if (Buffer) {
@@ -41,12 +41,14 @@ class PreviousMap {
41
41
  let charsetUri = /^data:application\/json;charset=utf-?8,/
42
42
  let uri = /^data:application\/json,/
43
43
 
44
- if (charsetUri.test(text) || uri.test(text)) {
45
- return decodeURIComponent(text.substr(RegExp.lastMatch.length))
44
+ let uriMatch = text.match(charsetUri) || text.match(uri)
45
+ if (uriMatch) {
46
+ return decodeURIComponent(text.substr(uriMatch[0].length))
46
47
  }
47
48
 
48
- if (baseCharsetUri.test(text) || baseUri.test(text)) {
49
- return fromBase64(text.substr(RegExp.lastMatch.length))
49
+ let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri)
50
+ if (baseUriMatch) {
51
+ return fromBase64(text.substr(baseUriMatch[0].length))
50
52
  }
51
53
 
52
54
  let encoding = text.match(/data:application\/json;([^,]+),/)[1]
@@ -67,7 +69,7 @@ class PreviousMap {
67
69
  }
68
70
 
69
71
  loadAnnotation(css) {
70
- let comments = css.match(/\/\*\s*# sourceMappingURL=/gm)
72
+ let comments = css.match(/\/\*\s*# sourceMappingURL=/g)
71
73
  if (!comments) return
72
74
 
73
75
  // sourceMappingURLs from comments, strings, etc.
@@ -51,7 +51,7 @@ declare class Processor_ {
51
51
  /**
52
52
  * @param plugins PostCSS plugins
53
53
  */
54
- constructor(plugins?: AcceptedPlugin[])
54
+ constructor(plugins?: readonly AcceptedPlugin[])
55
55
 
56
56
  /**
57
57
  * Parses source CSS and returns a `LazyResult` Promise proxy.
package/lib/processor.js CHANGED
@@ -1,13 +1,13 @@
1
1
  'use strict'
2
2
 
3
- let NoWorkResult = require('./no-work-result')
4
- let LazyResult = require('./lazy-result')
5
3
  let Document = require('./document')
4
+ let LazyResult = require('./lazy-result')
5
+ let NoWorkResult = require('./no-work-result')
6
6
  let Root = require('./root')
7
7
 
8
8
  class Processor {
9
9
  constructor(plugins = []) {
10
- this.version = '8.4.40'
10
+ this.version = '8.4.42'
11
11
  this.plugins = this.normalize(plugins)
12
12
  }
13
13
 
package/lib/result.d.ts CHANGED
@@ -39,7 +39,6 @@ declare namespace Result {
39
39
  plugin?: string
40
40
  }
41
41
 
42
-
43
42
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
44
43
  export { Result_ as default }
45
44
  }
package/lib/root.d.ts CHANGED
@@ -62,9 +62,9 @@ declare class Root_ extends Container {
62
62
  constructor(defaults?: Root.RootProps)
63
63
 
64
64
  assign(overrides: object | Root.RootProps): this
65
- clone(overrides?: Partial<Root.RootProps>): Root
66
- cloneAfter(overrides?: Partial<Root.RootProps>): Root
67
- cloneBefore(overrides?: Partial<Root.RootProps>): Root
65
+ clone(overrides?: Partial<Root.RootProps>): this
66
+ cloneAfter(overrides?: Partial<Root.RootProps>): this
67
+ cloneBefore(overrides?: Partial<Root.RootProps>): this
68
68
 
69
69
  /**
70
70
  * Returns a `Result` instance representing the root’s CSS.
@@ -76,7 +76,7 @@ declare class Root_ extends Container {
76
76
  * const result = root1.toResult({ to: 'all.css', map: true })
77
77
  * ```
78
78
  *
79
- * @param opts Options.
79
+ * @param options Options.
80
80
  * @return Result with current root’s CSS.
81
81
  */
82
82
  toResult(options?: ProcessOptions): Result
package/lib/rule.d.ts CHANGED
@@ -40,14 +40,21 @@ declare namespace Rule {
40
40
  semicolon?: boolean
41
41
  }
42
42
 
43
- export interface RuleProps extends ContainerProps {
43
+ export type RuleProps = {
44
44
  /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
45
45
  raws?: RuleRaws
46
- /** Selector or selectors of the rule. */
47
- selector?: string
48
- /** Selectors of the rule represented as an array of strings. */
49
- selectors?: string[]
50
- }
46
+ } & (
47
+ | {
48
+ /** Selector or selectors of the rule. */
49
+ selector: string
50
+ selectors?: never
51
+ }
52
+ | {
53
+ selector?: never
54
+ /** Selectors of the rule represented as an array of strings. */
55
+ selectors: readonly string[]
56
+ }
57
+ ) & ContainerProps
51
58
 
52
59
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
53
60
  export { Rule_ as default }
@@ -75,6 +82,15 @@ declare class Rule_ extends Container {
75
82
  nodes: NonNullable<Container['nodes']>
76
83
  parent: ContainerWithChildren | undefined
77
84
  raws: Rule.RuleRaws
85
+ type: 'rule'
86
+ constructor(defaults?: Rule.RuleProps)
87
+
88
+ assign(overrides: object | Rule.RuleProps): this
89
+ clone(overrides?: Partial<Rule.RuleProps>): this
90
+
91
+ cloneAfter(overrides?: Partial<Rule.RuleProps>): this
92
+
93
+ cloneBefore(overrides?: Partial<Rule.RuleProps>): this
78
94
  /**
79
95
  * The rule’s full selector represented as a string.
80
96
  *
@@ -85,8 +101,7 @@ declare class Rule_ extends Container {
85
101
  * ```
86
102
  */
87
103
  get selector(): string
88
- set selector(value: string);
89
-
104
+ set selector(value: string)
90
105
  /**
91
106
  * An array containing the rule’s individual selectors.
92
107
  * Groups of selectors are split at commas.
@@ -103,15 +118,7 @@ declare class Rule_ extends Container {
103
118
  * ```
104
119
  */
105
120
  get selectors(): string[]
106
- set selectors(values: string[]);
107
-
108
- type: 'rule'
109
-
110
- constructor(defaults?: Rule.RuleProps)
111
- assign(overrides: object | Rule.RuleProps): this
112
- clone(overrides?: Partial<Rule.RuleProps>): Rule
113
- cloneAfter(overrides?: Partial<Rule.RuleProps>): Rule
114
- cloneBefore(overrides?: Partial<Rule.RuleProps>): Rule
121
+ set selectors(values: string[])
115
122
  }
116
123
 
117
124
  declare class Rule extends Rule_ {}
package/lib/tokenize.js CHANGED
@@ -29,8 +29,8 @@ module.exports = function tokenizer(input, options = {}) {
29
29
  let css = input.css.valueOf()
30
30
  let ignore = options.ignoreErrors
31
31
 
32
- let code, next, quote, content, escape
33
- let escaped, escapePos, prev, n, currentToken
32
+ let code, content, escape, next, quote
33
+ let currentToken, escaped, escapePos, n, prev
34
34
 
35
35
  let length = css.length
36
36
  let pos = 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss",
3
- "version": "8.4.40",
3
+ "version": "8.4.42",
4
4
  "description": "Tool for transforming styles with JS plugins",
5
5
  "engines": {
6
6
  "node": "^10 || ^12 || >=14"