MCPcopy
hub / github.com/postcss/postcss / cloneNode

Function cloneNode

lib/node.js:8–33  ·  view source on GitHub ↗
(obj, parent)

Source from the content-addressed store, hash-verified

6let { isClean, my } = require('./symbols')
7
8function cloneNode(obj, parent) {
9 let cloned = new obj.constructor()
10
11 for (let i in obj) {
12 if (!Object.prototype.hasOwnProperty.call(obj, i)) {
13 /* c8 ignore next 2 */
14 continue
15 }
16 if (i === 'proxyCache') continue
17 let value = obj[i]
18 let type = typeof value
19
20 if (i === 'parent' && type === 'object') {
21 if (parent) cloned[i] = parent
22 } else if (i === 'source') {
23 cloned[i] = value
24 } else if (Array.isArray(value)) {
25 cloned[i] = value.map(j => cloneNode(j, cloned))
26 } else {
27 if (type === 'object' && value !== null) value = cloneNode(value)
28 cloned[i] = value
29 }
30 }
31
32 return cloned
33}
34
35function sourceOffset(inputCSS, position) {
36 // Not all custom syntaxes support `offset` in `source.start` and `source.end`

Callers 1

cloneMethod · 0.85

Calls 1

mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…