From f93fa28c908cbc6170551465fd946d0bc4602285 Mon Sep 17 00:00:00 2001 From: James DiGioia Date: Fri, 6 Jul 2018 13:01:35 -0400 Subject: [PATCH] Improve error messages around pipeline option (#8279) --- .../babel-plugin-syntax-pipeline-operator/src/index.js | 9 +++++++-- packages/babel-preset-stage-0/src/index.js | 6 ++++-- packages/babel-preset-stage-1/src/index.js | 7 +++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/babel-plugin-syntax-pipeline-operator/src/index.js b/packages/babel-plugin-syntax-pipeline-operator/src/index.js index ae371a3792..9d58042b20 100644 --- a/packages/babel-plugin-syntax-pipeline-operator/src/index.js +++ b/packages/babel-plugin-syntax-pipeline-operator/src/index.js @@ -1,12 +1,17 @@ import { declare } from "@babel/helper-plugin-utils"; -const proposals = ["minimal"]; +export const proposals = ["minimal"]; export default declare((api, { proposal }) => { api.assertVersion(7); if (typeof proposal !== "string" || !proposals.includes(proposal)) { - throw new Error("'proposal' must be one of: " + proposals.join(", ")); + throw new Error( + "The pipeline operator plugin requires a 'proposal' option." + + "'proposal' must be one of: " + + proposals.join(", ") + + ". More details: https://babeljs.io/docs/en/next/babel-plugin-proposal-pipeline-operator", + ); } return { diff --git a/packages/babel-preset-stage-0/src/index.js b/packages/babel-preset-stage-0/src/index.js index b5034e4e6c..28d9dd33cc 100644 --- a/packages/babel-preset-stage-0/src/index.js +++ b/packages/babel-preset-stage-0/src/index.js @@ -2,6 +2,7 @@ import { declare } from "@babel/helper-plugin-utils"; import presetStage1 from "@babel/preset-stage-1"; import transformFunctionBind from "@babel/plugin-proposal-function-bind"; +import { proposals } from "@babel/plugin-proposal-pipeline-operator"; export default declare((api, opts = {}) => { api.assertVersion(7); @@ -38,8 +39,9 @@ export default declare((api, opts = {}) => { if (typeof pipelineProposal !== "string") { throw new Error( "The pipeline operator requires a proposal set." + - " You must pass the 'pipelineProposal' option to" + - " @babel/preset-stage-0", + " You must pass 'pipelineProposal' option to" + + " @babel/preset-stage-0 whose value must be one of: " + + proposals.join(", "), ); } diff --git a/packages/babel-preset-stage-1/src/index.js b/packages/babel-preset-stage-1/src/index.js index 12d0c64de0..2c50a12fca 100644 --- a/packages/babel-preset-stage-1/src/index.js +++ b/packages/babel-preset-stage-1/src/index.js @@ -4,7 +4,9 @@ import presetStage2 from "@babel/preset-stage-2"; import transformExportDefaultFrom from "@babel/plugin-proposal-export-default-from"; import transformLogicalAssignmentOperators from "@babel/plugin-proposal-logical-assignment-operators"; import transformOptionalChaining from "@babel/plugin-proposal-optional-chaining"; -import transformPipelineOperator from "@babel/plugin-proposal-pipeline-operator"; +import transformPipelineOperator, { + proposals, +} from "@babel/plugin-proposal-pipeline-operator"; import transformNullishCoalescingOperator from "@babel/plugin-proposal-nullish-coalescing-operator"; import transformDoExpressions from "@babel/plugin-proposal-do-expressions"; @@ -44,7 +46,8 @@ export default declare((api, opts = {}) => { throw new Error( "The pipeline operator requires a proposal set." + " You must pass 'pipelineProposal' option to" + - " @babel/preset-stage-1", + " @babel/preset-stage-1 whose value must be one of: " + + proposals.join(", "), ); }