-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
ES6ModulesP3internal-issue-createdAn internal Google issue has been created to track this GitHub issueAn internal Google issue has been created to track this GitHub issuetriage-doneHas been reviewed by someone on triage rotation.Has been reviewed by someone on triage rotation.
Description
The following code works correctly uncompiled:
// input0
/** @typedef {number} */
export const Bits = {};
Bits.of = () => 42;
Bits.of();
// input1
import {Bits} from './input0';
Bits.of();
But it compiles to
/** @const @typedef {number} */ var Bits$$module$input0 = {};
/** @return {!Bits$$module$input0} */
Bits$$module$input0.of = function() { return 42; };
Bits$$module$input0.of();
/** @const */ var module$input0 = {};
/** @typedef {Bits$$module$input0} */ module$input0.Bits;
module$input0.Bits.of();
/** @const */ var module$input1 = {};
Note that the child module calls module$input0.Bits.of()
while the parent module calls Bits$$module$input0.of()
. Moreover, the previous two lines (at the end of the parent) are (removing comments):
var module$input0 = {};
module$input0.Bits;
module$input0.Bits.of();
It's very clear that this will be a runtime error, since the module$input0.Bits
stub is not actually defined. This works correctly for goog.module
s and for single scripts. It's just ES modules that get it wrong.
Metadata
Metadata
Assignees
Labels
ES6ModulesP3internal-issue-createdAn internal Google issue has been created to track this GitHub issueAn internal Google issue has been created to track this GitHub issuetriage-doneHas been reviewed by someone on triage rotation.Has been reviewed by someone on triage rotation.