Skip to content

Commit

Permalink
fix: it should set asserts: true for ThisTypePredicate
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 9, 2019
1 parent 2842e77 commit f66434d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -942,15 +942,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>

if (asserts && this.match(tt._this)) {
// When asserts is false, thisKeyword is handled by tsParseNonArrayType
const node = this.startNodeAtNode(t);
// : asserts this is type
let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
// if it turns out to be a `TSThisType`, wrap it with `TSTypePredicate`
// : asserts this
if (thisTypePredicate.type === "TSThisType") {
node.parameterName = thisTypePredicate;
const node: N.TsTypePredicate = this.startNodeAtNode(t);
node.parameterName = (thisTypePredicate: N.TsThisType);
node.asserts = true;
thisTypePredicate = this.finishNode(node, "TSTypePredicate");
} else {
(thisTypePredicate: N.TsTypePredicate).asserts = true;
}
t.typeAnnotation = thisTypePredicate;
return this.finishNode(t, "TSTypeAnnotation");
Expand All @@ -966,7 +968,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.tsParseTypeAnnotation(/* eatColon */ false, t);
}

const node = this.startNodeAtNode(t);
const node: N.TsTypePredicate = this.startNodeAtNode(t);
// : asserts foo
node.parameterName = this.parseIdentifier();
node.asserts = asserts;
Expand Down
Expand Up @@ -203,7 +203,8 @@
"name": "Foo"
}
}
}
},
"asserts": true
}
},
"body": {
Expand Down Expand Up @@ -360,7 +361,8 @@
"name": "Foo"
}
}
}
},
"asserts": true
}
},
"id": null,
Expand Down

0 comments on commit f66434d

Please sign in to comment.