Skip to content

Commit

Permalink
add readonly to TSTypeOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Feb 18, 2019
1 parent 44e70bc commit 92ff7c6
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 9 deletions.
8 changes: 6 additions & 2 deletions packages/babel-parser/src/plugins/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return type;
}

tsParseTypeOperator(operator: "keyof" | "unique"): N.TsTypeOperator {
tsParseTypeOperator(
operator: "keyof" | "unique" | "readonly",
): N.TsTypeOperator {
const node: N.TsTypeOperator = this.startNode();
this.expectContextual(operator);
node.operator = operator;
Expand All @@ -719,7 +721,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

tsParseTypeOperatorOrHigher(): N.TsType {
const operator = ["keyof", "unique"].find(kw => this.isContextual(kw));
const operator = ["keyof", "unique", "readonly"].find(kw =>
this.isContextual(kw),
);
return operator
? this.tsParseTypeOperator(operator)
: this.isContextual("infer")
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ export type TsParenthesizedType = TsTypeBase & {

export type TsTypeOperator = TsTypeBase & {
type: "TSTypeOperator",
operator: "keyof" | "unique",
operator: "keyof" | "unique" | "readonly",
typeAnnotation: TsType,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
let x: keyof T;
let y: unique symbol;
let z: readonly number[];
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
{
"type": "File",
"start": 0,
"end": 37,
"end": 63,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 21
"line": 3,
"column": 25
}
},
"program": {
"type": "Program",
"start": 0,
"end": 37,
"end": 63,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 21
"line": 3,
"column": 25
}
},
"sourceType": "module",
Expand Down Expand Up @@ -239,6 +239,118 @@
}
],
"kind": "let"
},
{
"type": "VariableDeclaration",
"start": 38,
"end": 63,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 25
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 42,
"end": 62,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 24
}
},
"id": {
"type": "Identifier",
"start": 42,
"end": 62,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 24
},
"identifierName": "z"
},
"name": "z",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start": 43,
"end": 62,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 24
}
},
"typeAnnotation": {
"type": "TSTypeOperator",
"start": 45,
"end": 62,
"loc": {
"start": {
"line": 3,
"column": 7
},
"end": {
"line": 3,
"column": 24
}
},
"operator": "readonly",
"typeAnnotation": {
"type": "TSArrayType",
"start": 54,
"end": 62,
"loc": {
"start": {
"line": 3,
"column": 16
},
"end": {
"line": 3,
"column": 24
}
},
"elementType": {
"type": "TSNumberKeyword",
"start": 54,
"end": 60,
"loc": {
"start": {
"line": 3,
"column": 16
},
"end": {
"line": 3,
"column": 22
}
}
}
}
}
}
},
"init": null
}
],
"kind": "let"
}
],
"directives": []
Expand Down

0 comments on commit 92ff7c6

Please sign in to comment.