Skip to content

Commit

Permalink
babel-generator for typescript assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Oct 16, 2019
1 parent 5c86f68 commit 1991a7e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/babel-generator/src/generators/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ export function TSNullKeyword() {
export function TSNeverKeyword() {
this.word("never");
}
export function TSAssertsKeyword() {
this.word("asserts");
}

export function TSThisType() {
this.word("this");
Expand Down Expand Up @@ -197,11 +200,17 @@ export function TSTypeReference(node) {
}

export function TSTypePredicate(node) {
if (node.assertsModifier) {
this.print(node.assertsModifier);
this.space();
}
this.print(node.parameterName);
this.space();
this.word("is");
this.space();
this.print(node.typeAnnotation.typeAnnotation);
if (node.typeAnnotation) {
this.space();
this.word("is");
this.space();
this.print(node.typeAnnotation.typeAnnotation);
}
}

export function TSTypeQuery(node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(x: any): asserts x => true;
(x: any): asserts x is boolean => true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(x: any): asserts x => true;

(x: any): asserts x is boolean => true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function f(x: any): asserts x {}
(function(x: any): asserts x is boolean {})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function f(x: any): asserts x {}

(function (x: any): asserts x is boolean {});

0 comments on commit 1991a7e

Please sign in to comment.