postcss
Advanced tools
Comparing version 8.2.0 to 8.2.1
# Change Log | ||
This project adheres to [Semantic Versioning](https://semver.org/). | ||
## 8.2.1 | ||
* Fixed `Node#toJSON()` and `postcss.fromJSON()` (by Niklas Mischkulnig). | ||
## 8.2 “Prince Orobas” | ||
* Add `Node#toJSON()` and `postcss.fromJSON()` (by Niklas Mischkulnig). | ||
* Added `Node#toJSON()` and `postcss.fromJSON()` (by Niklas Mischkulnig). | ||
@@ -7,0 +10,0 @@ ## 8.1.14 |
@@ -11,31 +11,36 @@ 'use strict' | ||
function fromJSON (json) { | ||
let defaults = { ...json } | ||
if (json.nodes) { | ||
defaults.nodes = json.nodes.map(i => fromJSON(i)) | ||
} | ||
if (json.type === 'root') { | ||
if (defaults.source) { | ||
defaults.source = { ...defaults.source } | ||
if (defaults.source.input) { | ||
defaults.source.input = { | ||
...defaults.source.input, | ||
__proto__: Input.prototype | ||
function fromJSON (json, inputs) { | ||
let { inputs: ownInputs, ...defaults } = json | ||
if (ownInputs) { | ||
inputs = [] | ||
for (let input of ownInputs) { | ||
let inputHydrated = { ...input, __proto__: Input.prototype } | ||
if (inputHydrated.map) { | ||
inputHydrated.map = { | ||
...inputHydrated.map, | ||
__proto__: PreviousMap.prototype | ||
} | ||
if (defaults.source.input.map) { | ||
defaults.source.input.map = { | ||
...defaults.source.input.map, | ||
__proto__: PreviousMap.prototype | ||
} | ||
} | ||
} | ||
inputs.push(inputHydrated) | ||
} | ||
} | ||
if (defaults.nodes) { | ||
defaults.nodes = json.nodes.map(n => fromJSON(n, inputs)) | ||
} | ||
if (defaults.source) { | ||
let { inputId, ...source } = defaults.source | ||
defaults.source = source | ||
if (inputId != null) { | ||
defaults.source.input = inputs[inputId] | ||
} | ||
} | ||
if (defaults.type === 'root') { | ||
return new Root(defaults) | ||
} else if (json.type === 'decl') { | ||
} else if (defaults.type === 'decl') { | ||
return new Declaration(defaults) | ||
} else if (json.type === 'rule') { | ||
} else if (defaults.type === 'rule') { | ||
return new Rule(defaults) | ||
} else if (json.type === 'comment') { | ||
} else if (defaults.type === 'comment') { | ||
return new Comment(defaults) | ||
} else if (json.type === 'atrule') { | ||
} else if (defaults.type === 'atrule') { | ||
return new AtRule(defaults) | ||
@@ -42,0 +47,0 @@ } else { |
@@ -169,4 +169,7 @@ 'use strict' | ||
toJSON () { | ||
toJSON (inputs) { | ||
let fixed = {} | ||
let emitInputs = inputs == null | ||
inputs = inputs || new Map() | ||
let inputsNextIndex = 0 | ||
@@ -184,3 +187,3 @@ for (let name in this) { | ||
if (typeof i === 'object' && i.toJSON) { | ||
return i.toJSON() | ||
return i.toJSON(inputs) | ||
} else { | ||
@@ -191,7 +194,14 @@ return i | ||
} else if (typeof value === 'object' && value.toJSON) { | ||
fixed[name] = value.toJSON() | ||
} else if (this.type === 'root' && name === 'source') { | ||
fixed[name] = value.toJSON(inputs) | ||
} else if (name === 'source') { | ||
let inputId = inputs.get(value.input) | ||
if (inputId == null) { | ||
inputId = inputsNextIndex | ||
inputs.set(value.input, inputsNextIndex) | ||
inputsNextIndex++ | ||
} | ||
fixed[name] = { | ||
input: value.input.toJSON(), | ||
start: value.start | ||
inputId, | ||
start: value.start, | ||
end: value.end | ||
} | ||
@@ -203,2 +213,6 @@ } else { | ||
if (emitInputs) { | ||
fixed.inputs = [...inputs.keys()].map(input => input.toJSON()) | ||
} | ||
return fixed | ||
@@ -205,0 +219,0 @@ } |
@@ -8,3 +8,3 @@ 'use strict' | ||
constructor (plugins = []) { | ||
this.version = '8.2.0' | ||
this.version = '8.2.1' | ||
this.plugins = this.normalize(plugins) | ||
@@ -11,0 +11,0 @@ } |
{ | ||
"name": "postcss", | ||
"version": "8.2.0", | ||
"version": "8.2.1", | ||
"description": "Tool for transforming styles with JS plugins", | ||
@@ -5,0 +5,0 @@ "engines": { |
203037
5772