Skip to content

Commit ff490af

Browse files
committed
[MERGE #5780 @rhuanjl] Fix module-namespace indirect exports
Merge pull request #5780 from rhuanjl:indirectExports Saw the solution to this whilst working on #5779 @digitalinfinity conscious the issue for this (5501) was assigned to you, was intending to leave but saw the fix whilst looking at the code for something else. Let me know if this PR is unwanted and I will close it. This fixes two cases where a module-namespace object could have undefined indirect exports: 1. `export {a as b} from "thisModule";` - due to it not being in the localExports list but then being marked as a local export when processing the indirectExports 2. `export {default as otherName} from "anyModule";` - due to seemingly unnecessary special handling of `default` Test262 note, this fix introduces passes for 6 es6 module tests, it is also necessary for several Dynamic Import tests to pass - and for some `export * as ns` tests. The 6 es6 tests that this fixes are: test/language/module-code/namespace/internals/get-own-property-str-found-init.js test/language/module-code/namespace/internals/get-str-initialize.js test/language/module-code/namespace/internals/get-str-found-init.js test/language/module-code/namespace/internals/get-str-update.js test/language/module-code/namespace/internals/has-property-str-found-uninit.js test/language/module-code/namespace/internals/has-property-str-found-init.js fix #5501
2 parents ce09d0e + 586a1a0 commit ff490af

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

lib/Parser/Parse.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,8 +2908,7 @@ ParseNodePtr Parser::ParseDefaultExportClause()
29082908
}
29092909

29102910
IdentPtr exportName = wellKnownPropertyPids._default;
2911-
IdentPtr localName = wellKnownPropertyPids._starDefaultStar;
2912-
AddModuleImportOrExportEntry(EnsureModuleLocalExportEntryList(), nullptr, localName, exportName, nullptr);
2911+
AddModuleImportOrExportEntry(EnsureModuleLocalExportEntryList(), nullptr, exportName, exportName, nullptr);
29132912

29142913
return pnode;
29152914
}
@@ -11544,7 +11543,6 @@ void Parser::InitPids()
1154411543
wellKnownPropertyPids.as = this->GetHashTbl()->PidHashNameLen(_u("as"), sizeof("as") - 1);
1154511544
wellKnownPropertyPids.from = this->GetHashTbl()->PidHashNameLen(_u("from"), sizeof("from") - 1);
1154611545
wellKnownPropertyPids._default = this->GetHashTbl()->PidHashNameLen(_u("default"), sizeof("default") - 1);
11547-
wellKnownPropertyPids._starDefaultStar = this->GetHashTbl()->PidHashNameLen(_u("*default*"), sizeof("*default*") - 1);
1154811546
wellKnownPropertyPids._star = this->GetHashTbl()->PidHashNameLen(_u("*"), sizeof("*") - 1);
1154911547
wellKnownPropertyPids._this = this->GetHashTbl()->PidHashNameLen(_u("*this*"), sizeof("*this*") - 1);
1155011548
wellKnownPropertyPids._newTarget = this->GetHashTbl()->PidHashNameLen(_u("*new.target*"), sizeof("*new.target*") - 1);

lib/Parser/Parse.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ class Parser
483483
IdentPtr as;
484484
IdentPtr _default;
485485
IdentPtr _star; // Special '*' identifier for modules
486-
IdentPtr _starDefaultStar; // Special '*default*' identifier for modules
487486
IdentPtr _this; // Special 'this' identifier
488487
IdentPtr _newTarget; // Special new.target identifier
489488
IdentPtr _super; // Special super identifier

lib/Runtime/Language/ModuleNamespace.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,16 @@ namespace Js
109109
if (moduleNameRecord->module == moduleRecord)
110110
{
111111
// skip local exports as they are covered in the localExportSlots.
112+
// have to check the property map to avoid filtering out aliased local re-exports
113+
// which are not covered in localExportSlots
114+
if (propertyMap->ContainsKey(scriptContext->GetThreadContext()->GetPropertyName(propertyId)))
115+
{
112116
#if DBG
113-
localExportCount++;
117+
localExportCount++;
114118
#endif
115-
return;
119+
return;
120+
}
116121
}
117-
Assert(moduleNameRecord->module != moduleRecord);
118122
this->AddUnambiguousNonLocalExport(propertyId, moduleNameRecord);
119123
});
120124
}

test/es6module/module-bugfixes.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ var tests = [
9393
const start = 'import "b.js"; import "a.js"; import "c.js";';
9494
testRunner.LoadModule(start);
9595
}
96+
},
97+
{
98+
// https://github.com/Microsoft/ChakraCore/issues/5501
99+
name : "Issue 5501: Indirect exports excluded from namespace object - POC 1",
100+
body()
101+
{
102+
WScript.RegisterModuleSource("test5501Part1", `
103+
export {bar as foo} from "test5501Part1";
104+
export const bar = 5;
105+
import * as stuff from "test5501Part1";
106+
assert.areEqual(stuff.bar, stuff.foo);
107+
`);
108+
testRunner.LoadModule("import 'test5501Part1'");
109+
}
110+
},
111+
{
112+
name : "Issue 5501: Indirect exports excluded from namespace object - POC 2",
113+
body()
114+
{
115+
WScript.RegisterModuleSource("test5501Part2a", "export default function () { return true; }");
116+
WScript.RegisterModuleSource("test5501Part2b", "export {default as aliasName} from 'test5501Part2a'");
117+
118+
testRunner.LoadModule(`
119+
import {aliasName} from 'test5501Part2b';
120+
assert.isTrue(aliasName());
121+
`);
122+
}
96123
}
97124
];
98125

0 commit comments

Comments
 (0)