diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 85e67eb8cbb59..07724be25ba0e 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -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 { diff --git a/tests/cases/fourslash/refactorConvertExport_namedToDefault.ts b/tests/cases/fourslash/refactorConvertExport_namedToDefault1.ts similarity index 100% rename from tests/cases/fourslash/refactorConvertExport_namedToDefault.ts rename to tests/cases/fourslash/refactorConvertExport_namedToDefault1.ts diff --git a/tests/cases/fourslash/refactorConvertExport_namedToDefault2.ts b/tests/cases/fourslash/refactorConvertExport_namedToDefault2.ts new file mode 100644 index 0000000000000..3692e8493a5ae --- /dev/null +++ b/tests/cases/fourslash/refactorConvertExport_namedToDefault2.ts @@ -0,0 +1,23 @@ +/// + +// @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 {}`, +});