Skip to content

Commit

Permalink
updated error messages for invalid parser syntaxType option
Browse files Browse the repository at this point in the history
  • Loading branch information
rickbutton committed Jan 15, 2020
1 parent 2ddfcd0 commit 7686bf4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/babel-generator/src/generators/types.js
Expand Up @@ -119,7 +119,7 @@ export function RecordExpression(node: Object) {
endToken = "}";
} else {
throw new Error(
`The "recordAndTupleSyntaxType" generator option must be either "bar" or "hash" (${JSON.stringify(
`The "recordAndTupleSyntaxType" generator option must be "bar" or "hash" (${JSON.stringify(
this.format.recordAndTupleSyntaxType,
)} received).`,
);
Expand Down
13 changes: 13 additions & 0 deletions packages/babel-parser/src/plugin-utils.js
Expand Up @@ -39,6 +39,7 @@ export function getPluginOption(
}

const PIPELINE_PROPOSALS = ["minimal", "smart", "fsharp"];
const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];

export function validatePlugins(plugins: PluginList) {
if (hasPlugin(plugins, "decorators")) {
Expand Down Expand Up @@ -84,6 +85,18 @@ export function validatePlugins(plugins: PluginList) {
PIPELINE_PROPOSALS.map(p => `'${p}'`).join(", "),
);
}

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

// These plugins are defined using a mixin which extends the parser class.
Expand Down
@@ -1,4 +1,4 @@
{
"plugins": [["recordAndTuple", { "syntaxType": "invalid" }]],
"throws": "Unexpected token (1:1)"
"throws": "'recordAndTuple' requires 'syntaxType' option whose value should be one of: 'hash', 'bar'"
}
@@ -1,4 +1,4 @@
{
"plugins": [["recordAndTuple", { "syntaxType": "invalid" }]],
"throws": "Unexpected token (1:1)"
"throws": "'recordAndTuple' requires 'syntaxType' option whose value should be one of: 'hash', 'bar'"
}
@@ -1,4 +1,4 @@
{
"plugins": [["recordAndTuple", { "syntaxType": "invalid" }]],
"throws": "Unexpected character '#' (1:0)"
"throws": "'recordAndTuple' requires 'syntaxType' option whose value should be one of: 'hash', 'bar'"
}
@@ -1,4 +1,4 @@
{
"plugins": [["recordAndTuple", { "syntaxType": "invalid" }]],
"throws": "Unexpected character '#' (1:0)"
"throws": "'recordAndTuple' requires 'syntaxType' option whose value should be one of: 'hash', 'bar'"
}

0 comments on commit 7686bf4

Please sign in to comment.