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
A minor change to make this less verbose.
Reviewed by @tolmasky.
  • Loading branch information
tolmasky committed Jul 25, 2022
commit 9ed5f69342dd941660717547d0be1e984c46c140
4 changes: 2 additions & 2 deletions packages/babel-parser/src/parse-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function toParseErrorConstructor<ErrorDetails>({
};

return function constructor({ loc, details }: ConstructorArgument) {
return instantiate<SyntaxError, ParseError<ErrorDetails>>(
return instantiate(
SyntaxError,
{ ...properties, loc },
{
Expand Down Expand Up @@ -97,7 +97,7 @@ function toParseErrorConstructor<ErrorDetails>({
enumerable: true,
},
},
);
) as ParseError<ErrorDetails>;
};
}

Expand Down
6 changes: 3 additions & 3 deletions packages/babel-parser/src/parse-error/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const reflect = (keys: string[], last = keys.length - 1) => ({
},
});

const instantiate = <T, U extends T>(
constructor: new () => T,
const instantiate = (
constructor: new () => unknown,
properties: any,
descriptors: any,
) =>
Expand All @@ -59,7 +59,7 @@ const instantiate = <T, U extends T>(
configurable: true,
...descriptor,
}),
Object.assign(new constructor() as U, properties),
Object.assign(new constructor(), properties),
);

export { instantiate };