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 +4 -1
- package/lib/fromJSON.js +27 -22
- package/lib/node.js +20 -6
- package/lib/processor.js +1 -1
- package/package.json +1 -1
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
|
-
*
|
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
|
13
|
-
if (
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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 (
|
38
|
+
} else if (defaults.type === 'decl') {
|
34
39
|
return new Declaration(defaults)
|
35
|
-
} else if (
|
40
|
+
} else if (defaults.type === 'rule') {
|
36
41
|
return new Rule(defaults)
|
37
|
-
} else if (
|
42
|
+
} else if (defaults.type === 'comment') {
|
38
43
|
return new Comment(defaults)
|
39
|
-
} else if (
|
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 (
|
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
|
-
|
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