postcss 8.2.0 → 8.2.1

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/CHANGELOG.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Change Log
2
2
  This project adheres to [Semantic Versioning](https://semver.org/).
3
3
 
4
+ ## 8.2.1
5
+ * Fixed `Node#toJSON()` and `postcss.fromJSON()` (by Niklas Mischkulnig).
6
+
4
7
  ## 8.2 “Prince Orobas”
5
- * Add `Node#toJSON()` and `postcss.fromJSON()` (by Niklas Mischkulnig).
8
+ * Added `Node#toJSON()` and `postcss.fromJSON()` (by Niklas Mischkulnig).
6
9
 
7
10
  ## 8.1.14
8
11
  * Fixed parser performance regression.
package/lib/fromJSON.js CHANGED
@@ -8,35 +8,40 @@ let Input = require('./input')
8
8
  let Root = require('./root')
9
9
  let Rule = require('./rule')
10
10
 
11
- function fromJSON (json) {
12
- let defaults = { ...json }
13
- if (json.nodes) {
14
- defaults.nodes = json.nodes.map(i => fromJSON(i))
15
- }
16
- if (json.type === 'root') {
17
- if (defaults.source) {
18
- defaults.source = { ...defaults.source }
19
- if (defaults.source.input) {
20
- defaults.source.input = {
21
- ...defaults.source.input,
22
- __proto__: Input.prototype
23
- }
24
- if (defaults.source.input.map) {
25
- defaults.source.input.map = {
26
- ...defaults.source.input.map,
27
- __proto__: PreviousMap.prototype
28
- }
11
+ function fromJSON (json, inputs) {
12
+ let { inputs: ownInputs, ...defaults } = json
13
+ if (ownInputs) {
14
+ inputs = []
15
+ for (let input of ownInputs) {
16
+ let inputHydrated = { ...input, __proto__: Input.prototype }
17
+ if (inputHydrated.map) {
18
+ inputHydrated.map = {
19
+ ...inputHydrated.map,
20
+ __proto__: PreviousMap.prototype
29
21
  }
30
22
  }
23
+ inputs.push(inputHydrated)
24
+ }
25
+ }
26
+ if (defaults.nodes) {
27
+ defaults.nodes = json.nodes.map(n => fromJSON(n, inputs))
28
+ }
29
+ if (defaults.source) {
30
+ let { inputId, ...source } = defaults.source
31
+ defaults.source = source
32
+ if (inputId != null) {
33
+ defaults.source.input = inputs[inputId]
31
34
  }
35
+ }
36
+ if (defaults.type === 'root') {
32
37
  return new Root(defaults)
33
- } else if (json.type === 'decl') {
38
+ } else if (defaults.type === 'decl') {
34
39
  return new Declaration(defaults)
35
- } else if (json.type === 'rule') {
40
+ } else if (defaults.type === 'rule') {
36
41
  return new Rule(defaults)
37
- } else if (json.type === 'comment') {
42
+ } else if (defaults.type === 'comment') {
38
43
  return new Comment(defaults)
39
- } else if (json.type === 'atrule') {
44
+ } else if (defaults.type === 'atrule') {
40
45
  return new AtRule(defaults)
41
46
  } else {
42
47
  throw new Error('Unknown node type: ' + json.type)
package/lib/node.js CHANGED
@@ -166,8 +166,11 @@ class Node {
166
166
  if (!keepBetween) delete this.raws.between
167
167
  }
168
168
 
169
- toJSON () {
169
+ toJSON (inputs) {
170
170
  let fixed = {}
171
+ let emitInputs = inputs == null
172
+ inputs = inputs || new Map()
173
+ let inputsNextIndex = 0
171
174
 
172
175
  for (let name in this) {
173
176
  if (!Object.prototype.hasOwnProperty.call(this, name)) {
@@ -180,23 +183,34 @@ class Node {
180
183
  if (Array.isArray(value)) {
181
184
  fixed[name] = value.map(i => {
182
185
  if (typeof i === 'object' && i.toJSON) {
183
- return i.toJSON()
186
+ return i.toJSON(inputs)
184
187
  } else {
185
188
  return i
186
189
  }
187
190
  })
188
191
  } else if (typeof value === 'object' && value.toJSON) {
189
- fixed[name] = value.toJSON()
190
- } else if (this.type === 'root' && name === 'source') {
192
+ fixed[name] = value.toJSON(inputs)
193
+ } else if (name === 'source') {
194
+ let inputId = inputs.get(value.input)
195
+ if (inputId == null) {
196
+ inputId = inputsNextIndex
197
+ inputs.set(value.input, inputsNextIndex)
198
+ inputsNextIndex++
199
+ }
191
200
  fixed[name] = {
192
- input: value.input.toJSON(),
193
- start: value.start
201
+ inputId,
202
+ start: value.start,
203
+ end: value.end
194
204
  }
195
205
  } else {
196
206
  fixed[name] = value
197
207
  }
198
208
  }
199
209
 
210
+ if (emitInputs) {
211
+ fixed.inputs = [...inputs.keys()].map(input => input.toJSON())
212
+ }
213
+
200
214
  return fixed
201
215
  }
202
216
 
package/lib/processor.js CHANGED
@@ -5,7 +5,7 @@ let Root = require('./root')
5
5
 
6
6
  class Processor {
7
7
  constructor (plugins = []) {
8
- this.version = '8.2.0'
8
+ this.version = '8.2.1'
9
9
  this.plugins = this.normalize(plugins)
10
10
  }
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss",
3
- "version": "8.2.0",
3
+ "version": "8.2.1",
4
4
  "description": "Tool for transforming styles with JS plugins",
5
5
  "engines": {
6
6
  "node": "^10 || ^12 || >=14"