Skip to content

Commit

Permalink
Fix module-namespace handling of:
Browse files Browse the repository at this point in the history
a) re-export of default and
b) local indirect exports
  • Loading branch information
rhuanjl committed Oct 31, 2018
1 parent ce09d0e commit 586a1a0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
4 changes: 1 addition & 3 deletions lib/Parser/Parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2908,8 +2908,7 @@ ParseNodePtr Parser::ParseDefaultExportClause()
}

IdentPtr exportName = wellKnownPropertyPids._default;
IdentPtr localName = wellKnownPropertyPids._starDefaultStar;
AddModuleImportOrExportEntry(EnsureModuleLocalExportEntryList(), nullptr, localName, exportName, nullptr);
AddModuleImportOrExportEntry(EnsureModuleLocalExportEntryList(), nullptr, exportName, exportName, nullptr);

return pnode;
}
Expand Down Expand Up @@ -11544,7 +11543,6 @@ void Parser::InitPids()
wellKnownPropertyPids.as = this->GetHashTbl()->PidHashNameLen(_u("as"), sizeof("as") - 1);
wellKnownPropertyPids.from = this->GetHashTbl()->PidHashNameLen(_u("from"), sizeof("from") - 1);
wellKnownPropertyPids._default = this->GetHashTbl()->PidHashNameLen(_u("default"), sizeof("default") - 1);
wellKnownPropertyPids._starDefaultStar = this->GetHashTbl()->PidHashNameLen(_u("*default*"), sizeof("*default*") - 1);
wellKnownPropertyPids._star = this->GetHashTbl()->PidHashNameLen(_u("*"), sizeof("*") - 1);
wellKnownPropertyPids._this = this->GetHashTbl()->PidHashNameLen(_u("*this*"), sizeof("*this*") - 1);
wellKnownPropertyPids._newTarget = this->GetHashTbl()->PidHashNameLen(_u("*new.target*"), sizeof("*new.target*") - 1);
Expand Down
1 change: 0 additions & 1 deletion lib/Parser/Parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ class Parser
IdentPtr as;
IdentPtr _default;
IdentPtr _star; // Special '*' identifier for modules
IdentPtr _starDefaultStar; // Special '*default*' identifier for modules
IdentPtr _this; // Special 'this' identifier
IdentPtr _newTarget; // Special new.target identifier
IdentPtr _super; // Special super identifier
Expand Down
10 changes: 7 additions & 3 deletions lib/Runtime/Language/ModuleNamespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ namespace Js
if (moduleNameRecord->module == moduleRecord)
{
// skip local exports as they are covered in the localExportSlots.
// have to check the property map to avoid filtering out aliased local re-exports
// which are not covered in localExportSlots
if (propertyMap->ContainsKey(scriptContext->GetThreadContext()->GetPropertyName(propertyId)))
{
#if DBG
localExportCount++;
localExportCount++;
#endif
return;
return;
}
}
Assert(moduleNameRecord->module != moduleRecord);
this->AddUnambiguousNonLocalExport(propertyId, moduleNameRecord);
});
}
Expand Down
27 changes: 27 additions & 0 deletions test/es6module/module-bugfixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ var tests = [
const start = 'import "b.js"; import "a.js"; import "c.js";';
testRunner.LoadModule(start);
}
},
{
// https://github.com/Microsoft/ChakraCore/issues/5501
name : "Issue 5501: Indirect exports excluded from namespace object - POC 1",
body()
{
WScript.RegisterModuleSource("test5501Part1", `
export {bar as foo} from "test5501Part1";
export const bar = 5;
import * as stuff from "test5501Part1";
assert.areEqual(stuff.bar, stuff.foo);
`);
testRunner.LoadModule("import 'test5501Part1'");
}
},
{
name : "Issue 5501: Indirect exports excluded from namespace object - POC 2",
body()
{
WScript.RegisterModuleSource("test5501Part2a", "export default function () { return true; }");
WScript.RegisterModuleSource("test5501Part2b", "export {default as aliasName} from 'test5501Part2a'");

testRunner.LoadModule(`
import {aliasName} from 'test5501Part2b';
assert.isTrue(aliasName());
`);
}
}
];

Expand Down

0 comments on commit 586a1a0

Please sign in to comment.