Skip to content

In JS, fix crash with in a file with conflicting ES2015/commonjs exports#24960

Merged
sandersn merged 2 commits into
masterfrom
js/fix-crash-for-conflicting-es2015-commonjs
Jun 14, 2018
Merged

In JS, fix crash with in a file with conflicting ES2015/commonjs exports#24960
sandersn merged 2 commits into
masterfrom
js/fix-crash-for-conflicting-es2015-commonjs

Conversation

@sandersn
Copy link
Copy Markdown
Member

Previously, the binder would try to bind commonjs module.exports even if the file was known to be an ES2015 module. This caused a crash in the checker when it tried to check the export symbol as a value.

Fixes #24934

@sandersn sandersn requested review from a user and mhegazy June 14, 2018 17:01
Comment thread src/compiler/binder.ts Outdated

// 'module.exports = expr' assignment
setCommonJsModuleIndicator(node);
if (!setCommonJsModuleIndicator(node)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: The code was this way before, but this is a case of:

if (something) {
    foo();
    return;
}

foo();
doSomethingElse();

The if (!setCommonJsModuleIndicator(node)) { return; } could be moved up before if (isEmptyObjectLiteral(assignedExpression) ... to avoid this duplication.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. Fixed.

@sandersn sandersn merged commit a56b272 into master Jun 14, 2018
@sandersn sandersn deleted the js/fix-crash-for-conflicting-es2015-commonjs branch June 14, 2018 18:18
@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.

1 participant