Uh oh!
There was an error while loading. Please reload this page.
Add inline variable refactor - #54281
Conversation
TypeScript Bot (typescript-bot)
commented
May 16, 2023
The TypeScript team hasn't accepted the linked issue #18459. If you can get it accepted, this PR will have a better chance of being reviewed. |
TypeScript Bot (typescript-bot)
commented
May 16, 2023
The TypeScript team hasn't accepted the linked issue #18459. If you can get it accepted, this PR will have a better chance of being reviewed. |
1 similar comment
TypeScript Bot (typescript-bot)
commented
May 16, 2023
The TypeScript team hasn't accepted the linked issue #18459. If you can get it accepted, this PR will have a better chance of being reviewed. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
fae73f0 to
2c58756CompareUh oh!
There was an error while loading. Please reload this page.
Matt Bierner (mjbvz)
left a comment
There was a problem hiding this comment.
Excited to test this out!
There was a problem hiding this comment.
I think there are a couple other invalid inlinings to consider.
- Type queries:
constBar=classBar{}typeBarConstructor=typeofBar;
typeofcan only take an identifier reference. - Merged type/value meanings:
There’s one symbol for
consta="hello";typea=any;typeT=a;
awith two declarations, so Find All References might returnaintype T = aas a reference, even though you wouldn’t want to inline"hello"there. The real case for merging meanings is usually more likeand in those cases it seems undesirable to inline anyway. I think you can implement a simple rule that says if a symbol has more than one declaration, it can’t be inlined.// Simulate type/value duality of real class declarationsconstSomeClass=mixin(OtherClass);typeSomeClass=typeofSomeClass;
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
This is looking really good! The implementation is impressively small and readable and I like that each test is very focused.
Have you tried to beat this up on some more complicated real-world code? Do that if you haven’t already, and then I would also suggest having one or two kitchen-sink tests that exercise more complex cases with several references and complex expressions (multi-line function expression?)
Uh oh!
There was an error while loading. Please reload this page.
Maria Solano (MariaSolOs)
commented
May 29, 2023
Andrew Branch (@andrewbranch) I've added a couple more tests with more complex scenarios like call expressions. LMK what you think :) |
Andrew Branch (andrewbranch)
commented
May 30, 2023
I still think inlining a multi-line expression would be good to test: functionComponent(){constonClick/*inline me*/=()=>{console.log("clicked");};return(<buttononClick={onClick}>Dousefulthing</button>);} |
TypeScript Bot (@typescript-bot) pack this |
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
Looks good to me, nice job 👍
I SAID TypeScript Bot (@typescript-bot) pack this |
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the diff-based user code test suite (tsserver) on this PR at 2f97c5c. You can monitor the build here. Update: The results are in! |
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the tarball bundle task on this PR at 2f97c5c. You can monitor the build here. |
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the diff-based top-repos suite (tsserver) on this PR at 2f97c5c. You can monitor the build here. Update: The results are in! |
That's what I thought. |
Hey Daniel Rosenwasser (@DanielRosenwasser), I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
TypeScript Bot (typescript-bot)
commented
May 31, 2023
Daniel Rosenwasser (@DanielRosenwasser) Here are the results of running the user test suite comparing Everything looks good! |
Here's a fun one I just tried out: const/**/yadda=()=>yadda; |
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
436e243 to
9f39bfbCompareMaria Solano (MariaSolOs)
commented
Jun 12, 2023
Daniel Rosenwasser (@DanielRosenwasser) I believe we should stick with option 1, since there would be an ambiguity about what to inline in cases like However, if I change this bit to: if(isIdentifier(token)&&isInitializedVariable(parent)&&isVariableDeclarationInVariableStatement(parent)){The refactor is still available in |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Bot (@typescript-bot) pack this |
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the tarball bundle task on this PR at 67a5880. You can monitor the build here. |
Hey Daniel Rosenwasser (@DanielRosenwasser), I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
Uh oh!
There was an error while loading. Please reload this page.
Michael Borislav (awerlogus)
commented
Dec 4, 2023
Inlining variable constdata=newMap()constgetter=()=>data.get('foo')data.set('foo','bar')console.log(getter()) |
Fixes#18459