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/list.js
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
3
|
let list = {
|
4
|
+
comma(string) {
|
5
|
+
return list.split(string, [','], true)
|
6
|
+
},
|
7
|
+
|
8
|
+
space(string) {
|
9
|
+
let spaces = [' ', '\n', '\t']
|
10
|
+
return list.split(string, spaces)
|
11
|
+
},
|
12
|
+
|
4
13
|
split(string, separators, last) {
|
5
14
|
let array = []
|
6
15
|
let current = ''
|
7
16
|
let split = false
|
8
17
|
|
9
18
|
let func = 0
|
10
|
-
let
|
19
|
+
let inQuote = false
|
20
|
+
let prevQuote = ''
|
11
21
|
let escape = false
|
12
22
|
|
13
23
|
for (let letter of string) {
|
@@ -15,12 +25,13 @@ let list = {
|
|
15
25
|
escape = false
|
16
26
|
} else if (letter === '\\') {
|
17
27
|
escape = true
|
18
|
-
} else if (
|
19
|
-
if (letter ===
|
20
|
-
|
28
|
+
} else if (inQuote) {
|
29
|
+
if (letter === prevQuote) {
|
30
|
+
inQuote = false
|
21
31
|
}
|
22
32
|
} else if (letter === '"' || letter === "'") {
|
23
|
-
|
33
|
+
inQuote = true
|
34
|
+
prevQuote = letter
|
24
35
|
} else if (letter === '(') {
|
25
36
|
func += 1
|
26
37
|
} else if (letter === ')') {
|
@@ -40,15 +51,6 @@ let list = {
|
|
40
51
|
|
41
52
|
if (last || current !== '') array.push(current.trim())
|
42
53
|
return array
|
43
|
-
},
|
44
|
-
|
45
|
-
space(string) {
|
46
|
-
let spaces = [' ', '\n', '\t']
|
47
|
-
return list.split(string, spaces)
|
48
|
-
},
|
49
|
-
|
50
|
-
comma(string) {
|
51
|
-
return list.split(string, [','], true)
|
52
54
|
}
|
53
55
|
}
|
54
56
|
|
package/lib/map-generator.js
CHANGED
@@ -1,96 +1,45 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
3
|
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
4
|
-
let { dirname,
|
4
|
+
let { dirname, relative, resolve, sep } = require('path')
|
5
5
|
let { pathToFileURL } = require('url')
|
6
6
|
|
7
|
+
let Input = require('./input')
|
8
|
+
|
7
9
|
let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
|
8
10
|
let pathAvailable = Boolean(dirname && resolve && relative && sep)
|
9
11
|
|
10
12
|
class MapGenerator {
|
11
|
-
constructor(stringify, root, opts) {
|
13
|
+
constructor(stringify, root, opts, cssString) {
|
12
14
|
this.stringify = stringify
|
13
15
|
this.mapOpts = opts.map || {}
|
14
16
|
this.root = root
|
15
17
|
this.opts = opts
|
16
|
-
|
17
|
-
|
18
|
-
isMap() {
|
19
|
-
if (typeof this.opts.map !== 'undefined') {
|
20
|
-
return !!this.opts.map
|
21
|
-
}
|
22
|
-
return this.previous().length > 0
|
23
|
-
}
|
24
|
-
|
25
|
-
previous() {
|
26
|
-
if (!this.previousMaps) {
|
27
|
-
this.previousMaps = []
|
28
|
-
this.root.walk(node => {
|
29
|
-
if (node.source && node.source.input.map) {
|
30
|
-
let map = node.source.input.map
|
31
|
-
if (!this.previousMaps.includes(map)) {
|
32
|
-
this.previousMaps.push(map)
|
33
|
-
}
|
34
|
-
}
|
35
|
-
})
|
36
|
-
}
|
18
|
+
this.css = cssString
|
19
|
+
this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute
|
37
20
|
|
38
|
-
|
21
|
+
this.memoizedFileURLs = new Map()
|
22
|
+
this.memoizedPaths = new Map()
|
23
|
+
this.memoizedURLs = new Map()
|
39
24
|
}
|
40
25
|
|
41
|
-
|
42
|
-
|
43
|
-
return this.mapOpts.inline
|
44
|
-
}
|
45
|
-
|
46
|
-
let annotation = this.mapOpts.annotation
|
47
|
-
if (typeof annotation !== 'undefined' && annotation !== true) {
|
48
|
-
return false
|
49
|
-
}
|
50
|
-
|
51
|
-
if (this.previous().length) {
|
52
|
-
return this.previous().some(i => i.inline)
|
53
|
-
}
|
54
|
-
return true
|
55
|
-
}
|
56
|
-
|
57
|
-
isSourcesContent() {
|
58
|
-
if (typeof this.mapOpts.sourcesContent !== 'undefined') {
|
59
|
-
return this.mapOpts.sourcesContent
|
60
|
-
}
|
61
|
-
if (this.previous().length) {
|
62
|
-
return this.previous().some(i => i.withContent())
|
63
|
-
}
|
64
|
-
return true
|
65
|
-
}
|
66
|
-
|
67
|
-
clearAnnotation() {
|
68
|
-
if (this.mapOpts.annotation === false) return
|
26
|
+
addAnnotation() {
|
27
|
+
let content
|
69
28
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
29
|
+
if (this.isInline()) {
|
30
|
+
content =
|
31
|
+
'data:application/json;base64,' + this.toBase64(this.map.toString())
|
32
|
+
} else if (typeof this.mapOpts.annotation === 'string') {
|
33
|
+
content = this.mapOpts.annotation
|
34
|
+
} else if (typeof this.mapOpts.annotation === 'function') {
|
35
|
+
content = this.mapOpts.annotation(this.opts.to, this.root)
|
36
|
+
} else {
|
37
|
+
content = this.outputFile() + '.map'
|
77
38
|
}
|
78
|
-
|
39
|
+
let eol = '\n'
|
40
|
+
if (this.css.includes('\r\n')) eol = '\r\n'
|
79
41
|
|
80
|
-
|
81
|
-
let already = {}
|
82
|
-
this.root.walk(node => {
|
83
|
-
if (node.source) {
|
84
|
-
let from = node.source.input.from
|
85
|
-
if (from && !already[from]) {
|
86
|
-
already[from] = true
|
87
|
-
this.map.setSourceContent(
|
88
|
-
this.toUrl(this.path(from)),
|
89
|
-
node.source.input.css
|
90
|
-
)
|
91
|
-
}
|
92
|
-
}
|
93
|
-
})
|
42
|
+
this.css += eol + '/*# sourceMappingURL=' + content + ' */'
|
94
43
|
}
|
95
44
|
|
96
45
|
applyPrevMaps() {
|
@@ -112,107 +61,62 @@ class MapGenerator {
|
|
112
61
|
}
|
113
62
|
}
|
114
63
|
|
115
|
-
|
116
|
-
if (this.
|
117
|
-
return true
|
118
|
-
}
|
119
|
-
if (typeof this.mapOpts.annotation !== 'undefined') {
|
120
|
-
return this.mapOpts.annotation
|
121
|
-
}
|
122
|
-
if (this.previous().length) {
|
123
|
-
return this.previous().some(i => i.annotation)
|
124
|
-
}
|
125
|
-
return true
|
126
|
-
}
|
64
|
+
clearAnnotation() {
|
65
|
+
if (this.mapOpts.annotation === false) return
|
127
66
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
67
|
+
if (this.root) {
|
68
|
+
let node
|
69
|
+
for (let i = this.root.nodes.length - 1; i >= 0; i--) {
|
70
|
+
node = this.root.nodes[i]
|
71
|
+
if (node.type !== 'comment') continue
|
72
|
+
if (node.text.indexOf('# sourceMappingURL=') === 0) {
|
73
|
+
this.root.removeChild(i)
|
74
|
+
}
|
75
|
+
}
|
76
|
+
} else if (this.css) {
|
77
|
+
this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
|
134
78
|
}
|
135
79
|
}
|
136
80
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
content =
|
142
|
-
'data:application/json;base64,' + this.toBase64(this.map.toString())
|
143
|
-
} else if (typeof this.mapOpts.annotation === 'string') {
|
144
|
-
content = this.mapOpts.annotation
|
145
|
-
} else if (typeof this.mapOpts.annotation === 'function') {
|
146
|
-
content = this.mapOpts.annotation(this.opts.to, this.root)
|
81
|
+
generate() {
|
82
|
+
this.clearAnnotation()
|
83
|
+
if (pathAvailable && sourceMapAvailable && this.isMap()) {
|
84
|
+
return this.generateMap()
|
147
85
|
} else {
|
148
|
-
|
86
|
+
let result = ''
|
87
|
+
this.stringify(this.root, i => {
|
88
|
+
result += i
|
89
|
+
})
|
90
|
+
return [result]
|
149
91
|
}
|
150
|
-
|
151
|
-
let eol = '\n'
|
152
|
-
if (this.css.includes('\r\n')) eol = '\r\n'
|
153
|
-
|
154
|
-
this.css += eol + '/*# sourceMappingURL=' + content + ' */'
|
155
92
|
}
|
156
93
|
|
157
|
-
|
158
|
-
if (this.
|
159
|
-
|
160
|
-
}
|
161
|
-
|
162
|
-
|
94
|
+
generateMap() {
|
95
|
+
if (this.root) {
|
96
|
+
this.generateString()
|
97
|
+
} else if (this.previous().length === 1) {
|
98
|
+
let prev = this.previous()[0].consumer()
|
99
|
+
prev.file = this.outputFile()
|
100
|
+
this.map = SourceMapGenerator.fromSourceMap(prev)
|
101
|
+
} else {
|
102
|
+
this.map = new SourceMapGenerator({ file: this.outputFile() })
|
103
|
+
this.map.addMapping({
|
104
|
+
generated: { column: 0, line: 1 },
|
105
|
+
original: { column: 0, line: 1 },
|
106
|
+
source: this.opts.from
|
107
|
+
? this.toUrl(this.path(this.opts.from))
|
108
|
+
: '<no source>'
|
109
|
+
})
|
163
110
|
}
|
164
|
-
return 'to.css'
|
165
|
-
}
|
166
111
|
|
167
|
-
generateMap() {
|
168
|
-
this.generateString()
|
169
112
|
if (this.isSourcesContent()) this.setSourcesContent()
|
170
|
-
if (this.previous().length > 0) this.applyPrevMaps()
|
113
|
+
if (this.root && this.previous().length > 0) this.applyPrevMaps()
|
171
114
|
if (this.isAnnotation()) this.addAnnotation()
|
172
115
|
|
173
116
|
if (this.isInline()) {
|
174
117
|
return [this.css]
|
175
|
-
}
|
176
|
-
return [this.css, this.map]
|
177
|
-
}
|
178
|
-
|
179
|
-
path(file) {
|
180
|
-
if (file.indexOf('<') === 0) return file
|
181
|
-
if (/^\w+:\/\//.test(file)) return file
|
182
|
-
if (this.mapOpts.absolute) return file
|
183
|
-
|
184
|
-
let from = this.opts.to ? dirname(this.opts.to) : '.'
|
185
|
-
|
186
|
-
if (typeof this.mapOpts.annotation === 'string') {
|
187
|
-
from = dirname(resolve(from, this.mapOpts.annotation))
|
188
|
-
}
|
189
|
-
|
190
|
-
file = relative(from, file)
|
191
|
-
return file
|
192
|
-
}
|
193
|
-
|
194
|
-
toUrl(path) {
|
195
|
-
if (sep === '\\') {
|
196
|
-
// istanbul ignore next
|
197
|
-
path = path.replace(/\\/g, '/')
|
198
|
-
}
|
199
|
-
return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
|
200
|
-
}
|
201
|
-
|
202
|
-
sourcePath(node) {
|
203
|
-
if (this.mapOpts.from) {
|
204
|
-
return this.toUrl(this.mapOpts.from)
|
205
|
-
} else if (this.mapOpts.absolute) {
|
206
|
-
if (pathToFileURL) {
|
207
|
-
return pathToFileURL(node.source.input.from).toString()
|
208
|
-
} else {
|
209
|
-
// istanbul ignore next
|
210
|
-
throw new Error(
|
211
|
-
'`map.absolute` option is not available in this PostCSS build'
|
212
|
-
)
|
213
|
-
}
|
214
118
|
} else {
|
215
|
-
return this.
|
119
|
+
return [this.css, this.map]
|
216
120
|
}
|
217
121
|
}
|
218
122
|
|
@@ -225,9 +129,9 @@ class MapGenerator {
|
|
225
129
|
|
226
130
|
let noSource = '<no source>'
|
227
131
|
let mapping = {
|
228
|
-
|
229
|
-
|
230
|
-
|
132
|
+
generated: { column: 0, line: 0 },
|
133
|
+
original: { column: 0, line: 0 },
|
134
|
+
source: ''
|
231
135
|
}
|
232
136
|
|
233
137
|
let lines, last
|
@@ -261,7 +165,9 @@ class MapGenerator {
|
|
261
165
|
|
262
166
|
if (node && type !== 'start') {
|
263
167
|
let p = node.parent || { raws: {} }
|
264
|
-
|
168
|
+
let childless =
|
169
|
+
node.type === 'decl' || (node.type === 'atrule' && !node.nodes)
|
170
|
+
if (!childless || node !== p.last || p.raws.semicolon) {
|
265
171
|
if (node.source && node.source.end) {
|
266
172
|
mapping.source = this.sourcePath(node)
|
267
173
|
mapping.original.line = node.source.end.line
|
@@ -282,18 +188,171 @@ class MapGenerator {
|
|
282
188
|
})
|
283
189
|
}
|
284
190
|
|
285
|
-
|
286
|
-
this.
|
191
|
+
isAnnotation() {
|
192
|
+
if (this.isInline()) {
|
193
|
+
return true
|
194
|
+
}
|
195
|
+
if (typeof this.mapOpts.annotation !== 'undefined') {
|
196
|
+
return this.mapOpts.annotation
|
197
|
+
}
|
198
|
+
if (this.previous().length) {
|
199
|
+
return this.previous().some(i => i.annotation)
|
200
|
+
}
|
201
|
+
return true
|
202
|
+
}
|
287
203
|
|
288
|
-
|
289
|
-
|
204
|
+
isInline() {
|
205
|
+
if (typeof this.mapOpts.inline !== 'undefined') {
|
206
|
+
return this.mapOpts.inline
|
290
207
|
}
|
291
208
|
|
292
|
-
let
|
293
|
-
|
294
|
-
|
295
|
-
}
|
296
|
-
|
209
|
+
let annotation = this.mapOpts.annotation
|
210
|
+
if (typeof annotation !== 'undefined' && annotation !== true) {
|
211
|
+
return false
|
212
|
+
}
|
213
|
+
|
214
|
+
if (this.previous().length) {
|
215
|
+
return this.previous().some(i => i.inline)
|
216
|
+
}
|
217
|
+
return true
|
218
|
+
}
|
219
|
+
|
220
|
+
isMap() {
|
221
|
+
if (typeof this.opts.map !== 'undefined') {
|
222
|
+
return !!this.opts.map
|
223
|
+
}
|
224
|
+
return this.previous().length > 0
|
225
|
+
}
|
226
|
+
|
227
|
+
isSourcesContent() {
|
228
|
+
if (typeof this.mapOpts.sourcesContent !== 'undefined') {
|
229
|
+
return this.mapOpts.sourcesContent
|
230
|
+
}
|
231
|
+
if (this.previous().length) {
|
232
|
+
return this.previous().some(i => i.withContent())
|
233
|
+
}
|
234
|
+
return true
|
235
|
+
}
|
236
|
+
|
237
|
+
outputFile() {
|
238
|
+
if (this.opts.to) {
|
239
|
+
return this.path(this.opts.to)
|
240
|
+
} else if (this.opts.from) {
|
241
|
+
return this.path(this.opts.from)
|
242
|
+
} else {
|
243
|
+
return 'to.css'
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
path(file) {
|
248
|
+
if (this.mapOpts.absolute) return file
|
249
|
+
if (file.charCodeAt(0) === 60 /* `<` */) return file
|
250
|
+
if (/^\w+:\/\//.test(file)) return file
|
251
|
+
let cached = this.memoizedPaths.get(file)
|
252
|
+
if (cached) return cached
|
253
|
+
|
254
|
+
let from = this.opts.to ? dirname(this.opts.to) : '.'
|
255
|
+
|
256
|
+
if (typeof this.mapOpts.annotation === 'string') {
|
257
|
+
from = dirname(resolve(from, this.mapOpts.annotation))
|
258
|
+
}
|
259
|
+
|
260
|
+
let path = relative(from, file)
|
261
|
+
this.memoizedPaths.set(file, path)
|
262
|
+
|
263
|
+
return path
|
264
|
+
}
|
265
|
+
|
266
|
+
previous() {
|
267
|
+
if (!this.previousMaps) {
|
268
|
+
this.previousMaps = []
|
269
|
+
if (this.root) {
|
270
|
+
this.root.walk(node => {
|
271
|
+
if (node.source && node.source.input.map) {
|
272
|
+
let map = node.source.input.map
|
273
|
+
if (!this.previousMaps.includes(map)) {
|
274
|
+
this.previousMaps.push(map)
|
275
|
+
}
|
276
|
+
}
|
277
|
+
})
|
278
|
+
} else {
|
279
|
+
let input = new Input(this.css, this.opts)
|
280
|
+
if (input.map) this.previousMaps.push(input.map)
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
return this.previousMaps
|
285
|
+
}
|
286
|
+
|
287
|
+
setSourcesContent() {
|
288
|
+
let already = {}
|
289
|
+
if (this.root) {
|
290
|
+
this.root.walk(node => {
|
291
|
+
if (node.source) {
|
292
|
+
let from = node.source.input.from
|
293
|
+
if (from && !already[from]) {
|
294
|
+
already[from] = true
|
295
|
+
let fromUrl = this.usesFileUrls
|
296
|
+
? this.toFileUrl(from)
|
297
|
+
: this.toUrl(this.path(from))
|
298
|
+
this.map.setSourceContent(fromUrl, node.source.input.css)
|
299
|
+
}
|
300
|
+
}
|
301
|
+
})
|
302
|
+
} else if (this.css) {
|
303
|
+
let from = this.opts.from
|
304
|
+
? this.toUrl(this.path(this.opts.from))
|
305
|
+
: '<no source>'
|
306
|
+
this.map.setSourceContent(from, this.css)
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
sourcePath(node) {
|
311
|
+
if (this.mapOpts.from) {
|
312
|
+
return this.toUrl(this.mapOpts.from)
|
313
|
+
} else if (this.usesFileUrls) {
|
314
|
+
return this.toFileUrl(node.source.input.from)
|
315
|
+
} else {
|
316
|
+
return this.toUrl(this.path(node.source.input.from))
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
toBase64(str) {
|
321
|
+
if (Buffer) {
|
322
|
+
return Buffer.from(str).toString('base64')
|
323
|
+
} else {
|
324
|
+
return window.btoa(unescape(encodeURIComponent(str)))
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
toFileUrl(path) {
|
329
|
+
let cached = this.memoizedFileURLs.get(path)
|
330
|
+
if (cached) return cached
|
331
|
+
|
332
|
+
if (pathToFileURL) {
|
333
|
+
let fileURL = pathToFileURL(path).toString()
|
334
|
+
this.memoizedFileURLs.set(path, fileURL)
|
335
|
+
|
336
|
+
return fileURL
|
337
|
+
} else {
|
338
|
+
throw new Error(
|
339
|
+
'`map.absolute` option is not available in this PostCSS build'
|
340
|
+
)
|
341
|
+
}
|
342
|
+
}
|
343
|
+
|
344
|
+
toUrl(path) {
|
345
|
+
let cached = this.memoizedURLs.get(path)
|
346
|
+
if (cached) return cached
|
347
|
+
|
348
|
+
if (sep === '\\') {
|
349
|
+
path = path.replace(/\\/g, '/')
|
350
|
+
}
|
351
|
+
|
352
|
+
let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent)
|
353
|
+
this.memoizedURLs.set(path, url)
|
354
|
+
|
355
|
+
return url
|
297
356
|
}
|
298
357
|
}
|
299
358
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import LazyResult from './lazy-result.js'
|
2
|
+
import { SourceMap } from './postcss.js'
|
3
|
+
import Processor from './processor.js'
|
4
|
+
import Result, { Message, ResultOptions } from './result.js'
|
5
|
+
import Root from './root.js'
|
6
|
+
import Warning from './warning.js'
|
7
|
+
|
8
|
+
declare namespace NoWorkResult {
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
10
|
+
export { NoWorkResult_ as default }
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* A Promise proxy for the result of PostCSS transformations.
|
15
|
+
* This lazy result instance doesn't parse css unless `NoWorkResult#root` or `Result#root`
|
16
|
+
* are accessed. See the example below for details.
|
17
|
+
* A `NoWork` instance is returned by `Processor#process` ONLY when no plugins defined.
|
18
|
+
*
|
19
|
+
* ```js
|
20
|
+
* const noWorkResult = postcss().process(css) // No plugins are defined.
|
21
|
+
* // CSS is not parsed
|
22
|
+
* let root = noWorkResult.root // now css is parsed because we accessed the root
|
23
|
+
* ```
|
24
|
+
*/
|
25
|
+
declare class NoWorkResult_ implements LazyResult<Root> {
|
26
|
+
catch: Promise<Result<Root>>['catch']
|
27
|
+
finally: Promise<Result<Root>>['finally']
|
28
|
+
then: Promise<Result<Root>>['then']
|
29
|
+
constructor(processor: Processor, css: string, opts: ResultOptions)
|
30
|
+
async(): Promise<Result<Root>>
|
31
|
+
sync(): Result<Root>
|
32
|
+
toString(): string
|
33
|
+
warnings(): Warning[]
|
34
|
+
get content(): string
|
35
|
+
get css(): string
|
36
|
+
get map(): SourceMap
|
37
|
+
get messages(): Message[]
|
38
|
+
get opts(): ResultOptions
|
39
|
+
get processor(): Processor
|
40
|
+
get root(): Root
|
41
|
+
get [Symbol.toStringTag](): string
|
42
|
+
}
|
43
|
+
|
44
|
+
declare class NoWorkResult extends NoWorkResult_ {}
|
45
|
+
|
46
|
+
export = NoWorkResult
|
@@ -0,0 +1,135 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
let MapGenerator = require('./map-generator')
|
4
|
+
let stringify = require('./stringify')
|
5
|
+
let warnOnce = require('./warn-once')
|
6
|
+
let parse = require('./parse')
|
7
|
+
const Result = require('./result')
|
8
|
+
|
9
|
+
class NoWorkResult {
|
10
|
+
constructor(processor, css, opts) {
|
11
|
+
css = css.toString()
|
12
|
+
this.stringified = false
|
13
|
+
|
14
|
+
this._processor = processor
|
15
|
+
this._css = css
|
16
|
+
this._opts = opts
|
17
|
+
this._map = undefined
|
18
|
+
let root
|
19
|
+
|
20
|
+
let str = stringify
|
21
|
+
this.result = new Result(this._processor, root, this._opts)
|
22
|
+
this.result.css = css
|
23
|
+
|
24
|
+
let self = this
|
25
|
+
Object.defineProperty(this.result, 'root', {
|
26
|
+
get() {
|
27
|
+
return self.root
|
28
|
+
}
|
29
|
+
})
|
30
|
+
|
31
|
+
let map = new MapGenerator(str, root, this._opts, css)
|
32
|
+
if (map.isMap()) {
|
33
|
+
let [generatedCSS, generatedMap] = map.generate()
|
34
|
+
if (generatedCSS) {
|
35
|
+
this.result.css = generatedCSS
|
36
|
+
}
|
37
|
+
if (generatedMap) {
|
38
|
+
this.result.map = generatedMap
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
async() {
|
44
|
+
if (this.error) return Promise.reject(this.error)
|
45
|
+
return Promise.resolve(this.result)
|
46
|
+
}
|
47
|
+
|
48
|
+
catch(onRejected) {
|
49
|
+
return this.async().catch(onRejected)
|
50
|
+
}
|
51
|
+
|
52
|
+
finally(onFinally) {
|
53
|
+
return this.async().then(onFinally, onFinally)
|
54
|
+
}
|
55
|
+
|
56
|
+
sync() {
|
57
|
+
if (this.error) throw this.error
|
58
|
+
return this.result
|
59
|
+
}
|
60
|
+
|
61
|
+
then(onFulfilled, onRejected) {
|
62
|
+
if (process.env.NODE_ENV !== 'production') {
|
63
|
+
if (!('from' in this._opts)) {
|
64
|
+
warnOnce(
|
65
|
+
'Without `from` option PostCSS could generate wrong source map ' +
|
66
|
+
'and will not find Browserslist config. Set it to CSS file path ' +
|
67
|
+
'or to `undefined` to prevent this warning.'
|
68
|
+
)
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
return this.async().then(onFulfilled, onRejected)
|
73
|
+
}
|
74
|
+
|
75
|
+
toString() {
|
76
|
+
return this._css
|
77
|
+
}
|
78
|
+
|
79
|
+
warnings() {
|
80
|
+
return []
|
81
|
+
}
|
82
|
+
|
83
|
+
get content() {
|
84
|
+
return this.result.css
|
85
|
+
}
|
86
|
+
|
87
|
+
get css() {
|
88
|
+
return this.result.css
|
89
|
+
}
|
90
|
+
|
91
|
+
get map() {
|
92
|
+
return this.result.map
|
93
|
+
}
|
94
|
+
|
95
|
+
get messages() {
|
96
|
+
return []
|
97
|
+
}
|
98
|
+
|
99
|
+
get opts() {
|
100
|
+
return this.result.opts
|
101
|
+
}
|
102
|
+
|
103
|
+
get processor() {
|
104
|
+
return this.result.processor
|
105
|
+
}
|
106
|
+
|
107
|
+
get root() {
|
108
|
+
if (this._root) {
|
109
|
+
return this._root
|
110
|
+
}
|
111
|
+
|
112
|
+
let root
|
113
|
+
let parser = parse
|
114
|
+
|
115
|
+
try {
|
116
|
+
root = parser(this._css, this._opts)
|
117
|
+
} catch (error) {
|
118
|
+
this.error = error
|
119
|
+
}
|
120
|
+
|
121
|
+
if (this.error) {
|
122
|
+
throw this.error
|
123
|
+
} else {
|
124
|
+
this._root = root
|
125
|
+
return root
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
get [Symbol.toStringTag]() {
|
130
|
+
return 'NoWorkResult'
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
module.exports = NoWorkResult
|
135
|
+
NoWorkResult.default = NoWorkResult
|