-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Description:** The related issue is a product to the fact that the lexer sees a `<<` token in `fun<<T>...` and therefore parses the type args as an arrow function. This PR adds the handling of the "split" of `<<` when beginning to parse type args. I am open for suggestions, I still find this a bit odd (in `parse_ts_type_args()`): ```rs if is!(p, "<<") { p.input.cut_lshift(); } else { expect!(p, '<'); } ``` **Related issue:** - Closes #7187 - Closes #8209 - Closes #8581
- Loading branch information
1 parent
c3f67ce
commit 9e6dad9
Showing
16 changed files
with
1,210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true | ||
}, | ||
"target": "es2022", | ||
"transform": { | ||
"useDefineForClassFields": true, | ||
"react": { | ||
"importSource": "https://esm.sh/preact", | ||
"runtime": "automatic" | ||
} | ||
}, | ||
"loose": false | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
assertType<<K>(key: K) => K>(foo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
assertType(foo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true | ||
}, | ||
"target": "es2022", | ||
"transform": { | ||
"optimizer": { | ||
"globals": { | ||
"vars": { | ||
"__NODE__": "true" | ||
} | ||
}, | ||
}, | ||
}, | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
} | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const Context = createContext<<Key extends keyof Config>(key: Key) => Config[Key]>( | ||
(key) => properties[key]?.default | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const Context = createContext((key)=>properties[key]?.default); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
assertType<<K>(key: K) => K>(foo); |
169 changes: 169 additions & 0 deletions
169
crates/swc_ecma_parser/tests/typescript/issue-7187/input.ts.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
"type": "Script", | ||
"span": { | ||
"start": 1, | ||
"end": 35, | ||
"ctxt": 0 | ||
}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"span": { | ||
"start": 1, | ||
"end": 35, | ||
"ctxt": 0 | ||
}, | ||
"expression": { | ||
"type": "CallExpression", | ||
"span": { | ||
"start": 1, | ||
"end": 34, | ||
"ctxt": 0 | ||
}, | ||
"callee": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 1, | ||
"end": 11, | ||
"ctxt": 0 | ||
}, | ||
"value": "assertType", | ||
"optional": false | ||
}, | ||
"arguments": [ | ||
{ | ||
"spread": null, | ||
"expression": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 30, | ||
"end": 33, | ||
"ctxt": 0 | ||
}, | ||
"value": "foo", | ||
"optional": false | ||
} | ||
} | ||
], | ||
"typeArguments": { | ||
"type": "TsTypeParameterInstantiation", | ||
"span": { | ||
"start": 11, | ||
"end": 29, | ||
"ctxt": 0 | ||
}, | ||
"params": [ | ||
{ | ||
"type": "TsFunctionType", | ||
"span": { | ||
"start": 12, | ||
"end": 28, | ||
"ctxt": 0 | ||
}, | ||
"params": [ | ||
{ | ||
"type": "Identifier", | ||
"span": { | ||
"start": 16, | ||
"end": 22, | ||
"ctxt": 0 | ||
}, | ||
"value": "key", | ||
"optional": false, | ||
"typeAnnotation": { | ||
"type": "TsTypeAnnotation", | ||
"span": { | ||
"start": 19, | ||
"end": 22, | ||
"ctxt": 0 | ||
}, | ||
"typeAnnotation": { | ||
"type": "TsTypeReference", | ||
"span": { | ||
"start": 21, | ||
"end": 22, | ||
"ctxt": 0 | ||
}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 21, | ||
"end": 22, | ||
"ctxt": 0 | ||
}, | ||
"value": "K", | ||
"optional": false | ||
}, | ||
"typeParams": null | ||
} | ||
} | ||
} | ||
], | ||
"typeParams": { | ||
"type": "TsTypeParameterDeclaration", | ||
"span": { | ||
"start": 12, | ||
"end": 15, | ||
"ctxt": 0 | ||
}, | ||
"parameters": [ | ||
{ | ||
"type": "TsTypeParameter", | ||
"span": { | ||
"start": 13, | ||
"end": 14, | ||
"ctxt": 0 | ||
}, | ||
"name": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 13, | ||
"end": 14, | ||
"ctxt": 0 | ||
}, | ||
"value": "K", | ||
"optional": false | ||
}, | ||
"in": false, | ||
"out": false, | ||
"const": false, | ||
"constraint": null, | ||
"default": null | ||
} | ||
] | ||
}, | ||
"typeAnnotation": { | ||
"type": "TsTypeAnnotation", | ||
"span": { | ||
"start": 24, | ||
"end": 28, | ||
"ctxt": 0 | ||
}, | ||
"typeAnnotation": { | ||
"type": "TsTypeReference", | ||
"span": { | ||
"start": 27, | ||
"end": 28, | ||
"ctxt": 0 | ||
}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 27, | ||
"end": 28, | ||
"ctxt": 0 | ||
}, | ||
"value": "K", | ||
"optional": false | ||
}, | ||
"typeParams": null | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"interpreter": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const Context = createContext<<Key extends keyof Config>(key: Key) => Config[Key]>( | ||
(key) => properties[key]?.default | ||
); |
Oops, something went wrong.