Skip to content

Commit

Permalink
Fix union and intersection type start (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Mar 22, 2020
1 parent b677115 commit b17b249
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ecmascript/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "swc_ecma_parser"
version = "0.21.5"
version = "0.21.6"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git"
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/parser/src/parser/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2235,9 +2235,9 @@ impl<'a, I: Tokens> Parser<'a, I> {
{
debug_assert!(self.input.syntax().typescript());

let start = cur_pos!(); // include the leading operator in the start
self.input.eat(operator);

let start = cur_pos!();
let ty = parse_constituent_type(self)?;
if self.input.is(&operator) {
let mut types = vec![ty];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ let union: number | null | undefined;
let intersection: number & string;
let precedence1: number | string & boolean;
let precedence2: number & string | boolean;
type LeadingUnion =
| string
| number;
type LeadingIntersection =
& number
& string;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "Module",
"span": {
"start": 0,
"end": 160,
"end": 261,
"ctxt": 0
},
"body": [
Expand Down Expand Up @@ -324,6 +324,104 @@
"definite": false
}
]
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 161,
"end": 207,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 166,
"end": 178,
"ctxt": 0
},
"value": "LeadingUnion",
"typeAnnotation": null,
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsUnionType",
"span": {
"start": 185,
"end": 206,
"ctxt": 0
},
"types": [
{
"type": "TsKeywordType",
"span": {
"start": 187,
"end": 193,
"ctxt": 0
},
"kind": "string"
},
{
"type": "TsKeywordType",
"span": {
"start": 200,
"end": 206,
"ctxt": 0
},
"kind": "number"
}
]
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 208,
"end": 261,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 213,
"end": 232,
"ctxt": 0
},
"value": "LeadingIntersection",
"typeAnnotation": null,
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsIntersectionType",
"span": {
"start": 239,
"end": 260,
"ctxt": 0
},
"types": [
{
"type": "TsKeywordType",
"span": {
"start": 241,
"end": 247,
"ctxt": 0
},
"kind": "number"
},
{
"type": "TsKeywordType",
"span": {
"start": 254,
"end": 260,
"ctxt": 0
},
"kind": "string"
}
]
}
}
],
"interpreter": null
Expand Down

0 comments on commit b17b249

Please sign in to comment.