| 231 | const VB_PATTERNS = new Map<string, VbPatterns>(); |
| 232 | |
| 233 | function patternsFor(name: string): VbPatterns { |
| 234 | const key = name.toLowerCase(); |
| 235 | const hit = VB_PATTERNS.get(key); |
| 236 | if (hit) return hit; |
| 237 | const r = escapeRegex(key); |
| 238 | const patterns: VbPatterns = { |
| 239 | declared: new RegExp(`(?<![\\w.])${r}(?![\\w.]|\\s*\\.|\\s*\\((?![\\s\\d,]*\\)))`, 'i'), |
| 240 | asClause: new RegExp(`(?<![\\w.])${r}(\\s*\\([\\s\\d,]*\\))?\\s*\\??\\s+As\\s+(New\\s+)?`, 'gi'), |
| 241 | listed: new RegExp(`\\b(?:Dim|Static)\\s+(?:[A-Za-z_]\\w*\\s*,\\s*)*${r}\\s*,[\\w\\s,]*?\\bAs\\s+`, 'i'), |
| 242 | typeChar: new RegExp( |
| 243 | `(?:\\b(?:Dim|Static|Const|ByVal|ByRef|Optional|ParamArray|Each|For|Using|Private|Public|Friend|Protected|Shared|ReadOnly|WithEvents)\\s+|[,(]\\s*)` + |
| 244 | `${r}([$%&!#@])(\\s*\\([\\s\\d,]*\\))?(?![\\w$%&!#@])`, |
| 245 | 'i', |
| 246 | ), |
| 247 | inferred: new RegExp(`\\b(?:Dim|Static|Const|Using)\\s+${r}\\s*=(?!=)`, 'i'), |
| 248 | forEach: new RegExp(`\\bFor\\s+Each\\s+${r}\\s+In\\s+(.+)$`, 'i'), |
| 249 | loose: new RegExp( |
| 250 | `\\bFor\\s+(?:Each\\s+)?${r}\\b|\\b(?:From|Aggregate)\\s+${r}\\s+In\\b|\\bLet\\s+${r}\\s*=|\\bCatch\\s+${r}\\b|` + |
| 251 | `\\b(?:Function|Sub)\\s*\\((?:[^()]*,)?\\s*(?:ByVal\\s+|ByRef\\s+)?${r}\\s*[,)]`, |
| 252 | 'i', |
| 253 | ), |
| 254 | }; |
| 255 | if (VB_PATTERNS.size >= 4096) VB_PATTERNS.delete(VB_PATTERNS.keys().next().value!); |
| 256 | VB_PATTERNS.set(key, patterns); |
| 257 | return patterns; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * What every binding of a name has on its line: a declaring keyword, or a |