import type { BuiltInParserName } from 'prettier' ; import type { AttributeToken } from 'pug-lexer' ; const jsonSuffixRe = /\+(json|yaml)$/i ; const wrappingQuotesRe = /(^("|'|`))|(("|'|`)$)/g ; const scriptTypeToParserMap = new Map ( [ [ 'application/ecmascript' , 'babel' ] , [ 'application/javascript' , 'babel' ] , [ 'application/json' , 'json' ] , [ 'text/ecmascript' , 'babel' ] , [ 'text/javascript' , 'babel' ] , [ 'text/markdown' , 'markdown' ] , [ 'text/typescript' , 'typescript' ] , [ 'module' , 'babel' ] , ] ) ; param typeAttrToken returns export function getScriptParserName ( typeAttrToken ? ) { if ( ! typeAttrToken ) { return 'babel' ; } const typeRaw = typeAttrToken . val ; if ( typeof typeRaw !== 'string' ) { return ; } const type = typeRaw . replace ( wrappingQuotesRe , '' ) ; if ( ! type ) { return 'babel' ; } const suffixExec = jsonSuffixRe . exec ( type ) ; if ( suffixExec ) { return suffixExec [ 1 ] as unknown as 'json' | 'yaml' ; } return scriptTypeToParserMap . get ( type ) ; }