import type { AttributeToken , TagToken , Token } from 'pug-lexer' ; import type { Logger } from '../logger' ; import type { PugFramework } from '../options/pug-framework' ; param tokens param index returns export function previousTagToken ( tokens , index ) { for ( let i = index - 1 ; i >= 0 ; i -- ) { const token = tokens [ i ] ; if ( ! token ) { return ; } if ( token . type === 'tag' ) { return token ; } } return ; } param tokens param index returns export function previousNormalAttributeToken ( tokens , index ) { for ( let i = index - 1 ; i > 0 ; i -- ) { const token = tokens [ i ] ; if ( ! token || token . type === 'start-attributes' ) { return ; } if ( token . type === 'attribute' ) { if ( token . name !== 'class' && token . name !== 'id' ) { return token ; } } } return ; } param tokens param index returns export function previousTypeAttributeToken ( tokens , index ) { for ( let i = index - 1 ; i > 0 ; i -- ) { const token = tokens [ i ] ; if ( ! token || token . type === 'start-attributes' || token . type === 'tag' ) { return ; } if ( token . type === 'attribute' ) { if ( token . name === 'type' ) { return token ; } } } return ; } param value returns export function unwrapLineFeeds ( value ) { return value . includes ( '\n' ) ? value . split ( '\n' ) . map ( ( part ) => part . trim ( ) ) . map ( ( part ) => ( part [ 0 ] === '.' ? '' : ' ' ) + part ) . join ( '' ) . trim ( ) : value ; } param name param val returns export function isStyleAttribute ( name , val ) { return name === 'style' && isQuoted ( val ) ; } param val param start param end param offset returns export function isWrappedWith ( val , start , end , offset = 0 ) { return ( val . startsWith ( start , offset ) && val . endsWith ( end , val . length - offset ) ) ; } param val returns export function isQuoted ( val ) { if ( /^(["'`])(.*)\1$/ . test ( val ) ) { const regex = new RegExp ( `${ val [ 0 ] }(?<!\\\\${ val [ 0 ] })` ) ; return ! regex . test ( val . slice ( 1 , - 1 ) ) ; } return false ; } param val returns export function isSingleLineWithInterpolation ( val ) { return /^`[\s\S]*`$/ . test ( val ) && val . includes ( '${' ) ; } param val returns export function isMultilineInterpolation ( val ) { return /^`[\s\S]*`$/m . test ( val ) && val . includes ( '\n' ) ; } param bracketSpacing param code param param2 param param2 . param param2 . returns export function handleBracketSpacing ( bracketSpacing , code , [ opening , closing ] = [ '{{' , '}}' ] ) { return bracketSpacing ? `${ opening } ${ code } ${ closing }` : `${ opening }${ code }${ closing }` ; } param rawContent param enclosingQuote param unescapeUnnecessaryEscapes returns see export function makeString ( rawContent , enclosingQuote , unescapeUnnecessaryEscapes = false ) { const otherQuote = enclosingQuote === '"' ? "'" : '"' ; const newContent = rawContent . replace ( /\\([\s\S])|(['"])/g , ( match , escaped , quote ) => { if ( escaped === otherQuote ) { return escaped ; } if ( quote === enclosingQuote ) { return `\\${ quote }` ; } if ( quote ) { return quote ; } return unescapeUnnecessaryEscapes && /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/ . test ( escaped ) ? escaped : `\\${ escaped }` ; } ) ; return enclosingQuote + newContent + enclosingQuote ; } param code param quotes param otherQuotes param logger returns export function detectDangerousQuoteCombination ( code , quotes , otherQuotes , logger ) { const q1 = code . indexOf ( quotes ) ; const q2 = code . indexOf ( otherQuotes ) ; const qb = code . indexOf ( '`' ) ; if ( q1 >= 0 && q2 >= 0 && q2 > q1 && ( qb < 0 || q1 < qb ) ) { logger . log ( { code , quotes , otherQuotes , q1 , q2 , qb } ) ; return true ; } return false ; } returns export function detectFramework ( ) { try { const npmPackages = Object . keys ( process . env ) . filter ( ( key ) => key . startsWith ( 'npm_package_' ) ) . filter ( ( key ) => /(dev)?[Dd]ependencies_+/ . test ( key ) ) ; if ( npmPackages . some ( ( pack ) => pack . includes ( 'vue' ) && ! pack . includes ( 'vuepress' ) ) ) { return 'vue' ; } else if ( npmPackages . some ( ( pack ) => pack . includes ( 'svelte' ) ) ) { return 'svelte' ; } else if ( npmPackages . some ( ( pack ) => pack . includes ( 'angular' ) ) ) { return 'angular' ; } } catch { return 'auto' ; } return 'auto' ; }