Skip to content

Commit 7243340

Browse files
committed
chore(parser)!: upgrade parser to Langium v4
Updates the `@mermaid-js/parser` to Langium v4. There were a couple of breaking changes we had to fix to do this upgrade: - Rename all the grammers from Abc to AbcGrammar, as rules within grammars cannot have the same name as the grammar. - Update the tests, since the generated type names from `ast.ts` have been moved from `<typeName>` to `<typeName>.$type`. - Turn the EOL fragment into a rule, as in Langium v4, it's no longer allowed and throws an error. As this is a **BREAKING CHANGE** for users, I've made a new major release in the changeset (and it means we can finally get a v1.0.0 of `@mermaid-js/parser`).
1 parent 156dc11 commit 7243340

26 files changed

Lines changed: 179 additions & 154 deletions

.changeset/shiny-coats-stay.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@mermaid-js/parser': major
3+
---
4+
5+
chore: upgrade to Langium v4
6+
7+
Upgrade `@mermaid-js/parser` to use Langium v4,
8+
see https://github.com/eclipse-langium/langium/releases/tag/v4.0.0
9+
for more details.
10+
11+
The major breaking changes that impact consumers of this package are:
12+
13+
- Due to various type-related changes, `langium` now requires version `>= 5.8.0`
14+
of TypeScript.
15+
- The generated type names from `ast.ts` have been moved from `<typeName>` to
16+
`<typeName>.$type`
17+
([langium#1942](https://github.com/eclipse-langium/langium/pull/1942)).
18+
19+
This also removes a transitive dependency on lodash versions that are vulnerable
20+
to CVE-2025-13465, although
21+
[chevrotain doesn't use the affected functions](https://github.com/Chevrotain/chevrotain/blob/21f20cd9754f8d5e85243fd9286d1fff397363ab/packages/website/docs/changes/CHANGELOG.md?plain=1#L5-L8),
22+
so this is only to silence security scanners.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"jison": "^0.4.18",
114114
"js-yaml": "^4.1.0",
115115
"jsdom": "^26.1.0",
116-
"langium-cli": "^3.5.0",
116+
"langium-cli": "^4.0.0",
117117
"lint-staged": "^16.1.6",
118118
"markdown-table": "^3.0.4",
119119
"nyc": "^17.1.0",

packages/mermaid/src/diagrams/git/gitGraphParser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ if (import.meta.vitest) {
181181
const dummy: GitGraph = {
182182
$type: 'GitGraph',
183183
statements: [],
184+
accDescr: '',
185+
accTitle: '',
186+
title: '',
184187
};
185188
const gitGraphAst: GitGraph = {
186189
$type: 'GitGraph',
@@ -220,6 +223,9 @@ if (import.meta.vitest) {
220223
parent: '2',
221224
},
222225
],
226+
accDescr: '',
227+
accTitle: '',
228+
title: '',
223229
};
224230

225231
populate(gitGraphAst, mockDB);

packages/parser/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
"ast"
3434
],
3535
"dependencies": {
36-
"langium": "^3.5.0"
36+
"langium": "^4.0.0"
3737
},
3838
"devDependencies": {
39-
"chevrotain": "^11.0.3"
39+
"chevrotain": "~11.1.1"
4040
},
4141
"files": [
4242
"dist/"

packages/parser/src/language/architecture/architecture.langium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
grammar Architecture
1+
grammar ArchitectureGrammar
22
import "../common/common";
33
import "arch";
44

packages/parser/src/language/architecture/module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
inject,
1313
} from 'langium';
1414

15-
import { MermaidGeneratedSharedModule, ArchitectureGeneratedModule } from '../generated/module.js';
15+
import {
16+
MermaidGeneratedSharedModule,
17+
ArchitectureGrammarGeneratedModule as ArchitectureGeneratedModule,
18+
} from '../generated/module.js';
1619
import { ArchitectureTokenBuilder } from './tokenBuilder.js';
1720
import { ArchitectureValueConverter } from './valueConverter.js';
1821

packages/parser/src/language/common/common.langium

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
// When imported, the terminals are considered after the terminals in the importing grammar
44
// Note: Hence, to add a terminal greedier than the common terminals, import it separately after the common import
55

6-
fragment EOL returns string:
7-
NEWLINE+ | EOF
8-
;
6+
EOL returns string: NEWLINE+ | EOF;
97

108
fragment TitleAndAccessibilities:
119
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+

packages/parser/src/language/gitGraph/gitGraph.langium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
grammar GitGraph
1+
grammar GitGraphGrammar
22
import "../common/common";
33
import "reference";
44

packages/parser/src/language/gitGraph/module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
EmptyFileSystem,
1313
} from 'langium';
1414
import { CommonValueConverter } from '../common/valueConverter.js';
15-
import { MermaidGeneratedSharedModule, GitGraphGeneratedModule } from '../generated/module.js';
15+
import {
16+
MermaidGeneratedSharedModule,
17+
GitGraphGrammarGeneratedModule as GitGraphGeneratedModule,
18+
} from '../generated/module.js';
1619
import { GitGraphTokenBuilder } from './tokenBuilder.js';
1720

1821
interface GitGraphAddedServices {

packages/parser/src/language/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export {
2727
} from './generated/ast.js';
2828

2929
export {
30-
InfoGeneratedModule,
30+
InfoGrammarGeneratedModule as InfoGeneratedModule,
3131
MermaidGeneratedSharedModule,
32-
PacketGeneratedModule,
33-
PieGeneratedModule,
34-
ArchitectureGeneratedModule,
35-
GitGraphGeneratedModule,
36-
RadarGeneratedModule,
37-
TreemapGeneratedModule,
32+
PacketGrammarGeneratedModule as PacketGeneratedModule,
33+
PieGrammarGeneratedModule as PieGeneratedModule,
34+
ArchitectureGrammarGeneratedModule as ArchitectureGeneratedModule,
35+
GitGraphGrammarGeneratedModule as GitGraphGeneratedModule,
36+
RadarGrammarGeneratedModule as RadarGeneratedModule,
37+
TreemapGrammarGeneratedModule as TreemapGeneratedModule,
3838
} from './generated/module.js';
3939

4040
export * from './gitGraph/index.js';

0 commit comments

Comments
 (0)