-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Convert function into ES2015 class
quickfix returns empty result
#33600
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
Comments
Note that we probably just can't drop this result entirely on the VS Code as the UX would be weird: users will still see the |
I don't know if it is of any relevance, but I noticed the quick fix isn't suggested without an assigment to a member of |
I suppose the expected fix for this issue is skipping QF suggestion. Is it true? Or need to generate |
Looking at tests:
e.g. we have a test like this: // @allowJs: true
// @Filename: /a.js
/////** Doc */
////const C = function() { this.x = 0; }
verify.codeFix({
description: "Convert function to an ES2015 class",
newFileContent:
`
/** Doc */
class C {
constructor() { this.x = 0; }
}
`,
}); and /// <reference path='fourslash.ts' />
// @allowNonTsExtensions: true
// @Filename: test123.js
////export function /**/MyClass() {
////}
////MyClass.prototype.foo = function() {
////}
verify.codeFix({
description: "Convert function to an ES2015 class",
newFileContent:
`export class MyClass {
constructor() {
}
foo() {
}
}
`,
}); My gut stays maybe the IIFE is making the response not work as expected (not tested) but I'd expect a test to look something like this: /// <reference path='fourslash.ts' />
// @allowNonTsExtensions: true
// @Filename: test123.js
////(function() {
//// let /**/x = () => {
//// this.y = 1;
//// };
//// x;
////})();
verify.codeFix({
description: "Convert function to an ES2015 class",
newFileContent:
`(function() {
class x {
constructor() {
this.y = 1;
}
}
x
})();
`,
}); |
@orta About the last sample, I think we don't need to convert arrow function to const /**/x = function () {
const y = () => {
this.x = 10;
}
} After class x {
constructor() {
const y = () => {
this.x = 10;
};
}
} The question is, do we need to suggest QF for IIEF which causes the issue. I think no because there is no name that should be used as for the name. What do you think? Does that make sense? |
Great points! Yeah, the arrow funds is a good point. I also agree about the IIFE, I think for the sample it shouldn't offer the fixits for that. So the test would be that the sample doesn't return that quick fix IMO |
From microsoft/vscode#81409
TypeScript Version: 3.7.0-dev.20190924
Search Terms:
Code
For the js
Try running the suggested
convert function into class
refactoringBug:
Nothing happens.
This is because TS Server returns a response with no changes:
I believe we can filter this out on the VS Code side but it is odd that this result is included
The text was updated successfully, but these errors were encountered: