Skip to content
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

Merged
9 commits merged into from
Jun 25, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented Jun 11, 2018

Fixes #19260

@ghost ghost requested a review from amcasey June 11, 2018 22:50
@ghost ghost force-pushed the convertExport branch from d2fdc78 to d421257 Compare June 11, 2018 22:50
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;
Copy link
Contributor

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:
Copy link
Contributor

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..

Copy link
Contributor

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:
Copy link
Contributor

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 { }

Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

Copy link
Author

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.

@ghost
Copy link
Author

ghost commented Jun 18, 2018

@mhegazy Please re-review

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant