MCPcopy Create free account
hub / github.com/babel/babel / ParseErrorEnum

Function ParseErrorEnum

packages/babel-parser/src/parse-error.ts:195–232  ·  view source on GitHub ↗
(
  argument: TemplateStringsArray | ParseErrorTemplates,
  syntaxPlugin?: SyntaxPlugin,
)

Source from the content-addressed store, hash-verified

193// });
194//
195export 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
234import ModuleErrors from "./parse-error/module-errors.ts";
235import StandardErrors from "./parse-error/standard-errors.ts";

Callers 5

placeholders.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
parse-error.tsFile · 0.85

Calls 1

toParseErrorConstructorFunction · 0.85

Tested by

no test coverage detected