( argument: TemplateStringsArray | ParseErrorTemplates, syntaxPlugin?: SyntaxPlugin, )
| 193 | // }); |
| 194 | // |
| 195 | export function ParseErrorEnum( |
| 196 | argument: TemplateStringsArray | ParseErrorTemplates, |
| 197 | syntaxPlugin?: SyntaxPlugin, |
| 198 | ) { |
| 199 | // If the first parameter is an array, that means we were called with a tagged |
| 200 | // template literal. Extract the syntaxPlugin from this, and call again in |
| 201 | // the "normalized" form. |
| 202 | if (Array.isArray(argument)) { |
| 203 | return (parseErrorTemplates: ParseErrorTemplates) => |
| 204 | ParseErrorEnum(parseErrorTemplates, argument[0]); |
| 205 | } |
| 206 | |
| 207 | const ParseErrorConstructors = {} as Record< |
| 208 | string, |
| 209 | ParseErrorConstructor<unknown> |
| 210 | >; |
| 211 | |
| 212 | for (const reasonCode of Object.keys(argument)) { |
| 213 | const template = (argument as ParseErrorTemplates)[reasonCode]; |
| 214 | const { message, ...rest } = |
| 215 | typeof template === "string" |
| 216 | ? { message: () => template } |
| 217 | : typeof template === "function" |
| 218 | ? { message: template } |
| 219 | : template; |
| 220 | const toMessage = typeof message === "string" ? () => message : message; |
| 221 | |
| 222 | ParseErrorConstructors[reasonCode] = toParseErrorConstructor({ |
| 223 | code: "BABEL_PARSER_SYNTAX_ERROR", |
| 224 | reasonCode, |
| 225 | toMessage, |
| 226 | ...(syntaxPlugin ? { syntaxPlugin } : {}), |
| 227 | ...rest, |
| 228 | }); |
| 229 | } |
| 230 | |
| 231 | return ParseErrorConstructors; |
| 232 | } |
| 233 | |
| 234 | import ModuleErrors from "./parse-error/module-errors.ts"; |
| 235 | import StandardErrors from "./parse-error/standard-errors.ts"; |
no test coverage detected