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.
- 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 +124 -124
- 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/input.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
4
4
|
let { fileURLToPath, pathToFileURL } = require('url')
|
5
|
-
let {
|
5
|
+
let { isAbsolute, resolve } = require('path')
|
6
6
|
let { nanoid } = require('nanoid/non-secure')
|
7
7
|
|
8
8
|
let terminalHighlight = require('./terminal-highlight')
|
@@ -60,48 +60,6 @@ class Input {
|
|
60
60
|
if (this.map) this.map.file = this.from
|
61
61
|
}
|
62
62
|
|
63
|
-
fromOffset(offset) {
|
64
|
-
let lastLine, lineToIndex
|
65
|
-
if (!this[fromOffsetCache]) {
|
66
|
-
let lines = this.css.split('\n')
|
67
|
-
lineToIndex = new Array(lines.length)
|
68
|
-
let prevIndex = 0
|
69
|
-
|
70
|
-
for (let i = 0, l = lines.length; i < l; i++) {
|
71
|
-
lineToIndex[i] = prevIndex
|
72
|
-
prevIndex += lines[i].length + 1
|
73
|
-
}
|
74
|
-
|
75
|
-
this[fromOffsetCache] = lineToIndex
|
76
|
-
} else {
|
77
|
-
lineToIndex = this[fromOffsetCache]
|
78
|
-
}
|
79
|
-
lastLine = lineToIndex[lineToIndex.length - 1]
|
80
|
-
|
81
|
-
let min = 0
|
82
|
-
if (offset >= lastLine) {
|
83
|
-
min = lineToIndex.length - 1
|
84
|
-
} else {
|
85
|
-
let max = lineToIndex.length - 2
|
86
|
-
let mid
|
87
|
-
while (min < max) {
|
88
|
-
mid = min + ((max - min) >> 1)
|
89
|
-
if (offset < lineToIndex[mid]) {
|
90
|
-
max = mid - 1
|
91
|
-
} else if (offset >= lineToIndex[mid + 1]) {
|
92
|
-
min = mid + 1
|
93
|
-
} else {
|
94
|
-
min = mid
|
95
|
-
break
|
96
|
-
}
|
97
|
-
}
|
98
|
-
}
|
99
|
-
return {
|
100
|
-
line: min + 1,
|
101
|
-
col: offset - lineToIndex[min] + 1
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
63
|
error(message, line, column, opts = {}) {
|
106
64
|
let result, endLine, endColumn
|
107
65
|
|
@@ -136,10 +94,10 @@ class Input {
|
|
136
94
|
message,
|
137
95
|
origin.endLine === undefined
|
138
96
|
? origin.line
|
139
|
-
: {
|
97
|
+
: { column: origin.column, line: origin.line },
|
140
98
|
origin.endLine === undefined
|
141
99
|
? origin.column
|
142
|
-
: {
|
100
|
+
: { column: origin.endColumn, line: origin.endLine },
|
143
101
|
origin.source,
|
144
102
|
origin.file,
|
145
103
|
opts.plugin
|
@@ -147,15 +105,15 @@ class Input {
|
|
147
105
|
} else {
|
148
106
|
result = new CssSyntaxError(
|
149
107
|
message,
|
150
|
-
endLine === undefined ? line : {
|
151
|
-
endLine === undefined ? column : {
|
108
|
+
endLine === undefined ? line : { column, line },
|
109
|
+
endLine === undefined ? column : { column: endColumn, line: endLine },
|
152
110
|
this.css,
|
153
111
|
this.file,
|
154
112
|
opts.plugin
|
155
113
|
)
|
156
114
|
}
|
157
115
|
|
158
|
-
result.input = {
|
116
|
+
result.input = { column, endColumn, endLine, line, source: this.css }
|
159
117
|
if (this.file) {
|
160
118
|
if (pathToFileURL) {
|
161
119
|
result.input.url = pathToFileURL(this.file).toString()
|
@@ -166,16 +124,69 @@ class Input {
|
|
166
124
|
return result
|
167
125
|
}
|
168
126
|
|
127
|
+
get from() {
|
128
|
+
return this.file || this.id
|
129
|
+
}
|
130
|
+
|
131
|
+
fromOffset(offset) {
|
132
|
+
let lastLine, lineToIndex
|
133
|
+
if (!this[fromOffsetCache]) {
|
134
|
+
let lines = this.css.split('\n')
|
135
|
+
lineToIndex = new Array(lines.length)
|
136
|
+
let prevIndex = 0
|
137
|
+
|
138
|
+
for (let i = 0, l = lines.length; i < l; i++) {
|
139
|
+
lineToIndex[i] = prevIndex
|
140
|
+
prevIndex += lines[i].length + 1
|
141
|
+
}
|
142
|
+
|
143
|
+
this[fromOffsetCache] = lineToIndex
|
144
|
+
} else {
|
145
|
+
lineToIndex = this[fromOffsetCache]
|
146
|
+
}
|
147
|
+
lastLine = lineToIndex[lineToIndex.length - 1]
|
148
|
+
|
149
|
+
let min = 0
|
150
|
+
if (offset >= lastLine) {
|
151
|
+
min = lineToIndex.length - 1
|
152
|
+
} else {
|
153
|
+
let max = lineToIndex.length - 2
|
154
|
+
let mid
|
155
|
+
while (min < max) {
|
156
|
+
mid = min + ((max - min) >> 1)
|
157
|
+
if (offset < lineToIndex[mid]) {
|
158
|
+
max = mid - 1
|
159
|
+
} else if (offset >= lineToIndex[mid + 1]) {
|
160
|
+
min = mid + 1
|
161
|
+
} else {
|
162
|
+
min = mid
|
163
|
+
break
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
return {
|
168
|
+
col: offset - lineToIndex[min] + 1,
|
169
|
+
line: min + 1
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
mapResolve(file) {
|
174
|
+
if (/^\w+:\/\//.test(file)) {
|
175
|
+
return file
|
176
|
+
}
|
177
|
+
return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
|
178
|
+
}
|
179
|
+
|
169
180
|
origin(line, column, endLine, endColumn) {
|
170
181
|
if (!this.map) return false
|
171
182
|
let consumer = this.map.consumer()
|
172
183
|
|
173
|
-
let from = consumer.originalPositionFor({
|
184
|
+
let from = consumer.originalPositionFor({ column, line })
|
174
185
|
if (!from.source) return false
|
175
186
|
|
176
187
|
let to
|
177
188
|
if (typeof endLine === 'number') {
|
178
|
-
to = consumer.originalPositionFor({
|
189
|
+
to = consumer.originalPositionFor({ column: endColumn, line: endLine })
|
179
190
|
}
|
180
191
|
|
181
192
|
let fromUrl
|
@@ -190,11 +201,11 @@ class Input {
|
|
190
201
|
}
|
191
202
|
|
192
203
|
let result = {
|
193
|
-
url: fromUrl.toString(),
|
194
|
-
line: from.line,
|
195
204
|
column: from.column,
|
205
|
+
endColumn: to && to.column,
|
196
206
|
endLine: to && to.line,
|
197
|
-
|
207
|
+
line: from.line,
|
208
|
+
url: fromUrl.toString()
|
198
209
|
}
|
199
210
|
|
200
211
|
if (fromUrl.protocol === 'file:') {
|
@@ -212,17 +223,6 @@ class Input {
|
|
212
223
|
return result
|
213
224
|
}
|
214
225
|
|
215
|
-
mapResolve(file) {
|
216
|
-
if (/^\w+:\/\//.test(file)) {
|
217
|
-
return file
|
218
|
-
}
|
219
|
-
return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
|
220
|
-
}
|
221
|
-
|
222
|
-
get from() {
|
223
|
-
return this.file || this.id
|
224
|
-
}
|
225
|
-
|
226
226
|
toJSON() {
|
227
227
|
let json = {}
|
228
228
|
for (let name of ['hasBOM', 'css', 'file', 'id']) {
|
package/lib/lazy-result.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import Result, { Message, ResultOptions } from './result.js'
|
2
1
|
import { SourceMap } from './postcss.js'
|
3
2
|
import Processor from './processor.js'
|
4
|
-
import
|
3
|
+
import Result, { Message, ResultOptions } from './result.js'
|
5
4
|
import Root from './root.js'
|
5
|
+
import Warning from './warning.js'
|
6
6
|
|
7
7
|
declare namespace LazyResult {
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
@@ -21,48 +21,48 @@ declare namespace LazyResult {
|
|
21
21
|
declare class LazyResult_ implements PromiseLike<Result> {
|
22
22
|
/**
|
23
23
|
* Processes input CSS through synchronous and asynchronous plugins
|
24
|
-
* and calls
|
25
|
-
* an error, the `onRejected` callback will be executed.
|
24
|
+
* and calls onRejected for each error thrown in any plugin.
|
26
25
|
*
|
27
26
|
* It implements standard Promise API.
|
28
27
|
*
|
29
28
|
* ```js
|
30
|
-
* postcss([autoprefixer]).process(css
|
29
|
+
* postcss([autoprefixer]).process(css).then(result => {
|
31
30
|
* console.log(result.css)
|
31
|
+
* }).catch(error => {
|
32
|
+
* console.error(error)
|
32
33
|
* })
|
33
34
|
* ```
|
34
35
|
*/
|
35
|
-
|
36
|
+
catch: Promise<Result>['catch']
|
36
37
|
|
37
38
|
/**
|
38
39
|
* Processes input CSS through synchronous and asynchronous plugins
|
39
|
-
* and calls
|
40
|
+
* and calls onFinally on any error or when all plugins will finish work.
|
40
41
|
*
|
41
42
|
* It implements standard Promise API.
|
42
43
|
*
|
43
44
|
* ```js
|
44
|
-
* postcss([autoprefixer]).process(css).
|
45
|
-
* console.log(
|
46
|
-
* }).catch(error => {
|
47
|
-
* console.error(error)
|
45
|
+
* postcss([autoprefixer]).process(css).finally(() => {
|
46
|
+
* console.log('processing ended')
|
48
47
|
* })
|
49
48
|
* ```
|
50
49
|
*/
|
51
|
-
|
50
|
+
finally: Promise<Result>['finally']
|
52
51
|
|
53
52
|
/**
|
54
53
|
* Processes input CSS through synchronous and asynchronous plugins
|
55
|
-
* and calls
|
54
|
+
* and calls `onFulfilled` with a Result instance. If a plugin throws
|
55
|
+
* an error, the `onRejected` callback will be executed.
|
56
56
|
*
|
57
57
|
* It implements standard Promise API.
|
58
58
|
*
|
59
59
|
* ```js
|
60
|
-
* postcss([autoprefixer]).process(css).
|
61
|
-
* console.log(
|
60
|
+
* postcss([autoprefixer]).process(css, { from: cssPath }).then(result => {
|
61
|
+
* console.log(result.css)
|
62
62
|
* })
|
63
63
|
* ```
|
64
64
|
*/
|
65
|
-
|
65
|
+
then: Promise<Result>['then']
|
66
66
|
|
67
67
|
/**
|
68
68
|
* @param processor Processor used for this transformation.
|
@@ -72,25 +72,15 @@ declare class LazyResult_ implements PromiseLike<Result> {
|
|
72
72
|
constructor(processor: Processor, css: string, opts: ResultOptions)
|
73
73
|
|
74
74
|
/**
|
75
|
-
*
|
76
|
-
*
|
77
|
-
|
78
|
-
get [Symbol.toStringTag](): string
|
79
|
-
|
80
|
-
/**
|
81
|
-
* Returns a `Processor` instance, which will be used
|
82
|
-
* for CSS transformations.
|
83
|
-
*/
|
84
|
-
get processor(): Processor
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Options from the `Processor#process` call.
|
75
|
+
* Run plugin in async way and return `Result`.
|
76
|
+
*
|
77
|
+
* @return Result with output content.
|
88
78
|
*/
|
89
|
-
|
79
|
+
async(): Promise<Result>
|
90
80
|
|
91
81
|
/**
|
92
|
-
*
|
93
|
-
*
|
82
|
+
* An alias for the `css` property. Use it with syntaxes
|
83
|
+
* that generate non-CSS output.
|
94
84
|
*
|
95
85
|
* This property will only work with synchronous plugins.
|
96
86
|
* If the processor contains any asynchronous plugins
|
@@ -98,11 +88,11 @@ declare class LazyResult_ implements PromiseLike<Result> {
|
|
98
88
|
*
|
99
89
|
* PostCSS runners should always use `LazyResult#then`.
|
100
90
|
*/
|
101
|
-
get
|
91
|
+
get content(): string
|
102
92
|
|
103
93
|
/**
|
104
|
-
*
|
105
|
-
*
|
94
|
+
* Processes input CSS through synchronous plugins, converts `Root`
|
95
|
+
* to a CSS string and returns `Result#css`.
|
106
96
|
*
|
107
97
|
* This property will only work with synchronous plugins.
|
108
98
|
* If the processor contains any asynchronous plugins
|
@@ -110,7 +100,7 @@ declare class LazyResult_ implements PromiseLike<Result> {
|
|
110
100
|
*
|
111
101
|
* PostCSS runners should always use `LazyResult#then`.
|
112
102
|
*/
|
113
|
-
get
|
103
|
+
get css(): string
|
114
104
|
|
115
105
|
/**
|
116
106
|
* Processes input CSS through synchronous plugins
|
@@ -126,33 +116,49 @@ declare class LazyResult_ implements PromiseLike<Result> {
|
|
126
116
|
|
127
117
|
/**
|
128
118
|
* Processes input CSS through synchronous plugins
|
129
|
-
* and returns `Result#
|
119
|
+
* and returns `Result#messages`.
|
130
120
|
*
|
131
121
|
* This property will only work with synchronous plugins. If the processor
|
132
122
|
* contains any asynchronous plugins it will throw an error.
|
133
123
|
*
|
134
124
|
* PostCSS runners should always use `LazyResult#then`.
|
135
125
|
*/
|
136
|
-
get
|
126
|
+
get messages(): Message[]
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Options from the `Processor#process` call.
|
130
|
+
*/
|
131
|
+
get opts(): ResultOptions
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Returns a `Processor` instance, which will be used
|
135
|
+
* for CSS transformations.
|
136
|
+
*/
|
137
|
+
get processor(): Processor
|
137
138
|
|
138
139
|
/**
|
139
140
|
* Processes input CSS through synchronous plugins
|
140
|
-
* and returns `Result#
|
141
|
+
* and returns `Result#root`.
|
141
142
|
*
|
142
143
|
* This property will only work with synchronous plugins. If the processor
|
143
144
|
* contains any asynchronous plugins it will throw an error.
|
144
145
|
*
|
145
146
|
* PostCSS runners should always use `LazyResult#then`.
|
146
147
|
*/
|
147
|
-
get
|
148
|
+
get root(): Root
|
148
149
|
|
149
150
|
/**
|
150
|
-
*
|
151
|
-
*
|
151
|
+
* Returns the default string description of an object.
|
152
|
+
* Required to implement the Promise interface.
|
153
|
+
*/
|
154
|
+
get [Symbol.toStringTag](): string
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Run plugin in sync way and return `Result`.
|
152
158
|
*
|
153
|
-
* @return
|
159
|
+
* @return Result with output content.
|
154
160
|
*/
|
155
|
-
|
161
|
+
sync(): Result
|
156
162
|
|
157
163
|
/**
|
158
164
|
* Alias for the `LazyResult#css` property.
|
@@ -166,18 +172,12 @@ declare class LazyResult_ implements PromiseLike<Result> {
|
|
166
172
|
toString(): string
|
167
173
|
|
168
174
|
/**
|
169
|
-
*
|
170
|
-
*
|
171
|
-
* @return Result with output content.
|
172
|
-
*/
|
173
|
-
sync(): Result
|
174
|
-
|
175
|
-
/**
|
176
|
-
* Run plugin in async way and return `Result`.
|
175
|
+
* Processes input CSS through synchronous plugins
|
176
|
+
* and calls `Result#warnings`.
|
177
177
|
*
|
178
|
-
* @return
|
178
|
+
* @return Warnings from plugins.
|
179
179
|
*/
|
180
|
-
|
180
|
+
warnings(): Warning[]
|
181
181
|
}
|
182
182
|
|
183
183
|
declare class LazyResult extends LazyResult_ {}
|