Add support for flow's SymbolTypeAnnotation (#11077)
This commit is contained in:
@@ -524,6 +524,12 @@ export function assertStringTypeAnnotation(
|
||||
): void {
|
||||
assert("StringTypeAnnotation", node, opts);
|
||||
}
|
||||
export function assertSymbolTypeAnnotation(
|
||||
node: Object,
|
||||
opts?: Object = {},
|
||||
): void {
|
||||
assert("SymbolTypeAnnotation", node, opts);
|
||||
}
|
||||
export function assertThisTypeAnnotation(
|
||||
node: Object,
|
||||
opts?: Object = {},
|
||||
|
||||
@@ -469,6 +469,10 @@ export function StringTypeAnnotation(...args: Array<any>): Object {
|
||||
return builder("StringTypeAnnotation", ...args);
|
||||
}
|
||||
export { StringTypeAnnotation as stringTypeAnnotation };
|
||||
export function SymbolTypeAnnotation(...args: Array<any>): Object {
|
||||
return builder("SymbolTypeAnnotation", ...args);
|
||||
}
|
||||
export { SymbolTypeAnnotation as symbolTypeAnnotation };
|
||||
export function ThisTypeAnnotation(...args: Array<any>): Object {
|
||||
return builder("ThisTypeAnnotation", ...args);
|
||||
}
|
||||
|
||||
@@ -372,6 +372,10 @@ defineType("StringTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"],
|
||||
});
|
||||
|
||||
defineType("SymbolTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"],
|
||||
});
|
||||
|
||||
defineType("ThisTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"],
|
||||
});
|
||||
|
||||
@@ -1692,6 +1692,20 @@ export function isStringTypeAnnotation(node: ?Object, opts?: Object): boolean {
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isSymbolTypeAnnotation(node: ?Object, opts?: Object): boolean {
|
||||
if (!node) return false;
|
||||
|
||||
const nodeType = node.type;
|
||||
if (nodeType === "SymbolTypeAnnotation") {
|
||||
if (typeof opts === "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return shallowEqual(node, opts);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isThisTypeAnnotation(node: ?Object, opts?: Object): boolean {
|
||||
if (!node) return false;
|
||||
|
||||
@@ -4270,6 +4284,7 @@ export function isFlow(node: ?Object, opts?: Object): boolean {
|
||||
"QualifiedTypeIdentifier" === nodeType ||
|
||||
"StringLiteralTypeAnnotation" === nodeType ||
|
||||
"StringTypeAnnotation" === nodeType ||
|
||||
"SymbolTypeAnnotation" === nodeType ||
|
||||
"ThisTypeAnnotation" === nodeType ||
|
||||
"TupleTypeAnnotation" === nodeType ||
|
||||
"TypeofTypeAnnotation" === nodeType ||
|
||||
@@ -4316,6 +4331,7 @@ export function isFlowType(node: ?Object, opts?: Object): boolean {
|
||||
"ObjectTypeAnnotation" === nodeType ||
|
||||
"StringLiteralTypeAnnotation" === nodeType ||
|
||||
"StringTypeAnnotation" === nodeType ||
|
||||
"SymbolTypeAnnotation" === nodeType ||
|
||||
"ThisTypeAnnotation" === nodeType ||
|
||||
"TupleTypeAnnotation" === nodeType ||
|
||||
"TypeofTypeAnnotation" === nodeType ||
|
||||
@@ -4344,6 +4360,7 @@ export function isFlowBaseAnnotation(node: ?Object, opts?: Object): boolean {
|
||||
"EmptyTypeAnnotation" === nodeType ||
|
||||
"NumberTypeAnnotation" === nodeType ||
|
||||
"StringTypeAnnotation" === nodeType ||
|
||||
"SymbolTypeAnnotation" === nodeType ||
|
||||
"ThisTypeAnnotation" === nodeType ||
|
||||
"VoidTypeAnnotation" === nodeType
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user