-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export default enum
is not valid syntax..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nor is export default namespace N { }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we fix #18628 instead of working around it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the workaround so we can get this in for now.
@mhegazy Please re-review |
Fixes #19260