Skip to content

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

@ghost ghost merged commit 806a661 into master Jun 25, 2018
@ghost ghost deleted the convertExport branch June 25, 2018 17:34
@ghost ghost mentioned this pull request Jun 25, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant