-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (27 loc) · 1.03 KB
/
Copy pathindex.js
File metadata and controls
33 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module.exports = {
directives: {
extend: ({ value, get, path }, source) => {
if (!source || typeof source !== 'string') {
throw new Error(`[kyoml-extend-plugin] @extend should be called with a path`);
}
const fullSource = `document.${source}`;
const sourceObj = get(fullSource);
const sourceType = typeof sourceObj;
const destType = typeof value;
if (sourceType !== 'object') {
throw new Error(`[kyoml-extend-plugin] Cannot read from source '${fullSource}', expected an object, found ${sourceType} instead`);
}
if (destType !== 'object') {
throw new Error(`[kyoml-extend-plugin] Failed to extend '${path}', expected an object, found ${destType} instead`);
}
if (path.indexOf(fullSource) === 0) {
throw new Error(`[kyoml-extend-plugin] Extending a parent would cause circular reference`);
}
for (const key in sourceObj) {
if (!value.hasOwnProperty(key)) {
value[key] = sourceObj[key];
}
}
}
}
}