-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Allow type arguments in generic tagged templates #23430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b409888
Added tests.
DanielRosenwasser 23567ee
Accepted baselines.
DanielRosenwasser 60b6d3f
Fixed up test. Thanks arrow functions...
DanielRosenwasser da7967a
Added basic support for parsing/emitting type arguments in tagged tem…
DanielRosenwasser 090f6bd
Accepted baselines.
DanielRosenwasser 7aa916a
Strip away type arguments from tagged templates when emitting.
DanielRosenwasser 4785acb
Accepted baselines.
DanielRosenwasser 82e09c9
Perform checking and resolution of tagged template type arguments.
DanielRosenwasser fe8615d
Accepted baselines.
DanielRosenwasser 6107e05
Added test for tagged templates in new expressions.
DanielRosenwasser 2510c19
Accepted baselines.
DanielRosenwasser eb8eeaf
Allow parsing tagged templates with type arguments in new expressions.
DanielRosenwasser a2073f1
Accepted baselines.
DanielRosenwasser 4bfb1a3
Avoid breaking change by introducing overloads for 'createTaggedTempl…
DanielRosenwasser 78e98c3
Accepted baselines.
DanielRosenwasser 8e27f46
Added test for ASI concerns.
DanielRosenwasser e21a8b8
Accepted baselines.
DanielRosenwasser 7f96fec
Added test in case 'super' is ever possibly parsed as a tagged templa…
DanielRosenwasser 70feb7b
Avoid duplicate code when checking for tagged templates.
DanielRosenwasser 87bb96d
Accepted baselines.
DanielRosenwasser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
72 changes: 72 additions & 0 deletions
72
tests/baselines/reference/taggedTemplatesWithTypeArguments1.js
This file contains hidden or 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,72 @@ | ||
//// [taggedTemplatesWithTypeArguments1.ts] | ||
declare function f<T>(strs: TemplateStringsArray, ...callbacks: Array<(x: T) => any>): void; | ||
|
||
interface Stuff { | ||
x: number; | ||
y: string; | ||
z: boolean; | ||
} | ||
|
||
export const a = f<Stuff> ` | ||
hello | ||
${stuff => stuff.x} | ||
brave | ||
${stuff => stuff.y} | ||
world | ||
${stuff => stuff.z} | ||
`; | ||
|
||
declare function g<Input, T, U, V>( | ||
strs: TemplateStringsArray, | ||
t: (i: Input) => T, u: (i: Input) => U, v: (i: Input) => V): T | U | V; | ||
|
||
export const b = g<Stuff, number, string, boolean> ` | ||
hello | ||
${stuff => stuff.x} | ||
brave | ||
${stuff => stuff.y} | ||
world | ||
${stuff => stuff.z} | ||
`; | ||
|
||
declare let obj: { | ||
prop: <T>(strs: TemplateStringsArray, x: (input: T) => T) => { | ||
returnedObjProp: T | ||
} | ||
} | ||
|
||
export let c = obj["prop"]<Stuff> `${(input) => ({ ...input })}` | ||
c.returnedObjProp.x; | ||
c.returnedObjProp.y; | ||
c.returnedObjProp.z; | ||
|
||
c = obj.prop<Stuff> `${(input) => ({ ...input })}` | ||
c.returnedObjProp.x; | ||
c.returnedObjProp.y; | ||
c.returnedObjProp.z; | ||
|
||
//// [taggedTemplatesWithTypeArguments1.js] | ||
export const a = f ` | ||
hello | ||
${stuff => stuff.x} | ||
brave | ||
${stuff => stuff.y} | ||
world | ||
${stuff => stuff.z} | ||
`; | ||
export const b = g ` | ||
hello | ||
${stuff => stuff.x} | ||
brave | ||
${stuff => stuff.y} | ||
world | ||
${stuff => stuff.z} | ||
`; | ||
export let c = obj["prop"] `${(input) => ({ ...input })}`; | ||
c.returnedObjProp.x; | ||
c.returnedObjProp.y; | ||
c.returnedObjProp.z; | ||
c = obj.prop `${(input) => ({ ...input })}`; | ||
c.returnedObjProp.x; | ||
c.returnedObjProp.y; | ||
c.returnedObjProp.z; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this duplicates the logic in the
else if
below, no? You should just need to add to theCallExpression
cast below. (I'd add aCallLikeExpressionWithTypeArguments
, that'sCallLikeExpression
sans decorators, which are the only one without them)