Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889/** Collection literal mutations: arrays and objects. @example ```ts collectionReplacements({ node, parent: undefined, source }); ``` */
import { FILLER_TEXT, } from './literals.ts';import type { EstreeNode, Replacement,} from '../types.ts';
/** Emits collection replacements for one node. Non-empty arrays and objects empty out; empty arrays gain one filler element, mirroring Stryker's ArrayDeclaration and ObjectLiteral. @param options - Node under inspection with parent and source. @returns Replacements, possibly empty. @example ```ts collectionReplacements({ node: arrayExpression, parent: undefined, source }); ``` */export function collectionReplacements(options: { readonly node: EstreeNode; readonly parent?: EstreeNode; readonly source: string;},): readonly Replacement[] { if (options.node .type === 'ArrayExpression') { /** Whether the array literal has any elements. */ const hasElements = Array.isArray(options.node .elements,) && (options.node .elements .length > 0);
return [{ start: options.node .start, end: options.node .end, text: hasElements ? '[]' : `['${FILLER_TEXT}']`, operator: 'array', description: hasElements ? 'emptied array' : 'filled empty array', },]; }
if (options.node .type === 'ObjectExpression') { /** Whether the object literal has any properties. */ const hasProperties = Array.isArray(options.node .properties,) && (options.node .properties .length > 0);
if (!hasProperties) return [];
return [{ start: options.node .start, end: options.node .end, text: '{}', operator: 'object', description: 'emptied object', },]; }
return [];}