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.js
CHANGED
@@ -10,7 +10,7 @@ function cloneNode(obj, parent) {
|
|
10
10
|
|
11
11
|
for (let i in obj) {
|
12
12
|
if (!Object.prototype.hasOwnProperty.call(obj, i)) {
|
13
|
-
|
13
|
+
/* c8 ignore next 2 */
|
14
14
|
continue
|
15
15
|
}
|
16
16
|
if (i === 'proxyCache') continue
|
@@ -54,37 +54,23 @@ class Node {
|
|
54
54
|
}
|
55
55
|
}
|
56
56
|
|
57
|
-
error
|
58
|
-
|
59
|
-
|
60
|
-
|
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}$&`
|
64
|
+
)
|
61
65
|
}
|
62
|
-
return
|
63
|
-
}
|
64
|
-
|
65
|
-
warn(result, text, opts) {
|
66
|
-
let data = { node: this }
|
67
|
-
for (let i in opts) data[i] = opts[i]
|
68
|
-
return result.warn(text, data)
|
66
|
+
return error
|
69
67
|
}
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
this.parent.removeChild(this)
|
74
|
-
}
|
75
|
-
this.parent = undefined
|
69
|
+
after(add) {
|
70
|
+
this.parent.insertAfter(this, add)
|
76
71
|
return this
|
77
72
|
}
|
78
73
|
|
79
|
-
toString(stringifier = stringify) {
|
80
|
-
if (stringifier.stringify) stringifier = stringifier.stringify
|
81
|
-
let result = ''
|
82
|
-
stringifier(this, i => {
|
83
|
-
result += i
|
84
|
-
})
|
85
|
-
return result
|
86
|
-
}
|
87
|
-
|
88
74
|
assign(overrides = {}) {
|
89
75
|
for (let name in overrides) {
|
90
76
|
this[name] = overrides[name]
|
@@ -92,6 +78,17 @@ class Node {
|
|
92
78
|
return this
|
93
79
|
}
|
94
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
|
+
|
95
92
|
clone(overrides = {}) {
|
96
93
|
let cloned = cloneNode(this)
|
97
94
|
for (let name in overrides) {
|
@@ -100,39 +97,70 @@ class Node {
|
|
100
97
|
return cloned
|
101
98
|
}
|
102
99
|
|
103
|
-
|
100
|
+
cloneAfter(overrides = {}) {
|
104
101
|
let cloned = this.clone(overrides)
|
105
|
-
this.parent.
|
102
|
+
this.parent.insertAfter(this, cloned)
|
106
103
|
return cloned
|
107
104
|
}
|
108
105
|
|
109
|
-
|
106
|
+
cloneBefore(overrides = {}) {
|
110
107
|
let cloned = this.clone(overrides)
|
111
|
-
this.parent.
|
108
|
+
this.parent.insertBefore(this, cloned)
|
112
109
|
return cloned
|
113
110
|
}
|
114
111
|
|
115
|
-
|
116
|
-
if (this.
|
117
|
-
let
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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()
|
125
132
|
} else {
|
126
|
-
|
133
|
+
return node[prop]
|
127
134
|
}
|
128
|
-
}
|
135
|
+
},
|
129
136
|
|
130
|
-
|
131
|
-
|
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
|
132
152
|
}
|
133
153
|
}
|
154
|
+
}
|
134
155
|
|
135
|
-
|
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
|
+
}
|
136
164
|
}
|
137
165
|
|
138
166
|
next() {
|
@@ -141,19 +169,128 @@ class Node {
|
|
141
169
|
return this.parent.nodes[index + 1]
|
142
170
|
}
|
143
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
|
+
|
144
201
|
prev() {
|
145
202
|
if (!this.parent) return undefined
|
146
203
|
let index = this.parent.index(this)
|
147
204
|
return this.parent.nodes[index - 1]
|
148
205
|
}
|
149
206
|
|
150
|
-
|
151
|
-
|
207
|
+
rangeBy(opts) {
|
208
|
+
let start = {
|
209
|
+
column: this.source.start.column,
|
210
|
+
line: this.source.start.line
|
211
|
+
}
|
212
|
+
let end = this.source.end
|
213
|
+
? {
|
214
|
+
column: this.source.end.column + 1,
|
215
|
+
line: this.source.end.line
|
216
|
+
}
|
217
|
+
: {
|
218
|
+
column: start.column + 1,
|
219
|
+
line: start.line
|
220
|
+
}
|
221
|
+
|
222
|
+
if (opts.word) {
|
223
|
+
let stringRepresentation = this.toString()
|
224
|
+
let index = stringRepresentation.indexOf(opts.word)
|
225
|
+
if (index !== -1) {
|
226
|
+
start = this.positionInside(index, stringRepresentation)
|
227
|
+
end = this.positionInside(index + opts.word.length, stringRepresentation)
|
228
|
+
}
|
229
|
+
} else {
|
230
|
+
if (opts.start) {
|
231
|
+
start = {
|
232
|
+
column: opts.start.column,
|
233
|
+
line: opts.start.line
|
234
|
+
}
|
235
|
+
} else if (opts.index) {
|
236
|
+
start = this.positionInside(opts.index)
|
237
|
+
}
|
238
|
+
|
239
|
+
if (opts.end) {
|
240
|
+
end = {
|
241
|
+
column: opts.end.column,
|
242
|
+
line: opts.end.line
|
243
|
+
}
|
244
|
+
} else if (opts.endIndex) {
|
245
|
+
end = this.positionInside(opts.endIndex)
|
246
|
+
} else if (opts.index) {
|
247
|
+
end = this.positionInside(opts.index + 1)
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
if (
|
252
|
+
end.line < start.line ||
|
253
|
+
(end.line === start.line && end.column <= start.column)
|
254
|
+
) {
|
255
|
+
end = { column: start.column + 1, line: start.line }
|
256
|
+
}
|
257
|
+
|
258
|
+
return { end, start }
|
259
|
+
}
|
260
|
+
|
261
|
+
raw(prop, defaultType) {
|
262
|
+
let str = new Stringifier()
|
263
|
+
return str.raw(this, prop, defaultType)
|
264
|
+
}
|
265
|
+
|
266
|
+
remove() {
|
267
|
+
if (this.parent) {
|
268
|
+
this.parent.removeChild(this)
|
269
|
+
}
|
270
|
+
this.parent = undefined
|
152
271
|
return this
|
153
272
|
}
|
154
273
|
|
155
|
-
|
156
|
-
this.parent
|
274
|
+
replaceWith(...nodes) {
|
275
|
+
if (this.parent) {
|
276
|
+
let bookmark = this
|
277
|
+
let foundSelf = false
|
278
|
+
for (let node of nodes) {
|
279
|
+
if (node === this) {
|
280
|
+
foundSelf = true
|
281
|
+
} else if (foundSelf) {
|
282
|
+
this.parent.insertAfter(bookmark, node)
|
283
|
+
bookmark = node
|
284
|
+
} else {
|
285
|
+
this.parent.insertBefore(bookmark, node)
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
if (!foundSelf) {
|
290
|
+
this.remove()
|
291
|
+
}
|
292
|
+
}
|
293
|
+
|
157
294
|
return this
|
158
295
|
}
|
159
296
|
|
@@ -165,17 +302,6 @@ class Node {
|
|
165
302
|
return result
|
166
303
|
}
|
167
304
|
|
168
|
-
raw(prop, defaultType) {
|
169
|
-
let str = new Stringifier()
|
170
|
-
return str.raw(this, prop, defaultType)
|
171
|
-
}
|
172
|
-
|
173
|
-
cleanRaws(keepBetween) {
|
174
|
-
delete this.raws.before
|
175
|
-
delete this.raws.after
|
176
|
-
if (!keepBetween) delete this.raws.between
|
177
|
-
}
|
178
|
-
|
179
305
|
toJSON(_, inputs) {
|
180
306
|
let fixed = {}
|
181
307
|
let emitInputs = inputs == null
|
@@ -184,7 +310,7 @@ class Node {
|
|
184
310
|
|
185
311
|
for (let name in this) {
|
186
312
|
if (!Object.prototype.hasOwnProperty.call(this, name)) {
|
187
|
-
|
313
|
+
/* c8 ignore next 2 */
|
188
314
|
continue
|
189
315
|
}
|
190
316
|
if (name === 'parent' || name === 'proxyCache') continue
|
@@ -208,9 +334,9 @@ class Node {
|
|
208
334
|
inputsNextIndex++
|
209
335
|
}
|
210
336
|
fixed[name] = {
|
337
|
+
end: value.end,
|
211
338
|
inputId,
|
212
|
-
start: value.start
|
213
|
-
end: value.end
|
339
|
+
start: value.start
|
214
340
|
}
|
215
341
|
} else {
|
216
342
|
fixed[name] = value
|
@@ -224,64 +350,6 @@ class Node {
|
|
224
350
|
return fixed
|
225
351
|
}
|
226
352
|
|
227
|
-
positionInside(index) {
|
228
|
-
let string = this.toString()
|
229
|
-
let column = this.source.start.column
|
230
|
-
let line = this.source.start.line
|
231
|
-
|
232
|
-
for (let i = 0; i < index; i++) {
|
233
|
-
if (string[i] === '\n') {
|
234
|
-
column = 1
|
235
|
-
line += 1
|
236
|
-
} else {
|
237
|
-
column += 1
|
238
|
-
}
|
239
|
-
}
|
240
|
-
|
241
|
-
return { line, column }
|
242
|
-
}
|
243
|
-
|
244
|
-
positionBy(opts) {
|
245
|
-
let pos = this.source.start
|
246
|
-
if (opts.index) {
|
247
|
-
pos = this.positionInside(opts.index)
|
248
|
-
} else if (opts.word) {
|
249
|
-
let index = this.toString().indexOf(opts.word)
|
250
|
-
if (index !== -1) pos = this.positionInside(index)
|
251
|
-
}
|
252
|
-
return pos
|
253
|
-
}
|
254
|
-
|
255
|
-
getProxyProcessor() {
|
256
|
-
return {
|
257
|
-
set(node, prop, value) {
|
258
|
-
if (node[prop] === value) return true
|
259
|
-
node[prop] = value
|
260
|
-
if (
|
261
|
-
prop === 'prop' ||
|
262
|
-
prop === 'value' ||
|
263
|
-
prop === 'name' ||
|
264
|
-
prop === 'params' ||
|
265
|
-
prop === 'important' ||
|
266
|
-
prop === 'text'
|
267
|
-
) {
|
268
|
-
node.markDirty()
|
269
|
-
}
|
270
|
-
return true
|
271
|
-
},
|
272
|
-
|
273
|
-
get(node, prop) {
|
274
|
-
if (prop === 'proxyOf') {
|
275
|
-
return node
|
276
|
-
} else if (prop === 'root') {
|
277
|
-
return () => node.root().toProxy()
|
278
|
-
} else {
|
279
|
-
return node[prop]
|
280
|
-
}
|
281
|
-
}
|
282
|
-
}
|
283
|
-
}
|
284
|
-
|
285
353
|
toProxy() {
|
286
354
|
if (!this.proxyCache) {
|
287
355
|
this.proxyCache = new Proxy(this, this.getProxyProcessor())
|
@@ -289,26 +357,19 @@ class Node {
|
|
289
357
|
return this.proxyCache
|
290
358
|
}
|
291
359
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
)
|
300
|
-
}
|
301
|
-
return error
|
360
|
+
toString(stringifier = stringify) {
|
361
|
+
if (stringifier.stringify) stringifier = stringifier.stringify
|
362
|
+
let result = ''
|
363
|
+
stringifier(this, i => {
|
364
|
+
result += i
|
365
|
+
})
|
366
|
+
return result
|
302
367
|
}
|
303
368
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
while ((next = next.parent)) {
|
309
|
-
next[isClean] = false
|
310
|
-
}
|
311
|
-
}
|
369
|
+
warn(result, text, opts) {
|
370
|
+
let data = { node: this }
|
371
|
+
for (let i in opts) data[i] = opts[i]
|
372
|
+
return result.warn(text, data)
|
312
373
|
}
|
313
374
|
|
314
375
|
get proxyOf() {
|