From 374b063858a23235961f98c594a124d4308cc6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 10 Oct 2021 12:14:37 +0200 Subject: [PATCH] Update error message --- packages/babel-generator/src/generators/types.ts | 7 +++++-- .../TopicReference-with-invalid-topicToken/options.json | 2 +- .../TopicReference-with-missing-topicToken/options.json | 2 +- .../hack-caret/pipe-body-with-arrow-function/output.js | 3 ++- .../fixtures/hack-caret/pipe-in-arrow-function/output.js | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/babel-generator/src/generators/types.ts b/packages/babel-generator/src/generators/types.ts index c51cad9b303e..b75f5cba5916 100644 --- a/packages/babel-generator/src/generators/types.ts +++ b/packages/babel-generator/src/generators/types.ts @@ -246,8 +246,11 @@ export function TopicReference(this: Printer) { this.token(topicToken); } else { const givenTopicTokenJSON = JSON.stringify(topicToken); - const message = `The "topicToken" generator option must be "#" (${givenTopicTokenJSON} received instead).`; - throw new Error(message); + const validTopics = Array.from(validTopicTokenSet, v => JSON.stringify(v)); + throw new Error( + `The "topicToken" generator option must be one of ` + + `${validTopics.join(", ")} (${givenTopicTokenJSON} received instead).`, + ); } } diff --git a/packages/babel-generator/test/fixtures/types/TopicReference-with-invalid-topicToken/options.json b/packages/babel-generator/test/fixtures/types/TopicReference-with-invalid-topicToken/options.json index 4b1203dd72d8..3ef07c59571f 100644 --- a/packages/babel-generator/test/fixtures/types/TopicReference-with-invalid-topicToken/options.json +++ b/packages/babel-generator/test/fixtures/types/TopicReference-with-invalid-topicToken/options.json @@ -1,5 +1,5 @@ { "plugins": [["pipelineOperator", { "proposal": "hack", "topicToken": "#" }]], "topicToken": "invalid", - "throws": "The \"topicToken\" generator option must be \"#\" (\"invalid\" received instead)." + "throws": "The \"topicToken\" generator option must be one of \"^\", \"%\", \"#\" (\"invalid\" received instead)." } diff --git a/packages/babel-generator/test/fixtures/types/TopicReference-with-missing-topicToken/options.json b/packages/babel-generator/test/fixtures/types/TopicReference-with-missing-topicToken/options.json index 9e4d884dbf7f..1911353dc052 100644 --- a/packages/babel-generator/test/fixtures/types/TopicReference-with-missing-topicToken/options.json +++ b/packages/babel-generator/test/fixtures/types/TopicReference-with-missing-topicToken/options.json @@ -1,4 +1,4 @@ { "plugins": [["pipelineOperator", { "proposal": "hack", "topicToken": "#" }]], - "throws": "The \"topicToken\" generator option must be \"#\" (undefined received instead)." + "throws": "The \"topicToken\" generator option must be one of \"^\", \"%\", \"#\" (undefined received instead)." } diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-arrow-function/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-arrow-function/output.js index fb4695950f6c..5def3730d465 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-arrow-function/output.js +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-arrow-function/output.js @@ -2,6 +2,7 @@ var _ref, _ref2, _ref3; const result = (_ref3 = -2.2 // -2.2 , (_ref2 = Math.floor(_ref3) // -3 -, (_ref = () => Math.pow(_ref2, 5), _ref()))); // -243 +, (_ref = () => Math.pow(_ref2, 5) // () => -243 +, _ref()))); // -243 expect(result).toBe(-243); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-in-arrow-function/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-in-arrow-function/output.js index 99d111d1d55e..66106a985d16 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-in-arrow-function/output.js +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-in-arrow-function/output.js @@ -3,7 +3,8 @@ const result = () => { return _ref3 = -2.2 // -2.2 , (_ref2 = Math.floor(_ref3) // -3 - , (_ref = () => Math.pow(_ref2, 5), _ref())); + , (_ref = () => Math.pow(_ref2, 5) // () => -243 + , _ref())); }; // -243