-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5233 from mermaid-js/AsyncParse
refactor: Support async parsers [internal]
- Loading branch information
Showing
11 changed files
with
101 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
import { parser } from './infoParser.js'; | ||
|
||
describe('info', () => { | ||
it('should handle an info definition', () => { | ||
it('should handle an info definition', async () => { | ||
const str = `info`; | ||
expect(() => { | ||
parser.parse(str); | ||
}).not.toThrow(); | ||
await expect(parser.parse(str)).resolves.not.toThrow(); | ||
}); | ||
|
||
it('should handle an info definition with showInfo', () => { | ||
it('should handle an info definition with showInfo', async () => { | ||
const str = `info showInfo`; | ||
expect(() => { | ||
parser.parse(str); | ||
}).not.toThrow(); | ||
await expect(parser.parse(str)).resolves.not.toThrow(); | ||
}); | ||
|
||
it('should throw because of unsupported info grammar', () => { | ||
it('should throw because of unsupported info grammar', async () => { | ||
const str = `info unsupported`; | ||
expect(() => { | ||
parser.parse(str); | ||
}).toThrow('Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.'); | ||
await expect(parser.parse(str)).rejects.toThrow( | ||
'Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.' | ||
); | ||
}); | ||
|
||
it('should throw because of unsupported info grammar', () => { | ||
it('should throw because of unsupported info grammar', async () => { | ||
const str = `info unsupported`; | ||
expect(() => { | ||
parser.parse(str); | ||
}).toThrow('Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.'); | ||
await expect(parser.parse(str)).rejects.toThrow( | ||
'Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import type { Info } from '@mermaid-js/parser'; | ||
import { parse } from '@mermaid-js/parser'; | ||
|
||
import { log } from '../../logger.js'; | ||
import type { ParserDefinition } from '../../diagram-api/types.js'; | ||
import { log } from '../../logger.js'; | ||
|
||
export const parser: ParserDefinition = { | ||
parse: (input: string): void => { | ||
const ast: Info = parse('info', input); | ||
parse: async (input: string): Promise<void> => { | ||
const ast: Info = await parse('info', input); | ||
log.debug(ast); | ||
}, | ||
}; |
Oops, something went wrong.