Skip to content
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

fix(51245): Class with parameter decorator in arrow function causes "convert to default export" refactoring failure #51256

Merged
merged 2 commits into from Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/services/formatting/rules.ts
Expand Up @@ -725,17 +725,7 @@ namespace ts.formatting {
}

function isEndOfDecoratorContextOnSameLine(context: FormattingContext): boolean {
return context.TokensAreOnSameLine() &&
hasDecorators(context.contextNode) &&
nodeIsInDecoratorContext(context.currentTokenParent) &&
!nodeIsInDecoratorContext(context.nextTokenParent);
}

function nodeIsInDecoratorContext(node: Node): boolean {
while (isExpressionNode(node)) {
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
node = node.parent;
}
return node.kind === SyntaxKind.Decorator;
return context.TokensAreOnSameLine() && hasDecorators(context.contextNode) && isDecorator(context.currentTokenParent);
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
}

function isStartOfVariableDeclarationList(context: FormattingContext): boolean {
Expand Down
23 changes: 23 additions & 0 deletions tests/cases/fourslash/refactorConvertExport_namedToDefault2.ts
@@ -0,0 +1,23 @@
/// <reference path='fourslash.ts' />

// @Filename: /a.ts
/////*a*/export const f = () => {
//// return class C {
//// constructor(@Foo() param: any) { }
//// }
////}/*b*/
////function Foo(...args: any[]): any {}

goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert export",
actionName: "Convert named export to default export",
actionDescription: "Convert named export to default export",
newContent:
`export default () => {
return class C {
constructor(@Foo() param: any) { }
}
}
function Foo(...args: any[]): any {}`,
});