{"version":3,"file":"compilerr-BlECn_B4.js","sources":["../../node_modules/compilerr/build/es2019/module.js"],"sourcesContent":["import dashify from 'dashify';\nimport indefiniteArticle from 'indefinite-article';\n/*\n * @todo Explicitly referencing the barrel file seems to be necessary when enabling the\n * isolatedModules compiler option.\n */\nexport * from './interfaces/index';\nexport * from './types/index';\nconst applyModifiers = (name, modifiers) => {\n if (modifiers === undefined) {\n return name;\n }\n return modifiers.reduce((modifiedName, modifier) => {\n if (modifier === 'capitalize') {\n const head = modifiedName.charAt(0).toUpperCase();\n const tail = modifiedName.slice(1);\n return `${head}${tail}`;\n }\n if (modifier === 'dashify') {\n return dashify(modifiedName);\n }\n if (modifier === 'prependIndefiniteArticle') {\n return `${indefiniteArticle(modifiedName)} ${modifiedName}`;\n }\n return modifiedName;\n }, name);\n};\nconst buildRegex = (variable) => {\n const expression = variable.name + variable.modifiers.map((modifier) => `\\\\.${modifier}\\\\(\\\\)`).join('');\n return new RegExp(`\\\\$\\\\{${expression}}`, 'g');\n};\nconst preRenderString = (string, parameters) => {\n const expressionRegex = /\\${([^.}]+)((\\.[^(]+\\(\\))*)}/g;\n const variables = [];\n let expressionResult = expressionRegex.exec(string);\n while (expressionResult !== null) {\n const variable = {\n modifiers: [],\n name: expressionResult[1]\n };\n if (expressionResult[3] !== undefined) {\n const modifiersRegex = /\\.[^(]+\\(\\)/g;\n let modifiersRegexResult = modifiersRegex.exec(expressionResult[2]);\n while (modifiersRegexResult !== null) {\n variable.modifiers.push(modifiersRegexResult[0].slice(1, -2));\n modifiersRegexResult = modifiersRegex.exec(expressionResult[2]);\n }\n }\n variables.push(variable);\n expressionResult = expressionRegex.exec(string);\n }\n const preRenderedParts = variables.reduce((parts, variable) => parts\n .map((part) => {\n if (typeof part === 'string') {\n return part.split(buildRegex(variable)).reduce((prts, prt, index) => {\n if (index === 0) {\n return [prt];\n }\n if (variable.name in parameters) {\n return [...prts, applyModifiers(parameters[variable.name], variable.modifiers), prt];\n }\n return [...prts, (prmtrs) => applyModifiers(prmtrs[variable.name], variable.modifiers), prt];\n }, []);\n }\n return [part];\n })\n .reduce((prts, part) => [...prts, ...part], []), [string]);\n return (missingParameters) => preRenderedParts\n .reduce((renderedParts, preRenderedPart) => {\n if (typeof preRenderedPart === 'string') {\n return [...renderedParts, preRenderedPart];\n }\n return [...renderedParts, preRenderedPart(missingParameters)];\n }, [])\n .join('');\n};\nexport const compile = (template, knownParameters = {}) => {\n const renderCode = template.code === undefined ? undefined : preRenderString(template.code, knownParameters);\n const renderMessage = template.message === undefined ? undefined : preRenderString(template.message, knownParameters);\n function render(causeOrMissingParameters = {}, optionalCause) {\n const hasNoOptionalCause = optionalCause === undefined &&\n (causeOrMissingParameters instanceof Error ||\n (causeOrMissingParameters.code !== undefined &&\n causeOrMissingParameters.code.slice(-9) === 'Exception'));\n const { cause, missingParameters } = hasNoOptionalCause\n ? {\n cause: causeOrMissingParameters,\n missingParameters: {}\n }\n : {\n cause: optionalCause,\n missingParameters: causeOrMissingParameters\n };\n const err = ((renderMessage === undefined ? new Error() : new Error(renderMessage(missingParameters))));\n if (cause !== null) {\n err.cause = cause;\n }\n if (renderCode !== undefined) {\n err.code = renderCode(missingParameters);\n }\n if (template.status !== undefined) {\n err.status = template.status;\n }\n return err;\n }\n return render;\n};\n//# sourceMappingURL=module.js.map"],"names":["applyModifiers","name","modifiers","modifiedName","modifier","head","tail","dashify","indefiniteArticle","buildRegex","variable","expression","preRenderString","string","parameters","expressionRegex","variables","expressionResult","modifiersRegex","modifiersRegexResult","preRenderedParts","parts","part","prts","prt","index","prmtrs","missingParameters","renderedParts","preRenderedPart","compile","template","knownParameters","renderCode","renderMessage","render","causeOrMissingParameters","optionalCause","hasNoOptionalCause","cause","err"],"mappings":"waAQA,MAAMA,EAAiB,CAACC,EAAMC,IACtBA,IAAc,OACPD,EAEJC,EAAU,OAAO,CAACC,EAAcC,IAAa,CAChD,GAAIA,IAAa,aAAc,CAC3B,MAAMC,EAAOF,EAAa,OAAO,CAAC,EAA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