Skip to content

Commit

Permalink
Change new error messages to match consistent Babel style
Browse files Browse the repository at this point in the history
  • Loading branch information
js-choi committed Apr 9, 2021
1 parent da02613 commit 9a16589
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 31 deletions.
8 changes: 4 additions & 4 deletions packages/babel-parser/src/parser/error-message.js
Expand Up @@ -130,13 +130,13 @@ export const ErrorMessages = Object.freeze({
PatternHasAccessor: "Object pattern can't contain getter or setter",
PatternHasMethod: "Object pattern can't contain methods",
PipeBodyCannotBeArrow:
'Unexpected arrow "=>" after pipeline body; arrow function acting as pipe body must be parenthesized due to operator precedence',
'Unexpected arrow "=>" after pipeline body; arrow function acting as pipe body must be parenthesized due to operator precedence.',
PipeTopicRequiresHackPipes:
"Topic reference is used, but the pipelineOperator plugin was not passed a 'proposal': 'hack' option.",
'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" option.',
PipeTopicUnbound:
"Topic reference is unbound; it must be inside a Hack-style pipe body",
"Topic reference is unbound; it must be inside a Hack-style pipe body.",
PipeTopicUnused:
"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once",
"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
PrivateInExpectedIn:
"Private names are only allowed in property accesses (`obj.#%0`) or in `in` expressions (`#%0 in obj`)",
PrivateNameRedeclaration: "Duplicate private name #%0",
Expand Down
20 changes: 10 additions & 10 deletions packages/babel-parser/src/plugin-utils.js
Expand Up @@ -74,16 +74,16 @@ export function validatePlugins(plugins: PluginList) {
throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
}

if (
hasPlugin(plugins, "pipelineOperator") &&
!PIPELINE_PROPOSALS.includes(
getPluginOption(plugins, "pipelineOperator", "proposal"),
)
) {
throw new Error(
"'pipelineOperator' requires 'proposal' option whose value should be one of: " +
PIPELINE_PROPOSALS.map(p => `'${p}'`).join(", "),
);
if (hasPlugin(plugins, "pipelineOperator")) {
const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");

if (!PIPELINE_PROPOSALS.includes(proposal)) {
throw new Error(
`"pipelineOperator" requires "proposal" option whose value must be one of: ${PIPELINE_PROPOSALS.map(
p => `"${p}"`,
).join(", ")}.`,
);
}
}

if (hasPlugin(plugins, "moduleAttributes")) {
Expand Down
Expand Up @@ -2,8 +2,8 @@
"type": "File",
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
"errors": [
"SyntaxError: Topic reference is used, but the pipelineOperator plugin was not passed a 'proposal': 'hack' option. (1:5)",
"SyntaxError: Topic reference is unbound; it must be inside a Hack-style pipe body (1:5)"
"SyntaxError: Topic reference is used, but the pipelineOperator plugin was not passed a \"proposal\": \"hack\" option. (1:5)",
"SyntaxError: Topic reference is unbound; it must be inside a Hack-style pipe body. (1:5)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:9)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:9)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -5,7 +5,8 @@
{
"proposal": "hack"
}
]
],
"estree"
],
"throws": "Unexpected arrow \"=>\" after pipeline body; arrow function acting as pipe body must be parenthesized due to operator precedence (1:8)"
"throws": "Unexpected arrow \"=>\" after pipeline body; arrow function acting as pipe body must be parenthesized due to operator precedence. (1:8)"
}
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:9)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:9)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:9)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:9)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:16)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:16)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:5)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:5)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:11)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:11)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,8 +2,8 @@
"type": "File",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:11)",
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:5)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:11)",
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:5)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:9)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:9)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},
"errors": [
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:9)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:9)"
],
"program": {
"type": "Program",
Expand Down
@@ -1,4 +1,12 @@
{
"plugins": [["pipelineOperator", { "proposal": "invalid" }]],
"throws": "'pipelineOperator' requires 'proposal' option whose value should be one of: 'minimal', 'fsharp', 'hack'"
}
"plugins": [
[
"pipelineOperator",
{
"proposal": "invalid"
}
],
"estree"
],
"throws": "\"pipelineOperator\" requires \"proposal\" option whose value must be one of: \"minimal\", \"fsharp\", \"hack\"."
}

0 comments on commit 9a16589

Please sign in to comment.