fix(parser): [Babel8] Align error codes between Flow and TypeScript (#13294)

* Align error codes between Flow and TypeScript

* Implement compat fallback in makeErrorTemplates

* Add tests
This commit is contained in:
Sosuke Suzuki
2021-08-28 22:41:54 +09:00
committed by GitHub
parent 38d70e2da9
commit 64d116bd6a
5 changed files with 40 additions and 3 deletions

View File

@@ -99,7 +99,7 @@ const FlowErrors = makeErrorTemplates(
"`declare module` cannot be used inside another `declare module`.",
NestedFlowComment:
"Cannot have a flow comment inside another flow comment.",
OptionalBindingPattern:
PatternIsOptional:
"A binding pattern parameter cannot be optional in an implementation signature.",
SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
SpreadVariance: "Spread properties cannot have variance.",
@@ -137,6 +137,7 @@ const FlowErrors = makeErrorTemplates(
UnterminatedFlowComment: "Unterminated flow-comment.",
},
/* code */ ErrorCodes.SyntaxError,
/* syntaxPlugin */ "flow",
);
/* eslint-disable sort-keys */
@@ -2532,7 +2533,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
parseAssignableListItemTypes(param: N.Pattern): N.Pattern {
if (this.eat(tt.question)) {
if (param.type !== "Identifier") {
this.raise(param.start, FlowErrors.OptionalBindingPattern);
this.raise(param.start, FlowErrors.PatternIsOptional);
}
if (this.isThisParam(param)) {
this.raise(param.start, FlowErrors.ThisParamMayNotBeOptional);

View File

@@ -40,6 +40,7 @@ const JsxErrors = makeErrorTemplates(
"Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?",
},
/* code */ ErrorCodes.SyntaxError,
/* syntaxPlugin */ "jsx",
);
/* eslint-disable sort-keys */

View File

@@ -156,6 +156,7 @@ const TSErrors = makeErrorTemplates(
"Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got %0.",
},
/* code */ ErrorCodes.SyntaxError,
/* syntaxPlugin */ "typescript",
);
/* eslint-disable sort-keys */