You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/src/utils/removeObjectKey.js

10 lines
461 B

export default function removeObjectKey ( code, parsed, key ) {
if ( parsed.type !== 'ObjectExpression' ) return;
const properties = parsed.properties;
const index = properties.findIndex( property => property.key.type === 'Identifier' && property.key.name === key );
if ( index === -1 ) return;
const a = properties[ index ].start;
const b = index < properties.length - 1 ? properties[ index + 1 ].start : properties[ index ].end;
code.remove( a, b );
}