Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/sxzz/ast-kit. A toolkit for easy Babel AST generation and manipulation. jsr.io/@sxzz/ast-kit
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132import type * as t from '@babel/types'
/** * Locates the trailing comma in the given code within the specified range. * * @param code - The code to search for the trailing comma. * @param start - The start index of the range to search within. * @param end - The end index of the range to search within. * @param comments - Optional array of comments to exclude from the search range. * @returns The index of the trailing comma, or -1 if not found. */export function locateTrailingComma( code: string, start: number, end: number, comments: t.Comment[] = [],): number { let i = start while (i < end) { if (comments.some((c) => i >= c.start! && i < c.end!)) { i++ continue }
const char = code[i] if (['}', ')'].includes(char)) return -1 if (char === ',') return i i++ } return -1}