Skip to content

Commit d4f26c8

Browse files
authoredOct 26, 2022
fix(51245): Class with parameter decorator in arrow function causes "convert to default export" refactoring failure (#51256)
* fix(51245): don't rely on parent nodes in formatting rules * check existing parent node
1 parent 16faf45 commit d4f26c8

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed
 

‎src/services/formatting/rules.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,10 @@ namespace ts.formatting {
732732
}
733733

734734
function nodeIsInDecoratorContext(node: Node): boolean {
735-
while (isExpressionNode(node)) {
735+
while (node && isExpression(node)) {
736736
node = node.parent;
737737
}
738-
return node.kind === SyntaxKind.Decorator;
738+
return node && node.kind === SyntaxKind.Decorator;
739739
}
740740

741741
function isStartOfVariableDeclarationList(context: FormattingContext): boolean {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /a.ts
4+
/////*a*/export const f = () => {
5+
//// return class C {
6+
//// constructor(@Foo() param: any) { }
7+
//// }
8+
////}/*b*/
9+
////function Foo(...args: any[]): any {}
10+
11+
goTo.select("a", "b");
12+
edit.applyRefactor({
13+
refactorName: "Convert export",
14+
actionName: "Convert named export to default export",
15+
actionDescription: "Convert named export to default export",
16+
newContent:
17+
`export default () => {
18+
return class C {
19+
constructor(@Foo() param: any) { }
20+
}
21+
}
22+
function Foo(...args: any[]): any {}`,
23+
});

0 commit comments

Comments
 (0)
Please sign in to comment.