refactor: remove non-null assertion operator

Remove the non-null assertion operator when possible from PR
https://github.com/mermaid-js/mermaid/pull/5468
This commit is contained in:
Alois Klink
2024-05-14 03:28:59 +09:00
parent 50c9ede69d
commit 730fa89e4c
13 changed files with 96 additions and 104 deletions

View File

@@ -226,8 +226,9 @@ export const setCssClass = function (ids: string, className: string) {
if (_id[0].match(/\d/)) {
id = MERMAID_DOM_ID_PREFIX + id;
}
if (classes.has(id)) {
classes.get(id)!.cssClasses.push(className);
const classNode = classes.get(id);
if (classNode) {
classNode.cssClasses.push(className);
}
});
};
@@ -268,8 +269,8 @@ export const setLink = function (ids: string, linkStr: string, target: string) {
if (_id[0].match(/\d/)) {
id = MERMAID_DOM_ID_PREFIX + id;
}
if (classes.has(id)) {
const theClass = classes.get(id)!;
const theClass = classes.get(id);
if (theClass) {
theClass.link = utils.formatUrl(linkStr, config);
if (config.securityLevel === 'sandbox') {
theClass.linkTarget = '_top';