postcss 8.4.5 → 8.4.8

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.

@@ -78,9 +78,12 @@ class NoWorkResult {
78
78
  this.error = error
79
79
  }
80
80
 
81
- this._root = root
82
-
83
- return root
81
+ if (this.error) {
82
+ throw this.error
83
+ } else {
84
+ this._root = root
85
+ return root
86
+ }
84
87
  }
85
88
 
86
89
  get messages() {
package/lib/node.d.ts CHANGED
@@ -3,7 +3,7 @@ import Comment, { CommentProps } from './comment.js'
3
3
  import { Stringifier, Syntax } from './postcss.js'
4
4
  import AtRule, { AtRuleProps } from './at-rule.js'
5
5
  import Rule, { RuleProps } from './rule.js'
6
- import { WarningOptions } from './warning.js'
6
+ import Warning, { WarningOptions } from './warning.js'
7
7
  import CssSyntaxError from './css-syntax-error.js'
8
8
  import Result from './result.js'
9
9
  import Input from './input.js'
@@ -241,7 +241,7 @@ export default abstract class Node {
241
241
  *
242
242
  * @return Created warning object.
243
243
  */
244
- warn(result: Result, text: string, opts?: WarningOptions): void
244
+ warn(result: Result, text: string, opts?: WarningOptions): Warning
245
245
 
246
246
  /**
247
247
  * Removes the node from its parent and cleans the parent properties
package/lib/parser.js CHANGED
@@ -7,6 +7,19 @@ let AtRule = require('./at-rule')
7
7
  let Root = require('./root')
8
8
  let Rule = require('./rule')
9
9
 
10
+ const SAFE_COMMENT_NEIGHBOR = {
11
+ empty: true,
12
+ space: true
13
+ }
14
+
15
+ function findLastWithPosition(tokens) {
16
+ for (let i = tokens.length - 1; i >= 0; i--) {
17
+ let token = tokens[i]
18
+ let pos = token[3] || token[2]
19
+ if (pos) return pos
20
+ }
21
+ }
22
+
10
23
  class Parser {
11
24
  constructor(input) {
12
25
  this.input = input
@@ -139,10 +152,12 @@ class Parser {
139
152
  if (brackets.length > 0) this.unclosedBracket(bracket)
140
153
 
141
154
  if (end && colon) {
142
- while (tokens.length) {
143
- token = tokens[tokens.length - 1][0]
144
- if (token !== 'space' && token !== 'comment') break
145
- this.tokenizer.back(tokens.pop())
155
+ if (!customProperty) {
156
+ while (tokens.length) {
157
+ token = tokens[tokens.length - 1][0]
158
+ if (token !== 'space' && token !== 'comment') break
159
+ this.tokenizer.back(tokens.pop())
160
+ }
146
161
  }
147
162
  this.decl(tokens, customProperty)
148
163
  } else {
@@ -170,7 +185,10 @@ class Parser {
170
185
  this.semicolon = true
171
186
  tokens.pop()
172
187
  }
173
- node.source.end = this.getPosition(last[3] || last[2])
188
+
189
+ node.source.end = this.getPosition(
190
+ last[3] || last[2] || findLastWithPosition(tokens)
191
+ )
174
192
 
175
193
  while (tokens[0][0] !== 'word') {
176
194
  if (tokens.length === 1) this.unknownWord(tokens)
@@ -208,7 +226,15 @@ class Parser {
208
226
  node.raws.before += node.prop[0]
209
227
  node.prop = node.prop.slice(1)
210
228
  }
211
- let firstSpaces = this.spacesAndCommentsFromStart(tokens)
229
+
230
+ let firstSpaces = []
231
+ let next
232
+ while (tokens.length) {
233
+ next = tokens[0][0]
234
+ if (next !== 'space' && next !== 'comment') break
235
+ firstSpaces.push(tokens.shift())
236
+ }
237
+
212
238
  this.precheckMissedSemicolon(tokens)
213
239
 
214
240
  for (let i = tokens.length - 1; i >= 0; i--) {
@@ -242,12 +268,12 @@ class Parser {
242
268
  }
243
269
 
244
270
  let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment')
245
- this.raw(node, 'value', tokens)
271
+
246
272
  if (hasWord) {
247
- node.raws.between += firstSpaces
248
- } else {
249
- node.value = firstSpaces + node.value
273
+ node.raws.between += firstSpaces.map(i => i[1]).join('')
274
+ firstSpaces = []
250
275
  }
276
+ this.raw(node, 'value', firstSpaces.concat(tokens), customProperty)
251
277
 
252
278
  if (node.value.includes(':') && !customProperty) {
253
279
  this.checkMissedSemicolon(tokens)
@@ -395,38 +421,30 @@ class Parser {
395
421
  if (node.type !== 'comment') this.semicolon = false
396
422
  }
397
423
 
398
- raw(node, prop, tokens) {
424
+ raw(node, prop, tokens, customProperty) {
399
425
  let token, type
400
426
  let length = tokens.length
401
427
  let value = ''
402
428
  let clean = true
403
429
  let next, prev
404
- let pattern = /^([#.|])?(\w)+/i
405
430
 
406
431
  for (let i = 0; i < length; i += 1) {
407
432
  token = tokens[i]
408
433
  type = token[0]
409
-
410
- if (type === 'comment' && node.type === 'rule') {
411
- prev = tokens[i - 1]
412
- next = tokens[i + 1]
413
-
414
- if (
415
- prev[0] !== 'space' &&
416
- next[0] !== 'space' &&
417
- pattern.test(prev[1]) &&
418
- pattern.test(next[1])
419
- ) {
420
- value += token[1]
434
+ if (type === 'space' && i === length - 1 && !customProperty) {
435
+ clean = false
436
+ } else if (type === 'comment') {
437
+ prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty'
438
+ next = tokens[i + 1] ? tokens[i + 1][0] : 'empty'
439
+ if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
440
+ if (value.slice(-1) === ',') {
441
+ clean = false
442
+ } else {
443
+ value += token[1]
444
+ }
421
445
  } else {
422
446
  clean = false
423
447
  }
424
-
425
- continue
426
- }
427
-
428
- if (type === 'comment' || (type === 'space' && i === length - 1)) {
429
- clean = false
430
448
  } else {
431
449
  value += token[1]
432
450
  }
package/lib/processor.js CHANGED
@@ -7,7 +7,7 @@ let Root = require('./root')
7
7
 
8
8
  class Processor {
9
9
  constructor(plugins = []) {
10
- this.version = '8.4.5'
10
+ this.version = '8.4.8'
11
11
  this.plugins = this.normalize(plugins)
12
12
  }
13
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss",
3
- "version": "8.4.5",
3
+ "version": "8.4.8",
4
4
  "description": "Tool for transforming styles with JS plugins",
5
5
  "engines": {
6
6
  "node": "^10 || ^12 || >=14"
@@ -65,9 +65,9 @@
65
65
  "url": "https://github.com/postcss/postcss/issues"
66
66
  },
67
67
  "dependencies": {
68
- "nanoid": "^3.1.30",
68
+ "nanoid": "^3.3.1",
69
69
  "picocolors": "^1.0.0",
70
- "source-map-js": "^1.0.1"
70
+ "source-map-js": "^1.0.2"
71
71
  },
72
72
  "browser": {
73
73
  "./lib/terminal-highlight": false,