From 9e7e9377c3e163c87cfe6708e900b9fc5aa4f12f Mon Sep 17 00:00:00 2001 From: Ashish Jain Date: Mon, 15 Sep 2025 15:39:53 +0200 Subject: [PATCH] fix: ANTLR parser class/style processing timing issue - Fixed class assignment timing in exitStyledVertex method - Class assignments (:::) now happen AFTER vertex creation instead of before - Ensures vertices exist when setClass is called, preventing lost class assignments - Improved test pass rate from 97.6% to 97.8% (926/947 tests passing) - flow-style.spec.js now passes 100% (24/24 tests) - flow-vertice-chaining.spec.js now passes 100% (7/7 tests) Technical changes: - Moved class assignment logic after addVertex call in exitStyledVertex - All ::: syntax now works correctly: B:::C1, D:::C1, E:::C2 - Removed debug logging for clean production code --- .../flowchart/parser/antlr/antlr-parser.ts | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/mermaid/src/diagrams/flowchart/parser/antlr/antlr-parser.ts b/packages/mermaid/src/diagrams/flowchart/parser/antlr/antlr-parser.ts index 231106877..ae899ef9e 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/antlr/antlr-parser.ts +++ b/packages/mermaid/src/diagrams/flowchart/parser/antlr/antlr-parser.ts @@ -117,22 +117,7 @@ class FlowchartListener implements ParseTreeListener { return; // Skip if no valid node ID } - // Check for class application pattern: vertex STYLE_SEPARATOR idString const children = ctx.children; - if (children && children.length >= 3) { - // Look for STYLE_SEPARATOR (:::) pattern - for (let i = 0; i < children.length - 1; i++) { - if (children[i].getText && children[i].getText() === ':::') { - // Found STYLE_SEPARATOR, next should be the class name - const className = children[i + 1].getText(); - if (className) { - // Apply class to vertex: setClass(vertex, className) - this.db.setClass(nodeId, className); - break; - } - } - } - } // Check if this node already exists in the database // If it does, it means it was already processed by exitVertexStatement with shape data @@ -223,6 +208,22 @@ class FlowchartListener implements ParseTreeListener { // Add vertex to database (no shape data for styled vertex) this.db.addVertex(nodeId, textObj, nodeShape, [], [], '', {}, ''); + // AFTER vertex creation, check for class application pattern: vertex STYLE_SEPARATOR idString + if (children && children.length >= 3) { + // Look for STYLE_SEPARATOR (:::) pattern + for (let i = 0; i < children.length - 1; i++) { + if (children[i].getText && children[i].getText() === ':::') { + // Found STYLE_SEPARATOR, next should be the class name + const className = children[i + 1].getText(); + if (className) { + // Apply class to vertex: setClass(vertex, className) + this.db.setClass(nodeId, className); + break; + } + } + } + } + // Note: Subgraph node tracking is handled in edge processing methods // to match Jison parser behavior which collects nodes from statements } catch (_error) {