postcss 8.2.6 → 8.2.10

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/input.js CHANGED
@@ -10,8 +10,10 @@ let PreviousMap = require('./previous-map')
10
10
 
11
11
  let fromOffsetCache = Symbol('fromOffset cache')
12
12
 
13
+ let pathAvailable = Boolean(resolve && isAbsolute)
14
+
13
15
  class Input {
14
- constructor (css, opts = {}) {
16
+ constructor(css, opts = {}) {
15
17
  if (
16
18
  css === null ||
17
19
  typeof css === 'undefined' ||
@@ -30,18 +32,24 @@ class Input {
30
32
  }
31
33
 
32
34
  if (opts.from) {
33
- if (/^\w+:\/\//.test(opts.from) || isAbsolute(opts.from)) {
35
+ if (
36
+ !pathAvailable ||
37
+ /^\w+:\/\//.test(opts.from) ||
38
+ isAbsolute(opts.from)
39
+ ) {
34
40
  this.file = opts.from
35
41
  } else {
36
42
  this.file = resolve(opts.from)
37
43
  }
38
44
  }
39
45
 
40
- let map = new PreviousMap(this.css, opts)
41
- if (map.text) {
42
- this.map = map
43
- let file = map.consumer().file
44
- if (!this.file && file) this.file = this.mapResolve(file)
46
+ if (pathAvailable) {
47
+ let map = new PreviousMap(this.css, opts)
48
+ if (map.text) {
49
+ this.map = map
50
+ let file = map.consumer().file
51
+ if (!this.file && file) this.file = this.mapResolve(file)
52
+ }
45
53
  }
46
54
 
47
55
  if (!this.file) {
@@ -50,7 +58,7 @@ class Input {
50
58
  if (this.map) this.map.file = this.from
51
59
  }
52
60
 
53
- fromOffset (offset) {
61
+ fromOffset(offset) {
54
62
  let lastLine, lineToIndex
55
63
  if (!this[fromOffsetCache]) {
56
64
  let lines = this.css.split('\n')
@@ -92,7 +100,7 @@ class Input {
92
100
  }
93
101
  }
94
102
 
95
- error (message, line, column, opts = {}) {
103
+ error(message, line, column, opts = {}) {
96
104
  let result
97
105
  if (!column) {
98
106
  let pos = this.fromOffset(line)
@@ -122,14 +130,16 @@ class Input {
122
130
 
123
131
  result.input = { line, column, source: this.css }
124
132
  if (this.file) {
125
- result.input.url = pathToFileURL(this.file).toString()
133
+ if (pathToFileURL) {
134
+ result.input.url = pathToFileURL(this.file).toString()
135
+ }
126
136
  result.input.file = this.file
127
137
  }
128
138
 
129
139
  return result
130
140
  }
131
141
 
132
- origin (line, column) {
142
+ origin(line, column) {
133
143
  if (!this.map) return false
134
144
  let consumer = this.map.consumer()
135
145
 
@@ -154,7 +164,12 @@ class Input {
154
164
  }
155
165
 
156
166
  if (fromUrl.protocol === 'file:') {
157
- result.file = fileURLToPath(fromUrl)
167
+ if (fileURLToPath) {
168
+ result.file = fileURLToPath(fromUrl)
169
+ } else {
170
+ // istanbul ignore next
171
+ throw new Error(`file: protocol is not available in this PostCSS build`);
172
+ }
158
173
  }
159
174
 
160
175
  let source = consumer.sourceContentFor(from.source)
@@ -163,18 +178,18 @@ class Input {
163
178
  return result
164
179
  }
165
180
 
166
- mapResolve (file) {
181
+ mapResolve(file) {
167
182
  if (/^\w+:\/\//.test(file)) {
168
183
  return file
169
184
  }
170
185
  return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
171
186
  }
172
187
 
173
- get from () {
188
+ get from() {
174
189
  return this.file || this.id
175
190
  }
176
191
 
177
- toJSON () {
192
+ toJSON() {
178
193
  let json = {}
179
194
  for (let name of ['hasBOM', 'css', 'file', 'id']) {
180
195
  if (this[name] != null) {
@@ -64,24 +64,24 @@ export default class LazyResult implements PromiseLike<Result> {
64
64
  * @param css CSS to parse and transform.
65
65
  * @param opts Options from the `Processor#process` or `Root#toResult`.
66
66
  */
67
- constructor (processor: Processor, css: string, opts: ResultOptions)
67
+ constructor(processor: Processor, css: string, opts: ResultOptions)
68
68
 
69
69
  /**
70
70
  * Returns the default string description of an object.
71
71
  * Required to implement the Promise interface.
72
72
  */
73
- get [Symbol.toStringTag] (): string
73
+ get [Symbol.toStringTag](): string
74
74
 
75
75
  /**
76
76
  * Returns a `Processor` instance, which will be used
77
77
  * for CSS transformations.
78
78
  */
79
- get processor (): Processor
79
+ get processor(): Processor
80
80
 
81
81
  /**
82
82
  * Options from the `Processor#process` call.
83
83
  */
84
- get opts (): ResultOptions
84
+ get opts(): ResultOptions
85
85
 
86
86
  /**
87
87
  * Processes input CSS through synchronous plugins, converts `Root`
@@ -92,7 +92,7 @@ export default class LazyResult implements PromiseLike<Result> {
92
92
  * it will throw an error. This is why this method is only
93
93
  * for debug purpose, you should always use `LazyResult#then`.
94
94
  */
95
- get css (): string
95
+ get css(): string
96
96
 
97
97
  /**
98
98
  * An alias for the `css` property. Use it with syntaxes
@@ -103,7 +103,7 @@ export default class LazyResult implements PromiseLike<Result> {
103
103
  * it will throw an error. This is why this method is only
104
104
  * for debug purpose, you should always use `LazyResult#then`.
105
105
  */
106
- get content (): string
106
+ get content(): string
107
107
 
108
108
  /**
109
109
  * Processes input CSS through synchronous plugins
@@ -114,7 +114,7 @@ export default class LazyResult implements PromiseLike<Result> {
114
114
  * it will throw an error. This is why this method is only
115
115
  * for debug purpose, you should always use `LazyResult#then`.
116
116
  */
117
- get map (): SourceMap
117
+ get map(): SourceMap
118
118
 
119
119
  /**
120
120
  * Processes input CSS through synchronous plugins
@@ -126,7 +126,7 @@ export default class LazyResult implements PromiseLike<Result> {
126
126
  * This is why this method is only for debug purpose,
127
127
  * you should always use `LazyResult#then`.
128
128
  */
129
- get root (): Root
129
+ get root(): Root
130
130
 
131
131
  /**
132
132
  * Processes input CSS through synchronous plugins
@@ -138,7 +138,7 @@ export default class LazyResult implements PromiseLike<Result> {
138
138
  * This is why this method is only for debug purpose,
139
139
  * you should always use `LazyResult#then`.
140
140
  */
141
- get messages (): Message[]
141
+ get messages(): Message[]
142
142
 
143
143
  /**
144
144
  * Processes input CSS through synchronous plugins
@@ -146,7 +146,7 @@ export default class LazyResult implements PromiseLike<Result> {
146
146
  *
147
147
  * @return Warnings from plugins.
148
148
  */
149
- warnings (): Warning[]
149
+ warnings(): Warning[]
150
150
 
151
151
  /**
152
152
  * Alias for the `LazyResult#css` property.
@@ -157,19 +157,19 @@ export default class LazyResult implements PromiseLike<Result> {
157
157
  *
158
158
  * @return Output CSS.
159
159
  */
160
- toString (): string
160
+ toString(): string
161
161
 
162
162
  /**
163
163
  * Run plugin in sync way and return `Result`.
164
164
  *
165
165
  * @return Result with output content.
166
166
  */
167
- sync (): Result
167
+ sync(): Result
168
168
 
169
169
  /**
170
170
  * Run plugin in async way and return `Result`.
171
171
  *
172
172
  * @return Result with output content.
173
173
  */
174
- async (): Promise<Result>
174
+ async(): Promise<Result>
175
175
  }
@@ -41,11 +41,11 @@ const NOT_VISITORS = {
41
41
 
42
42
  const CHILDREN = 0
43
43
 
44
- function isPromise (obj) {
44
+ function isPromise(obj) {
45
45
  return typeof obj === 'object' && typeof obj.then === 'function'
46
46
  }
47
47
 
48
- function getEvents (node) {
48
+ function getEvents(node) {
49
49
  let key = false
50
50
  let type = TYPE_TO_CLASS_NAME[node.type]
51
51
  if (node.type === 'decl') {
@@ -71,7 +71,7 @@ function getEvents (node) {
71
71
  }
72
72
  }
73
73
 
74
- function toStack (node) {
74
+ function toStack(node) {
75
75
  let events
76
76
  if (node.type === 'root') {
77
77
  events = ['Root', CHILDREN, 'RootExit']
@@ -89,7 +89,7 @@ function toStack (node) {
89
89
  }
90
90
  }
91
91
 
92
- function cleanMarks (node) {
92
+ function cleanMarks(node) {
93
93
  node[isClean] = false
94
94
  if (node.nodes) node.nodes.forEach(i => cleanMarks(i))
95
95
  return node
@@ -98,7 +98,7 @@ function cleanMarks (node) {
98
98
  let postcss = {}
99
99
 
100
100
  class LazyResult {
101
- constructor (processor, css, opts) {
101
+ constructor(processor, css, opts) {
102
102
  this.stringified = false
103
103
  this.processed = false
104
104
 
@@ -137,47 +137,47 @@ class LazyResult {
137
137
  })
138
138
  }
139
139
 
140
- get [Symbol.toStringTag] () {
140
+ get [Symbol.toStringTag]() {
141
141
  return 'LazyResult'
142
142
  }
143
143
 
144
- get processor () {
144
+ get processor() {
145
145
  return this.result.processor
146
146
  }
147
147
 
148
- get opts () {
148
+ get opts() {
149
149
  return this.result.opts
150
150
  }
151
151
 
152
- get css () {
152
+ get css() {
153
153
  return this.stringify().css
154
154
  }
155
155
 
156
- get content () {
156
+ get content() {
157
157
  return this.stringify().content
158
158
  }
159
159
 
160
- get map () {
160
+ get map() {
161
161
  return this.stringify().map
162
162
  }
163
163
 
164
- get root () {
164
+ get root() {
165
165
  return this.sync().root
166
166
  }
167
167
 
168
- get messages () {
168
+ get messages() {
169
169
  return this.sync().messages
170
170
  }
171
171
 
172
- warnings () {
172
+ warnings() {
173
173
  return this.sync().warnings()
174
174
  }
175
175
 
176
- toString () {
176
+ toString() {
177
177
  return this.css
178
178
  }
179
179
 
180
- then (onFulfilled, onRejected) {
180
+ then(onFulfilled, onRejected) {
181
181
  if (process.env.NODE_ENV !== 'production') {
182
182
  if (!('from' in this.opts)) {
183
183
  warnOnce(
@@ -190,15 +190,15 @@ class LazyResult {
190
190
  return this.async().then(onFulfilled, onRejected)
191
191
  }
192
192
 
193
- catch (onRejected) {
193
+ catch(onRejected) {
194
194
  return this.async().catch(onRejected)
195
195
  }
196
196
 
197
- finally (onFinally) {
197
+ finally(onFinally) {
198
198
  return this.async().then(onFinally, onFinally)
199
199
  }
200
200
 
201
- async () {
201
+ async() {
202
202
  if (this.error) return Promise.reject(this.error)
203
203
  if (this.processed) return Promise.resolve(this.result)
204
204
  if (!this.processing) {
@@ -207,7 +207,7 @@ class LazyResult {
207
207
  return this.processing
208
208
  }
209
209
 
210
- sync () {
210
+ sync() {
211
211
  if (this.error) throw this.error
212
212
  if (this.processed) return this.result
213
213
  this.processed = true
@@ -238,7 +238,7 @@ class LazyResult {
238
238
  return this.result
239
239
  }
240
240
 
241
- stringify () {
241
+ stringify() {
242
242
  if (this.error) throw this.error
243
243
  if (this.stringified) return this.result
244
244
  this.stringified = true
@@ -259,7 +259,7 @@ class LazyResult {
259
259
  return this.result
260
260
  }
261
261
 
262
- walkSync (node) {
262
+ walkSync(node) {
263
263
  node[isClean] = true
264
264
  let events = getEvents(node)
265
265
  for (let event of events) {
@@ -278,7 +278,7 @@ class LazyResult {
278
278
  }
279
279
  }
280
280
 
281
- visitSync (visitors, node) {
281
+ visitSync(visitors, node) {
282
282
  for (let [plugin, visitor] of visitors) {
283
283
  this.result.lastPlugin = plugin
284
284
  let promise
@@ -294,7 +294,7 @@ class LazyResult {
294
294
  }
295
295
  }
296
296
 
297
- runOnRoot (plugin) {
297
+ runOnRoot(plugin) {
298
298
  this.result.lastPlugin = plugin
299
299
  try {
300
300
  if (typeof plugin === 'object' && plugin.Once) {
@@ -307,11 +307,11 @@ class LazyResult {
307
307
  }
308
308
  }
309
309
 
310
- getAsyncError () {
310
+ getAsyncError() {
311
311
  throw new Error('Use process(css).then(cb) to work with async plugins')
312
312
  }
313
313
 
314
- handleError (error, node) {
314
+ handleError(error, node) {
315
315
  let plugin = this.result.lastPlugin
316
316
  try {
317
317
  if (node) node.addToError(error)
@@ -348,7 +348,7 @@ class LazyResult {
348
348
  return error
349
349
  }
350
350
 
351
- async runAsync () {
351
+ async runAsync() {
352
352
  this.plugin = 0
353
353
  for (let i = 0; i < this.plugins.length; i++) {
354
354
  let plugin = this.plugins[i]
@@ -397,7 +397,7 @@ class LazyResult {
397
397
  return this.stringify()
398
398
  }
399
399
 
400
- prepareVisitors () {
400
+ prepareVisitors() {
401
401
  this.listeners = {}
402
402
  let add = (plugin, type, cb) => {
403
403
  if (!this.listeners[type]) this.listeners[type] = []
@@ -435,7 +435,7 @@ class LazyResult {
435
435
  this.hasListener = Object.keys(this.listeners).length > 0
436
436
  }
437
437
 
438
- visitTick (stack) {
438
+ visitTick(stack) {
439
439
  let visit = stack[stack.length - 1]
440
440
  let { node, visitors } = visit
441
441
 
package/lib/list.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  let list = {
4
- split (string, separators, last) {
4
+ split(string, separators, last) {
5
5
  let array = []
6
6
  let current = ''
7
7
  let split = false
@@ -42,12 +42,12 @@ let list = {
42
42
  return array
43
43
  },
44
44
 
45
- space (string) {
45
+ space(string) {
46
46
  let spaces = [' ', '\n', '\t']
47
47
  return list.split(string, spaces)
48
48
  },
49
49
 
50
- comma (string) {
50
+ comma(string) {
51
51
  return list.split(string, [','], true)
52
52
  }
53
53
  }
@@ -4,22 +4,24 @@ let { dirname, resolve, relative, sep } = require('path')
4
4
  let { pathToFileURL } = require('url')
5
5
  let mozilla = require('source-map')
6
6
 
7
+ let pathAvailable = Boolean(dirname && resolve && relative && sep)
8
+
7
9
  class MapGenerator {
8
- constructor (stringify, root, opts) {
10
+ constructor(stringify, root, opts) {
9
11
  this.stringify = stringify
10
12
  this.mapOpts = opts.map || {}
11
13
  this.root = root
12
14
  this.opts = opts
13
15
  }
14
16
 
15
- isMap () {
17
+ isMap() {
16
18
  if (typeof this.opts.map !== 'undefined') {
17
19
  return !!this.opts.map
18
20
  }
19
21
  return this.previous().length > 0
20
22
  }
21
23
 
22
- previous () {
24
+ previous() {
23
25
  if (!this.previousMaps) {
24
26
  this.previousMaps = []
25
27
  this.root.walk(node => {
@@ -35,7 +37,7 @@ class MapGenerator {
35
37
  return this.previousMaps
36
38
  }
37
39
 
38
- isInline () {
40
+ isInline() {
39
41
  if (typeof this.mapOpts.inline !== 'undefined') {
40
42
  return this.mapOpts.inline
41
43
  }
@@ -51,7 +53,7 @@ class MapGenerator {
51
53
  return true
52
54
  }
53
55
 
54
- isSourcesContent () {
56
+ isSourcesContent() {
55
57
  if (typeof this.mapOpts.sourcesContent !== 'undefined') {
56
58
  return this.mapOpts.sourcesContent
57
59
  }
@@ -61,7 +63,7 @@ class MapGenerator {
61
63
  return true
62
64
  }
63
65
 
64
- clearAnnotation () {
66
+ clearAnnotation() {
65
67
  if (this.mapOpts.annotation === false) return
66
68
 
67
69
  let node
@@ -74,7 +76,7 @@ class MapGenerator {
74
76
  }
75
77
  }
76
78
 
77
- setSourcesContent () {
79
+ setSourcesContent() {
78
80
  let already = {}
79
81
  this.root.walk(node => {
80
82
  if (node.source) {
@@ -90,7 +92,7 @@ class MapGenerator {
90
92
  })
91
93
  }
92
94
 
93
- applyPrevMaps () {
95
+ applyPrevMaps() {
94
96
  for (let prev of this.previous()) {
95
97
  let from = this.toUrl(this.path(prev.file))
96
98
  let root = prev.root || dirname(prev.file)
@@ -109,7 +111,7 @@ class MapGenerator {
109
111
  }
110
112
  }
111
113
 
112
- isAnnotation () {
114
+ isAnnotation() {
113
115
  if (this.isInline()) {
114
116
  return true
115
117
  }
@@ -122,7 +124,7 @@ class MapGenerator {
122
124
  return true
123
125
  }
124
126
 
125
- toBase64 (str) {
127
+ toBase64(str) {
126
128
  if (Buffer) {
127
129
  return Buffer.from(str).toString('base64')
128
130
  } else {
@@ -131,7 +133,7 @@ class MapGenerator {
131
133
  }
132
134
  }
133
135
 
134
- addAnnotation () {
136
+ addAnnotation() {
135
137
  let content
136
138
 
137
139
  if (this.isInline()) {
@@ -151,7 +153,7 @@ class MapGenerator {
151
153
  this.css += eol + '/*# sourceMappingURL=' + content + ' */'
152
154
  }
153
155
 
154
- outputFile () {
156
+ outputFile() {
155
157
  if (this.opts.to) {
156
158
  return this.path(this.opts.to)
157
159
  }
@@ -161,7 +163,7 @@ class MapGenerator {
161
163
  return 'to.css'
162
164
  }
163
165
 
164
- generateMap () {
166
+ generateMap() {
165
167
  this.generateString()
166
168
  if (this.isSourcesContent()) this.setSourcesContent()
167
169
  if (this.previous().length > 0) this.applyPrevMaps()
@@ -173,7 +175,7 @@ class MapGenerator {
173
175
  return [this.css, this.map]
174
176
  }
175
177
 
176
- path (file) {
178
+ path(file) {
177
179
  if (file.indexOf('<') === 0) return file
178
180
  if (/^\w+:\/\//.test(file)) return file
179
181
  if (this.mapOpts.absolute) return file
@@ -188,7 +190,7 @@ class MapGenerator {
188
190
  return file
189
191
  }
190
192
 
191
- toUrl (path) {
193
+ toUrl(path) {
192
194
  if (sep === '\\') {
193
195
  // istanbul ignore next
194
196
  path = path.replace(/\\/g, '/')
@@ -196,17 +198,22 @@ class MapGenerator {
196
198
  return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
197
199
  }
198
200
 
199
- sourcePath (node) {
201
+ sourcePath(node) {
200
202
  if (this.mapOpts.from) {
201
203
  return this.toUrl(this.mapOpts.from)
202
204
  } else if (this.mapOpts.absolute) {
203
- return pathToFileURL(node.source.input.from).toString()
205
+ if (pathToFileURL) {
206
+ return pathToFileURL(node.source.input.from).toString()
207
+ } else {
208
+ // istanbul ignore next
209
+ throw new Error('`map.absolute` option is not available in this PostCSS build')
210
+ }
204
211
  } else {
205
212
  return this.toUrl(this.path(node.source.input.from))
206
213
  }
207
214
  }
208
215
 
209
- generateString () {
216
+ generateString() {
210
217
  this.css = ''
211
218
  this.map = new mozilla.SourceMapGenerator({ file: this.outputFile() })
212
219
 
@@ -272,10 +279,10 @@ class MapGenerator {
272
279
  })
273
280
  }
274
281
 
275
- generate () {
282
+ generate() {
276
283
  this.clearAnnotation()
277
284
 
278
- if (this.isMap()) {
285
+ if (pathAvailable && this.isMap()) {
279
286
  return this.generateMap()
280
287
  }
281
288