Fix range on TypeScript this type predicate (#9339)
This commit is contained in:
parent
694e3fd8cf
commit
e8038863c3
@ -264,7 +264,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
|
||||
tsParseThisTypePredicate(lhs: N.TsThisType): N.TsTypePredicate {
|
||||
this.next();
|
||||
const node: N.TsTypePredicate = this.startNode();
|
||||
const node: N.TsTypePredicate = this.startNodeAtNode(lhs);
|
||||
node.parameterName = lhs;
|
||||
node.typeAnnotation = this.tsParseTypeAnnotation(/* eatColon */ false);
|
||||
return this.finishNode(node, "TSTypePredicate");
|
||||
|
||||
6
packages/babel-parser/test/fixtures/typescript/class/predicate-types/input.js
vendored
Normal file
6
packages/babel-parser/test/fixtures/typescript/class/predicate-types/input.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
isBar(): this is string {
|
||||
}
|
||||
isBaz = (): this is string => {
|
||||
}
|
||||
}
|
||||
361
packages/babel-parser/test/fixtures/typescript/class/predicate-types/output.json
vendored
Normal file
361
packages/babel-parser/test/fixtures/typescript/class/predicate-types/output.json
vendored
Normal file
@ -0,0 +1,361 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 83,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 83,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start": 0,
|
||||
"end": 83,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 6,
|
||||
"end": 9,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"identifierName": "Foo"
|
||||
},
|
||||
"name": "Foo"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 10,
|
||||
"end": 83,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start": 14,
|
||||
"end": 43,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 14,
|
||||
"end": 19,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 7
|
||||
},
|
||||
"identifierName": "isBar"
|
||||
},
|
||||
"name": "isBar"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"returnType": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start": 21,
|
||||
"end": 37,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypePredicate",
|
||||
"start": 23,
|
||||
"end": 37,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"parameterName": {
|
||||
"type": "TSThisType",
|
||||
"start": 23,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
}
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start": 31,
|
||||
"end": 37,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSStringKeyword",
|
||||
"start": 31,
|
||||
"end": 37,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 25
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 38,
|
||||
"end": 43,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 26
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ClassProperty",
|
||||
"start": 46,
|
||||
"end": 81,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 46,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 7
|
||||
},
|
||||
"identifierName": "isBaz"
|
||||
},
|
||||
"name": "isBaz"
|
||||
},
|
||||
"computed": false,
|
||||
"value": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start": 54,
|
||||
"end": 81,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"returnType": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start": 56,
|
||||
"end": 72,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 28
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypePredicate",
|
||||
"start": 58,
|
||||
"end": 72,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 14
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 28
|
||||
}
|
||||
},
|
||||
"parameterName": {
|
||||
"type": "TSThisType",
|
||||
"start": 58,
|
||||
"end": 62,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 14
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 18
|
||||
}
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start": 66,
|
||||
"end": 72,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 22
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 28
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSStringKeyword",
|
||||
"start": 66,
|
||||
"end": 72,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 22
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 28
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 76,
|
||||
"end": 81,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 32
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user