Skip to content

Commit 233c19e

Browse files
committed
Resolve base correctly when using structural inheritance. Fixes #2
1 parent df4be75 commit 233c19e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/common/JSONImporter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ define([
3838
json.attribute_meta[name] = this.core.getAttributeMeta(node, name);
3939
});
4040

41-
json.pointers.base = this.core.getPointerPath(node, 'base');
4241
this.core.getOwnPointerNames(node).forEach(name => {
4342
json.pointers[name] = this.core.getPointerPath(node, name);
4443
});
44+
const baseNode = this.core.getBase(node);
45+
json.pointers.base = baseNode && this.core.getPath(baseNode);
4546

4647
this.core.getOwnValidPointerNames(node).forEach(name => {
4748
json.pointer_meta[name] = this.core.getPointerMeta(node, name);

test/common/JSONImporter.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,25 @@ describe('JSONImporter', function () {
265265
assert.equal(core.getAttribute(node, 'name'), 'NewMetaNodeName');
266266
assert.equal(core.getPointerPath(fco, 'testPtr'), core.getPath(node));
267267
});
268+
269+
it('should set base correctly during structural inheritance', async function() {
270+
const fco = await core.loadByPath(root, '/1');
271+
const nodeA = core.createNode({base: fco, parent: root});
272+
core.setAttribute(nodeA, 'name', 'A');
273+
274+
const nodeB = core.createNode({base: fco, parent: nodeA});
275+
core.setAttribute(nodeB, 'name', 'B');
276+
277+
const nodeAp = core.createNode({base: nodeA, parent: root});
278+
core.setAttribute(nodeAp, 'name', 'A prime');
279+
280+
const [childPath] = core.getChildrenPaths(nodeAp);
281+
const nodeBp = await core.loadByPath(root, childPath);
282+
283+
const schemaAp = await importer.toJSON(nodeAp);
284+
const [schemaBp] = schemaAp.children;
285+
assert.equal(schemaBp.pointers.base, core.getPath(nodeB));
286+
});
268287
});
269288

270289
describe('pointer meta', function() {

0 commit comments

Comments
 (0)