* 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)
| 1114 | * for a published `property OnClick;`. |
| 1115 | */ |
| 1116 | function declaredTypeText(node: Node, context: ResolutionContext): string { |
| 1117 | const lines = fileLines(node.filePath, context); |
| 1118 | const name = escapeRegExp(node.name); |
| 1119 | const re = node.kind === 'property' |
| 1120 | ? new RegExp(`\\bproperty\\s+${name}\\s*(?:\\[[^\\]]*\\])?\\s*:\\s*(.*)$`, 'i') |
| 1121 | : new RegExp(`\\b${name}\\b(?:\\s*,\\s*[A-Za-z_]\\w*)*\\s*,?\\s*:(?!=)\\s*(.*)$`, 'i'); |
| 1122 | let text = ''; |
| 1123 | for (let i = node.startLine - 1; i < node.startLine + 5 && i < lines.length; i++) { |
| 1124 | text += ' ' + lines[i]!.replace(/\/\/.*$|\{[^}]*\}|\(\*.*?\*\)/g, ' '); |
| 1125 | const m = re.exec(text); |
| 1126 | if (m) return m[1]!.trim(); |
| 1127 | // A list goes on only after a comma. |
| 1128 | if (node.kind === 'property' || !/,\s*$/.test(text)) break; |
| 1129 | } |
| 1130 | return ''; |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * Whether data holds a routine, by its declared type: one written in place |
no test coverage detected