+20
-6
@@ -28,4 +28,9 @@ 'use strict' | ||
| } | ||
| // Rehydrate children separately and attach them after construction. | ||
| // Passing them through the container constructor would re-run insertion | ||
| // spacing normalization and overwrite each child's own `raws.before`. | ||
| let nodes | ||
| if (defaults.nodes) { | ||
| defaults.nodes = json.nodes.map(n => fromJSON(n, inputs)) | ||
| nodes = json.nodes.map(n => fromJSON(n, inputs)) | ||
| delete defaults.nodes | ||
| } | ||
@@ -39,15 +44,24 @@ if (defaults.source) { | ||
| } | ||
| let node | ||
| if (defaults.type === 'root') { | ||
| return new Root(defaults) | ||
| node = new Root(defaults) | ||
| } else if (defaults.type === 'decl') { | ||
| return new Declaration(defaults) | ||
| node = new Declaration(defaults) | ||
| } else if (defaults.type === 'rule') { | ||
| return new Rule(defaults) | ||
| node = new Rule(defaults) | ||
| } else if (defaults.type === 'comment') { | ||
| return new Comment(defaults) | ||
| node = new Comment(defaults) | ||
| } else if (defaults.type === 'atrule') { | ||
| return new AtRule(defaults) | ||
| node = new AtRule(defaults) | ||
| } else { | ||
| throw new Error('Unknown node type: ' + json.type) | ||
| } | ||
| if (nodes) { | ||
| node.nodes = nodes | ||
| for (let child of nodes) child.parent = node | ||
| } | ||
| return node | ||
| } | ||
@@ -54,0 +68,0 @@ |
+7
-4
@@ -209,3 +209,3 @@ 'use strict' | ||
| let from = consumer.originalPositionFor({ column, line }) | ||
| let from = consumer.originalPositionFor({ column: column - 1, line }) | ||
| if (!from.source) return false | ||
@@ -215,3 +215,6 @@ | ||
| if (typeof endLine === 'number') { | ||
| to = consumer.originalPositionFor({ column: endColumn, line: endLine }) | ||
| to = consumer.originalPositionFor({ | ||
| column: endColumn - 1, | ||
| line: endLine | ||
| }) | ||
| } | ||
@@ -231,4 +234,4 @@ | ||
| let result = { | ||
| column: from.column, | ||
| endColumn: to && to.column, | ||
| column: from.column + 1, | ||
| endColumn: to && to.column + 1, | ||
| endLine: to && to.line, | ||
@@ -235,0 +238,0 @@ line: from.line, |
+15
-8
@@ -76,3 +76,6 @@ 'use strict' | ||
| for (let node of defaults[name]) { | ||
| if (typeof node.clone === 'function') { | ||
| // Clone only nodes that already belong to another tree, so passing a | ||
| // freshly created (parent-less) node adopts that instance instead of | ||
| // a copy and keeps the caller's reference usable. See #1987. | ||
| if (typeof node.clone === 'function' && node.parent) { | ||
| this.append(node.clone()) | ||
@@ -210,10 +213,14 @@ } else { | ||
| positionBy(opts = {}) { | ||
| let pos = this.source.start | ||
| let inputString = | ||
| 'document' in this.source.input | ||
| ? this.source.input.document | ||
| : this.source.input.css | ||
| let pos = { | ||
| column: this.source.start.column, | ||
| line: this.source.start.line, | ||
| offset: sourceOffset(inputString, this.source.start) | ||
| } | ||
| if (opts.index) { | ||
| pos = this.positionInside(opts.index) | ||
| } else if (opts.word) { | ||
| let inputString = | ||
| 'document' in this.source.input | ||
| ? this.source.input.document | ||
| : this.source.input.css | ||
| let stringRepresentation = inputString.slice( | ||
@@ -303,3 +310,3 @@ sourceOffset(inputString, this.source.start), | ||
| } | ||
| } else if (opts.index) { | ||
| } else if (typeof opts.index === 'number') { | ||
| start = this.positionInside(opts.index) | ||
@@ -316,3 +323,3 @@ } | ||
| end = this.positionInside(opts.endIndex) | ||
| } else if (opts.index) { | ||
| } else if (typeof opts.index === 'number') { | ||
| end = this.positionInside(opts.index + 1) | ||
@@ -319,0 +326,0 @@ } |
+1
-1
@@ -10,3 +10,3 @@ 'use strict' | ||
| constructor(plugins = []) { | ||
| this.version = '8.5.15' | ||
| this.version = '8.5.16' | ||
| this.plugins = this.normalize(plugins) | ||
@@ -13,0 +13,0 @@ } |
+1
-1
| { | ||
| "name": "postcss", | ||
| "version": "8.5.15", | ||
| "version": "8.5.16", | ||
| "description": "Tool for transforming styles with JS plugins", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+0
-3
@@ -26,4 +26,1 @@ # PostCSS | ||
| [plugins]: https://github.com/postcss/postcss#plugins | ||
| ## Docs | ||
| Read full docs **[here](https://postcss.org/)**. |
206377
0.37%7089
0.3%26
-10.34%