-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ParseError much simpler now that we can use TypeScript (#14796)
- Loading branch information
Showing
10 changed files
with
707 additions
and
883 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { ParseErrorCodes, toParseErrorCredentials } from "../parse-error"; | ||
import { ParseErrorCode } from "../parse-error"; | ||
|
||
export default (_: typeof toParseErrorCredentials) => ({ | ||
ImportMetaOutsideModule: _( | ||
`import.meta may appear only with 'sourceType: "module"'`, | ||
{ code: ParseErrorCodes.SourceTypeModuleError }, | ||
), | ||
ImportOutsideModule: _( | ||
`'import' and 'export' may appear only with 'sourceType: "module"'`, | ||
{ code: ParseErrorCodes.SourceTypeModuleError }, | ||
), | ||
}); | ||
export default { | ||
ImportMetaOutsideModule: { | ||
message: `import.meta may appear only with 'sourceType: "module"'`, | ||
code: ParseErrorCode.SourceTypeModuleError, | ||
}, | ||
ImportOutsideModule: { | ||
message: `'import' and 'export' may appear only with 'sourceType: "module"'`, | ||
code: ParseErrorCode.SourceTypeModuleError, | ||
}, | ||
}; |
68 changes: 28 additions & 40 deletions
68
packages/babel-parser/src/parse-error/pipeline-operator-errors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,51 @@ | ||
import { toParseErrorCredentials } from "../parse-error"; | ||
import toNodeDescription from "./to-node-description"; | ||
|
||
const UnparenthesizedPipeBodyDescriptionsList = [ | ||
export const UnparenthesizedPipeBodyDescriptions = new Set([ | ||
"ArrowFunctionExpression", | ||
"AssignmentExpression", | ||
"ConditionalExpression", | ||
"YieldExpression", | ||
] as const; | ||
export const UnparenthesizedPipeBodyDescriptions = new Set( | ||
UnparenthesizedPipeBodyDescriptionsList, | ||
); | ||
] as const); | ||
|
||
export default (_: typeof toParseErrorCredentials) => ({ | ||
type GetSetMemberType<T extends Set<any>> = T extends Set<infer M> | ||
? M | ||
: unknown; | ||
|
||
type UnparanthesizedPipeBodyTypes = GetSetMemberType< | ||
typeof UnparenthesizedPipeBodyDescriptions | ||
>; | ||
|
||
export default { | ||
// This error is only used by the smart-mix proposal | ||
PipeBodyIsTighter: _( | ||
PipeBodyIsTighter: | ||
"Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.", | ||
), | ||
PipeTopicRequiresHackPipes: _( | ||
PipeTopicRequiresHackPipes: | ||
'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.', | ||
), | ||
PipeTopicUnbound: _( | ||
PipeTopicUnbound: | ||
"Topic reference is unbound; it must be inside a pipe body.", | ||
), | ||
PipeTopicUnconfiguredToken: _<{ token: string }>( | ||
({ token }) => | ||
`Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`, | ||
), | ||
PipeTopicUnused: _( | ||
PipeTopicUnconfiguredToken: ({ token }: { token: string }) => | ||
`Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`, | ||
PipeTopicUnused: | ||
"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.", | ||
), | ||
PipeUnparenthesizedBody: _<{ | ||
type: typeof UnparenthesizedPipeBodyDescriptionsList[number]; | ||
}>( | ||
({ type }) => | ||
`Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({ | ||
type, | ||
})}; please wrap it in parentheses.`, | ||
), | ||
PipeUnparenthesizedBody: ({ type }: { type: UnparanthesizedPipeBodyTypes }) => | ||
`Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({ | ||
type, | ||
})}; please wrap it in parentheses.`, | ||
|
||
// Messages whose codes start with “Pipeline” or “PrimaryTopic” | ||
// are retained for backwards compatibility | ||
// with the deprecated smart-mix pipe operator proposal plugin. | ||
// They are subject to removal in a future major version. | ||
PipelineBodyNoArrow: _( | ||
PipelineBodyNoArrow: | ||
'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.', | ||
), | ||
PipelineBodySequenceExpression: _( | ||
PipelineBodySequenceExpression: | ||
"Pipeline body may not be a comma-separated sequence expression.", | ||
), | ||
PipelineHeadSequenceExpression: _( | ||
PipelineHeadSequenceExpression: | ||
"Pipeline head should not be a comma-separated sequence expression.", | ||
), | ||
PipelineTopicUnused: _( | ||
PipelineTopicUnused: | ||
"Pipeline is in topic style but does not use topic reference.", | ||
), | ||
PrimaryTopicNotAllowed: _( | ||
PrimaryTopicNotAllowed: | ||
"Topic reference was used in a lexical context without topic binding.", | ||
), | ||
PrimaryTopicRequiresSmartPipeline: _( | ||
PrimaryTopicRequiresSmartPipeline: | ||
'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.', | ||
), | ||
}); | ||
}; |
Oops, something went wrong.