import type { AttributeToken } from 'pug-lexer' ; import type { PugEmptyAttributes , PugEmptyAttributesForceQuotes } from '.' ; const EMPTY_VALUES = [ true , '""' , "''" ] ; param token param pugEmptyAttributes param pugEmptyAttributesForceQuotes export function formatEmptyAttribute ( token , pugEmptyAttributes , pugEmptyAttributesForceQuotes ) { const { val , name } = token ; const forceQuotesPatterns = pugEmptyAttributesForceQuotes . map ( ( pattern ) => new RegExp ( pattern ) ) ; const isForced = forceQuotesPatterns . some ( ( pattern ) => pattern . test ( name ) ) ; if ( isForced ) { if ( token . val === true ) { token . val = '""' ; } return ; } if ( pugEmptyAttributes === 'as-is' || ! EMPTY_VALUES . includes ( val ) ) { return ; } switch ( pugEmptyAttributes ) { case 'all' : { if ( token . val === true ) { token . val = '""' ; } break ; } case 'none' : { if ( token . val === '""' || token . val === "''" ) { token . val = true ; } break ; } } }