postcss 8.3.9 → 8.4.31

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.
Files changed (44) hide show
  1. package/README.md +7 -23
  2. package/lib/at-rule.d.ts +58 -49
  3. package/lib/comment.d.ts +43 -32
  4. package/lib/container.d.ts +233 -223
  5. package/lib/container.js +251 -244
  6. package/lib/css-syntax-error.d.ts +117 -61
  7. package/lib/css-syntax-error.js +10 -3
  8. package/lib/declaration.d.ts +85 -61
  9. package/lib/document.d.ts +27 -16
  10. package/lib/fromJSON.d.ts +6 -2
  11. package/lib/input.d.ts +118 -54
  12. package/lib/input.js +87 -55
  13. package/lib/lazy-result.d.ts +82 -67
  14. package/lib/lazy-result.js +234 -232
  15. package/lib/list.d.ts +53 -47
  16. package/lib/list.js +16 -14
  17. package/lib/map-generator.js +231 -172
  18. package/lib/no-work-result.d.ts +46 -0
  19. package/lib/no-work-result.js +135 -0
  20. package/lib/node.d.ts +345 -253
  21. package/lib/node.js +200 -139
  22. package/lib/parse.d.ts +6 -2
  23. package/lib/parser.js +354 -309
  24. package/lib/postcss.d.mts +72 -0
  25. package/lib/postcss.d.ts +288 -319
  26. package/lib/postcss.js +18 -12
  27. package/lib/postcss.mjs +1 -0
  28. package/lib/previous-map.d.ts +23 -14
  29. package/lib/previous-map.js +37 -40
  30. package/lib/processor.d.ts +55 -41
  31. package/lib/processor.js +20 -27
  32. package/lib/result.d.ts +87 -76
  33. package/lib/root.d.ts +49 -36
  34. package/lib/root.js +12 -10
  35. package/lib/rule.d.ts +54 -45
  36. package/lib/stringifier.d.ts +46 -0
  37. package/lib/stringifier.js +140 -138
  38. package/lib/stringify.d.ts +6 -2
  39. package/lib/terminal-highlight.js +11 -11
  40. package/lib/tokenize.js +2 -2
  41. package/lib/warn-once.js +1 -0
  42. package/lib/warning.d.ts +79 -36
  43. package/lib/warning.js +6 -4
  44. package/package.json +20 -10
@@ -1,5 +1,25 @@
1
1
  import { FilePosition } from './input.js'
2
2
 
3
+ declare namespace CssSyntaxError {
4
+ /**
5
+ * A position that is part of a range.
6
+ */
7
+ export interface RangePosition {
8
+ /**
9
+ * The column number in the input.
10
+ */
11
+ column: number
12
+
13
+ /**
14
+ * The line number in the input.
15
+ */
16
+ line: number
17
+ }
18
+
19
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
20
+ export { CssSyntaxError_ as default }
21
+ }
22
+
3
23
  /**
4
24
  * The CSS parser throws this error for broken CSS.
5
25
  *
@@ -29,58 +49,47 @@ import { FilePosition } from './input.js'
29
49
  * }
30
50
  * ```
31
51
  */
32
- export default class CssSyntaxError {
33
- /**
34
- * @param message Error message.
35
- * @param line Source line of the error.
36
- * @param column Source column of the error.
37
- * @param source Source code of the broken file.
38
- * @param file Absolute path to the broken file.
39
- * @param plugin PostCSS plugin name, if error came from plugin.
40
- */
41
- constructor(
42
- message: string,
43
- line?: number,
44
- column?: number,
45
- source?: string,
46
- file?: string,
47
- plugin?: string
48
- )
49
-
50
- stack: string
51
-
52
+ declare class CssSyntaxError_ {
52
53
  /**
53
- * Always equal to `'CssSyntaxError'`. You should always check error type
54
- * by `error.name === 'CssSyntaxError'`
55
- * instead of `error instanceof CssSyntaxError`,
56
- * because npm could have several PostCSS versions.
54
+ * Source column of the error.
57
55
  *
58
56
  * ```js
59
- * if (error.name === 'CssSyntaxError') {
60
- * error //=> CssSyntaxError
61
- * }
57
+ * error.column //=> 1
58
+ * error.input.column //=> 4
62
59
  * ```
60
+ *
61
+ * PostCSS will use the input source map to detect the original location.
62
+ * If you need the position in the PostCSS input, use `error.input.column`.
63
63
  */
64
- name: 'CssSyntaxError'
64
+ column?: number
65
65
 
66
66
  /**
67
- * Error message.
67
+ * Source column of the error's end, exclusive. Provided if the error pertains
68
+ * to a range.
68
69
  *
69
70
  * ```js
70
- * error.message //=> 'Unclosed block'
71
+ * error.endColumn //=> 1
72
+ * error.input.endColumn //=> 4
71
73
  * ```
74
+ *
75
+ * PostCSS will use the input source map to detect the original location.
76
+ * If you need the position in the PostCSS input, use `error.input.endColumn`.
72
77
  */
73
- reason: string
78
+ endColumn?: number
74
79
 
75
80
  /**
76
- * Full error text in the GNU error format
77
- * with plugin, file, line and column.
81
+ * Source line of the error's end, exclusive. Provided if the error pertains
82
+ * to a range.
78
83
  *
79
84
  * ```js
80
- * error.message //=> 'a.css:1:1: Unclosed block'
85
+ * error.endLine //=> 3
86
+ * error.input.endLine //=> 4
81
87
  * ```
88
+ *
89
+ * PostCSS will use the input source map to detect the original location.
90
+ * If you need the position in the PostCSS input, use `error.input.endLine`.
82
91
  */
83
- message: string
92
+ endLine?: number
84
93
 
85
94
  /**
86
95
  * Absolute path to the broken file.
@@ -95,6 +104,20 @@ export default class CssSyntaxError {
95
104
  */
96
105
  file?: string
97
106
 
107
+ /**
108
+ * Input object with PostCSS internal information
109
+ * about input file. If input has source map
110
+ * from previous tool, PostCSS will use origin
111
+ * (for example, Sass) source. You can use this
112
+ * object to get PostCSS input source.
113
+ *
114
+ * ```js
115
+ * error.input.file //=> 'a.css'
116
+ * error.file //=> 'a.sass'
117
+ * ```
118
+ */
119
+ input?: FilePosition
120
+
98
121
  /**
99
122
  * Source line of the error.
100
123
  *
@@ -109,27 +132,28 @@ export default class CssSyntaxError {
109
132
  line?: number
110
133
 
111
134
  /**
112
- * Source column of the error.
135
+ * Full error text in the GNU error format
136
+ * with plugin, file, line and column.
113
137
  *
114
138
  * ```js
115
- * error.column //=> 1
116
- * error.input.column //=> 4
139
+ * error.message //=> 'a.css:1:1: Unclosed block'
117
140
  * ```
118
- *
119
- * PostCSS will use the input source map to detect the original location.
120
- * If you need the position in the PostCSS input, use `error.input.column`.
121
141
  */
122
- column?: number
142
+ message: string
123
143
 
124
144
  /**
125
- * Source code of the broken file.
145
+ * Always equal to `'CssSyntaxError'`. You should always check error type
146
+ * by `error.name === 'CssSyntaxError'`
147
+ * instead of `error instanceof CssSyntaxError`,
148
+ * because npm could have several PostCSS versions.
126
149
  *
127
150
  * ```js
128
- * error.source //=> 'a { b {} }'
129
- * error.input.source //=> 'a b { }'
151
+ * if (error.name === 'CssSyntaxError') {
152
+ * error //=> CssSyntaxError
153
+ * }
130
154
  * ```
131
155
  */
132
- source?: string
156
+ name: 'CssSyntaxError'
133
157
 
134
158
  /**
135
159
  * Plugin name, if error came from plugin.
@@ -141,31 +165,46 @@ export default class CssSyntaxError {
141
165
  plugin?: string
142
166
 
143
167
  /**
144
- * Input object with PostCSS internal information
145
- * about input file. If input has source map
146
- * from previous tool, PostCSS will use origin
147
- * (for example, Sass) source. You can use this
148
- * object to get PostCSS input source.
168
+ * Error message.
149
169
  *
150
170
  * ```js
151
- * error.input.file //=> 'a.css'
152
- * error.file //=> 'a.sass'
171
+ * error.message //=> 'Unclosed block'
153
172
  * ```
154
173
  */
155
- input?: FilePosition
174
+ reason: string
156
175
 
157
176
  /**
158
- * Returns error position, message and source code of the broken part.
177
+ * Source code of the broken file.
159
178
  *
160
179
  * ```js
161
- * error.toString() //=> "CssSyntaxError: app.css:1:1: Unclosed block
162
- * // > 1 | a {
163
- * // | ^"
180
+ * error.source //=> 'a { b {} }'
181
+ * error.input.source //=> 'a b { }'
164
182
  * ```
165
- *
166
- * @return Error position, message and source code.
167
183
  */
168
- toString(): string
184
+ source?: string
185
+
186
+ stack: string
187
+
188
+ /**
189
+ * Instantiates a CSS syntax error. Can be instantiated for a single position
190
+ * or for a range.
191
+ * @param message Error message.
192
+ * @param lineOrStartPos If for a single position, the line number, or if for
193
+ * a range, the inclusive start position of the error.
194
+ * @param columnOrEndPos If for a single position, the column number, or if for
195
+ * a range, the exclusive end position of the error.
196
+ * @param source Source code of the broken file.
197
+ * @param file Absolute path to the broken file.
198
+ * @param plugin PostCSS plugin name, if error came from plugin.
199
+ */
200
+ constructor(
201
+ message: string,
202
+ lineOrStartPos?: CssSyntaxError.RangePosition | number,
203
+ columnOrEndPos?: CssSyntaxError.RangePosition | number,
204
+ source?: string,
205
+ file?: string,
206
+ plugin?: string
207
+ )
169
208
 
170
209
  /**
171
210
  * Returns a few lines of CSS source that caused the error.
@@ -189,4 +228,21 @@ export default class CssSyntaxError {
189
228
  * @return Few lines of CSS source that caused the error.
190
229
  */
191
230
  showSourceCode(color?: boolean): string
231
+
232
+ /**
233
+ * Returns error position, message and source code of the broken part.
234
+ *
235
+ * ```js
236
+ * error.toString() //=> "CssSyntaxError: app.css:1:1: Unclosed block
237
+ * // > 1 | a {
238
+ * // | ^"
239
+ * ```
240
+ *
241
+ * @return Error position, message and source code.
242
+ */
243
+ toString(): string
192
244
  }
245
+
246
+ declare class CssSyntaxError extends CssSyntaxError_ {}
247
+
248
+ export = CssSyntaxError
@@ -20,8 +20,15 @@ class CssSyntaxError extends Error {
20
20
  this.plugin = plugin
21
21
  }
22
22
  if (typeof line !== 'undefined' && typeof column !== 'undefined') {
23
- this.line = line
24
- this.column = column
23
+ if (typeof line === 'number') {
24
+ this.line = line
25
+ this.column = column
26
+ } else {
27
+ this.line = line.line
28
+ this.column = line.column
29
+ this.endLine = column.line
30
+ this.endColumn = column.column
31
+ }
25
32
  }
26
33
 
27
34
  this.setMessage()
@@ -57,7 +64,7 @@ class CssSyntaxError extends Error {
57
64
 
58
65
  let mark, aside
59
66
  if (color) {
60
- let { bold, red, gray } = pico.createColors(true)
67
+ let { bold, gray, red } = pico.createColors(true)
61
68
  mark = text => bold(red(text))
62
69
  aside = text => gray(text)
63
70
  } else {
@@ -1,124 +1,148 @@
1
1
  import Container from './container.js'
2
2
  import Node from './node.js'
3
3
 
4
- interface DeclarationRaws {
5
- /**
6
- * The space symbols before the node. It also stores `*`
7
- * and `_` symbols before the declaration (IE hack).
8
- */
9
- before?: string
4
+ declare namespace Declaration {
5
+ export interface DeclarationRaws extends Record<string, unknown> {
6
+ /**
7
+ * The space symbols before the node. It also stores `*`
8
+ * and `_` symbols before the declaration (IE hack).
9
+ */
10
+ before?: string
10
11
 
11
- /**
12
- * The symbols between the property and value for declarations.
13
- */
14
- between?: string
12
+ /**
13
+ * The symbols between the property and value for declarations.
14
+ */
15
+ between?: string
15
16
 
16
- /**
17
- * The content of the important statement, if it is not just `!important`.
18
- */
19
- important?: string
17
+ /**
18
+ * The content of the important statement, if it is not just `!important`.
19
+ */
20
+ important?: string
20
21
 
21
- /**
22
- * Declaration value with comments.
23
- */
24
- value: {
22
+ /**
23
+ * Declaration value with comments.
24
+ */
25
+ value?: {
26
+ raw: string
27
+ value: string
28
+ }
29
+ }
30
+
31
+ export interface DeclarationProps {
32
+ /** Whether the declaration has an `!important` annotation. */
33
+ important?: boolean
34
+ /** Name of the declaration. */
35
+ prop: string
36
+ /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
37
+ raws?: DeclarationRaws
38
+ /** Value of the declaration. */
25
39
  value: string
26
- raw: string
27
40
  }
28
- }
29
41
 
30
- export interface DeclarationProps {
31
- /** Name of the declaration. */
32
- prop: string
33
- /** Value of the declaration. */
34
- value: string
35
- /** Whether the declaration has an `!important` annotation. */
36
- important?: boolean
37
- /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
38
- raws?: DeclarationRaws
42
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
43
+ export { Declaration_ as default }
39
44
  }
40
45
 
41
46
  /**
42
- * Represents a CSS declaration.
47
+ * It represents a class that handles
48
+ * [CSS declarations](https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declarations)
43
49
  *
44
50
  * ```js
45
51
  * Once (root, { Declaration }) {
46
- * let color = new Declaration({ prop: 'color', value: 'black' })
52
+ * const color = new Declaration({ prop: 'color', value: 'black' })
47
53
  * root.append(color)
48
54
  * }
49
55
  * ```
50
56
  *
51
57
  * ```js
52
58
  * const root = postcss.parse('a { color: black }')
53
- * const decl = root.first.first
59
+ * const decl = root.first?.first
60
+ *
54
61
  * decl.type //=> 'decl'
55
62
  * decl.toString() //=> ' color: black'
56
63
  * ```
57
64
  */
58
- export default class Declaration extends Node {
59
- type: 'decl'
65
+ declare class Declaration_ extends Node {
66
+ /**
67
+ * It represents a specificity of the declaration.
68
+ *
69
+ * If true, the CSS declaration will have an
70
+ * [important](https://developer.mozilla.org/en-US/docs/Web/CSS/important)
71
+ * specifier.
72
+ *
73
+ * ```js
74
+ * const root = postcss.parse('a { color: black !important; color: red }')
75
+ *
76
+ * root.first.first.important //=> true
77
+ * root.first.last.important //=> undefined
78
+ * ```
79
+ */
80
+ important: boolean
81
+
60
82
  parent: Container | undefined
61
- raws: DeclarationRaws
62
83
 
63
84
  /**
64
- * The declaration's property name.
85
+ * The property name for a CSS declaration.
65
86
  *
66
87
  * ```js
67
88
  * const root = postcss.parse('a { color: black }')
68
89
  * const decl = root.first.first
90
+ *
69
91
  * decl.prop //=> 'color'
70
92
  * ```
71
93
  */
72
94
  prop: string
73
95
 
96
+ raws: Declaration.DeclarationRaws
97
+
98
+ type: 'decl'
99
+
74
100
  /**
75
- * The declaration’s value.
101
+ * The property value for a CSS declaration.
102
+ *
103
+ * Any CSS comments inside the value string will be filtered out.
104
+ * CSS comments present in the source value will be available in
105
+ * the `raws` property.
76
106
  *
77
- * This value will be cleaned of comments. If the source value contained
78
- * comments, those comments will be available in the `raws` property.
79
- * If you have not changed the value, the result of `decl.toString()`
80
- * will include the original raws value (comments and all).
107
+ * Assigning new `value` would ignore the comments in `raws`
108
+ * property while compiling node to string.
81
109
  *
82
110
  * ```js
83
111
  * const root = postcss.parse('a { color: black }')
84
112
  * const decl = root.first.first
113
+ *
85
114
  * decl.value //=> 'black'
86
115
  * ```
87
116
  */
88
117
  value: string
89
118
 
90
119
  /**
91
- * `true` if the declaration has an `!important` annotation.
92
- *
93
- * ```js
94
- * const root = postcss.parse('a { color: black !important; color: red }')
95
- * root.first.first.important //=> true
96
- * root.first.last.important //=> undefined
97
- * ```
98
- */
99
- important: boolean
100
-
101
- /**
102
- * `true` if declaration is declaration of CSS Custom Property
103
- * or Sass variable.
120
+ * It represents a getter that returns `true` if a declaration starts with
121
+ * `--` or `$`, which are used to declare variables in CSS and SASS/SCSS.
104
122
  *
105
123
  * ```js
106
124
  * const root = postcss.parse(':root { --one: 1 }')
107
- * let one = root.first.first
125
+ * const one = root.first.first
126
+ *
108
127
  * one.variable //=> true
109
128
  * ```
110
129
  *
111
130
  * ```js
112
131
  * const root = postcss.parse('$one: 1')
113
- * let one = root.first
132
+ * const one = root.first
133
+ *
114
134
  * one.variable //=> true
115
135
  * ```
116
136
  */
117
137
  variable: boolean
118
138
 
119
- constructor(defaults?: DeclarationProps)
120
- assign(overrides: object | DeclarationProps): this
121
- clone(overrides?: Partial<DeclarationProps>): this
122
- cloneBefore(overrides?: Partial<DeclarationProps>): this
123
- cloneAfter(overrides?: Partial<DeclarationProps>): this
139
+ constructor(defaults?: Declaration.DeclarationProps)
140
+ assign(overrides: Declaration.DeclarationProps | object): this
141
+ clone(overrides?: Partial<Declaration.DeclarationProps>): Declaration
142
+ cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): Declaration
143
+ cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): Declaration
124
144
  }
145
+
146
+ declare class Declaration extends Declaration_ {}
147
+
148
+ export = Declaration
package/lib/document.d.ts CHANGED
@@ -1,22 +1,24 @@
1
1
  import Container, { ContainerProps } from './container.js'
2
2
  import { ProcessOptions } from './postcss.js'
3
3
  import Result from './result.js'
4
- import Root, { RootProps } from './root.js'
4
+ import Root from './root.js'
5
5
 
6
- export interface DocumentProps extends ContainerProps {
7
- nodes?: Root[]
6
+ declare namespace Document {
7
+ export interface DocumentProps extends ContainerProps {
8
+ nodes?: Root[]
8
9
 
9
- /**
10
- * Information to generate byte-to-byte equal node string as it was
11
- * in the origin input.
12
- *
13
- * Every parser saves its own properties.
14
- */
15
- raws?: Record<string, any>
16
- }
10
+ /**
11
+ * Information to generate byte-to-byte equal node string as it was
12
+ * in the origin input.
13
+ *
14
+ * Every parser saves its own properties.
15
+ */
16
+ raws?: Record<string, any>
17
+ }
17
18
 
18
- type ChildNode = Root
19
- type ChildProps = RootProps
19
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
20
+ export { Document_ as default }
21
+ }
20
22
 
21
23
  /**
22
24
  * Represents a file and contains all its parsed nodes.
@@ -32,11 +34,16 @@ type ChildProps = RootProps
32
34
  * document.nodes.length //=> 2
33
35
  * ```
34
36
  */
35
- export default class Document extends Container<Root> {
36
- type: 'document'
37
+ declare class Document_ extends Container<Root> {
37
38
  parent: undefined
39
+ type: 'document'
40
+
41
+ constructor(defaults?: Document.DocumentProps)
38
42
 
39
- constructor(defaults?: DocumentProps)
43
+ assign(overrides: Document.DocumentProps | object): this
44
+ clone(overrides?: Partial<Document.DocumentProps>): Document
45
+ cloneAfter(overrides?: Partial<Document.DocumentProps>): Document
46
+ cloneBefore(overrides?: Partial<Document.DocumentProps>): Document
40
47
 
41
48
  /**
42
49
  * Returns a `Result` instance representing the document’s CSS roots.
@@ -55,3 +62,7 @@ export default class Document extends Container<Root> {
55
62
  */
56
63
  toResult(options?: ProcessOptions): Result
57
64
  }
65
+
66
+ declare class Document extends Document_ {}
67
+
68
+ export = Document
package/lib/fromJSON.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { JSONHydrator } from './postcss.js'
2
2
 
3
- declare const fromJSON: JSONHydrator
3
+ interface FromJSON extends JSONHydrator {
4
+ default: FromJSON
5
+ }
4
6
 
5
- export default fromJSON
7
+ declare const fromJSON: FromJSON
8
+
9
+ export = fromJSON