microsoft / microsoft/TypeScript
extract function including traling comment that is not selected
Open
Nobody has claimed this yet.
Domain: LS: Refactorings
Experience Enhancement
Help Wanted
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
extract function including traling comment that is not selected
🔎 Search Terms
🕗 Version & Regression Information
- This is a bug in 4.3.2-latest version
When I use 'extract to method in class C' in following code, the selected region does not contain comment '/end/', but when I excecute 'extract to method in class C', the extractd method contains comment '/end/'. Is this a bug?I think it would better comment not selected appear in newMethod.
⏯ Playground Link
Playground link with relevant code
💻 Code
class C{
a() {
let z =1;
/*start*/let a1= {x:1};
let y =10;
z=42
return a1.x+ 10 /*end*/
}
}
🙁 Actual behavior
class C{
a() {
let z = 1;
/*start*/
let __return;
({ __return, z } = this.newMethod(z));
return __return; /*end*
}
private newMethod(z: number) {
let a1 = { x: 1 };
let y = 10;
z = 42;
return { __return: a1.x + 10 /*end*/
, z };
}
}
🙂 Expected behavior
class C{
a() {
let z = 1;
/*start*/
let __return;
({ __return, z } = this.newMethod(z));
return __return; /*end*/
}
private newMethod(z: number) {
let a1 = { x: 1 };
let y = 10;
z = 42;
return { __return: a1.x + 10 , z };
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the extract-to-method behavior from the linked TypeScript Playground using the supplied class C example, comparing the selected region with the generated method. Trace the extract-function refactoring entry point and add coverage for the trailing comment; done means the comment stays with the original return statement rather than appearing in the extracted method.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100