Skip to content

Improve test for 'symbol.exports' #25523

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

Merged
3 commits merged into from
Jul 11, 2018
Merged

Improve test for 'symbol.exports' #25523

3 commits merged into from
Jul 11, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jul 9, 2018

Fixes #25484

@ghost ghost requested a review from weswigham July 9, 2018 19:30
@@ -171,8 +171,8 @@ namespace ts {
}
const t = getTypeOfSymbol(symbol);
visitType(t); // Should handle members on classes and such
if (symbol.flags & SymbolFlags.HasExports) {
symbol.exports!.forEach(visitSymbol);
if (symbol.exports) {
Copy link
Contributor

Choose a reason for hiding this comment

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

so when does it have the flag but no exports? this is more concerning than the error really.

Copy link
Author

Choose a reason for hiding this comment

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

We don't have a repro for this unfortunately.

Copy link
Contributor

Choose a reason for hiding this comment

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

we only use HasExports in two places other than this one.. once in the binder and once
in the checker.. I wounder if we can just remove it all together, and check exports instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

@weswigham and @sandersn thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

HasExports afaik is set on container symbols which can have exports, while the member is present if there actually are any. I imagine the usage in the checker is likely incorrect - AFAIK it should only be used in the binder to determine how to initialize a symbol.

Copy link
Member

Choose a reason for hiding this comment

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

It's only an alias, so even in the binder, the code might actually be clearer without it. (or with a comment instead)

@ghost
Copy link
Author

ghost commented Jul 11, 2018

@sandersn A JS baseline needed an update -- pretty sure this is correct since exports.x = 0; exports.x = 1; is an error, but just want to confirm.

@ghost ghost force-pushed the symbol_exports branch from 6b216f5 to e6cadc7 Compare July 11, 2018 16:18
@sandersn
Copy link
Member

That baseline came from #22461, which has examples from graceful-fs, uglify and webpack. All of those assign exports to exports and to an alias, but none of those makes multiple assignments to the same property. So I think the baseline change is good.

@@ -225,11 +225,11 @@ namespace ts {
node.symbol = symbol;
symbol.declarations = append(symbol.declarations, node);

if (symbolFlags & SymbolFlags.HasExports && !symbol.exports) {
if (symbolFlags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.Module | SymbolFlags.Variable) && !symbol.exports) {
Copy link
Member

Choose a reason for hiding this comment

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

I like this change.

@ghost ghost merged commit 8a3090b into master Jul 11, 2018
@ghost ghost deleted the symbol_exports branch July 11, 2018 16:37
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.

3 participants