export function countNakedNewlines()

in src/typescript/ast-utils.ts [172:190]


export function countNakedNewlines(str: string) {
  let ret = 0;
  for (const s of scanText(str, 0, str.length).filter((r) => r.type === 'other' || r.type === 'blockcomment')) {
    if (s.type === 'other') {
      // Count newlines in non-comments
      for (let i = s.pos; i < s.end; i++) {
        if (str[i] === '\n') {
          ret++;
        }
      }
    } else {
      // Discount newlines at the end of block comments
      if (s.hasTrailingNewLine) {
        ret--;
      }
    }
  }
  return ret;
}