Add refactor to convert named to default export and back#24878
Conversation
| const span = getRefactorContextSpan(context); | ||
| const token = getTokenAtPosition(file, span.start, /*includeJsDocComment*/ false); | ||
| const exportNode = getParentNodeInSpan(token, file, span); | ||
| if (!exportNode || exportNode.parent !== file) return undefined; |
There was a problem hiding this comment.
what if this is an ambient module declaration? the parent will not be the file.
| case SyntaxKind.FunctionDeclaration: | ||
| case SyntaxKind.ClassDeclaration: | ||
| case SyntaxKind.InterfaceDeclaration: | ||
| case SyntaxKind.EnumDeclaration: |
There was a problem hiding this comment.
export default enum is not valid syntax..
There was a problem hiding this comment.
What about type alias and variable statements?
| case SyntaxKind.ClassDeclaration: | ||
| case SyntaxKind.InterfaceDeclaration: | ||
| case SyntaxKind.EnumDeclaration: | ||
| case SyntaxKind.ModuleDeclaration: |
There was a problem hiding this comment.
nor is export default namespace N { }
There was a problem hiding this comment.
For namespace, enum, type aliase, and variable declaration, you want to remove the export modifier from the declaration, and add export default <Id>; at the end of the file.
variable statements are gonna be tricky since they can have multiple declarations, and you can not just remove the export from them all. i would say we do not need to support variable statements with binding patterns or more than one declaration.
There was a problem hiding this comment.
Could we fix #18628 instead of working around it here?
There was a problem hiding this comment.
Did the workaround so we can get this in for now.
|
@mhegazy Please re-review |
Fixes #19260