mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-17 03:04:07 +01:00
Merge pull request #3921 from tomperr/fix/3795_class_tilde_visibility
fix(generic): fix generic type detection
This commit is contained in:
@@ -138,7 +138,20 @@
|
|||||||
Pineapple : -int leafCount()
|
Pineapple : -int leafCount()
|
||||||
Pineapple : -int spikeCount()
|
Pineapple : -int spikeCount()
|
||||||
</pre>
|
</pre>
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<pre class="mermaid">
|
||||||
|
classDiagram
|
||||||
|
class Person {
|
||||||
|
+Id : Guid
|
||||||
|
+FirstName : string
|
||||||
|
+LastName : string
|
||||||
|
-privateProperty : string
|
||||||
|
#ProtectedProperty : string
|
||||||
|
~InternalProperty : string
|
||||||
|
~AnotherInternalProperty : List~List~string~~
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
<script src="./mermaid.js"></script>
|
<script src="./mermaid.js"></script>
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ class BankAccount{
|
|||||||
|
|
||||||
#### Generic Types
|
#### Generic Types
|
||||||
|
|
||||||
Members can be defined using generic types, such as `List<int>`, for fields, parameters, and return types by enclosing the type within `~` (**tilde**). Note: **nested** type declarations such as `List<List<int>>` are not currently supported.
|
Members can be defined using generic types, such as `List<int>`, for fields, parameters, and return types by enclosing the type within `~` (**tilde**). **Nested** type declarations such as `List<List<int>>` are supported.
|
||||||
|
|
||||||
Generics can be represented as part of a class definition and also in the parameters or the return value of a method/function:
|
Generics can be represented as part of a class definition and also in the parameters or the return value of a method/function:
|
||||||
|
|
||||||
@@ -222,6 +222,7 @@ class Square~Shape~{
|
|||||||
Square : -List~string~ messages
|
Square : -List~string~ messages
|
||||||
Square : +setMessages(List~string~ messages)
|
Square : +setMessages(List~string~ messages)
|
||||||
Square : +getMessages() List~string~
|
Square : +getMessages() List~string~
|
||||||
|
Square : +getDistanceMatrix() List~List~int~~
|
||||||
```
|
```
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
@@ -236,6 +237,7 @@ class Square~Shape~{
|
|||||||
Square : -List~string~ messages
|
Square : -List~string~ messages
|
||||||
Square : +setMessages(List~string~ messages)
|
Square : +setMessages(List~string~ messages)
|
||||||
Square : +getMessages() List~string~
|
Square : +getMessages() List~string~
|
||||||
|
Square : +getDistanceMatrix() List~List~int~~
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Visibility
|
#### Visibility
|
||||||
|
|||||||
@@ -68,5 +68,7 @@ describe('generic parser', function () {
|
|||||||
expect(parseGenericTypes('test ~Array~Array~string[]~~~')).toEqual(
|
expect(parseGenericTypes('test ~Array~Array~string[]~~~')).toEqual(
|
||||||
'test <Array<Array<string[]>>>'
|
'test <Array<Array<string[]>>>'
|
||||||
);
|
);
|
||||||
|
expect(parseGenericTypes('~test')).toEqual('~test');
|
||||||
|
expect(parseGenericTypes('~test Array~string~')).toEqual('~test Array<string>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -154,11 +154,17 @@ export const evaluate = (val?: string | boolean): boolean =>
|
|||||||
export const parseGenericTypes = function (text: string): string {
|
export const parseGenericTypes = function (text: string): string {
|
||||||
let cleanedText = text;
|
let cleanedText = text;
|
||||||
|
|
||||||
if (text.includes('~')) {
|
if (text.split('~').length - 1 >= 2) {
|
||||||
cleanedText = cleanedText.replace(/~([^~].*)/, '<$1');
|
let newCleanedText = cleanedText;
|
||||||
cleanedText = cleanedText.replace(/~([^~]*)$/, '>$1');
|
|
||||||
|
|
||||||
return parseGenericTypes(cleanedText);
|
// use a do...while loop instead of replaceAll to detect recursion
|
||||||
|
// e.g. Array~Array~T~~
|
||||||
|
do {
|
||||||
|
cleanedText = newCleanedText;
|
||||||
|
newCleanedText = cleanedText.replace(/~([^\s,:;]+)~/, '<$1>');
|
||||||
|
} while (newCleanedText != cleanedText);
|
||||||
|
|
||||||
|
return parseGenericTypes(newCleanedText);
|
||||||
} else {
|
} else {
|
||||||
return cleanedText;
|
return cleanedText;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class BankAccount{
|
|||||||
|
|
||||||
#### Generic Types
|
#### Generic Types
|
||||||
|
|
||||||
Members can be defined using generic types, such as `List<int>`, for fields, parameters, and return types by enclosing the type within `~` (**tilde**). Note: **nested** type declarations such as `List<List<int>>` are not currently supported.
|
Members can be defined using generic types, such as `List<int>`, for fields, parameters, and return types by enclosing the type within `~` (**tilde**). **Nested** type declarations such as `List<List<int>>` are supported.
|
||||||
|
|
||||||
Generics can be represented as part of a class definition and also in the parameters or the return value of a method/function:
|
Generics can be represented as part of a class definition and also in the parameters or the return value of a method/function:
|
||||||
|
|
||||||
@@ -139,6 +139,7 @@ class Square~Shape~{
|
|||||||
Square : -List~string~ messages
|
Square : -List~string~ messages
|
||||||
Square : +setMessages(List~string~ messages)
|
Square : +setMessages(List~string~ messages)
|
||||||
Square : +getMessages() List~string~
|
Square : +getMessages() List~string~
|
||||||
|
Square : +getDistanceMatrix() List~List~int~~
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Visibility
|
#### Visibility
|
||||||
|
|||||||
Reference in New Issue
Block a user