• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mermaid-js / mermaid / 5224495283

pending completion
5224495283

Pull #4450

github

web-flow
Merge c0a0e2627 into 6115f6976
Pull Request #4450: add `mermaid-parser` separate package

3318 of 3758 branches covered (88.29%)

Branch coverage included in aggregate %.

2098 of 2098 new or added lines in 35 files covered. (100.0%)

38611 of 54295 relevant lines covered (71.11%)

243.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.64
/packages/parser/src/language/services/value-converters/commonValueConverters.ts
1
/* eslint-disable @typescript-eslint/no-non-null-assertion */
1✔
2
import { CstNode, DefaultValueConverter, GrammarAST, ValueType } from 'langium';
1✔
3

1✔
4
import {
1✔
5
  accessibilityDescrRegex,
1✔
6
  accessibilityTitleRegex,
1✔
7
  titleRegex,
1✔
8
} from '../matchers/common.js';
1✔
9

1✔
10
export class CommonValueConverter extends DefaultValueConverter {
1✔
11
  public override runConverter(
1✔
12
    rule: GrammarAST.AbstractRule,
×
13
    input: string,
×
14
    cstNode: CstNode
×
15
  ): ValueType {
×
16
    const value = CommonValueConverter.customRunConverter(rule, input, cstNode);
×
17
    if (value === null) {
×
18
      return super.runConverter(rule, input, cstNode);
×
19
    } else {
×
20
      return value;
×
21
    }
×
22
  }
×
23

1✔
24
  /**
1✔
25
   * A method contains convert logic to be used by class itself or `MermaidValueConverter`.
1✔
26
   *
1✔
27
   * @param rule - Parsed rule.
1✔
28
   * @param input - Matched string.
1✔
29
   * @param cstNode - Node in the Concrete Syntax Tree (CST).
1✔
30
   * @returns converted the value if it's common rule or `null` if it's not.
1✔
31
   */
1✔
32
  public static customRunConverter(
1✔
33
    rule: GrammarAST.AbstractRule,
197✔
34
    input: string,
197✔
35
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
197✔
36
    cstNode: CstNode
197✔
37
  ): ValueType | null {
197✔
38
    let regex: RegExp | undefined;
197✔
39
    switch (rule.name) {
197✔
40
      case 'ACC_DESCR': {
197✔
41
        regex = new RegExp(accessibilityDescrRegex.source);
45✔
42
        break;
45✔
43
      }
45✔
44
      case 'ACC_TITLE': {
197✔
45
        regex = new RegExp(accessibilityTitleRegex.source);
31✔
46
        break;
31✔
47
      }
31✔
48
      case 'TITLE': {
197✔
49
        regex = new RegExp(titleRegex.source);
46✔
50
        break;
46✔
51
      }
46✔
52
    }
197✔
53
    if (regex !== undefined) {
197✔
54
      const match = regex.exec(input);
122✔
55
      if (match !== null) {
122✔
56
        // single line title, accTitle, accDescr
122✔
57
        if (match[1] !== undefined) {
122✔
58
          const result = match[1].trim().replaceAll(/[\t ]{2,}/gm, ' ');
97✔
59
          return result || undefined!;
97✔
60
        }
97✔
61
        // multi line accDescr
25✔
62
        else if (match[2] !== undefined) {
25✔
63
          const result = match[2]
22✔
64
            .replaceAll(/^\s*/gm, '')
22✔
65
            .replaceAll(/\s+$/gm, '')
22✔
66
            .replaceAll(/[\t ]{2,}/gm, ' ')
22✔
67
            .replaceAll(/[\n\r]{2,}/gm, '\n');
22✔
68
          return result || undefined!;
22✔
69
        }
22✔
70
        return undefined!;
3✔
71
      }
3✔
72
    }
122✔
73
    return null;
75✔
74
  }
197✔
75
}
1✔
76
/* eslint-enable @typescript-eslint/no-non-null-assertion */
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc