postcss 8.4.23 → 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.
- package/lib/at-rule.d.ts +19 -19
- package/lib/comment.d.ts +12 -10
- package/lib/container.d.ts +212 -212
- package/lib/container.js +239 -239
- package/lib/css-syntax-error.d.ts +95 -95
- package/lib/css-syntax-error.js +1 -1
- package/lib/declaration.d.ts +55 -42
- package/lib/document.d.ts +1 -1
- package/lib/input.d.ts +70 -70
- package/lib/input.js +64 -64
- package/lib/lazy-result.d.ts +54 -54
- package/lib/lazy-result.js +226 -226
- package/lib/list.d.ts +14 -14
- package/lib/list.js +9 -9
- package/lib/map-generator.js +188 -188
- package/lib/no-work-result.d.ts +12 -12
- package/lib/no-work-result.js +30 -30
- package/lib/node.d.ts +277 -230
- package/lib/node.js +201 -199
- package/lib/parser.js +286 -286
- package/lib/postcss.d.ts +122 -129
- package/lib/previous-map.d.ts +13 -13
- package/lib/previous-map.js +33 -33
- package/lib/processor.d.ts +37 -37
- package/lib/processor.js +19 -19
- package/lib/result.d.ts +44 -44
- package/lib/result.js +4 -4
- package/lib/root.d.ts +8 -8
- package/lib/root.js +10 -10
- package/lib/rule.d.ts +16 -16
- package/lib/stringifier.d.ts +21 -21
- package/lib/stringifier.js +139 -139
- package/lib/terminal-highlight.js +11 -11
- package/lib/tokenize.js +1 -1
- package/lib/warning.d.ts +38 -38
- package/lib/warning.js +1 -1
- package/package.json +1 -1
package/lib/node.js
CHANGED
@@ -54,42 +54,23 @@ class Node {
|
|
54
54
|
}
|
55
55
|
}
|
56
56
|
|
57
|
-
error
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
{
|
63
|
-
{
|
64
|
-
opts
|
57
|
+
addToError(error) {
|
58
|
+
error.postcssNode = this
|
59
|
+
if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
|
60
|
+
let s = this.source
|
61
|
+
error.stack = error.stack.replace(
|
62
|
+
/\n\s{4}at /,
|
63
|
+
`$&${s.input.from}:${s.start.line}:${s.start.column}$&`
|
65
64
|
)
|
66
65
|
}
|
67
|
-
return
|
68
|
-
}
|
69
|
-
|
70
|
-
warn(result, text, opts) {
|
71
|
-
let data = { node: this }
|
72
|
-
for (let i in opts) data[i] = opts[i]
|
73
|
-
return result.warn(text, data)
|
66
|
+
return error
|
74
67
|
}
|
75
68
|
|
76
|
-
|
77
|
-
|
78
|
-
this.parent.removeChild(this)
|
79
|
-
}
|
80
|
-
this.parent = undefined
|
69
|
+
after(add) {
|
70
|
+
this.parent.insertAfter(this, add)
|
81
71
|
return this
|
82
72
|
}
|
83
73
|
|
84
|
-
toString(stringifier = stringify) {
|
85
|
-
if (stringifier.stringify) stringifier = stringifier.stringify
|
86
|
-
let result = ''
|
87
|
-
stringifier(this, i => {
|
88
|
-
result += i
|
89
|
-
})
|
90
|
-
return result
|
91
|
-
}
|
92
|
-
|
93
74
|
assign(overrides = {}) {
|
94
75
|
for (let name in overrides) {
|
95
76
|
this[name] = overrides[name]
|
@@ -97,6 +78,17 @@ class Node {
|
|
97
78
|
return this
|
98
79
|
}
|
99
80
|
|
81
|
+
before(add) {
|
82
|
+
this.parent.insertBefore(this, add)
|
83
|
+
return this
|
84
|
+
}
|
85
|
+
|
86
|
+
cleanRaws(keepBetween) {
|
87
|
+
delete this.raws.before
|
88
|
+
delete this.raws.after
|
89
|
+
if (!keepBetween) delete this.raws.between
|
90
|
+
}
|
91
|
+
|
100
92
|
clone(overrides = {}) {
|
101
93
|
let cloned = cloneNode(this)
|
102
94
|
for (let name in overrides) {
|
@@ -105,39 +97,70 @@ class Node {
|
|
105
97
|
return cloned
|
106
98
|
}
|
107
99
|
|
108
|
-
|
100
|
+
cloneAfter(overrides = {}) {
|
109
101
|
let cloned = this.clone(overrides)
|
110
|
-
this.parent.
|
102
|
+
this.parent.insertAfter(this, cloned)
|
111
103
|
return cloned
|
112
104
|
}
|
113
105
|
|
114
|
-
|
106
|
+
cloneBefore(overrides = {}) {
|
115
107
|
let cloned = this.clone(overrides)
|
116
|
-
this.parent.
|
108
|
+
this.parent.insertBefore(this, cloned)
|
117
109
|
return cloned
|
118
110
|
}
|
119
111
|
|
120
|
-
|
121
|
-
if (this.
|
122
|
-
let
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
112
|
+
error(message, opts = {}) {
|
113
|
+
if (this.source) {
|
114
|
+
let { end, start } = this.rangeBy(opts)
|
115
|
+
return this.source.input.error(
|
116
|
+
message,
|
117
|
+
{ column: start.column, line: start.line },
|
118
|
+
{ column: end.column, line: end.line },
|
119
|
+
opts
|
120
|
+
)
|
121
|
+
}
|
122
|
+
return new CssSyntaxError(message)
|
123
|
+
}
|
124
|
+
|
125
|
+
getProxyProcessor() {
|
126
|
+
return {
|
127
|
+
get(node, prop) {
|
128
|
+
if (prop === 'proxyOf') {
|
129
|
+
return node
|
130
|
+
} else if (prop === 'root') {
|
131
|
+
return () => node.root().toProxy()
|
130
132
|
} else {
|
131
|
-
|
133
|
+
return node[prop]
|
132
134
|
}
|
133
|
-
}
|
135
|
+
},
|
134
136
|
|
135
|
-
|
136
|
-
|
137
|
+
set(node, prop, value) {
|
138
|
+
if (node[prop] === value) return true
|
139
|
+
node[prop] = value
|
140
|
+
if (
|
141
|
+
prop === 'prop' ||
|
142
|
+
prop === 'value' ||
|
143
|
+
prop === 'name' ||
|
144
|
+
prop === 'params' ||
|
145
|
+
prop === 'important' ||
|
146
|
+
/* c8 ignore next */
|
147
|
+
prop === 'text'
|
148
|
+
) {
|
149
|
+
node.markDirty()
|
150
|
+
}
|
151
|
+
return true
|
137
152
|
}
|
138
153
|
}
|
154
|
+
}
|
139
155
|
|
140
|
-
|
156
|
+
markDirty() {
|
157
|
+
if (this[isClean]) {
|
158
|
+
this[isClean] = false
|
159
|
+
let next = this
|
160
|
+
while ((next = next.parent)) {
|
161
|
+
next[isClean] = false
|
162
|
+
}
|
163
|
+
}
|
141
164
|
}
|
142
165
|
|
143
166
|
next() {
|
@@ -146,28 +169,97 @@ class Node {
|
|
146
169
|
return this.parent.nodes[index + 1]
|
147
170
|
}
|
148
171
|
|
172
|
+
positionBy(opts, stringRepresentation) {
|
173
|
+
let pos = this.source.start
|
174
|
+
if (opts.index) {
|
175
|
+
pos = this.positionInside(opts.index, stringRepresentation)
|
176
|
+
} else if (opts.word) {
|
177
|
+
stringRepresentation = this.toString()
|
178
|
+
let index = stringRepresentation.indexOf(opts.word)
|
179
|
+
if (index !== -1) pos = this.positionInside(index, stringRepresentation)
|
180
|
+
}
|
181
|
+
return pos
|
182
|
+
}
|
183
|
+
|
184
|
+
positionInside(index, stringRepresentation) {
|
185
|
+
let string = stringRepresentation || this.toString()
|
186
|
+
let column = this.source.start.column
|
187
|
+
let line = this.source.start.line
|
188
|
+
|
189
|
+
for (let i = 0; i < index; i++) {
|
190
|
+
if (string[i] === '\n') {
|
191
|
+
column = 1
|
192
|
+
line += 1
|
193
|
+
} else {
|
194
|
+
column += 1
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
return { column, line }
|
199
|
+
}
|
200
|
+
|
149
201
|
prev() {
|
150
202
|
if (!this.parent) return undefined
|
151
203
|
let index = this.parent.index(this)
|
152
204
|
return this.parent.nodes[index - 1]
|
153
205
|
}
|
154
206
|
|
155
|
-
|
156
|
-
this.parent.insertBefore(this, add)
|
207
|
+
get proxyOf() {
|
157
208
|
return this
|
158
209
|
}
|
159
210
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
211
|
+
rangeBy(opts) {
|
212
|
+
let start = {
|
213
|
+
column: this.source.start.column,
|
214
|
+
line: this.source.start.line
|
215
|
+
}
|
216
|
+
let end = this.source.end
|
217
|
+
? {
|
218
|
+
column: this.source.end.column + 1,
|
219
|
+
line: this.source.end.line
|
220
|
+
}
|
221
|
+
: {
|
222
|
+
column: start.column + 1,
|
223
|
+
line: start.line
|
224
|
+
}
|
164
225
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
226
|
+
if (opts.word) {
|
227
|
+
let stringRepresentation = this.toString()
|
228
|
+
let index = stringRepresentation.indexOf(opts.word)
|
229
|
+
if (index !== -1) {
|
230
|
+
start = this.positionInside(index, stringRepresentation)
|
231
|
+
end = this.positionInside(index + opts.word.length, stringRepresentation)
|
232
|
+
}
|
233
|
+
} else {
|
234
|
+
if (opts.start) {
|
235
|
+
start = {
|
236
|
+
column: opts.start.column,
|
237
|
+
line: opts.start.line
|
238
|
+
}
|
239
|
+
} else if (opts.index) {
|
240
|
+
start = this.positionInside(opts.index)
|
241
|
+
}
|
242
|
+
|
243
|
+
if (opts.end) {
|
244
|
+
end = {
|
245
|
+
column: opts.end.column,
|
246
|
+
line: opts.end.line
|
247
|
+
}
|
248
|
+
} else if (opts.endIndex) {
|
249
|
+
end = this.positionInside(opts.endIndex)
|
250
|
+
} else if (opts.index) {
|
251
|
+
end = this.positionInside(opts.index + 1)
|
252
|
+
}
|
169
253
|
}
|
170
|
-
|
254
|
+
|
255
|
+
if (
|
256
|
+
end.line < start.line ||
|
257
|
+
(end.line === start.line && end.column <= start.column)
|
258
|
+
) {
|
259
|
+
end = { column: start.column + 1, line: start.line }
|
260
|
+
}
|
261
|
+
|
262
|
+
return { end, start }
|
171
263
|
}
|
172
264
|
|
173
265
|
raw(prop, defaultType) {
|
@@ -175,10 +267,43 @@ class Node {
|
|
175
267
|
return str.raw(this, prop, defaultType)
|
176
268
|
}
|
177
269
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
270
|
+
remove() {
|
271
|
+
if (this.parent) {
|
272
|
+
this.parent.removeChild(this)
|
273
|
+
}
|
274
|
+
this.parent = undefined
|
275
|
+
return this
|
276
|
+
}
|
277
|
+
|
278
|
+
replaceWith(...nodes) {
|
279
|
+
if (this.parent) {
|
280
|
+
let bookmark = this
|
281
|
+
let foundSelf = false
|
282
|
+
for (let node of nodes) {
|
283
|
+
if (node === this) {
|
284
|
+
foundSelf = true
|
285
|
+
} else if (foundSelf) {
|
286
|
+
this.parent.insertAfter(bookmark, node)
|
287
|
+
bookmark = node
|
288
|
+
} else {
|
289
|
+
this.parent.insertBefore(bookmark, node)
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
if (!foundSelf) {
|
294
|
+
this.remove()
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
return this
|
299
|
+
}
|
300
|
+
|
301
|
+
root() {
|
302
|
+
let result = this
|
303
|
+
while (result.parent && result.parent.type !== 'document') {
|
304
|
+
result = result.parent
|
305
|
+
}
|
306
|
+
return result
|
182
307
|
}
|
183
308
|
|
184
309
|
toJSON(_, inputs) {
|
@@ -213,9 +338,9 @@ class Node {
|
|
213
338
|
inputsNextIndex++
|
214
339
|
}
|
215
340
|
fixed[name] = {
|
341
|
+
end: value.end,
|
216
342
|
inputId,
|
217
|
-
start: value.start
|
218
|
-
end: value.end
|
343
|
+
start: value.start
|
219
344
|
}
|
220
345
|
} else {
|
221
346
|
fixed[name] = value
|
@@ -229,118 +354,6 @@ class Node {
|
|
229
354
|
return fixed
|
230
355
|
}
|
231
356
|
|
232
|
-
positionInside(index) {
|
233
|
-
let string = this.toString()
|
234
|
-
let column = this.source.start.column
|
235
|
-
let line = this.source.start.line
|
236
|
-
|
237
|
-
for (let i = 0; i < index; i++) {
|
238
|
-
if (string[i] === '\n') {
|
239
|
-
column = 1
|
240
|
-
line += 1
|
241
|
-
} else {
|
242
|
-
column += 1
|
243
|
-
}
|
244
|
-
}
|
245
|
-
|
246
|
-
return { line, column }
|
247
|
-
}
|
248
|
-
|
249
|
-
positionBy(opts) {
|
250
|
-
let pos = this.source.start
|
251
|
-
if (opts.index) {
|
252
|
-
pos = this.positionInside(opts.index)
|
253
|
-
} else if (opts.word) {
|
254
|
-
let index = this.toString().indexOf(opts.word)
|
255
|
-
if (index !== -1) pos = this.positionInside(index)
|
256
|
-
}
|
257
|
-
return pos
|
258
|
-
}
|
259
|
-
|
260
|
-
rangeBy(opts) {
|
261
|
-
let start = {
|
262
|
-
line: this.source.start.line,
|
263
|
-
column: this.source.start.column
|
264
|
-
}
|
265
|
-
let end = this.source.end
|
266
|
-
? {
|
267
|
-
line: this.source.end.line,
|
268
|
-
column: this.source.end.column + 1
|
269
|
-
}
|
270
|
-
: {
|
271
|
-
line: start.line,
|
272
|
-
column: start.column + 1
|
273
|
-
}
|
274
|
-
|
275
|
-
if (opts.word) {
|
276
|
-
let index = this.toString().indexOf(opts.word)
|
277
|
-
if (index !== -1) {
|
278
|
-
start = this.positionInside(index)
|
279
|
-
end = this.positionInside(index + opts.word.length)
|
280
|
-
}
|
281
|
-
} else {
|
282
|
-
if (opts.start) {
|
283
|
-
start = {
|
284
|
-
line: opts.start.line,
|
285
|
-
column: opts.start.column
|
286
|
-
}
|
287
|
-
} else if (opts.index) {
|
288
|
-
start = this.positionInside(opts.index)
|
289
|
-
}
|
290
|
-
|
291
|
-
if (opts.end) {
|
292
|
-
end = {
|
293
|
-
line: opts.end.line,
|
294
|
-
column: opts.end.column
|
295
|
-
}
|
296
|
-
} else if (opts.endIndex) {
|
297
|
-
end = this.positionInside(opts.endIndex)
|
298
|
-
} else if (opts.index) {
|
299
|
-
end = this.positionInside(opts.index + 1)
|
300
|
-
}
|
301
|
-
}
|
302
|
-
|
303
|
-
if (
|
304
|
-
end.line < start.line ||
|
305
|
-
(end.line === start.line && end.column <= start.column)
|
306
|
-
) {
|
307
|
-
end = { line: start.line, column: start.column + 1 }
|
308
|
-
}
|
309
|
-
|
310
|
-
return { start, end }
|
311
|
-
}
|
312
|
-
|
313
|
-
getProxyProcessor() {
|
314
|
-
return {
|
315
|
-
set(node, prop, value) {
|
316
|
-
if (node[prop] === value) return true
|
317
|
-
node[prop] = value
|
318
|
-
if (
|
319
|
-
prop === 'prop' ||
|
320
|
-
prop === 'value' ||
|
321
|
-
prop === 'name' ||
|
322
|
-
prop === 'params' ||
|
323
|
-
prop === 'important' ||
|
324
|
-
/* c8 ignore next */
|
325
|
-
prop === 'text'
|
326
|
-
) {
|
327
|
-
node.markDirty()
|
328
|
-
}
|
329
|
-
return true
|
330
|
-
},
|
331
|
-
|
332
|
-
get(node, prop) {
|
333
|
-
if (prop === 'proxyOf') {
|
334
|
-
return node
|
335
|
-
} else if (prop === 'root') {
|
336
|
-
return () => node.root().toProxy()
|
337
|
-
} else {
|
338
|
-
return node[prop]
|
339
|
-
}
|
340
|
-
}
|
341
|
-
}
|
342
|
-
}
|
343
|
-
|
344
357
|
toProxy() {
|
345
358
|
if (!this.proxyCache) {
|
346
359
|
this.proxyCache = new Proxy(this, this.getProxyProcessor())
|
@@ -348,30 +361,19 @@ class Node {
|
|
348
361
|
return this.proxyCache
|
349
362
|
}
|
350
363
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
)
|
359
|
-
}
|
360
|
-
return error
|
361
|
-
}
|
362
|
-
|
363
|
-
markDirty() {
|
364
|
-
if (this[isClean]) {
|
365
|
-
this[isClean] = false
|
366
|
-
let next = this
|
367
|
-
while ((next = next.parent)) {
|
368
|
-
next[isClean] = false
|
369
|
-
}
|
370
|
-
}
|
364
|
+
toString(stringifier = stringify) {
|
365
|
+
if (stringifier.stringify) stringifier = stringifier.stringify
|
366
|
+
let result = ''
|
367
|
+
stringifier(this, i => {
|
368
|
+
result += i
|
369
|
+
})
|
370
|
+
return result
|
371
371
|
}
|
372
372
|
|
373
|
-
|
374
|
-
|
373
|
+
warn(result, text, opts) {
|
374
|
+
let data = { node: this }
|
375
|
+
for (let i in opts) data[i] = opts[i]
|
376
|
+
return result.warn(text, data)
|
375
377
|
}
|
376
378
|
}
|
377
379
|
|