Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/shiny-coats-stay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@mermaid-js/parser': major
---

chore: upgrade to Langium v4

Upgrade `@mermaid-js/parser` to use Langium v4,
see https://github.com/eclipse-langium/langium/releases/tag/v4.0.0
for more details.

The major breaking changes that impact consumers of this package are:

- Due to various type-related changes, `langium` now requires version `>= 5.8.0`
of TypeScript.
- The generated type names from `ast.ts` have been moved from `<typeName>` to
`<typeName>.$type`
([langium#1942](https://github.com/eclipse-langium/langium/pull/1942)).

This also removes a transitive dependency on lodash versions that are vulnerable
to CVE-2025-13465, although
[chevrotain doesn't use the affected functions](https://github.com/Chevrotain/chevrotain/blob/21f20cd9754f8d5e85243fd9286d1fff397363ab/packages/website/docs/changes/CHANGELOG.md?plain=1#L5-L8),
so this is only to silence security scanners.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"devDependencies": {
"@applitools/eyes-cypress": "^3.44.9",
"@argos-ci/cypress": "^6.1.1",
"@argos-ci/cypress": "^6.2.2",
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.27.12",
"@cspell/eslint-plugin": "^8.19.4",
Expand Down Expand Up @@ -113,7 +113,7 @@
"jison": "^0.4.18",
"js-yaml": "^4.1.0",
"jsdom": "^26.1.0",
"langium-cli": "3.3.0",
"langium-cli": "^4.0.0",
"lint-staged": "^16.1.6",
"markdown-table": "^3.0.4",
"nyc": "^17.1.0",
Expand All @@ -125,7 +125,7 @@
"start-server-and-test": "^2.0.13",
"tslib": "^2.8.1",
"tsx": "^4.7.3",
"typescript": "~5.7.3",
"typescript": "~5.8.0",
"typescript-eslint": "^8.38.0",
"vite": "^7.0.6",
"vite-plugin-istanbul": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"dompurify": "^3.2.5",
"katex": "^0.16.22",
"khroma": "^2.1.0",
"lodash-es": "^4.17.21",
"lodash-es": "^4.17.23",
"marked": "^16.2.1",
"roughjs": "^4.6.6",
"stylis": "^4.3.6",
Expand Down
6 changes: 6 additions & 0 deletions packages/mermaid/src/diagrams/git/gitGraphParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ if (import.meta.vitest) {
const dummy: GitGraph = {
$type: 'GitGraph',
statements: [],
accDescr: '',
accTitle: '',
title: '',
};
const gitGraphAst: GitGraph = {
$type: 'GitGraph',
Expand Down Expand Up @@ -220,6 +223,9 @@ if (import.meta.vitest) {
parent: '2',
},
],
accDescr: '',
accTitle: '',
title: '',
};

populate(gitGraphAst, mockDB);
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/info/infoDb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InfoFields, InfoDB } from './infoTypes.js';
import packageJson from '../../../package.json' assert { type: 'json' };
import packageJson from '../../../package.json' with { type: 'json' };

export const DEFAULT_INFO_DB: InfoFields = {
version: packageJson.version + (includeLargeFeatures ? '' : '-tiny'),
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MarkdownOptions } from 'vitepress';
import { defineConfig } from 'vitepress';
import packageJson from '../../../package.json' assert { type: 'json' };
import packageJson from '../../../package.json' with { type: 'json' };
import { addCanonicalUrls } from './canonical-urls.js';
import { getHeaderLogo, getHeaderLogoLink, withConditionalHomeNav } from './headerDomainRules.js';
import MermaidExample from './mermaid-markdown-all.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/mermaidAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { select } from 'd3';
import { compile, serialize, stringify } from 'stylis';
import DOMPurify from 'dompurify';
import isEmpty from 'lodash-es/isEmpty.js';
import packageJson from '../package.json' assert { type: 'json' };
import packageJson from '../package.json' with { type: 'json' };
import { addSVGa11yTitleDescription, setA11yDiagramInfo } from './accessibility.js';
import assignWithDepth from './assignWithDepth.js';
import * as configApi from './config.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"ast"
],
"dependencies": {
"langium": "3.3.1"
"langium": "^4.0.0"
},
"devDependencies": {
"chevrotain": "^11.0.3"
"chevrotain": "~11.1.1"
},
"files": [
"dist/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar Architecture
grammar ArchitectureGrammar
import "../common/common";
import "arch";

Expand Down
5 changes: 4 additions & 1 deletion packages/parser/src/language/architecture/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
inject,
} from 'langium';

import { MermaidGeneratedSharedModule, ArchitectureGeneratedModule } from '../generated/module.js';
import {
MermaidGeneratedSharedModule,
ArchitectureGrammarGeneratedModule as ArchitectureGeneratedModule,
} from '../generated/module.js';
import { ArchitectureTokenBuilder } from './tokenBuilder.js';
import { ArchitectureValueConverter } from './valueConverter.js';

Expand Down
4 changes: 1 addition & 3 deletions packages/parser/src/language/common/common.langium
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// When imported, the terminals are considered after the terminals in the importing grammar
// Note: Hence, to add a terminal greedier than the common terminals, import it separately after the common import

fragment EOL returns string:
NEWLINE+ | EOF
;
EOL returns string: NEWLINE+ | EOF;

fragment TitleAndAccessibilities:
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/language/gitGraph/gitGraph.langium
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar GitGraph
grammar GitGraphGrammar
import "../common/common";
import "reference";

Expand Down
5 changes: 4 additions & 1 deletion packages/parser/src/language/gitGraph/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
EmptyFileSystem,
} from 'langium';
import { CommonValueConverter } from '../common/valueConverter.js';
import { MermaidGeneratedSharedModule, GitGraphGeneratedModule } from '../generated/module.js';
import {
MermaidGeneratedSharedModule,
GitGraphGrammarGeneratedModule as GitGraphGeneratedModule,
} from '../generated/module.js';
import { GitGraphTokenBuilder } from './tokenBuilder.js';

interface GitGraphAddedServices {
Expand Down
14 changes: 7 additions & 7 deletions packages/parser/src/language/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export {
} from './generated/ast.js';

export {
InfoGeneratedModule,
InfoGrammarGeneratedModule as InfoGeneratedModule,
MermaidGeneratedSharedModule,
PacketGeneratedModule,
PieGeneratedModule,
ArchitectureGeneratedModule,
GitGraphGeneratedModule,
RadarGeneratedModule,
TreemapGeneratedModule,
PacketGrammarGeneratedModule as PacketGeneratedModule,
PieGrammarGeneratedModule as PieGeneratedModule,
ArchitectureGrammarGeneratedModule as ArchitectureGeneratedModule,
GitGraphGrammarGeneratedModule as GitGraphGeneratedModule,
RadarGrammarGeneratedModule as RadarGeneratedModule,
TreemapGrammarGeneratedModule as TreemapGeneratedModule,
} from './generated/module.js';

export * from './gitGraph/index.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/language/info/info.langium
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar Info
grammar InfoGrammar
import "../common/common";

entry Info:
Expand Down
5 changes: 4 additions & 1 deletion packages/parser/src/language/info/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
} from 'langium';

import { CommonValueConverter } from '../common/index.js';
import { InfoGeneratedModule, MermaidGeneratedSharedModule } from '../generated/module.js';
import {
InfoGrammarGeneratedModule as InfoGeneratedModule,
MermaidGeneratedSharedModule,
} from '../generated/module.js';
import { InfoTokenBuilder } from './tokenBuilder.js';

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/parser/src/language/packet/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
} from 'langium';

import { CommonValueConverter } from '../common/valueConverter.js';
import { MermaidGeneratedSharedModule, PacketGeneratedModule } from '../generated/module.js';
import {
MermaidGeneratedSharedModule,
PacketGrammarGeneratedModule as PacketGeneratedModule,
} from '../generated/module.js';
import { PacketTokenBuilder } from './tokenBuilder.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/language/packet/packet.langium
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar Packet
grammar PacketGrammar
import "../common/common";

entry Packet:
Expand Down
5 changes: 4 additions & 1 deletion packages/parser/src/language/pie/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
inject,
} from 'langium';

import { MermaidGeneratedSharedModule, PieGeneratedModule } from '../generated/module.js';
import {
MermaidGeneratedSharedModule,
PieGrammarGeneratedModule as PieGeneratedModule,
} from '../generated/module.js';
import { PieTokenBuilder } from './tokenBuilder.js';
import { PieValueConverter } from './valueConverter.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/language/pie/pie.langium
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar Pie
grammar PieGrammar
import "../common/common";

entry Pie:
Expand All @@ -17,4 +17,4 @@ PieSection:

terminal FLOAT_PIE returns number: /-?[0-9]+\.[0-9]+(?!\.)/;
terminal INT_PIE returns number: /-?(0|[1-9][0-9]*)(?!\.)/;
terminal NUMBER_PIE returns number: FLOAT_PIE | INT_PIE;
terminal NUMBER_PIE returns number: FLOAT_PIE | INT_PIE;
5 changes: 4 additions & 1 deletion packages/parser/src/language/radar/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
inject,
} from 'langium';
import { CommonValueConverter } from '../common/valueConverter.js';
import { MermaidGeneratedSharedModule, RadarGeneratedModule } from '../generated/module.js';
import {
MermaidGeneratedSharedModule,
RadarGrammarGeneratedModule as RadarGeneratedModule,
} from '../generated/module.js';
import { RadarTokenBuilder } from './tokenBuilder.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/language/radar/radar.langium
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar Radar
grammar RadarGrammar
import "../common/common";

entry Radar:
Expand Down Expand Up @@ -52,4 +52,4 @@ Option:
)
;

terminal GRATICULE returns string: 'circle' | 'polygon';
terminal GRATICULE returns string: 'circle' | 'polygon';
5 changes: 4 additions & 1 deletion packages/parser/src/language/treemap/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
inject,
} from 'langium';

import { MermaidGeneratedSharedModule, TreemapGeneratedModule } from '../generated/module.js';
import {
MermaidGeneratedSharedModule,
TreemapGrammarGeneratedModule as TreemapGeneratedModule,
} from '../generated/module.js';
import { TreemapTokenBuilder } from './tokenBuilder.js';
import { TreemapValueConverter } from './valueConverter.js';
import { TreemapValidator, registerValidationChecks } from './treemap-validator.js';
Expand Down
8 changes: 4 additions & 4 deletions packages/parser/src/language/treemap/treemap.langium
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* before the treemap keyword, allowing for empty lines and comments before the
* treemap declaration.
*/
grammar Treemap
grammar TreemapGrammar



Expand Down Expand Up @@ -54,6 +54,9 @@ terminal STYLE_SEPARATOR: ':::';
terminal SEPARATOR: ':';
terminal COMMA: ',';

// This should be processed before whitespace is ignored
terminal INDENTATION: /[ \t]{1,}/; // One or more spaces/tabs for indentation

hidden terminal WS: /[ \t]+/; // One or more spaces or tabs for hidden whitespace
hidden terminal ML_COMMENT: /\%\%[^\n]*/;
hidden terminal NL: /\r?\n/;
Expand All @@ -75,9 +78,6 @@ Section returns Section:
Leaf returns Leaf:
name=STRING2 INDENTATION? (SEPARATOR | COMMA) INDENTATION? value=MyNumber (STYLE_SEPARATOR classSelector=ID2)?;

// This should be processed before whitespace is ignored
terminal INDENTATION: /[ \t]{1,}/; // One or more spaces/tabs for indentation

// Keywords with fixed text patterns
terminal ID2: /[a-zA-Z_][a-zA-Z0-9_]*/;
// Define as a terminal rule
Expand Down
10 changes: 5 additions & 5 deletions packages/parser/tests/architecture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('architecture', () => {
])('should handle regular architecture', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.$type).toBe(Architecture.$type);
});
});

Expand All @@ -30,7 +30,7 @@ describe('architecture', () => {
])('should handle regular architecture + title in same line', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.$type).toBe(Architecture.$type);

const { title } = result.value;
expect(title).toBe('sample title');
Expand All @@ -45,7 +45,7 @@ describe('architecture', () => {
])('should handle regular architecture + title in next line', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.$type).toBe(Architecture.$type);

const { title } = result.value;
expect(title).toBe('sample title');
Expand All @@ -59,7 +59,7 @@ describe('architecture', () => {
`;
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.$type).toBe(Architecture.$type);

const { title, accTitle, accDescr } = result.value;
expect(title).toBe('sample title');
Expand All @@ -77,7 +77,7 @@ describe('architecture', () => {
`;
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.$type).toBe(Architecture.$type);

const { title, accTitle, accDescr } = result.value;
expect(title).toBe('sample title');
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/tests/info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('info', () => {
])('should handle empty info', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Info);
expect(result.value.$type).toBe(Info.$type);
});

it.each([
Expand All @@ -43,6 +43,6 @@ describe('info', () => {
])('should handle showInfo', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Info);
expect(result.value.$type).toBe(Info.$type);
});
});
2 changes: 1 addition & 1 deletion packages/parser/tests/packet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ describe('packet', () => {
])('should handle regular packet', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Packet);
expect(result.value.$type).toBe(Packet.$type);
});
});
Loading
Loading