Skip to content

Conversation

@sandersn
Copy link
Member

getCommonJSExportEquals merges export assignments and export property assignments. Something like this, which has no equivalent structure in TS:

module.exports = function() { }
module.exports.expando = 1

However, it is sometimes called with an alias, when its parent, resolveExternalModuleSymbol, is called with dontResolveAlias: true, and when the initialiser of the export assignment is an alias:

function alias() { }
module.exports = alias
module.exports.expando = 1

In this case, (1) the actual value alias will have already merged in a previous call to getCommonJSExportEquals and (2) getTypeOfSymbol will follow the alias symbol to get the right type. So getCommonJSExportEquals should do nothing in this case.

This bug manifests in the code for dynamic imports, which calls getTypeOfSymbol on the incorrectly merged alias, which now has enough value flags--Function, for example--to take the wrong branch and subsequently crash.

Fixes #28014

getCommonJSExportEquals merges export assignments and export property
assignments. Something like this, which has no equivalent structure in
TS:

```js
module.exports = function() { }
module.exports.expando = 1
```

However, it is sometimes called with an alias, when its
parent, resolveExternalModuleSymbol, is called with dontResolveAlias:
true, and when the initialiser of the export assignment is an alias:

```js
function alias() { }
module.exports = alias
module.exports.expando = 1
```

In this case, (1) the actual value `alias` will have already merged in a
previous call to getCommonJSExportEquals and
(2) getTypeOfSymbol will follow the alias symbol to get the right type.
So getCommonJSExportEquals should do nothing in this case.

This bug manifests in the code for dynamic imports, which calls
getTypeOfSymbol on the incorrectly merged alias, which now has enough
value flags--Function, for example--to take the wrong branch and
subsequently crash.
@sandersn sandersn changed the title Do not merge commonsjs exports onto an alias Do not merge commonJS exports into an alias Oct 25, 2018
@sandersn sandersn requested review from a user and weswigham October 25, 2018 20:48
@ghost
Copy link

ghost commented Oct 25, 2018

Potentially related: #27857

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.

compiler crashes with allowJs and dynamic import

2 participants