(source: string)
| 2738 | * point, so both the wasm and kernel C arms see the same bytes. |
| 2739 | */ |
| 2740 | export function blankCDesignatedMacroArgs(source: string): string { |
| 2741 | if (source.indexOf('=') === -1) return source; |
| 2742 | const rawStrings = maskCppRawStrings(source); |
| 2743 | source = rawStrings.source; |
| 2744 | let out: string[] | null = null; |
| 2745 | const re = /^[ \t]*([A-Z_][A-Z0-9_]*)\s*\(/gm; |
| 2746 | let m: RegExpExecArray | null; |
| 2747 | while ((m = re.exec(source))) { |
| 2748 | const open = m.index + m[0].length - 1; |
| 2749 | let depth = 1; |
| 2750 | let i = open + 1; |
| 2751 | for (; i < source.length && depth > 0; i++) { |
| 2752 | const c = source[i]; |
| 2753 | if (c === '(') depth++; |
| 2754 | else if (c === ')') depth--; |
| 2755 | } |
| 2756 | if (depth !== 0) continue; |
| 2757 | const close = i - 1; |
| 2758 | const args = source.slice(open + 1, close); |
| 2759 | // A designator at argument depth: `.name =` or `[index] =`. |
| 2760 | if (!/(^|[,{(\s])(\.[A-Za-z_]\w*|\[[^\]]+\])\s*=[^=]/.test(args)) continue; |
| 2761 | if (!/^\s*;/.test(source.slice(close + 1))) continue; |
| 2762 | out ??= source.split(''); |
| 2763 | for (let k = open + 1; k < close; k++) if (out[k] !== '\n') out[k] = ' '; |
| 2764 | re.lastIndex = close; |
| 2765 | } |
| 2766 | return rawStrings.restore(out ? out.join('') : source); |
| 2767 | } |
| 2768 | |
| 2769 | /** |
| 2770 | * Open up a `#if … #elif … #else … #endif` group whose branches are not |
no test coverage detected