TypeScript: Support parsing 'unique' type operator (#7239)
This commit is contained in:
parent
5759c33b4c
commit
dccfed3601
@ -1 +1,2 @@
|
||||
let x: keyof T;
|
||||
let y: unique symbol;
|
||||
|
||||
@ -1 +1,2 @@
|
||||
let x: keyof T;
|
||||
let x: keyof T;
|
||||
let y: unique symbol;
|
||||
@ -609,8 +609,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return type;
|
||||
}
|
||||
|
||||
tsParseTypeOperator(operator: "keyof"): N.TsTypeOperator {
|
||||
const node = this.startNode();
|
||||
tsParseTypeOperator(operator: "keyof" | "unique"): N.TsTypeOperator {
|
||||
const node: N.TsTypeOperator = this.startNode();
|
||||
this.expectContextual(operator);
|
||||
node.operator = operator;
|
||||
node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
|
||||
@ -618,10 +618,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
|
||||
tsParseTypeOperatorOrHigher(): N.TsType {
|
||||
if (this.isContextual("keyof")) {
|
||||
return this.tsParseTypeOperator("keyof");
|
||||
}
|
||||
return this.tsParseArrayTypeOrHigher();
|
||||
const operator = ["keyof", "unique"].find(kw => this.isContextual(kw));
|
||||
return operator
|
||||
? this.tsParseTypeOperator(operator)
|
||||
: this.tsParseArrayTypeOrHigher();
|
||||
}
|
||||
|
||||
tsParseUnionOrIntersectionType(
|
||||
|
||||
@ -1149,7 +1149,7 @@ export type TsParenthesizedType = TsTypeBase & {
|
||||
|
||||
export type TsTypeOperator = TsTypeBase & {
|
||||
type: "TSTypeOperator",
|
||||
operator: "keyof",
|
||||
operator: "keyof" | "unique",
|
||||
typeAnnotation: TsType,
|
||||
};
|
||||
|
||||
|
||||
@ -1 +1,2 @@
|
||||
let x: keyof T;
|
||||
let y: unique symbol;
|
||||
|
||||
@ -1,29 +1,29 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 15,
|
||||
"end": 37,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
"line": 2,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 15,
|
||||
"end": 37,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
"line": 2,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
@ -141,6 +141,103 @@
|
||||
}
|
||||
],
|
||||
"kind": "let"
|
||||
},
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"start": 16,
|
||||
"end": 37,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start": 20,
|
||||
"end": 36,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 20,
|
||||
"end": 36,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 20
|
||||
},
|
||||
"identifierName": "y"
|
||||
},
|
||||
"name": "y",
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start": 21,
|
||||
"end": 36,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeOperator",
|
||||
"start": 23,
|
||||
"end": 36,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"operator": "unique",
|
||||
"typeAnnotation": {
|
||||
"type": "TSSymbolKeyword",
|
||||
"start": 30,
|
||||
"end": 36,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 14
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"init": null
|
||||
}
|
||||
],
|
||||
"kind": "let"
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user