diff --git a/packages/xod-project/src/flatten.js b/packages/xod-project/src/flatten.js index 0ed3ee3d2..b894ddc44 100644 --- a/packages/xod-project/src/flatten.js +++ b/packages/xod-project/src/flatten.js @@ -654,6 +654,9 @@ const traverseUpAndCollectTerminalChain = R.curry( R.compose(R.equals(nextNodeId), Link.getLinkInputNodeId), links ); + // If the uppermost node has no input link — return collected data + if (!nextLink) return collected; + return R.compose( traverseUpAndCollectTerminalChain(terminalNodeIds, links), R.over(R.lensIndex(0), R.append(nextNodeId)), diff --git a/packages/xod-project/test/fixtures/cast-custom-types.xodball b/packages/xod-project/test/fixtures/cast-custom-types.xodball index 95d8320cb..5a6ead60b 100644 --- a/packages/xod-project/test/fixtures/cast-custom-types.xodball +++ b/packages/xod-project/test/fixtures/cast-custom-types.xodball @@ -554,6 +554,117 @@ "type": "xod/patch-nodes/input-byte" } } + }, + "@/test-wrapped-i2c": { + "nodes": { + "wrapped-i2c-node": { + "id": "wrapped-i2c-node", + "position": { + "x": -2, + "y": -1, + "units": "slots" + }, + "type": "@/wrapped-i2c" + } + }, + "path": "@/main" + }, + "@/wrapped-i2c": { + "links": { + "terminal-to-node": { + "id": "terminal-to-node", + "input": { + "nodeId": "test-node", + "pinKey": "input-i2c" + }, + "output": { + "nodeId": "input-i2c-terminal", + "pinKey": "__out__" + } + } + }, + "nodes": { + "test-node": { + "id": "test-node", + "position": { + "x": 1, + "y": 1, + "units": "slots" + }, + "type": "xod/i2c/test" + }, + "input-i2c-terminal": { + "id": "input-i2c-terminal", + "label": "I2C", + "position": { + "x": 1, + "y": 0, + "units": "slots" + }, + "type": "xod/i2c/input-i2c" + } + }, + "path": "@/wrapped-i2c" + }, + "xod/i2c/i2c": { + "attachments": [ + { + "filename": "patch.cpp", + "encoding": "utf-8", + "content": "// implementation" + } + ], + "nodes": { + "output-self": { + "id": "output-self", + "position": { + "units": "slots", + "x": 2, + "y": 2 + }, + "type": "xod/patch-nodes/output-self" + }, + "niix": { + "id": "niix", + "position": { + "units": "slots", + "x": 2, + "y": 1 + }, + "type": "xod/patch-nodes/not-implemented-in-xod" + } + }, + "path": "xod/i2c/i2c" + }, + "xod/i2c/test": { + "attachments": [ + { + "filename": "patch.cpp", + "encoding": "utf-8", + "content": "// implementation" + } + ], + "nodes": { + "input-i2c": { + "id": "input-i2c", + "position": { + "units": "slots", + "x": 2, + "y": 2 + }, + "type": "xod/i2c/input-i2c" + }, + "niix": { + "id": "niix", + "position": { + "units": "slots", + "x": 2, + "y": 1 + }, + "type": "xod/patch-nodes/not-implemented-in-xod" + } + }, + "path": "xod/i2c/test" } } } diff --git a/packages/xod-project/test/flatten.spec.js b/packages/xod-project/test/flatten.spec.js index 66a243c70..e5714911b 100644 --- a/packages/xod-project/test/flatten.spec.js +++ b/packages/xod-project/test/flatten.spec.js @@ -1359,6 +1359,25 @@ describe('Flatten', () => { 'color-nested~nested-again~hsl-node-to-watch-node-pin-input-string' )); + it('should not create a cast node for a custom type if it not needed', () => { + const flatProject = flatten(project, '@/test-wrapped-i2c'); + Helper.expectEitherRight(newProject => { + const nodeIds = R.compose( + R.map(Node.getNodeId), + Patch.listNodes, + Project.getPatchByPathUnsafe('@/test-wrapped-i2c') + )(newProject); + + const links = R.compose( + Patch.listLinks, + Project.getPatchByPathUnsafe('@/test-wrapped-i2c') + )(newProject); + + assert.sameMembers(['wrapped-i2c-node~test-node'], nodeIds); + assert.isEmpty(links); + }, flatProject); + }); + it('should return Either.Left if custom type does not have a cast node', () => { const flatProject = flatten(project, '@/test-no-cast-node'); Helper.expectEitherError(