1class Node {
2    constructor(nodeDef, children) {
3        Object.assign(this, nodeDef);
4        this.children = children;
5    }
6}
7
8class DiffNode extends Node {
9    constructor(nodeDef, diffType, children) {
10        super(nodeDef, children);
11        this.diff = { type: diffType };
12        this.name = undefined;
13        this.stableId = undefined;
14        this.kind = undefined;
15        this.shortName = undefined;
16    }
17}
18
19class ObjNode extends Node {
20    constructor(name, children, combined, stableId) {
21        const nodeDef = {
22            kind: '',
23            name: name,
24            stableId: stableId,
25        };
26        if (combined) {
27            nodeDef.combined = true;
28        }
29        super(nodeDef, children);
30    }
31}
32
33class ObjDiffNode extends ObjNode {
34    constructor(name, diffType, children, combined, stableId) {
35        super(name, children, combined, stableId);
36        this.diff = { type: diffType };
37    }
38}
39
40function isPrimitive(test) {
41    return test !== Object(test);
42};
43
44function toPlainObject(theClass) {
45    if (isPrimitive(theClass)) {
46        return theClass;
47    } else if (Array.isArray(theClass)) {
48        return theClass.map(item => toPlainObject(item));
49    } else {
50        const keys = Object.getOwnPropertyNames(Object.assign({}, theClass));
51        return keys.reduce((classAsObj, key) => {
52            classAsObj[key] = toPlainObject(theClass[key]);
53            return classAsObj;
54        }, {});
55    }
56}
57
58export { Node, DiffNode, ObjNode, ObjDiffNode, toPlainObject };
59