Skip to content

Commit

Permalink
errors
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Oct 31, 2023
1 parent cbd7bd8 commit c8b3fc8
Show file tree
Hide file tree
Showing 18 changed files with 616 additions and 728 deletions.
27 changes: 8 additions & 19 deletions packages/babel-parser/src/parse-error.ts
@@ -1,6 +1,4 @@
import { Position } from "./util/location.ts";
import type { Undone } from "./parser/node.ts";
import type { Node } from "./types.ts";

type SyntaxPlugin =
| "flow"
Expand Down Expand Up @@ -46,10 +44,10 @@ export type ParseError<ErrorDetails> = SyntaxError &
// separate classes from `SyntaxError`'s.
//
// 1. https://github.com/microsoft/TypeScript/blob/v4.5.5/lib/lib.es5.d.ts#L1027
export type ParseErrorConstructor<ErrorDetails> = (a: {
loc: Position;
details: ErrorDetails;
}) => ParseError<ErrorDetails>;
export type ParseErrorConstructor<ErrorDetails> = (
loc: Position,
details: ErrorDetails,
) => ParseError<ErrorDetails>;

type ToMessage<ErrorDetails> = (self: ErrorDetails) => string;

Expand All @@ -72,12 +70,7 @@ function toParseErrorConstructor<ErrorDetails extends object>({
toMessage,
...properties
}: ParseErrorCredentials<ErrorDetails>): ParseErrorConstructor<ErrorDetails> {
type ConstructorArgument = {
loc: Position;
details: ErrorDetails;
};

return function constructor({ loc, details }: ConstructorArgument) {
return function constructor(loc: Position, details: ErrorDetails) {
const error = new SyntaxError();
Object.assign(error, properties, { loc, pos: loc.index });
if ("missingPlugin" in details) {
Expand All @@ -90,9 +83,9 @@ function toParseErrorConstructor<ErrorDetails extends object>({
};
defineHidden(error, "clone", function clone(overrides: Overrides = {}) {
const { line, column, index } = overrides.loc ?? loc;
return constructor({
loc: new Position(line, column, index),
details: { ...details, ...overrides.details },
return constructor(new Position(line, column, index), {
...details,
...overrides.details,
});
});

Expand Down Expand Up @@ -216,10 +209,6 @@ export function ParseErrorEnum(
return ParseErrorConstructors;
}

export type RaiseProperties<ErrorDetails> = {
at: Position | Undone<Node>;
} & ErrorDetails;

import ModuleErrors from "./parse-error/module-errors.ts";
import StandardErrors from "./parse-error/standard-errors.ts";
import StrictModeErrors from "./parse-error/strict-mode-errors.ts";
Expand Down
Expand Up @@ -12,7 +12,7 @@ type GetSetMemberType<T extends Set<any>> = T extends Set<infer M>
? M
: unknown;

type UnparenthesizedPipeBodyTypes = GetSetMemberType<
export type UnparenthesizedPipeBodyTypes = GetSetMemberType<
typeof UnparenthesizedPipeBodyDescriptions
>;

Expand Down
3 changes: 3 additions & 0 deletions packages/babel-parser/src/parser/base.ts
Expand Up @@ -34,6 +34,9 @@ export default class BaseParser {
// not want to ever copy them, which happens if state gets cloned
declare input: string;
declare length: number;
declare chars: Int8Array;
declare chars2: number[];
declare data: Int32Array;
// Comment store for Program.comments
declare comments: Array<N.Comment>;

Expand Down

0 comments on commit c8b3fc8

Please sign in to comment.