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.
- package/README.md +7 -23
- package/lib/at-rule.d.ts +58 -49
- package/lib/comment.d.ts +43 -32
- package/lib/container.d.ts +233 -223
- package/lib/container.js +251 -244
- package/lib/css-syntax-error.d.ts +117 -61
- package/lib/css-syntax-error.js +10 -3
- package/lib/declaration.d.ts +85 -61
- package/lib/document.d.ts +27 -16
- package/lib/fromJSON.d.ts +6 -2
- package/lib/input.d.ts +118 -54
- package/lib/input.js +87 -55
- package/lib/lazy-result.d.ts +82 -67
- package/lib/lazy-result.js +234 -232
- package/lib/list.d.ts +53 -47
- package/lib/list.js +16 -14
- package/lib/map-generator.js +231 -172
- package/lib/no-work-result.d.ts +46 -0
- package/lib/no-work-result.js +135 -0
- package/lib/node.d.ts +345 -253
- package/lib/node.js +200 -139
- package/lib/parse.d.ts +6 -2
- package/lib/parser.js +354 -309
- package/lib/postcss.d.mts +72 -0
- package/lib/postcss.d.ts +288 -319
- package/lib/postcss.js +18 -12
- package/lib/postcss.mjs +1 -0
- package/lib/previous-map.d.ts +23 -14
- package/lib/previous-map.js +37 -40
- package/lib/processor.d.ts +55 -41
- package/lib/processor.js +20 -27
- package/lib/result.d.ts +87 -76
- package/lib/root.d.ts +49 -36
- package/lib/root.js +12 -10
- package/lib/rule.d.ts +54 -45
- package/lib/stringifier.d.ts +46 -0
- package/lib/stringifier.js +140 -138
- package/lib/stringify.d.ts +6 -2
- package/lib/terminal-highlight.js +11 -11
- package/lib/tokenize.js +2 -2
- package/lib/warn-once.js +1 -0
- package/lib/warning.d.ts +79 -36
- package/lib/warning.js +6 -4
- package/package.json +20 -10
package/lib/node.d.ts
CHANGED
@@ -1,274 +1,296 @@
|
|
1
|
-
import
|
1
|
+
import AtRule = require('./at-rule.js')
|
2
|
+
|
3
|
+
import { AtRuleProps } from './at-rule.js'
|
2
4
|
import Comment, { CommentProps } from './comment.js'
|
3
|
-
import
|
4
|
-
import AtRule, { AtRuleProps } from './at-rule.js'
|
5
|
-
import Rule, { RuleProps } from './rule.js'
|
6
|
-
import { WarningOptions } from './warning.js'
|
5
|
+
import Container from './container.js'
|
7
6
|
import CssSyntaxError from './css-syntax-error.js'
|
8
|
-
import
|
7
|
+
import Declaration, { DeclarationProps } from './declaration.js'
|
8
|
+
import Document from './document.js'
|
9
9
|
import Input from './input.js'
|
10
|
+
import { Stringifier, Syntax } from './postcss.js'
|
11
|
+
import Result from './result.js'
|
10
12
|
import Root from './root.js'
|
11
|
-
import
|
12
|
-
import
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
13
|
+
import Rule, { RuleProps } from './rule.js'
|
14
|
+
import Warning, { WarningOptions } from './warning.js'
|
15
|
+
|
16
|
+
declare namespace Node {
|
17
|
+
export type ChildNode = AtRule.default | Comment | Declaration | Rule
|
18
|
+
|
19
|
+
export type AnyNode =
|
20
|
+
| AtRule.default
|
21
|
+
| Comment
|
22
|
+
| Declaration
|
23
|
+
| Document
|
24
|
+
| Root
|
25
|
+
| Rule
|
26
|
+
|
27
|
+
export type ChildProps =
|
28
|
+
| AtRuleProps
|
29
|
+
| CommentProps
|
30
|
+
| DeclarationProps
|
31
|
+
| RuleProps
|
32
|
+
|
33
|
+
export interface Position {
|
34
|
+
/**
|
35
|
+
* Source line in file. In contrast to `offset` it starts from 1.
|
36
|
+
*/
|
37
|
+
column: number
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Source column in file.
|
41
|
+
*/
|
42
|
+
line: number
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Source offset in file. It starts from 0.
|
46
|
+
*/
|
47
|
+
offset: number
|
48
|
+
}
|
49
|
+
|
50
|
+
export interface Range {
|
51
|
+
/**
|
52
|
+
* End position, exclusive.
|
53
|
+
*/
|
54
|
+
end: Position
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Start position, inclusive.
|
58
|
+
*/
|
59
|
+
start: Position
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Source represents an interface for the {@link Node.source} property.
|
64
|
+
*/
|
65
|
+
export interface Source {
|
66
|
+
/**
|
67
|
+
* The inclusive ending position for the source
|
68
|
+
* code of a node.
|
69
|
+
*/
|
70
|
+
end?: Position
|
71
|
+
|
72
|
+
/**
|
73
|
+
* The source file from where a node has originated.
|
74
|
+
*/
|
75
|
+
input: Input
|
76
|
+
|
77
|
+
/**
|
78
|
+
* The inclusive starting position for the source
|
79
|
+
* code of a node.
|
80
|
+
*/
|
81
|
+
start?: Position
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Interface represents an interface for an object received
|
86
|
+
* as parameter by Node class constructor.
|
87
|
+
*/
|
88
|
+
export interface NodeProps {
|
89
|
+
source?: Source
|
90
|
+
}
|
91
|
+
|
92
|
+
export interface NodeErrorOptions {
|
93
|
+
/**
|
94
|
+
* An ending index inside a node's string that should be highlighted as
|
95
|
+
* source of error.
|
96
|
+
*/
|
97
|
+
endIndex?: number
|
98
|
+
/**
|
99
|
+
* An index inside a node's string that should be highlighted as source
|
100
|
+
* of error.
|
101
|
+
*/
|
102
|
+
index?: number
|
103
|
+
/**
|
104
|
+
* Plugin name that created this error. PostCSS will set it automatically.
|
105
|
+
*/
|
106
|
+
plugin?: string
|
107
|
+
/**
|
108
|
+
* A word inside a node's string, that should be highlighted as source
|
109
|
+
* of error.
|
110
|
+
*/
|
111
|
+
word?: string
|
112
|
+
}
|
113
|
+
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
115
|
+
class Node extends Node_ {}
|
116
|
+
export { Node as default }
|
75
117
|
}
|
76
118
|
|
77
119
|
/**
|
78
|
-
*
|
120
|
+
* It represents an abstract class that handles common
|
121
|
+
* methods for other CSS abstract syntax tree nodes.
|
79
122
|
*
|
80
|
-
*
|
81
|
-
*
|
123
|
+
* Any node that represents CSS selector or value should
|
124
|
+
* not extend the `Node` class.
|
82
125
|
*/
|
83
|
-
|
126
|
+
declare abstract class Node_ {
|
84
127
|
/**
|
85
|
-
*
|
86
|
-
* `rule`, `decl`, or `comment`.
|
128
|
+
* It represents parent of the current node.
|
87
129
|
*
|
88
130
|
* ```js
|
89
|
-
*
|
131
|
+
* root.nodes[0].parent === root //=> true
|
90
132
|
* ```
|
91
133
|
*/
|
92
|
-
|
134
|
+
parent: Container | Document | undefined
|
93
135
|
|
94
136
|
/**
|
95
|
-
*
|
137
|
+
* It represents unnecessary whitespace and characters present
|
138
|
+
* in the css source code.
|
139
|
+
*
|
140
|
+
* Information to generate byte-to-byte equal node string as it was
|
141
|
+
* in the origin input.
|
142
|
+
*
|
143
|
+
* The properties of the raws object are decided by parser,
|
144
|
+
* the default parser uses the following properties:
|
145
|
+
*
|
146
|
+
* * `before`: the space symbols before the node. It also stores `*`
|
147
|
+
* and `_` symbols before the declaration (IE hack).
|
148
|
+
* * `after`: the space symbols after the last child of the node
|
149
|
+
* to the end of the node.
|
150
|
+
* * `between`: the symbols between the property and value
|
151
|
+
* for declarations, selector and `{` for rules, or last parameter
|
152
|
+
* and `{` for at-rules.
|
153
|
+
* * `semicolon`: contains true if the last child has
|
154
|
+
* an (optional) semicolon.
|
155
|
+
* * `afterName`: the space between the at-rule name and its parameters.
|
156
|
+
* * `left`: the space symbols between `/*` and the comment’s text.
|
157
|
+
* * `right`: the space symbols between the comment’s text
|
158
|
+
* and <code>*/</code>.
|
159
|
+
* - `important`: the content of the important statement,
|
160
|
+
* if it is not just `!important`.
|
161
|
+
*
|
162
|
+
* PostCSS filters out the comments inside selectors, declaration values
|
163
|
+
* and at-rule parameters but it stores the origin content in raws.
|
96
164
|
*
|
97
165
|
* ```js
|
98
|
-
* root.
|
166
|
+
* const root = postcss.parse('a {\n color:black\n}')
|
167
|
+
* root.first.first.raws //=> { before: '\n ', between: ':' }
|
99
168
|
* ```
|
100
169
|
*/
|
101
|
-
|
170
|
+
raws: any
|
102
171
|
|
103
172
|
/**
|
104
|
-
*
|
173
|
+
* It represents information related to origin of a node and is required
|
174
|
+
* for generating source maps.
|
105
175
|
*
|
106
|
-
* The
|
176
|
+
* The nodes that are created manually using the public APIs
|
177
|
+
* provided by PostCSS will have `source` undefined and
|
178
|
+
* will be absent in the source map.
|
107
179
|
*
|
108
|
-
*
|
109
|
-
*
|
110
|
-
*
|
111
|
-
*
|
112
|
-
* source will reference the original, cloned node) or setting
|
113
|
-
* the `source` property manually.
|
180
|
+
* For this reason, the plugin developer should consider
|
181
|
+
* duplicating nodes as the duplicate node will have the
|
182
|
+
* same source as the original node by default or assign
|
183
|
+
* source to a node created manually.
|
114
184
|
*
|
115
185
|
* ```js
|
116
|
-
* decl.source.input.from //=> '/home/ai/
|
186
|
+
* decl.source.input.from //=> '/home/ai/source.css'
|
117
187
|
* decl.source.start //=> { line: 10, column: 2 }
|
118
188
|
* decl.source.end //=> { line: 10, column: 12 }
|
119
189
|
* ```
|
120
190
|
*
|
121
191
|
* ```js
|
122
|
-
* //
|
192
|
+
* // Incorrect method, source not specified!
|
123
193
|
* const prefixed = postcss.decl({
|
124
194
|
* prop: '-moz-' + decl.prop,
|
125
195
|
* value: decl.value
|
126
196
|
* })
|
127
197
|
*
|
128
|
-
* //
|
129
|
-
* const prefixed = decl.clone({
|
198
|
+
* // Correct method, source is inherited when duplicating.
|
199
|
+
* const prefixed = decl.clone({
|
200
|
+
* prop: '-moz-' + decl.prop
|
201
|
+
* })
|
130
202
|
* ```
|
131
203
|
*
|
132
204
|
* ```js
|
133
205
|
* if (atrule.name === 'add-link') {
|
134
|
-
* const rule = postcss.rule({
|
135
|
-
*
|
206
|
+
* const rule = postcss.rule({
|
207
|
+
* selector: 'a',
|
208
|
+
* source: atrule.source
|
209
|
+
* })
|
210
|
+
*
|
211
|
+
* atrule.parent.insertBefore(atrule, rule)
|
136
212
|
* }
|
137
213
|
* ```
|
138
214
|
*/
|
139
|
-
source?: Source
|
215
|
+
source?: Node.Source
|
140
216
|
|
141
217
|
/**
|
142
|
-
*
|
143
|
-
*
|
144
|
-
*
|
145
|
-
* Every parser saves its own properties,
|
146
|
-
* but the default CSS parser uses:
|
218
|
+
* It represents type of a node in
|
219
|
+
* an abstract syntax tree.
|
147
220
|
*
|
148
|
-
*
|
149
|
-
*
|
150
|
-
* * `after`: the space symbols after the last child of the node
|
151
|
-
* to the end of the node.
|
152
|
-
* * `between`: the symbols between the property and value
|
153
|
-
* for declarations, selector and `{` for rules, or last parameter
|
154
|
-
* and `{` for at-rules.
|
155
|
-
* * `semicolon`: contains true if the last child has
|
156
|
-
* an (optional) semicolon.
|
157
|
-
* * `afterName`: the space between the at-rule name and its parameters.
|
158
|
-
* * `left`: the space symbols between `/*` and the comment’s text.
|
159
|
-
* * `right`: the space symbols between the comment’s text
|
160
|
-
* and <code>*/</code>.
|
161
|
-
* * `important`: the content of the important statement,
|
162
|
-
* if it is not just `!important`.
|
163
|
-
*
|
164
|
-
* PostCSS cleans selectors, declaration values and at-rule parameters
|
165
|
-
* from comments and extra spaces, but it stores origin content in raws
|
166
|
-
* properties. As such, if you don’t change a declaration’s value,
|
167
|
-
* PostCSS will use the raw value with comments.
|
221
|
+
* A type of node helps in identification of a node
|
222
|
+
* and perform operation based on it's type.
|
168
223
|
*
|
169
224
|
* ```js
|
170
|
-
* const
|
171
|
-
*
|
225
|
+
* const declaration = new Declaration({
|
226
|
+
* prop: 'color',
|
227
|
+
* value: 'black'
|
228
|
+
* })
|
229
|
+
*
|
230
|
+
* declaration.type //=> 'decl'
|
172
231
|
* ```
|
173
232
|
*/
|
174
|
-
|
233
|
+
type: string
|
175
234
|
|
176
|
-
/**
|
177
|
-
* @param defaults Value for node properties.
|
178
|
-
*/
|
179
235
|
constructor(defaults?: object)
|
180
236
|
|
181
237
|
/**
|
182
|
-
*
|
183
|
-
* of the node in the source, showing line and column numbers and also
|
184
|
-
* a small excerpt to facilitate debugging.
|
185
|
-
*
|
186
|
-
* If present, an input source map will be used to get the original position
|
187
|
-
* of the source, even from a previous compilation step
|
188
|
-
* (e.g., from Sass compilation).
|
238
|
+
* Insert new node after current node to current node’s parent.
|
189
239
|
*
|
190
|
-
*
|
240
|
+
* Just alias for `node.parent.insertAfter(node, add)`.
|
191
241
|
*
|
192
242
|
* ```js
|
193
|
-
*
|
194
|
-
* throw decl.error(`Unknown variable ${name}`, { word: name })
|
195
|
-
* // CssSyntaxError: postcss-vars:a.sass:4:3: Unknown variable $black
|
196
|
-
* // color: $black
|
197
|
-
* // a
|
198
|
-
* // ^
|
199
|
-
* // background: white
|
200
|
-
* }
|
243
|
+
* decl.after('color: black')
|
201
244
|
* ```
|
202
245
|
*
|
203
|
-
* @param
|
204
|
-
* @
|
205
|
-
*
|
206
|
-
* @return Error object to throw it.
|
246
|
+
* @param newNode New node.
|
247
|
+
* @return This node for methods chain.
|
207
248
|
*/
|
208
|
-
|
249
|
+
after(newNode: Node | Node.ChildProps | Node[] | string): this
|
209
250
|
|
210
251
|
/**
|
211
|
-
*
|
252
|
+
* It assigns properties to an existing node instance.
|
212
253
|
*
|
213
254
|
* ```js
|
214
|
-
*
|
215
|
-
* bad: (decl, { result }) => {
|
216
|
-
* decl.warn(result, 'Deprecated property bad')
|
217
|
-
* }
|
218
|
-
* }
|
255
|
+
* decl.assign({ prop: 'word-wrap', value: 'break-word' })
|
219
256
|
* ```
|
220
257
|
*
|
221
|
-
* @param
|
222
|
-
* @param text Warning message.
|
223
|
-
* @param opts Warning Options.
|
258
|
+
* @param overrides New properties to override the node.
|
224
259
|
*
|
225
|
-
* @return
|
260
|
+
* @return `this` for method chaining.
|
226
261
|
*/
|
227
|
-
|
262
|
+
assign(overrides: object): this
|
228
263
|
|
229
264
|
/**
|
230
|
-
*
|
231
|
-
* from the node and its children.
|
232
|
-
*
|
233
|
-
* ```js
|
234
|
-
* if (decl.prop.match(/^-webkit-/)) {
|
235
|
-
* decl.remove()
|
236
|
-
* }
|
237
|
-
* ```
|
265
|
+
* Insert new node before current node to current node’s parent.
|
238
266
|
*
|
239
|
-
*
|
240
|
-
*/
|
241
|
-
remove(): this
|
242
|
-
|
243
|
-
/**
|
244
|
-
* Returns a CSS string representing the node.
|
267
|
+
* Just alias for `node.parent.insertBefore(node, add)`.
|
245
268
|
*
|
246
269
|
* ```js
|
247
|
-
*
|
270
|
+
* decl.before('content: ""')
|
248
271
|
* ```
|
249
272
|
*
|
250
|
-
* @param
|
251
|
-
* @return
|
273
|
+
* @param newNode New node.
|
274
|
+
* @return This node for methods chain.
|
252
275
|
*/
|
253
|
-
|
276
|
+
before(newNode: Node | Node.ChildProps | Node[] | string): this
|
254
277
|
|
255
278
|
/**
|
256
|
-
*
|
279
|
+
* Clear the code style properties for the node and its children.
|
257
280
|
*
|
258
281
|
* ```js
|
259
|
-
*
|
282
|
+
* node.raws.before //=> ' '
|
283
|
+
* node.cleanRaws()
|
284
|
+
* node.raws.before //=> undefined
|
260
285
|
* ```
|
261
286
|
*
|
262
|
-
* @param
|
263
|
-
* @return Current node to methods chain.
|
287
|
+
* @param keepBetween Keep the `raws.between` symbols.
|
264
288
|
*/
|
265
|
-
|
289
|
+
cleanRaws(keepBetween?: boolean): void
|
266
290
|
|
267
291
|
/**
|
268
|
-
*
|
269
|
-
*
|
270
|
-
* The resulting cloned node and its (cloned) children will retain
|
271
|
-
* code style properties.
|
292
|
+
* It creates clone of an existing node, which includes all the properties
|
293
|
+
* and their values, that includes `raws` but not `type`.
|
272
294
|
*
|
273
295
|
* ```js
|
274
296
|
* decl.raws.before //=> "\n "
|
@@ -278,9 +300,19 @@ export default abstract class Node {
|
|
278
300
|
* ```
|
279
301
|
*
|
280
302
|
* @param overrides New properties to override in the clone.
|
281
|
-
*
|
303
|
+
*
|
304
|
+
* @return Duplicate of the node instance.
|
305
|
+
*/
|
306
|
+
clone(overrides?: object): Node
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Shortcut to clone the node and insert the resulting cloned node
|
310
|
+
* after the current node.
|
311
|
+
*
|
312
|
+
* @param overrides New properties to override in the clone.
|
313
|
+
* @return New node.
|
282
314
|
*/
|
283
|
-
|
315
|
+
cloneAfter(overrides?: object): Node
|
284
316
|
|
285
317
|
/**
|
286
318
|
* Shortcut to clone the node and insert the resulting cloned node
|
@@ -294,34 +326,43 @@ export default abstract class Node {
|
|
294
326
|
*
|
295
327
|
* @return New node
|
296
328
|
*/
|
297
|
-
cloneBefore(overrides?: object):
|
329
|
+
cloneBefore(overrides?: object): Node
|
298
330
|
|
299
331
|
/**
|
300
|
-
*
|
301
|
-
*
|
332
|
+
* It creates an instance of the class `CssSyntaxError` and parameters passed
|
333
|
+
* to this method are assigned to the error instance.
|
302
334
|
*
|
303
|
-
*
|
304
|
-
*
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
*
|
335
|
+
* The error instance will have description for the
|
336
|
+
* error, original position of the node in the
|
337
|
+
* source, showing line and column number.
|
338
|
+
*
|
339
|
+
* If any previous map is present, it would be used
|
340
|
+
* to get original position of the source.
|
341
|
+
*
|
342
|
+
* The Previous Map here is referred to the source map
|
343
|
+
* generated by previous compilation, example: Less,
|
344
|
+
* Stylus and Sass.
|
345
|
+
*
|
346
|
+
* This method returns the error instance instead of
|
347
|
+
* throwing it.
|
310
348
|
*
|
311
349
|
* ```js
|
312
|
-
*
|
313
|
-
*
|
314
|
-
*
|
315
|
-
*
|
350
|
+
* if (!variables[name]) {
|
351
|
+
* throw decl.error(`Unknown variable ${name}`, { word: name })
|
352
|
+
* // CssSyntaxError: postcss-vars:a.sass:4:3: Unknown variable $black
|
353
|
+
* // color: $black
|
354
|
+
* // a
|
355
|
+
* // ^
|
356
|
+
* // background: white
|
316
357
|
* }
|
317
358
|
* ```
|
318
359
|
*
|
319
|
-
* @param
|
320
|
-
* @
|
360
|
+
* @param message Description for the error instance.
|
361
|
+
* @param options Options for the error instance.
|
362
|
+
*
|
363
|
+
* @return Error instance is returned.
|
321
364
|
*/
|
322
|
-
|
323
|
-
...nodes: (ChildNode | ChildProps | ChildNode[] | ChildProps[])[]
|
324
|
-
): this
|
365
|
+
error(message: string, options?: Node.NodeErrorOptions): CssSyntaxError
|
325
366
|
|
326
367
|
/**
|
327
368
|
* Returns the next child of the node’s parent.
|
@@ -338,7 +379,23 @@ export default abstract class Node {
|
|
338
379
|
*
|
339
380
|
* @return Next node.
|
340
381
|
*/
|
341
|
-
next(): ChildNode | undefined
|
382
|
+
next(): Node.ChildNode | undefined
|
383
|
+
|
384
|
+
/**
|
385
|
+
* Get the position for a word or an index inside the node.
|
386
|
+
*
|
387
|
+
* @param opts Options.
|
388
|
+
* @return Position.
|
389
|
+
*/
|
390
|
+
positionBy(opts?: Pick<WarningOptions, 'index' | 'word'>): Node.Position
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Convert string index to line/column.
|
394
|
+
*
|
395
|
+
* @param index The symbol number in the node’s string.
|
396
|
+
* @return Symbol position in file.
|
397
|
+
*/
|
398
|
+
positionInside(index: number): Node.Position
|
342
399
|
|
343
400
|
/**
|
344
401
|
* Returns the previous child of the node’s parent.
|
@@ -353,79 +410,85 @@ export default abstract class Node {
|
|
353
410
|
*
|
354
411
|
* @return Previous node.
|
355
412
|
*/
|
356
|
-
prev(): ChildNode | undefined
|
413
|
+
prev(): Node.ChildNode | undefined
|
357
414
|
|
358
415
|
/**
|
359
|
-
*
|
360
|
-
*
|
361
|
-
* Just alias for `node.parent.insertBefore(node, add)`.
|
416
|
+
* Get the range for a word or start and end index inside the node.
|
417
|
+
* The start index is inclusive; the end index is exclusive.
|
362
418
|
*
|
363
|
-
*
|
364
|
-
*
|
365
|
-
* ```
|
366
|
-
*
|
367
|
-
* @param newNode New node.
|
368
|
-
* @return This node for methods chain.
|
419
|
+
* @param opts Options.
|
420
|
+
* @return Range.
|
369
421
|
*/
|
370
|
-
|
422
|
+
rangeBy(
|
423
|
+
opts?: Pick<WarningOptions, 'endIndex' | 'index' | 'word'>
|
424
|
+
): Node.Range
|
371
425
|
|
372
426
|
/**
|
373
|
-
*
|
374
|
-
*
|
375
|
-
*
|
427
|
+
* Returns a `raws` value. If the node is missing
|
428
|
+
* the code style property (because the node was manually built or cloned),
|
429
|
+
* PostCSS will try to autodetect the code style property by looking
|
430
|
+
* at other nodes in the tree.
|
376
431
|
*
|
377
432
|
* ```js
|
378
|
-
*
|
433
|
+
* const root = postcss.parse('a { background: white }')
|
434
|
+
* root.nodes[0].append({ prop: 'color', value: 'black' })
|
435
|
+
* root.nodes[0].nodes[1].raws.before //=> undefined
|
436
|
+
* root.nodes[0].nodes[1].raw('before') //=> ' '
|
379
437
|
* ```
|
380
438
|
*
|
381
|
-
* @param
|
382
|
-
* @
|
439
|
+
* @param prop Name of code style property.
|
440
|
+
* @param defaultType Name of default value, it can be missed
|
441
|
+
* if the value is the same as prop.
|
442
|
+
* @return {string} Code style value.
|
383
443
|
*/
|
384
|
-
|
444
|
+
raw(prop: string, defaultType?: string): string
|
385
445
|
|
386
446
|
/**
|
387
|
-
*
|
447
|
+
* It removes the node from its parent and deletes its parent property.
|
388
448
|
*
|
389
449
|
* ```js
|
390
|
-
*
|
450
|
+
* if (decl.prop.match(/^-webkit-/)) {
|
451
|
+
* decl.remove()
|
452
|
+
* }
|
391
453
|
* ```
|
392
454
|
*
|
393
|
-
* @return
|
455
|
+
* @return `this` for method chaining.
|
394
456
|
*/
|
395
|
-
|
457
|
+
remove(): this
|
396
458
|
|
397
459
|
/**
|
398
|
-
*
|
399
|
-
* the code style property (because the node was manually built or cloned),
|
400
|
-
* PostCSS will try to autodetect the code style property by looking
|
401
|
-
* at other nodes in the tree.
|
460
|
+
* Inserts node(s) before the current node and removes the current node.
|
402
461
|
*
|
403
462
|
* ```js
|
404
|
-
*
|
405
|
-
*
|
406
|
-
*
|
407
|
-
*
|
463
|
+
* AtRule: {
|
464
|
+
* mixin: atrule => {
|
465
|
+
* atrule.replaceWith(mixinRules[atrule.params])
|
466
|
+
* }
|
467
|
+
* }
|
408
468
|
* ```
|
409
469
|
*
|
410
|
-
* @param
|
411
|
-
* @
|
412
|
-
* if the value is the same as prop.
|
413
|
-
* @return {string} Code style value.
|
470
|
+
* @param nodes Mode(s) to replace current one.
|
471
|
+
* @return Current node to methods chain.
|
414
472
|
*/
|
415
|
-
|
473
|
+
replaceWith(
|
474
|
+
...nodes: (
|
475
|
+
| Node.ChildNode
|
476
|
+
| Node.ChildNode[]
|
477
|
+
| Node.ChildProps
|
478
|
+
| Node.ChildProps[]
|
479
|
+
)[]
|
480
|
+
): this
|
416
481
|
|
417
482
|
/**
|
418
|
-
*
|
483
|
+
* Finds the Root instance of the node’s tree.
|
419
484
|
*
|
420
485
|
* ```js
|
421
|
-
*
|
422
|
-
* node.cleanRaws()
|
423
|
-
* node.raws.before //=> undefined
|
486
|
+
* root.nodes[0].nodes[0].root() === root
|
424
487
|
* ```
|
425
488
|
*
|
426
|
-
* @
|
489
|
+
* @return Root parent.
|
427
490
|
*/
|
428
|
-
|
491
|
+
root(): Root
|
429
492
|
|
430
493
|
/**
|
431
494
|
* Fix circular links on `JSON.stringify()`.
|
@@ -435,10 +498,39 @@ export default abstract class Node {
|
|
435
498
|
toJSON(): object
|
436
499
|
|
437
500
|
/**
|
438
|
-
*
|
501
|
+
* It compiles the node to browser readable cascading style sheets string
|
502
|
+
* depending on it's type.
|
439
503
|
*
|
440
|
-
*
|
441
|
-
*
|
504
|
+
* ```js
|
505
|
+
* new Rule({ selector: 'a' }).toString() //=> "a {}"
|
506
|
+
* ```
|
507
|
+
*
|
508
|
+
* @param stringifier A syntax to use in string generation.
|
509
|
+
* @return CSS string of this node.
|
442
510
|
*/
|
443
|
-
|
511
|
+
toString(stringifier?: Stringifier | Syntax): string
|
512
|
+
|
513
|
+
/**
|
514
|
+
* It is a wrapper for {@link Result#warn}, providing convenient
|
515
|
+
* way of generating warnings.
|
516
|
+
*
|
517
|
+
* ```js
|
518
|
+
* Declaration: {
|
519
|
+
* bad: (decl, { result }) => {
|
520
|
+
* decl.warn(result, 'Deprecated property: bad')
|
521
|
+
* }
|
522
|
+
* }
|
523
|
+
* ```
|
524
|
+
*
|
525
|
+
* @param result The `Result` instance that will receive the warning.
|
526
|
+
* @param message Description for the warning.
|
527
|
+
* @param options Options for the warning.
|
528
|
+
*
|
529
|
+
* @return `Warning` instance is returned
|
530
|
+
*/
|
531
|
+
warn(result: Result, message: string, options?: WarningOptions): Warning
|
444
532
|
}
|
533
|
+
|
534
|
+
declare class Node extends Node_ { }
|
535
|
+
|
536
|
+
export = Node
|