Skip to content

CommonJS: symbol not renamed in inline module.exports assignment #3501

@blutorange

Description

@blutorange
java -jar closure-compiler-v20191027.jar --version
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20191027
Built on: 2019-10-30 03:56

Came across this when running closure compiler on core-js, caused by this file: zloirock/core-js/internal-metadata.js. It contains a module.exports assignment within a compound assignment (see at the bottom).

Possibly related to #3093 ?

Minimal example that reproduces this:

// /tmp/export-wrong.js
var exp = () => {};
var meta = module.exports = {exp: exp}

This currently compiles to:

java -jar closure-compiler-v20191027.jar --process_common_js_modules=true --entry_point=/tmp/exports-wrong.js  --compilation_level=SIMPLE_OPTIMIZATIONS --js /tmp/exports-wrong.js
var module$tmp$exports_wrong={default:{}};
module$tmp$exports_wrong.default.exp=function(){};
var meta$$module$tmp$exports_wrong=module$tmp$exports_wrong.default={exp:exp};

Are these kind of exports supported? When this code is run, exp will be undefined. It works correctly when changing the export to a top-level assignment statement:

var exp = () => {};
var meta = {exp: exp};
module.exports = meta;

Metadata

Metadata

Labels

internal-issue-createdAn internal Google issue has been created to track this GitHub issuetriage-doneHas been reviewed by someone on triage rotation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions