postcss 8.2.8 → 8.2.12

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
@@ -13,7 +13,7 @@ let fromOffsetCache = Symbol('fromOffset cache')
13
13
  let pathAvailable = Boolean(resolve && isAbsolute)
14
14
 
15
15
  class Input {
16
- constructor (css, opts = {}) {
16
+ constructor(css, opts = {}) {
17
17
  if (
18
18
  css === null ||
19
19
  typeof css === 'undefined' ||
@@ -58,7 +58,7 @@ class Input {
58
58
  if (this.map) this.map.file = this.from
59
59
  }
60
60
 
61
- fromOffset (offset) {
61
+ fromOffset(offset) {
62
62
  let lastLine, lineToIndex
63
63
  if (!this[fromOffsetCache]) {
64
64
  let lines = this.css.split('\n')
@@ -100,7 +100,7 @@ class Input {
100
100
  }
101
101
  }
102
102
 
103
- error (message, line, column, opts = {}) {
103
+ error(message, line, column, opts = {}) {
104
104
  let result
105
105
  if (!column) {
106
106
  let pos = this.fromOffset(line)
@@ -130,14 +130,16 @@ class Input {
130
130
 
131
131
  result.input = { line, column, source: this.css }
132
132
  if (this.file) {
133
- result.input.url = pathToFileURL(this.file).toString()
133
+ if (pathToFileURL) {
134
+ result.input.url = pathToFileURL(this.file).toString()
135
+ }
134
136
  result.input.file = this.file
135
137
  }
136
138
 
137
139
  return result
138
140
  }
139
141
 
140
- origin (line, column) {
142
+ origin(line, column) {
141
143
  if (!this.map) return false
142
144
  let consumer = this.map.consumer()
143
145
 
@@ -162,7 +164,12 @@ class Input {
162
164
  }
163
165
 
164
166
  if (fromUrl.protocol === 'file:') {
165
- 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
+ }
166
173
  }
167
174
 
168
175
  let source = consumer.sourceContentFor(from.source)
@@ -171,18 +178,18 @@ class Input {
171
178
  return result
172
179
  }
173
180
 
174
- mapResolve (file) {
181
+ mapResolve(file) {
175
182
  if (/^\w+:\/\//.test(file)) {
176
183
  return file
177
184
  }
178
185
  return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
179
186
  }
180
187
 
181
- get from () {
188
+ get from() {
182
189
  return this.file || this.id
183
190
  }
184
191
 
185
- toJSON () {
192
+ toJSON() {
186
193
  let json = {}
187
194
  for (let name of ['hasBOM', 'css', 'file', 'id']) {
188
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,24 +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)
7
+ let pathAvailable = Boolean(dirname && resolve && relative && sep)
8
8
 
9
9
  class MapGenerator {
10
- constructor (stringify, root, opts) {
10
+ constructor(stringify, root, opts) {
11
11
  this.stringify = stringify
12
12
  this.mapOpts = opts.map || {}
13
13
  this.root = root
14
14
  this.opts = opts
15
15
  }
16
16
 
17
- isMap () {
17
+ isMap() {
18
18
  if (typeof this.opts.map !== 'undefined') {
19
19
  return !!this.opts.map
20
20
  }
21
21
  return this.previous().length > 0
22
22
  }
23
23
 
24
- previous () {
24
+ previous() {
25
25
  if (!this.previousMaps) {
26
26
  this.previousMaps = []
27
27
  this.root.walk(node => {
@@ -37,7 +37,7 @@ class MapGenerator {
37
37
  return this.previousMaps
38
38
  }
39
39
 
40
- isInline () {
40
+ isInline() {
41
41
  if (typeof this.mapOpts.inline !== 'undefined') {
42
42
  return this.mapOpts.inline
43
43
  }
@@ -53,7 +53,7 @@ class MapGenerator {
53
53
  return true
54
54
  }
55
55
 
56
- isSourcesContent () {
56
+ isSourcesContent() {
57
57
  if (typeof this.mapOpts.sourcesContent !== 'undefined') {
58
58
  return this.mapOpts.sourcesContent
59
59
  }
@@ -63,7 +63,7 @@ class MapGenerator {
63
63
  return true
64
64
  }
65
65
 
66
- clearAnnotation () {
66
+ clearAnnotation() {
67
67
  if (this.mapOpts.annotation === false) return
68
68
 
69
69
  let node
@@ -76,7 +76,7 @@ class MapGenerator {
76
76
  }
77
77
  }
78
78
 
79
- setSourcesContent () {
79
+ setSourcesContent() {
80
80
  let already = {}
81
81
  this.root.walk(node => {
82
82
  if (node.source) {
@@ -92,7 +92,7 @@ class MapGenerator {
92
92
  })
93
93
  }
94
94
 
95
- applyPrevMaps () {
95
+ applyPrevMaps() {
96
96
  for (let prev of this.previous()) {
97
97
  let from = this.toUrl(this.path(prev.file))
98
98
  let root = prev.root || dirname(prev.file)
@@ -111,7 +111,7 @@ class MapGenerator {
111
111
  }
112
112
  }
113
113
 
114
- isAnnotation () {
114
+ isAnnotation() {
115
115
  if (this.isInline()) {
116
116
  return true
117
117
  }
@@ -124,7 +124,7 @@ class MapGenerator {
124
124
  return true
125
125
  }
126
126
 
127
- toBase64 (str) {
127
+ toBase64(str) {
128
128
  if (Buffer) {
129
129
  return Buffer.from(str).toString('base64')
130
130
  } else {
@@ -133,7 +133,7 @@ class MapGenerator {
133
133
  }
134
134
  }
135
135
 
136
- addAnnotation () {
136
+ addAnnotation() {
137
137
  let content
138
138
 
139
139
  if (this.isInline()) {
@@ -153,7 +153,7 @@ class MapGenerator {
153
153
  this.css += eol + '/*# sourceMappingURL=' + content + ' */'
154
154
  }
155
155
 
156
- outputFile () {
156
+ outputFile() {
157
157
  if (this.opts.to) {
158
158
  return this.path(this.opts.to)
159
159
  }
@@ -163,7 +163,7 @@ class MapGenerator {
163
163
  return 'to.css'
164
164
  }
165
165
 
166
- generateMap () {
166
+ generateMap() {
167
167
  this.generateString()
168
168
  if (this.isSourcesContent()) this.setSourcesContent()
169
169
  if (this.previous().length > 0) this.applyPrevMaps()
@@ -175,7 +175,7 @@ class MapGenerator {
175
175
  return [this.css, this.map]
176
176
  }
177
177
 
178
- path (file) {
178
+ path(file) {
179
179
  if (file.indexOf('<') === 0) return file
180
180
  if (/^\w+:\/\//.test(file)) return file
181
181
  if (this.mapOpts.absolute) return file
@@ -190,7 +190,7 @@ class MapGenerator {
190
190
  return file
191
191
  }
192
192
 
193
- toUrl (path) {
193
+ toUrl(path) {
194
194
  if (sep === '\\') {
195
195
  // istanbul ignore next
196
196
  path = path.replace(/\\/g, '/')
@@ -198,17 +198,22 @@ class MapGenerator {
198
198
  return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
199
199
  }
200
200
 
201
- sourcePath (node) {
201
+ sourcePath(node) {
202
202
  if (this.mapOpts.from) {
203
203
  return this.toUrl(this.mapOpts.from)
204
204
  } else if (this.mapOpts.absolute) {
205
- 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
+ }
206
211
  } else {
207
212
  return this.toUrl(this.path(node.source.input.from))
208
213
  }
209
214
  }
210
215
 
211
- generateString () {
216
+ generateString() {
212
217
  this.css = ''
213
218
  this.map = new mozilla.SourceMapGenerator({ file: this.outputFile() })
214
219
 
@@ -274,7 +279,7 @@ class MapGenerator {
274
279
  })
275
280
  }
276
281
 
277
- generate () {
282
+ generate() {
278
283
  this.clearAnnotation()
279
284
 
280
285
  if (pathAvailable && this.isMap()) {