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.

@@ -6,14 +6,14 @@ declare namespace CssSyntaxError {
6
6
  */
7
7
  export interface RangePosition {
8
8
  /**
9
- * The line number in the input.
9
+ * The column number in the input.
10
10
  */
11
- line: number
11
+ column: number
12
12
 
13
13
  /**
14
- * The column number in the input.
14
+ * The line number in the input.
15
15
  */
16
- column: number
16
+ line: number
17
17
  }
18
18
 
19
19
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -51,60 +51,45 @@ declare namespace CssSyntaxError {
51
51
  */
52
52
  declare class CssSyntaxError_ {
53
53
  /**
54
- * Instantiates a CSS syntax error. Can be instantiated for a single position
55
- * or for a range.
56
- * @param message Error message.
57
- * @param lineOrStartPos If for a single position, the line number, or if for
58
- * a range, the inclusive start position of the error.
59
- * @param columnOrEndPos If for a single position, the column number, or if for
60
- * a range, the exclusive end position of the error.
61
- * @param source Source code of the broken file.
62
- * @param file Absolute path to the broken file.
63
- * @param plugin PostCSS plugin name, if error came from plugin.
64
- */
65
- constructor(
66
- message: string,
67
- lineOrStartPos?: number | CssSyntaxError.RangePosition,
68
- columnOrEndPos?: number | CssSyntaxError.RangePosition,
69
- source?: string,
70
- file?: string,
71
- plugin?: string
72
- )
73
-
74
- stack: string
75
-
76
- /**
77
- * Always equal to `'CssSyntaxError'`. You should always check error type
78
- * by `error.name === 'CssSyntaxError'`
79
- * instead of `error instanceof CssSyntaxError`,
80
- * because npm could have several PostCSS versions.
54
+ * Source column of the error.
81
55
  *
82
56
  * ```js
83
- * if (error.name === 'CssSyntaxError') {
84
- * error //=> CssSyntaxError
85
- * }
57
+ * error.column //=> 1
58
+ * error.input.column //=> 4
86
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`.
87
63
  */
88
- name: 'CssSyntaxError'
64
+ column?: number
89
65
 
90
66
  /**
91
- * Error message.
67
+ * Source column of the error's end, exclusive. Provided if the error pertains
68
+ * to a range.
92
69
  *
93
70
  * ```js
94
- * error.message //=> 'Unclosed block'
71
+ * error.endColumn //=> 1
72
+ * error.input.endColumn //=> 4
95
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`.
96
77
  */
97
- reason: string
78
+ endColumn?: number
98
79
 
99
80
  /**
100
- * Full error text in the GNU error format
101
- * with plugin, file, line and column.
81
+ * Source line of the error's end, exclusive. Provided if the error pertains
82
+ * to a range.
102
83
  *
103
84
  * ```js
104
- * error.message //=> 'a.css:1:1: Unclosed block'
85
+ * error.endLine //=> 3
86
+ * error.input.endLine //=> 4
105
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`.
106
91
  */
107
- message: string
92
+ endLine?: number
108
93
 
109
94
  /**
110
95
  * Absolute path to the broken file.
@@ -120,68 +105,55 @@ declare class CssSyntaxError_ {
120
105
  file?: string
121
106
 
122
107
  /**
123
- * Source line of the error.
124
- *
125
- * ```js
126
- * error.line //=> 2
127
- * error.input.line //=> 4
128
- * ```
129
- *
130
- * PostCSS will use the input source map to detect the original location.
131
- * If you need the position in the PostCSS input, use `error.input.line`.
132
- */
133
- line?: number
134
-
135
- /**
136
- * Source column of the error.
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.
137
113
  *
138
114
  * ```js
139
- * error.column //=> 1
140
- * error.input.column //=> 4
115
+ * error.input.file //=> 'a.css'
116
+ * error.file //=> 'a.sass'
141
117
  * ```
142
- *
143
- * PostCSS will use the input source map to detect the original location.
144
- * If you need the position in the PostCSS input, use `error.input.column`.
145
118
  */
146
- column?: number
119
+ input?: FilePosition
147
120
 
148
121
  /**
149
- * Source line of the error's end, exclusive. Provided if the error pertains
150
- * to a range.
122
+ * Source line of the error.
151
123
  *
152
124
  * ```js
153
- * error.endLine //=> 3
154
- * error.input.endLine //=> 4
125
+ * error.line //=> 2
126
+ * error.input.line //=> 4
155
127
  * ```
156
128
  *
157
129
  * PostCSS will use the input source map to detect the original location.
158
- * If you need the position in the PostCSS input, use `error.input.endLine`.
130
+ * If you need the position in the PostCSS input, use `error.input.line`.
159
131
  */
160
- endLine?: number
132
+ line?: number
161
133
 
162
134
  /**
163
- * Source column of the error's end, exclusive. Provided if the error pertains
164
- * to a range.
135
+ * Full error text in the GNU error format
136
+ * with plugin, file, line and column.
165
137
  *
166
138
  * ```js
167
- * error.endColumn //=> 1
168
- * error.input.endColumn //=> 4
139
+ * error.message //=> 'a.css:1:1: Unclosed block'
169
140
  * ```
170
- *
171
- * PostCSS will use the input source map to detect the original location.
172
- * If you need the position in the PostCSS input, use `error.input.endColumn`.
173
141
  */
174
- endColumn?: number
142
+ message: string
175
143
 
176
144
  /**
177
- * 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.
178
149
  *
179
150
  * ```js
180
- * error.source //=> 'a { b {} }'
181
- * error.input.source //=> 'a b { }'
151
+ * if (error.name === 'CssSyntaxError') {
152
+ * error //=> CssSyntaxError
153
+ * }
182
154
  * ```
183
155
  */
184
- source?: string
156
+ name: 'CssSyntaxError'
185
157
 
186
158
  /**
187
159
  * Plugin name, if error came from plugin.
@@ -193,31 +165,46 @@ declare class CssSyntaxError_ {
193
165
  plugin?: string
194
166
 
195
167
  /**
196
- * Input object with PostCSS internal information
197
- * about input file. If input has source map
198
- * from previous tool, PostCSS will use origin
199
- * (for example, Sass) source. You can use this
200
- * object to get PostCSS input source.
168
+ * Error message.
201
169
  *
202
170
  * ```js
203
- * error.input.file //=> 'a.css'
204
- * error.file //=> 'a.sass'
171
+ * error.message //=> 'Unclosed block'
205
172
  * ```
206
173
  */
207
- input?: FilePosition
174
+ reason: string
208
175
 
209
176
  /**
210
- * Returns error position, message and source code of the broken part.
177
+ * Source code of the broken file.
211
178
  *
212
179
  * ```js
213
- * error.toString() //=> "CssSyntaxError: app.css:1:1: Unclosed block
214
- * // > 1 | a {
215
- * // | ^"
180
+ * error.source //=> 'a { b {} }'
181
+ * error.input.source //=> 'a b { }'
216
182
  * ```
217
- *
218
- * @return Error position, message and source code.
219
183
  */
220
- 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
+ )
221
208
 
222
209
  /**
223
210
  * Returns a few lines of CSS source that caused the error.
@@ -241,6 +228,19 @@ declare class CssSyntaxError_ {
241
228
  * @return Few lines of CSS source that caused the error.
242
229
  */
243
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
244
244
  }
245
245
 
246
246
  declare class CssSyntaxError extends CssSyntaxError_ {}
@@ -64,7 +64,7 @@ class CssSyntaxError extends Error {
64
64
 
65
65
  let mark, aside
66
66
  if (color) {
67
- let { bold, red, gray } = pico.createColors(true)
67
+ let { bold, gray, red } = pico.createColors(true)
68
68
  mark = text => bold(red(text))
69
69
  aside = text => gray(text)
70
70
  } else {
@@ -23,20 +23,20 @@ declare namespace Declaration {
23
23
  * Declaration value with comments.
24
24
  */
25
25
  value?: {
26
- value: string
27
26
  raw: string
27
+ value: string
28
28
  }
29
29
  }
30
30
 
31
31
  export interface DeclarationProps {
32
- /** Name of the declaration. */
33
- prop: string
34
- /** Value of the declaration. */
35
- value: string
36
32
  /** Whether the declaration has an `!important` annotation. */
37
33
  important?: boolean
34
+ /** Name of the declaration. */
35
+ prop: string
38
36
  /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
39
37
  raws?: DeclarationRaws
38
+ /** Value of the declaration. */
39
+ value: string
40
40
  }
41
41
 
42
42
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -44,88 +44,101 @@ declare namespace Declaration {
44
44
  }
45
45
 
46
46
  /**
47
- * 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)
48
49
  *
49
50
  * ```js
50
51
  * Once (root, { Declaration }) {
51
- * let color = new Declaration({ prop: 'color', value: 'black' })
52
+ * const color = new Declaration({ prop: 'color', value: 'black' })
52
53
  * root.append(color)
53
54
  * }
54
55
  * ```
55
56
  *
56
57
  * ```js
57
58
  * const root = postcss.parse('a { color: black }')
58
- * const decl = root.first.first
59
- * decl.type //=> 'decl'
60
- * decl.toString() //=> ' color: black'
59
+ * const decl = root.first?.first
60
+ *
61
+ * console.log(decl.type) //=> 'decl'
62
+ * console.log(decl.toString()) //=> ' color: black'
61
63
  * ```
62
64
  */
63
65
  declare class Declaration_ extends Node {
64
- type: 'decl'
65
- parent: Container | undefined
66
- raws: Declaration.DeclarationRaws
67
-
68
66
  /**
69
- * The declaration's property name.
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.
70
72
  *
71
73
  * ```js
72
- * const root = postcss.parse('a { color: black }')
73
- * const decl = root.first.first
74
- * decl.prop //=> 'color'
74
+ * const root = postcss.parse('a { color: black !important; color: red }')
75
+ *
76
+ * console.log(root.first?.first?.important) //=> true
77
+ * console.log(root.first?.last?.important) //=> undefined
75
78
  * ```
76
79
  */
77
- prop: string
78
-
80
+ important: boolean
81
+ parent: Container | undefined
79
82
  /**
80
- * The declaration’s value.
81
- *
82
- * This value will be cleaned of comments. If the source value contained
83
- * comments, those comments will be available in the `raws` property.
84
- * If you have not changed the value, the result of `decl.toString()`
85
- * will include the original raws value (comments and all).
83
+ * The property name for a CSS declaration.
86
84
  *
87
85
  * ```js
88
86
  * const root = postcss.parse('a { color: black }')
89
- * const decl = root.first.first
90
- * decl.value //=> 'black'
87
+ * const decl = root.first?.first
88
+ *
89
+ * console.log(decl.prop) //=> 'color'
91
90
  * ```
92
91
  */
93
- value: string
92
+ prop: string
93
+
94
+ raws: Declaration.DeclarationRaws
95
+
96
+ type: 'decl'
94
97
 
95
98
  /**
96
- * `true` if the declaration has an `!important` annotation.
99
+ * The property value for a CSS declaration.
100
+ *
101
+ * Any CSS comments inside the value string will be filtered out.
102
+ * CSS comments present in the source value will be available in
103
+ * the `raws` property.
104
+ *
105
+ * Assigning new `value` would ignore the comments in `raws`
106
+ * property while compiling node to string.
97
107
  *
98
108
  * ```js
99
- * const root = postcss.parse('a { color: black !important; color: red }')
100
- * root.first.first.important //=> true
101
- * root.first.last.important //=> undefined
109
+ * const root = postcss.parse('a { color: black }')
110
+ * const decl = root.first?.first
111
+ *
112
+ * console.log(decl.value) //=> 'black'
102
113
  * ```
103
114
  */
104
- important: boolean
115
+ value: string
105
116
 
106
117
  /**
107
- * `true` if declaration is declaration of CSS Custom Property
108
- * or Sass variable.
118
+ * It represents a getter that returns `true` if a declaration starts with
119
+ * `--` or `$`, which are used to declare variables in CSS and SASS/SCSS.
109
120
  *
110
121
  * ```js
111
122
  * const root = postcss.parse(':root { --one: 1 }')
112
- * let one = root.first.first
113
- * one.variable //=> true
123
+ * const one = root.first?.first
124
+ *
125
+ * console.log(one?.variable) //=> true
114
126
  * ```
115
127
  *
116
128
  * ```js
117
129
  * const root = postcss.parse('$one: 1')
118
- * let one = root.first
119
- * one.variable //=> true
130
+ * const one = root.first
131
+ *
132
+ * console.log(one?.variable) //=> true
120
133
  * ```
121
134
  */
122
135
  variable: boolean
123
136
 
124
137
  constructor(defaults?: Declaration.DeclarationProps)
125
- assign(overrides: object | Declaration.DeclarationProps): this
138
+ assign(overrides: Declaration.DeclarationProps | object): this
126
139
  clone(overrides?: Partial<Declaration.DeclarationProps>): this
127
- cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this
128
140
  cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): this
141
+ cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this
129
142
  }
130
143
 
131
144
  declare class Declaration extends Declaration_ {}
package/lib/document.d.ts CHANGED
@@ -35,8 +35,8 @@ declare namespace Document {
35
35
  * ```
36
36
  */
37
37
  declare class Document_ extends Container<Root> {
38
- type: 'document'
39
38
  parent: undefined
39
+ type: 'document'
40
40
 
41
41
  constructor(defaults?: Document.DocumentProps)
42
42
 
package/lib/input.d.ts CHANGED
@@ -4,39 +4,39 @@ import PreviousMap from './previous-map.js'
4
4
  declare namespace Input {
5
5
  export interface FilePosition {
6
6
  /**
7
- * URL for the source file.
7
+ * Column of inclusive start position in source file.
8
8
  */
9
- url: string
9
+ column: number
10
10
 
11
11
  /**
12
- * Absolute path to the source file.
12
+ * Column of exclusive end position in source file.
13
13
  */
14
- file?: string
14
+ endColumn?: number
15
15
 
16
16
  /**
17
- * Line of inclusive start position in source file.
17
+ * Line of exclusive end position in source file.
18
18
  */
19
- line: number
19
+ endLine?: number
20
20
 
21
21
  /**
22
- * Column of inclusive start position in source file.
22
+ * Absolute path to the source file.
23
23
  */
24
- column: number
24
+ file?: string
25
25
 
26
26
  /**
27
- * Line of exclusive end position in source file.
27
+ * Line of inclusive start position in source file.
28
28
  */
29
- endLine?: number
29
+ line: number
30
30
 
31
31
  /**
32
- * Column of exclusive end position in source file.
32
+ * Source code.
33
33
  */
34
- endColumn?: number
34
+ source?: string
35
35
 
36
36
  /**
37
- * Source code.
37
+ * URL for the source file.
38
38
  */
39
- source?: string
39
+ url: string
40
40
  }
41
41
 
42
42
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -62,16 +62,6 @@ declare class Input_ {
62
62
  */
63
63
  css: string
64
64
 
65
- /**
66
- * The input source map passed from a compilation step before PostCSS
67
- * (for example, from Sass compiler).
68
- *
69
- * ```js
70
- * root.source.input.map.consumer().sources //=> ['a.sass']
71
- * ```
72
- */
73
- map: PreviousMap
74
-
75
65
  /**
76
66
  * The absolute path to the CSS source file defined
77
67
  * with the `from` option.
@@ -83,6 +73,11 @@ declare class Input_ {
83
73
  */
84
74
  file?: string
85
75
 
76
+ /**
77
+ * The flag to indicate whether or not the source code has Unicode BOM.
78
+ */
79
+ hasBOM: boolean
80
+
86
81
  /**
87
82
  * The unique ID of the CSS source. It will be created if `from` option
88
83
  * is not provided (because PostCSS does not know the file path).
@@ -96,9 +91,14 @@ declare class Input_ {
96
91
  id?: string
97
92
 
98
93
  /**
99
- * The flag to indicate whether or not the source code has Unicode BOM.
94
+ * The input source map passed from a compilation step before PostCSS
95
+ * (for example, from Sass compiler).
96
+ *
97
+ * ```js
98
+ * root.source.input.map.consumer().sources //=> ['a.sass']
99
+ * ```
100
100
  */
101
- hasBOM: boolean
101
+ map: PreviousMap
102
102
 
103
103
  /**
104
104
  * @param css Input CSS source.
@@ -106,6 +106,43 @@ declare class Input_ {
106
106
  */
107
107
  constructor(css: string, opts?: ProcessOptions)
108
108
 
109
+ error(
110
+ message: string,
111
+ start:
112
+ | {
113
+ column: number
114
+ line: number
115
+ }
116
+ | {
117
+ offset: number
118
+ },
119
+ end:
120
+ | {
121
+ column: number
122
+ line: number
123
+ }
124
+ | {
125
+ offset: number
126
+ },
127
+ opts?: { plugin?: CssSyntaxError['plugin'] }
128
+ ): CssSyntaxError
129
+
130
+ /**
131
+ * Returns `CssSyntaxError` with information about the error and its position.
132
+ */
133
+ error(
134
+ message: string,
135
+ line: number,
136
+ column: number,
137
+ opts?: { plugin?: CssSyntaxError['plugin'] }
138
+ ): CssSyntaxError
139
+
140
+ error(
141
+ message: string,
142
+ offset: number,
143
+ opts?: { plugin?: CssSyntaxError['plugin'] }
144
+ ): CssSyntaxError
145
+
109
146
  /**
110
147
  * The CSS source identifier. Contains `Input#file` if the user
111
148
  * set the `from` option, or `Input#id` if they did not.
@@ -119,7 +156,12 @@ declare class Input_ {
119
156
  * ```
120
157
  */
121
158
  get from(): string
122
-
159
+ /**
160
+ * Converts source offset to line and column.
161
+ *
162
+ * @param offset Source offset.
163
+ */
164
+ fromOffset(offset: number): { col: number; line: number } | null
123
165
  /**
124
166
  * Reads the input source map and returns a symbol position
125
167
  * in the input source (e.g., in a Sass file that was compiled
@@ -144,49 +186,7 @@ declare class Input_ {
144
186
  column: number,
145
187
  endLine?: number,
146
188
  endColumn?: number
147
- ): Input.FilePosition | false
148
-
149
- /**
150
- * Converts source offset to line and column.
151
- *
152
- * @param offset Source offset.
153
- */
154
- fromOffset(offset: number): { line: number; col: number } | null
155
-
156
- /**
157
- * Returns `CssSyntaxError` with information about the error and its position.
158
- */
159
- error(
160
- message: string,
161
- line: number,
162
- column: number,
163
- opts?: { plugin?: CssSyntaxError['plugin'] }
164
- ): CssSyntaxError
165
- error(
166
- message: string,
167
- offset: number,
168
- opts?: { plugin?: CssSyntaxError['plugin'] }
169
- ): CssSyntaxError
170
- error(
171
- message: string,
172
- start:
173
- | {
174
- offset: number
175
- }
176
- | {
177
- line: number
178
- column: number
179
- },
180
- end:
181
- | {
182
- offset: number
183
- }
184
- | {
185
- line: number
186
- column: number
187
- },
188
- opts?: { plugin?: CssSyntaxError['plugin'] }
189
- ): CssSyntaxError
189
+ ): false | Input.FilePosition
190
190
  }
191
191
 
192
192
  declare class Input extends Input_ {}