Skip to content

Commit

Permalink
Default to hash syntax for Record&Tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jul 8, 2022
1 parent 0d87fe7 commit e1c4980
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 15 deletions.
11 changes: 7 additions & 4 deletions packages/babel-generator/src/generators/types.ts
Expand Up @@ -117,15 +117,18 @@ export function RecordExpression(this: Printer, node: t.RecordExpression) {
if (this.format.recordAndTupleSyntaxType === "bar") {
startToken = "{|";
endToken = "|}";
} else if (this.format.recordAndTupleSyntaxType === "hash") {
startToken = "#{";
endToken = "}";
} else {
} else if (
this.format.recordAndTupleSyntaxType !== "hash" &&
this.format.recordAndTupleSyntaxType != null
) {
throw new Error(
`The "recordAndTupleSyntaxType" generator option must be "bar" or "hash" (${JSON.stringify(
this.format.recordAndTupleSyntaxType,
)} received).`,
);
} else {
startToken = "#{";
endToken = "}";
}

this.token(startToken);
Expand Down

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion packages/babel-parser/src/plugin-utils.js
Expand Up @@ -185,12 +185,13 @@ export function validatePlugins(plugins: PluginList) {

if (
hasPlugin(plugins, "recordAndTuple") &&
getPluginOption(plugins, "recordAndTuple", "syntaxType") != null &&
!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(
getPluginOption(plugins, "recordAndTuple", "syntaxType"),
)
) {
throw new Error(
"'recordAndTuple' requires 'syntaxType' option whose value should be one of: " +
"The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " +
RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "),
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -519,7 +519,7 @@ export default class Tokenizer extends CommentsParser {
// which is not allowed in the spec. Throwing expecting recordAndTuple is
// misleading
this.expectPlugin("recordAndTuple");
if (this.getPluginOption("recordAndTuple", "syntaxType") !== "hash") {
if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
throw this.raise(
next === charCodes.leftCurlyBrace
? Errors.RecordExpressionHashIncorrectStartSyntaxType
Expand Down
@@ -1,4 +1,4 @@
{
"plugins": [["recordAndTuple", { "syntaxType": "invalid" }]],
"throws": "'recordAndTuple' requires 'syntaxType' option whose value should be one of: 'hash', 'bar'"
"throws": "The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: 'hash', 'bar'"
}
@@ -1,4 +1,4 @@
{
"plugins": [["recordAndTuple", { "syntaxType": "invalid" }]],
"throws": "'recordAndTuple' requires 'syntaxType' option whose value should be one of: 'hash', 'bar'"
"throws": "The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: 'hash', 'bar'"
}
@@ -1,4 +1,4 @@
{
"plugins": [["recordAndTuple", { "syntaxType": "invalid" }]],
"throws": "'recordAndTuple' requires 'syntaxType' option whose value should be one of: 'hash', 'bar'"
"throws": "The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: 'hash', 'bar'"
}
@@ -1,4 +1,4 @@
{
"plugins": [["recordAndTuple", { "syntaxType": "invalid" }]],
"throws": "'recordAndTuple' requires 'syntaxType' option whose value should be one of: 'hash', 'bar'"
"throws": "The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: 'hash', 'bar'"
}

0 comments on commit e1c4980

Please sign in to comment.