Skip to content

Conversation

@mhegazy
Copy link
Contributor

@mhegazy mhegazy commented Mar 31, 2015

Fixes #2538

The binder creates two symbols for each exported declaration, one that is local and one that is exported. The local ones have a different symbol flags, to ensure we catch any redefinition, while the exported ones are the ones used after that. This works because we always search in the module.exports when looking up names.

this breaks in the case of export default class or export default function as the names of the two symbols are not the same. the name of the local symbol is the name of the declaration, where as the name of the exported symbol is "default".

this change ensures we are looking for these "default" properties if they exist.

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 adding function to avoid duplicating the same checks in two places?

function getLocalSymbolForExportDefault(symbol: Symbol) {
 return symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) && symbol.valueDeclaration.localSymbol ? symbol.valueDeclaration.localSymbol : undefined;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did that, but then the checks span multiple lines, and they are not much prettier.

Copy link
Contributor

Choose a reason for hiding this comment

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

I;m not very concerned about multiline checks - just would like to have these non-obvious tests in one place.

mhegazy added a commit that referenced this pull request Apr 1, 2015
Ensure we find export default declaration targets if we search for them by name
@mhegazy mhegazy merged commit e4a1c15 into master Apr 1, 2015
@mhegazy mhegazy deleted the exportDefaultReference branch April 1, 2015 15:31
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
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.

export default class throws reference error when the class name is referenced inside the declaration

4 participants