From 7b794d4777ce000782b70b9db74e8880fe549cc3 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Wed, 9 Oct 2024 16:43:29 +0200 Subject: [PATCH] Allow repeated tables, but ignore nested tables --- CHANGELOG.md | 8 +++++++- packages/core/package.json | 2 +- packages/core/src/toml.test.ts | 27 +++++++++++++++++++++++++++ packages/core/src/toml.ts | 8 ++++++-- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6802605..ac6635d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## @i-vresse/wb-core 3.2.4 - 2024-10-09 + +### Fixed + +- Do treat `['caprieval.1']` as a node, but `['section1.1'.mol1]` not as a node + ## @i-vresse/wb-core 3.2.3 - 2024-10-09 ### Fixed -- Do not treat `[topoaa.mol1]` as a module +- Do not treat `[topoaa.mol1]` as a node ## @i-vresse/wb-core 3.2.2 - 2024-10-09 diff --git a/packages/core/package.json b/packages/core/package.json index ce036ae..23a3a6c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@i-vresse/wb-core", - "version": "3.2.3", + "version": "3.2.4", "description": "React components to construct a workflow builder application", "keywords": [ "react", diff --git a/packages/core/src/toml.test.ts b/packages/core/src/toml.test.ts index 9b2234c..0811c0e 100644 --- a/packages/core/src/toml.test.ts +++ b/packages/core/src/toml.test.ts @@ -1129,4 +1129,31 @@ describe('lines2node()', () => { const expected = [-1, -1, -1, -1, -1, 0, 0, 0] expect(lookup).toEqual(expected) }) + + it('given repeated table with nested table', () => { + const workflow = [ + '', + 'molecules = [', + ']', + '', + '[section1]', // node 0 + '', + '[section1.mol1]', + '', + "['section1.1']", // node 1 + '', + "['section1.1'.mol1]", + '', + '[section2]', // node 2 + '', + "['section1.42']", // node 3 + '', + "['section1.42'.mol12]" + ].join('\n') + + const lookup = lines2node(workflow) + + const expected = [-1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3] + expect(lookup).toEqual(expected) + }) }) diff --git a/packages/core/src/toml.ts b/packages/core/src/toml.ts index 0d15a76..7d863f9 100644 --- a/packages/core/src/toml.ts +++ b/packages/core/src/toml.ts @@ -309,7 +309,8 @@ export function dedupWorkflow (inp: string): string { * For each line in the text, return the node index. * -1 for global parameters. * - * Ignores table with dots in the name. + * Ignores table with dots in the name, + * but do allow dot in the name if it inside qoutes. * * @param text The TOML text * @returns @@ -319,9 +320,12 @@ export function lines2node (text: string): number[] { // highlighter linenumber starts with 1 so add offset const nodeLines: number[] = [-1] let nodeIndex = -1 + // Matches ['section1.1'] , but not ['section1.1'.mol1] + const isRepeatedNodeRegexp = /^\[['"].*\.\d+['"]\]$/g for (let i = 0; i < lines.length; i++) { const line = lines[i] - if (line.startsWith('[') && !line.includes('.')) { + const isRepeatedNode = isRepeatedNodeRegexp.test(line) + if (line.startsWith('[') && (!line.includes('.') || isRepeatedNode)) { nodeIndex++ } nodeLines.push(nodeIndex)