fix(ts): include leading operator in TSUnionType and TSIntersectionType locations (#12757)
This commit is contained in:
parent
0fdec6b7e7
commit
d1cf66e8c1
@ -935,6 +935,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
parseConstituentType: () => N.TsType,
|
parseConstituentType: () => N.TsType,
|
||||||
operator: TokenType,
|
operator: TokenType,
|
||||||
): N.TsType {
|
): N.TsType {
|
||||||
|
const node: N.TsUnionType | N.TsIntersectionType = this.startNode();
|
||||||
this.eat(operator);
|
this.eat(operator);
|
||||||
let type = parseConstituentType();
|
let type = parseConstituentType();
|
||||||
if (this.match(operator)) {
|
if (this.match(operator)) {
|
||||||
@ -942,9 +943,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
while (this.eat(operator)) {
|
while (this.eat(operator)) {
|
||||||
types.push(parseConstituentType());
|
types.push(parseConstituentType());
|
||||||
}
|
}
|
||||||
const node: N.TsUnionType | N.TsIntersectionType = this.startNodeAtNode(
|
|
||||||
type,
|
|
||||||
);
|
|
||||||
node.types = types;
|
node.types = types;
|
||||||
type = this.finishNode(node, kind);
|
type = this.finishNode(node, kind);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,3 +2,8 @@ let union: number | null | undefined;
|
|||||||
let intersection: number & string;
|
let intersection: number & string;
|
||||||
let precedence1: number | string & boolean;
|
let precedence1: number | string & boolean;
|
||||||
let precedence2: number & string | boolean;
|
let precedence2: number & string | boolean;
|
||||||
|
|
||||||
|
type J = number | string
|
||||||
|
type F = number & string
|
||||||
|
type K = | number | string
|
||||||
|
type M = & number & string
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":160,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":43}},
|
"start":0,"end":265,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":26}},
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
"start":0,"end":160,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":43}},
|
"start":0,"end":265,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":26}},
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
"interpreter": null,
|
"interpreter": null,
|
||||||
"body": [
|
"body": [
|
||||||
@ -170,6 +170,98 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"kind": "let"
|
"kind": "let"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSTypeAliasDeclaration",
|
||||||
|
"start":162,"end":186,"loc":{"start":{"line":6,"column":0},"end":{"line":6,"column":24}},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":167,"end":168,"loc":{"start":{"line":6,"column":5},"end":{"line":6,"column":6},"identifierName":"J"},
|
||||||
|
"name": "J"
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSUnionType",
|
||||||
|
"start":171,"end":186,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":24}},
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "TSNumberKeyword",
|
||||||
|
"start":171,"end":177,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":15}}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":180,"end":186,"loc":{"start":{"line":6,"column":18},"end":{"line":6,"column":24}}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSTypeAliasDeclaration",
|
||||||
|
"start":187,"end":211,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":24}},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":192,"end":193,"loc":{"start":{"line":7,"column":5},"end":{"line":7,"column":6},"identifierName":"F"},
|
||||||
|
"name": "F"
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSIntersectionType",
|
||||||
|
"start":196,"end":211,"loc":{"start":{"line":7,"column":9},"end":{"line":7,"column":24}},
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "TSNumberKeyword",
|
||||||
|
"start":196,"end":202,"loc":{"start":{"line":7,"column":9},"end":{"line":7,"column":15}}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":205,"end":211,"loc":{"start":{"line":7,"column":18},"end":{"line":7,"column":24}}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSTypeAliasDeclaration",
|
||||||
|
"start":212,"end":238,"loc":{"start":{"line":8,"column":0},"end":{"line":8,"column":26}},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":217,"end":218,"loc":{"start":{"line":8,"column":5},"end":{"line":8,"column":6},"identifierName":"K"},
|
||||||
|
"name": "K"
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSUnionType",
|
||||||
|
"start":221,"end":238,"loc":{"start":{"line":8,"column":9},"end":{"line":8,"column":26}},
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "TSNumberKeyword",
|
||||||
|
"start":223,"end":229,"loc":{"start":{"line":8,"column":11},"end":{"line":8,"column":17}}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":232,"end":238,"loc":{"start":{"line":8,"column":20},"end":{"line":8,"column":26}}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSTypeAliasDeclaration",
|
||||||
|
"start":239,"end":265,"loc":{"start":{"line":9,"column":0},"end":{"line":9,"column":26}},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":244,"end":245,"loc":{"start":{"line":9,"column":5},"end":{"line":9,"column":6},"identifierName":"M"},
|
||||||
|
"name": "M"
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSIntersectionType",
|
||||||
|
"start":248,"end":265,"loc":{"start":{"line":9,"column":9},"end":{"line":9,"column":26}},
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "TSNumberKeyword",
|
||||||
|
"start":250,"end":256,"loc":{"start":{"line":9,"column":11},"end":{"line":9,"column":17}}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":259,"end":265,"loc":{"start":{"line":9,"column":20},"end":{"line":9,"column":26}}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"directives": []
|
"directives": []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user