Added support for record and tuple syntax. (#10865)
* Added support for record and tuple syntax.
This commit adds support for both the hash #{} and bar {||}
syntaxes to babel-parser, as well as adds the supporting
babel-plugin-syntax-record-and-tuple plugin to enable support
for the syntax. Does not include any transform for records and
tuples.
* typo
* added check to ensure recordAndTuple in babel-parser
* switched to syntaxType option instead of explicit entries for each record and tuple type
* switched to using recordAndTupleSyntaxType for generator options instead of adding to node
* added tests for generator option recordAndTupleSyntaxType
* added test for record and tuple bar syntax with flow typings
* added tests for invalid/missing recordAndTuple syntaxType parser option
* fixed flowcheck errors
* fix merge with class privates in tokenizer
* Update packages/babel-parser/src/types.js
Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
* improved recordAndTuple generator error message, added tests for invalid,missing options
* updated error messages for invalid parser syntaxType option
* updated error message
* added better error messages for when the recordAndTuple syntaxType is doesn't match the syntax used
* updated record and tuple support to use new error message templates
* added recordAndTuple to missing plugin helpers
* Fix linting
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
@@ -791,6 +791,12 @@ export function assertPrivateName(node: Object, opts?: Object = {}): void {
|
||||
export function assertBigIntLiteral(node: Object, opts?: Object = {}): void {
|
||||
assert("BigIntLiteral", node, opts);
|
||||
}
|
||||
export function assertRecordExpression(node: Object, opts?: Object = {}): void {
|
||||
assert("RecordExpression", node, opts);
|
||||
}
|
||||
export function assertTupleExpression(node: Object, opts?: Object = {}): void {
|
||||
assert("TupleExpression", node, opts);
|
||||
}
|
||||
export function assertTSParameterProperty(
|
||||
node: Object,
|
||||
opts?: Object = {},
|
||||
|
||||
@@ -716,6 +716,14 @@ export function BigIntLiteral(...args: Array<any>): Object {
|
||||
return builder("BigIntLiteral", ...args);
|
||||
}
|
||||
export { BigIntLiteral as bigIntLiteral };
|
||||
export function RecordExpression(...args: Array<any>): Object {
|
||||
return builder("RecordExpression", ...args);
|
||||
}
|
||||
export { RecordExpression as recordExpression };
|
||||
export function TupleExpression(...args: Array<any>): Object {
|
||||
return builder("TupleExpression", ...args);
|
||||
}
|
||||
export { TupleExpression as tupleExpression };
|
||||
export function TSParameterProperty(...args: Array<any>): Object {
|
||||
return builder("TSParameterProperty", ...args);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import defineType, {
|
||||
assertEach,
|
||||
assertNodeType,
|
||||
assertNodeOrValueType,
|
||||
assertValueType,
|
||||
chain,
|
||||
} from "./utils";
|
||||
@@ -276,3 +277,34 @@ defineType("BigIntLiteral", {
|
||||
},
|
||||
aliases: ["Expression", "Pureish", "Literal", "Immutable"],
|
||||
});
|
||||
|
||||
defineType("RecordExpression", {
|
||||
visitor: ["properties"],
|
||||
aliases: ["Expression"],
|
||||
fields: {
|
||||
properties: {
|
||||
validate: chain(
|
||||
assertValueType("array"),
|
||||
assertEach(
|
||||
assertNodeType("ObjectProperty", "ObjectMethod", "SpreadElement"),
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
defineType("TupleExpression", {
|
||||
fields: {
|
||||
elements: {
|
||||
validate: chain(
|
||||
assertValueType("array"),
|
||||
assertEach(
|
||||
assertNodeOrValueType("null", "Expression", "SpreadElement"),
|
||||
),
|
||||
),
|
||||
default: [],
|
||||
},
|
||||
},
|
||||
visitor: ["elements"],
|
||||
aliases: ["Expression"],
|
||||
});
|
||||
|
||||
@@ -2531,6 +2531,34 @@ export function isBigIntLiteral(node: ?Object, opts?: Object): boolean {
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isRecordExpression(node: ?Object, opts?: Object): boolean {
|
||||
if (!node) return false;
|
||||
|
||||
const nodeType = node.type;
|
||||
if (nodeType === "RecordExpression") {
|
||||
if (typeof opts === "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return shallowEqual(node, opts);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isTupleExpression(node: ?Object, opts?: Object): boolean {
|
||||
if (!node) return false;
|
||||
|
||||
const nodeType = node.type;
|
||||
if (nodeType === "TupleExpression") {
|
||||
if (typeof opts === "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return shallowEqual(node, opts);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isTSParameterProperty(node: ?Object, opts?: Object): boolean {
|
||||
if (!node) return false;
|
||||
|
||||
@@ -3460,6 +3488,8 @@ export function isExpression(node: ?Object, opts?: Object): boolean {
|
||||
"Import" === nodeType ||
|
||||
"DoExpression" === nodeType ||
|
||||
"BigIntLiteral" === nodeType ||
|
||||
"RecordExpression" === nodeType ||
|
||||
"TupleExpression" === nodeType ||
|
||||
"TSAsExpression" === nodeType ||
|
||||
"TSTypeAssertion" === nodeType ||
|
||||
"TSNonNullExpression" === nodeType ||
|
||||
|
||||
Reference in New Issue
Block a user