Skip to content

Commit

Permalink
babel-types for typescript assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Oct 16, 2019
1 parent 1991a7e commit 637bdbc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/babel-types/src/asserts/generated/index.js
Expand Up @@ -836,6 +836,9 @@ export function assertTSUnknownKeyword(node: Object, opts?: Object = {}): void {
export function assertTSVoidKeyword(node: Object, opts?: Object = {}): void {
assert("TSVoidKeyword", node, opts);
}
export function assertTSAssertsKeyword(node: Object, opts?: Object = {}): void {
assert("TSAssertsKeyword", node, opts);
}
export function assertTSThisType(node: Object, opts?: Object = {}): void {
assert("TSThisType", node, opts);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/babel-types/src/builders/generated/index.js
Expand Up @@ -781,6 +781,11 @@ export function TSVoidKeyword(...args: Array<any>): Object {
}
export { TSVoidKeyword as tsVoidKeyword };
export { TSVoidKeyword as tSVoidKeyword };
export function TSAssertsKeyword(...args: Array<any>): Object {
return builder("TSAssertsKeyword", ...args);
}
export { TSAssertsKeyword as tsAssertsKeyword };
export { TSAssertsKeyword as tSAssertsKeyword };
export function TSThisType(...args: Array<any>): Object {
return builder("TSThisType", ...args);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-types/src/definitions/typescript.js
Expand Up @@ -180,7 +180,7 @@ defineType("TSTypePredicate", {
fields: {
assertsModifier: validateOptionalType("TSAssertsKeyword"),
parameterName: validateType(["Identifier", "TSThisType"]),
typeAnnotation: validateType("TSTypeAnnotation"),
typeAnnotation: validateOptionalType("TSTypeAnnotation"),
},
});

Expand Down
15 changes: 15 additions & 0 deletions packages/babel-types/src/validators/generated/index.js
Expand Up @@ -2691,6 +2691,20 @@ export function isTSVoidKeyword(node: ?Object, opts?: Object): boolean {

return false;
}
export function isTSAssertsKeyword(node: ?Object, opts?: Object): boolean {
if (!node) return false;

const nodeType = node.type;
if (nodeType === "TSAssertsKeyword") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}

return false;
}
export function isTSThisType(node: ?Object, opts?: Object): boolean {
if (!node) return false;

Expand Down Expand Up @@ -4365,6 +4379,7 @@ export function isTSType(node: ?Object, opts?: Object): boolean {
"TSUndefinedKeyword" === nodeType ||
"TSUnknownKeyword" === nodeType ||
"TSVoidKeyword" === nodeType ||
"TSAssertsKeyword" === nodeType ||
"TSThisType" === nodeType ||
"TSFunctionType" === nodeType ||
"TSConstructorType" === nodeType ||
Expand Down

0 comments on commit 637bdbc

Please sign in to comment.