Skip to content

Commit

Permalink
Merge pull request #264 from codemile/fix/codenode-empty-inputs
Browse files Browse the repository at this point in the history
fix: input/output names on CodeNode can crash render
  • Loading branch information
abrenneke authored Dec 14, 2023
2 parents 15e4f2f + 882c006 commit 5e0b3b2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/model/nodes/CodeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { nodeDefinition } from '../NodeDefinition.js';

export type CodeNode = ChartNode<'code', CodeNodeData>;

const maskInput = (name: string) => name.trim().replace(/[^a-zA-Z0-9_]/g, '_');
const asValidNames = (names: string[]): string[] => Array(...new Set(names.map(maskInput))).filter(Boolean);

export type CodeNodeData = {
code: string;
inputNames: string | string[];
Expand Down Expand Up @@ -59,7 +62,7 @@ export class CodeNodeImpl extends NodeImpl<CodeNode> {
: [this.data.inputNames]
: [];

return inputNames.map((inputName) => {
return asValidNames(inputNames).map((inputName) => {
return {
type: 'any',
id: inputName.trim() as PortId,
Expand All @@ -77,7 +80,7 @@ export class CodeNodeImpl extends NodeImpl<CodeNode> {
: [this.data.outputNames]
: [];

return outputNames.map((outputName) => {
return asValidNames(outputNames).map((outputName) => {
return {
id: outputName.trim() as PortId,
title: outputName.trim(),
Expand Down

0 comments on commit 5e0b3b2

Please sign in to comment.