Skip to content

Conversation

@sandersn
Copy link
Member

@sandersn sandersn commented Nov 1, 2018

They are marked both as (1) alias and (2) assignment declaration. This fixes alias resolution in cases where multiple module.exports assignments exist, but differ in whether they are aliases or not:

function f() { }
module.exports = f
module.exports = 23

Previously, this construct would fail to resolve the alias f because the export= symbol would be marked as Alias | Value but not Assignment. This change just adds Assignment so that the assignment declaration alias-following rules apply: you should always follow the alias, regardless of other flags.

Also, isAliasSymbolDeclaration needed to be tightened up. Previously, I missed the condition that module.exports = aliases required an EntityNameDeclaration on right-hand-side, just like export default and export = aliases.

Fixes #27857

They are marked both as (1) alias and (2) assignment declaration. This
fixes alias resolution in cases where multiple module.exports
assignments exist, but differ in whether they are aliases or not:

```js
function f() { }
module.exports = f
module.exports = 23
```

Previously, this construct would fail to resolve the alias `f` because
the `export=` symbol would be marked as Alias | Value but not
Assignment. This change just adds Assignment so that the assignment
declaration alias-following rules apply: you should always follow the
alias, regardless of other flags.

Also, isAliasSymbolDeclaration needed to be tightened up. Previously, I
missed the condition that `module.exports =` aliases required an
EntityNameDeclaration on right-hand-side, just like `export default` and
`export =` aliases.
@sandersn sandersn requested review from a user and weswigham November 1, 2018 23:22
// 'module.exports = expr' assignment
const flags = exportAssignmentIsAlias(node)
? SymbolFlags.Alias // An export= with an EntityNameExpression or a ClassExpression exports all meanings of that identifier or class
? SymbolFlags.Alias | SymbolFlags.Assignment // An export= with an EntityNameExpression or a ClassExpression exports all meanings of that identifier or class
Copy link

Choose a reason for hiding this comment

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

So why is it not flagged as Assignment in the other case?

Copy link
Member Author

Choose a reason for hiding this comment

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

No good reason! The other uses of Assignment are unconditional now as well. Nice catch.

1. Rename test to be more accurate.
2. Always mark module.exports assignments with SymbolFlags.Assignment.
@sandersn sandersn merged commit a682a52 into master Nov 2, 2018
@sandersn sandersn deleted the js/fix-multiple-module-exports-flags branch November 2, 2018 16:08
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
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.

Code completion crashes when localStorage, postcss-object-fit-images, or gulp-watch packages are imported

3 participants