Skip to content

Commit

Permalink
fix(51245): Class with parameter decorator in arrow function causes "…
Browse files Browse the repository at this point in the history
…convert to default export" refactoring failure (#51256)

* fix(51245): don't rely on parent nodes in formatting rules

* check existing parent node
  • Loading branch information
a-tarasyuk committed Oct 26, 2022
1 parent 16faf45 commit d4f26c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/formatting/rules.ts
Expand Up @@ -732,10 +732,10 @@ namespace ts.formatting {
}

function nodeIsInDecoratorContext(node: Node): boolean {
while (isExpressionNode(node)) {
while (node && isExpression(node)) {
node = node.parent;
}
return node.kind === SyntaxKind.Decorator;
return node && node.kind === SyntaxKind.Decorator;
}

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 {}`,
});

0 comments on commit d4f26c8

Please sign in to comment.