* Restore preprocessor-directive lines to their original bytes after the * blanking passes ran. The token-level blanks match on shape, not context, so * a macro name that happens to sit inside a DIRECTIVE gets blanked too — and * blanking the name position of `#define FMT_API FMT_VISIBILITY("defa
(original: string, blanked: string)
| 760 | * construction and strictly reduces parse errors on both extraction arms. |
| 761 | */ |
| 762 | function restoreDirectiveLines(original: string, blanked: string): string { |
| 763 | if (blanked === original || original.indexOf('#') === -1) return blanked; |
| 764 | const o = original.split('\n'); |
| 765 | const b = blanked.split('\n'); |
| 766 | let changed = false; |
| 767 | let continuation: boolean = false; |
| 768 | for (let i = 0; i < o.length && i < b.length; i++) { |
| 769 | const line = o[i] as string; |
| 770 | const isDirective: boolean = continuation || /^[ \t]*#/.test(line); |
| 771 | if (isDirective && b[i] !== line) { |
| 772 | b[i] = line; |
| 773 | changed = true; |
| 774 | } |
| 775 | continuation = isDirective && /\\\s*$/.test(line.replace(/\r$/, '')); |
| 776 | } |
| 777 | return changed ? b.join('\n') : blanked; |
| 778 | } |
| 779 | |
| 780 | /** C/C++ source pre-processing before tree-sitter: recover macro-annotated class |
| 781 | * definitions, macro-prefixed function definitions, macro-prefixed members, and |
no test coverage detected