PlatformTargetAnalyzer.fromContent constructor
PlatformTargetAnalyzer.fromContent(
- String content
Parses the annotation from already-loaded content (zero file reads).
Uses balanced-paren scanning (not a [^)]+ regex) to find the matching
close paren — a plain [^)]+ stops at the FIRST ) regardless of
nesting, silently truncating the captured annotation (and every
getter's regex along with it) the moment any ) appears before the
real end — including inside an ordinary parenthesized comment like
// (see the docs) sitting between two annotation params. Found via a
real, self-inflicted repro: adding exactly such a comment to
nitro_type_coverage's @NitroModule made every getter on this class
silently return false.
Implementation
factory PlatformTargetAnalyzer.fromContent(String content) {
final startMatch = RegExp(r'@NitroModule\s*\(').firstMatch(content);
if (startMatch == null) return PlatformTargetAnalyzer._('');
final body = _scanBalancedParens(content, startMatch.end);
return PlatformTargetAnalyzer._(body.replaceAll('\n', ' '));
}