postcss 8.4.47 → 8.4.49
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/lib/node.js +47 -11
- package/lib/processor.js +1 -1
- package/package.json +2 -2
package/lib/node.js
CHANGED
@@ -32,6 +32,36 @@ function cloneNode(obj, parent) {
|
|
32
32
|
return cloned
|
33
33
|
}
|
34
34
|
|
35
|
+
function sourceOffset(inputCSS, position) {
|
36
|
+
// Not all custom syntaxes support `offset` in `source.start` and `source.end`
|
37
|
+
if (
|
38
|
+
position &&
|
39
|
+
typeof position.offset !== 'undefined'
|
40
|
+
) {
|
41
|
+
return position.offset;
|
42
|
+
}
|
43
|
+
|
44
|
+
let column = 1
|
45
|
+
let line = 1
|
46
|
+
let offset = 0
|
47
|
+
|
48
|
+
for (let i = 0; i < inputCSS.length; i++) {
|
49
|
+
if (line === position.line && column === position.column) {
|
50
|
+
offset = i
|
51
|
+
break
|
52
|
+
}
|
53
|
+
|
54
|
+
if (inputCSS[i] === '\n') {
|
55
|
+
column = 1
|
56
|
+
line += 1
|
57
|
+
} else {
|
58
|
+
column += 1
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
return offset
|
63
|
+
}
|
64
|
+
|
35
65
|
class Node {
|
36
66
|
constructor(defaults = {}) {
|
37
67
|
this.raws = {}
|
@@ -174,25 +204,29 @@ class Node {
|
|
174
204
|
return this.parent.nodes[index + 1]
|
175
205
|
}
|
176
206
|
|
177
|
-
positionBy(opts
|
207
|
+
positionBy(opts) {
|
178
208
|
let pos = this.source.start
|
179
209
|
if (opts.index) {
|
180
|
-
pos = this.positionInside(opts.index
|
210
|
+
pos = this.positionInside(opts.index)
|
181
211
|
} else if (opts.word) {
|
182
|
-
stringRepresentation = this.
|
212
|
+
let stringRepresentation = this.source.input.css.slice(
|
213
|
+
sourceOffset(this.source.input.css, this.source.start),
|
214
|
+
sourceOffset(this.source.input.css, this.source.end)
|
215
|
+
)
|
183
216
|
let index = stringRepresentation.indexOf(opts.word)
|
184
|
-
if (index !== -1) pos = this.positionInside(index
|
217
|
+
if (index !== -1) pos = this.positionInside(index)
|
185
218
|
}
|
186
219
|
return pos
|
187
220
|
}
|
188
221
|
|
189
|
-
positionInside(index
|
190
|
-
let string = stringRepresentation || this.toString()
|
222
|
+
positionInside(index) {
|
191
223
|
let column = this.source.start.column
|
192
224
|
let line = this.source.start.line
|
225
|
+
let offset = sourceOffset(this.source.input.css, this.source.start)
|
226
|
+
let end = offset + index
|
193
227
|
|
194
|
-
for (let i =
|
195
|
-
if (
|
228
|
+
for (let i = offset; i < end; i++) {
|
229
|
+
if (this.source.input.css[i] === '\n') {
|
196
230
|
column = 1
|
197
231
|
line += 1
|
198
232
|
} else {
|
@@ -225,13 +259,15 @@ class Node {
|
|
225
259
|
}
|
226
260
|
|
227
261
|
if (opts.word) {
|
228
|
-
let stringRepresentation = this.
|
262
|
+
let stringRepresentation = this.source.input.css.slice(
|
263
|
+
sourceOffset(this.source.input.css, this.source.start),
|
264
|
+
sourceOffset(this.source.input.css, this.source.end)
|
265
|
+
)
|
229
266
|
let index = stringRepresentation.indexOf(opts.word)
|
230
267
|
if (index !== -1) {
|
231
|
-
start = this.positionInside(index
|
268
|
+
start = this.positionInside(index)
|
232
269
|
end = this.positionInside(
|
233
270
|
index + opts.word.length,
|
234
|
-
stringRepresentation
|
235
271
|
)
|
236
272
|
}
|
237
273
|
} else {
|
package/lib/processor.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "postcss",
|
3
|
-
"version": "8.4.
|
3
|
+
"version": "8.4.49",
|
4
4
|
"description": "Tool for transforming styles with JS plugins",
|
5
5
|
"engines": {
|
6
6
|
"node": "^10 || ^12 || >=14"
|
@@ -75,7 +75,7 @@
|
|
75
75
|
},
|
76
76
|
"dependencies": {
|
77
77
|
"nanoid": "^3.3.7",
|
78
|
-
"picocolors": "^1.1.
|
78
|
+
"picocolors": "^1.1.1",
|
79
79
|
"source-map-js": "^1.2.1"
|
80
80
|
},
|
81
81
|
"browser": {
|