Add support for flow's SymbolTypeAnnotation (#11077)

This commit is contained in:
Brian Ng
2020-03-16 17:00:17 -05:00
committed by GitHub
parent 2bce1e5e20
commit 4f394e30d2
14 changed files with 291 additions and 2 deletions

View File

@@ -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 = {},

View File

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

View File

@@ -372,6 +372,10 @@ defineType("StringTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"],
});
defineType("SymbolTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"],
});
defineType("ThisTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"],
});

View File

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