* The text of the type a field, variable, constant or property declares, * from its declaration on: `TFoo; // the foo` for `FFoo: TFoo; // the foo`. * A name in a comma list (`FOnLoad,` above `FOnSave: TSaveEvent;`) takes the * type the list ends with, a few lines down. Empty when none is written
(node: Node, context: ResolutionContext)
| 2650 | * for a published `property OnClick;`. |
| 2651 | */ |
| 2652 | function declaredTypeText(node: Node, context: ResolutionContext): string { |
| 2653 | const lines = fileLines(node.filePath, context); |
| 2654 | const name = escapeRegExp(node.name); |
| 2655 | const re = node.kind === 'property' |
| 2656 | ? new RegExp(`\\bproperty\\s+${name}\\s*(?:\\[[^\\]]*\\])?\\s*:\\s*(.*)$`, 'i') |
| 2657 | : new RegExp(`\\b${name}\\b(?:\\s*,\\s*[A-Za-z_]\\w*)*\\s*,?\\s*:(?!=)\\s*(.*)$`, 'i'); |
| 2658 | let text = ''; |
| 2659 | for (let i = node.startLine - 1; i < node.startLine + 5 && i < lines.length; i++) { |
| 2660 | text += ' ' + lines[i]!.replace(/\/\/.*$|\{[^}]*\}|\(\*.*?\*\)/g, ' '); |
| 2661 | const m = re.exec(text); |
| 2662 | if (m) return m[1]!.trim(); |
| 2663 | // A list goes on only after a comma. |
| 2664 | if (node.kind === 'property' || !/,\s*$/.test(text)) break; |
| 2665 | } |
| 2666 | return ''; |
| 2667 | } |
| 2668 | |
| 2669 | /** |
| 2670 | * Whether data holds a routine, by its declared type: one written in place |
no test coverage detected