Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ParseError Much Simpler now that we can use TypeScript #14796

Merged
merged 8 commits into from
Jul 25, 2022
Prev Previous commit
Next Next commit
Add a comment explaining why we inline the type definition instead of…
… factoring it out.

Reviewed by @tolmasky.
  • Loading branch information
tolmasky committed Jul 25, 2022
commit b8ed13b839f98f443dcfa01708ee110d63d9ee07
7 changes: 7 additions & 0 deletions packages/babel-parser/src/parse-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ type ParseErrorTemplate =

type ParseErrorTemplates = { [reasonCode: string]: ParseErrorTemplate };

// This is the templated form of `ParseErrorEnum`.
//
// Note: We could factor out the return type calculation into something like
// `ParseErrorConstructor<T extends ParseErrorTemplates>`, and then we could
// reuse it in the non-templated form of `ParseErrorEnum`, but TypeScript
// doesn't seem to drill down that far when showing you the computed type of
// an object in an editor, so we'll leave it inlined for now.
export function ParseErrorEnum(a: TemplateStringsArray): <
T extends ParseErrorTemplates,
>(
Expand Down