fix: start TypePredicate node after returnToken (#12678)

This commit is contained in:
Huáng Jùnliàng 2021-01-23 12:06:54 -05:00 committed by GitHub
parent 8c03fb0152
commit 568679e301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 21 deletions

View File

@ -1050,6 +1050,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const t: N.TsTypeAnnotation = this.startNode(); const t: N.TsTypeAnnotation = this.startNode();
this.expect(returnToken); this.expect(returnToken);
const node = this.startNode<N.TsTypePredicate>();
const asserts = !!this.tsTryParse( const asserts = !!this.tsTryParse(
this.tsParseTypePredicateAsserts.bind(this), this.tsParseTypePredicateAsserts.bind(this),
); );
@ -1061,7 +1063,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// if it turns out to be a `TSThisType`, wrap it with `TSTypePredicate` // if it turns out to be a `TSThisType`, wrap it with `TSTypePredicate`
// : asserts this // : asserts this
if (thisTypePredicate.type === "TSThisType") { if (thisTypePredicate.type === "TSThisType") {
const node: N.TsTypePredicate = this.startNodeAtNode(t);
node.parameterName = (thisTypePredicate: N.TsThisType); node.parameterName = (thisTypePredicate: N.TsThisType);
node.asserts = true; node.asserts = true;
thisTypePredicate = this.finishNode(node, "TSTypePredicate"); thisTypePredicate = this.finishNode(node, "TSTypePredicate");
@ -1082,7 +1083,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.tsParseTypeAnnotation(/* eatColon */ false, t); return this.tsParseTypeAnnotation(/* eatColon */ false, t);
} }
const node: N.TsTypePredicate = this.startNodeAtNode(t);
// : asserts foo // : asserts foo
node.parameterName = this.parseIdentifier(); node.parameterName = this.parseIdentifier();
node.asserts = asserts; node.asserts = asserts;
@ -1092,7 +1092,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// : asserts foo is type // : asserts foo is type
const type = this.tsParseTypeAnnotation(/* eatColon */ false); const type = this.tsParseTypeAnnotation(/* eatColon */ false);
const node = this.startNodeAtNode(t);
node.parameterName = typePredicateVariable; node.parameterName = typePredicateVariable;
node.typeAnnotation = type; node.typeAnnotation = type;
node.asserts = asserts; node.asserts = asserts;

View File

@ -18,7 +18,7 @@
"start":8,"end":21,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":21}}, "start":8,"end":21,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":21}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":8,"end":21,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":21}}, "start":10,"end":21,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":21}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"x"}, "start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"x"},

View File

@ -27,7 +27,7 @@
"start":32,"end":57,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":57}}, "start":32,"end":57,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":57}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":32,"end":57,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":57}}, "start":34,"end":57,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":57}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":42,"end":47,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":47},"identifierName":"value"}, "start":42,"end":47,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":47},"identifierName":"value"},
@ -93,7 +93,7 @@
"start":96,"end":111,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":47}}, "start":96,"end":111,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":47}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":96,"end":111,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":47}}, "start":98,"end":111,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":47}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":106,"end":111,"loc":{"start":{"line":2,"column":42},"end":{"line":2,"column":47},"identifierName":"value"}, "start":106,"end":111,"loc":{"start":{"line":2,"column":42},"end":{"line":2,"column":47},"identifierName":"value"},

View File

@ -40,7 +40,7 @@
"start":15,"end":29,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":19}}, "start":15,"end":29,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":19}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":15,"end":29,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":19}}, "start":17,"end":29,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":19}},
"parameterName": { "parameterName": {
"type": "TSThisType", "type": "TSThisType",
"start":25,"end":29,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":19}} "start":25,"end":29,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":19}}

View File

@ -54,7 +54,7 @@
"start":42,"end":67,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":57}}, "start":42,"end":67,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":57}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":42,"end":67,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":57}}, "start":44,"end":67,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":57}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":52,"end":57,"loc":{"start":{"line":2,"column":42},"end":{"line":2,"column":47},"identifierName":"value"}, "start":52,"end":57,"loc":{"start":{"line":2,"column":42},"end":{"line":2,"column":47},"identifierName":"value"},

View File

@ -10,6 +10,7 @@
{ {
"type": "TSDeclareFunction", "type": "TSDeclareFunction",
"start":0,"end":63,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":63}}, "start":0,"end":63,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":63}},
"declare": true,
"id": { "id": {
"type": "Identifier", "type": "Identifier",
"start":17,"end":31,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":31},"identifierName":"assertIsString"}, "start":17,"end":31,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":31},"identifierName":"assertIsString"},
@ -37,7 +38,7 @@
"start":47,"end":62,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":62}}, "start":47,"end":62,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":62}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":47,"end":62,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":62}}, "start":49,"end":62,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":62}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":57,"end":62,"loc":{"start":{"line":1,"column":57},"end":{"line":1,"column":62},"identifierName":"value"}, "start":57,"end":62,"loc":{"start":{"line":1,"column":57},"end":{"line":1,"column":62},"identifierName":"value"},
@ -45,8 +46,7 @@
}, },
"asserts": true "asserts": true
} }
}, }
"declare": true
} }
], ],
"directives": [] "directives": []

View File

@ -10,6 +10,7 @@
{ {
"type": "TSDeclareFunction", "type": "TSDeclareFunction",
"start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":73}}, "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":73}},
"declare": true,
"id": { "id": {
"type": "Identifier", "type": "Identifier",
"start":17,"end":31,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":31},"identifierName":"assertIsString"}, "start":17,"end":31,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":31},"identifierName":"assertIsString"},
@ -37,7 +38,7 @@
"start":47,"end":72,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":72}}, "start":47,"end":72,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":72}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":47,"end":72,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":72}}, "start":49,"end":72,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":72}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":57,"end":62,"loc":{"start":{"line":1,"column":57},"end":{"line":1,"column":62},"identifierName":"value"}, "start":57,"end":62,"loc":{"start":{"line":1,"column":57},"end":{"line":1,"column":62},"identifierName":"value"},
@ -53,8 +54,7 @@
}, },
"asserts": true "asserts": true
} }
}, }
"declare": true
} }
], ],
"directives": [] "directives": []

View File

@ -37,7 +37,7 @@
"start":34,"end":59,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":59}}, "start":34,"end":59,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":59}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":34,"end":59,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":59}}, "start":36,"end":59,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":59}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":44,"end":49,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":49},"identifierName":"value"}, "start":44,"end":49,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":49},"identifierName":"value"},
@ -91,7 +91,7 @@
"start":98,"end":113,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":49}}, "start":98,"end":113,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":49}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":98,"end":113,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":49}}, "start":100,"end":113,"loc":{"start":{"line":2,"column":36},"end":{"line":2,"column":49}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":108,"end":113,"loc":{"start":{"line":2,"column":44},"end":{"line":2,"column":49},"identifierName":"value"}, "start":108,"end":113,"loc":{"start":{"line":2,"column":44},"end":{"line":2,"column":49},"identifierName":"value"},

View File

@ -13,6 +13,7 @@
{ {
"type": "TSDeclareFunction", "type": "TSDeclareFunction",
"start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":68}}, "start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":68}},
"declare": true,
"id": { "id": {
"type": "Identifier", "type": "Identifier",
"start":17,"end":31,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":31},"identifierName":"assertIsString"}, "start":17,"end":31,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":31},"identifierName":"assertIsString"},
@ -40,7 +41,7 @@
"start":47,"end":67,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":67}}, "start":47,"end":67,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":67}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":47,"end":67,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":67}}, "start":49,"end":67,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":67}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":62,"end":67,"loc":{"start":{"line":1,"column":62},"end":{"line":1,"column":67},"identifierName":"value"}, "start":62,"end":67,"loc":{"start":{"line":1,"column":62},"end":{"line":1,"column":67},"identifierName":"value"},
@ -48,8 +49,7 @@
}, },
"asserts": true "asserts": true
} }
}, }
"declare": true
} }
], ],
"directives": [] "directives": []

View File

@ -37,7 +37,7 @@
"start":18,"end":32,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":32}}, "start":18,"end":32,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":32}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":18,"end":32,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":32}}, "start":20,"end":32,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":32}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":20,"end":21,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":21},"identifierName":"x"}, "start":20,"end":21,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":21},"identifierName":"x"},
@ -94,7 +94,7 @@
"start":53,"end":67,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":31}}, "start":53,"end":67,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":31}},
"typeAnnotation": { "typeAnnotation": {
"type": "TSTypePredicate", "type": "TSTypePredicate",
"start":53,"end":67,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":31}}, "start":55,"end":67,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":31}},
"parameterName": { "parameterName": {
"type": "Identifier", "type": "Identifier",
"start":55,"end":56,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":20},"identifierName":"x"}, "start":55,"end":56,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":20},"identifierName":"x"},