Improve error messages around pipeline option (#8279)

This commit is contained in:
James DiGioia
2018-07-06 13:01:35 -04:00
committed by Henry Zhu
parent 430a105ae7
commit f93fa28c90
3 changed files with 16 additions and 6 deletions

View File

@@ -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 {

View File

@@ -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(", "),
);
}

View File

@@ -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(", "),
);
}