diff --git a/lib/Runtime/Language/SourceTextModuleRecord.cpp b/lib/Runtime/Language/SourceTextModuleRecord.cpp index 682c343f978..cb97db0ce42 100644 --- a/lib/Runtime/Language/SourceTextModuleRecord.cpp +++ b/lib/Runtime/Language/SourceTextModuleRecord.cpp @@ -1144,6 +1144,11 @@ namespace Js uint SourceTextModuleRecord::GetLocalExportSlotIndexByExportName(PropertyId exportNameId) { + if(!this->WasDeclarationInitialized())//allow for circular imports that reference each other's functions + { + ModuleDeclarationInstantiation(); + } + Assert(localSlotCount != 0); Assert(localExportSlots != nullptr); uint slotIndex = InvalidSlotIndex; @@ -1160,6 +1165,11 @@ namespace Js uint SourceTextModuleRecord::GetLocalExportSlotIndexByLocalName(PropertyId localNameId) { + if(!this->WasDeclarationInitialized())//allow for circular imports that reference each other's functions + { + ModuleDeclarationInstantiation(); + } + Assert(localSlotCount != 0 || localNameId == PropertyIds::star_); Assert(localExportSlots != nullptr); uint slotIndex = InvalidSlotIndex; diff --git a/test/es6/module-4482-bug-dep1.js b/test/es6/module-4482-bug-dep1.js new file mode 100644 index 00000000000..fb7a948266b --- /dev/null +++ b/test/es6/module-4482-bug-dep1.js @@ -0,0 +1,12 @@ +//------------------------------------------------------------------------------------------------------- +// Copyright (C) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- + + +import {Thing2} from "./module-4482-bug.js"; + +export default function Thing1() +{ + Thing2(); +} diff --git a/test/es6/module-4482-bug-dep2.js b/test/es6/module-4482-bug-dep2.js new file mode 100644 index 00000000000..b3adebbb7b9 --- /dev/null +++ b/test/es6/module-4482-bug-dep2.js @@ -0,0 +1,11 @@ +//------------------------------------------------------------------------------------------------------- +// Copyright (C) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- + + +import {Thing1} from "./module-4482-bug.js"; + +export default function Thing2() +{ +} diff --git a/test/es6/module-4482-bug.js b/test/es6/module-4482-bug.js new file mode 100644 index 00000000000..a2a68cc65c3 --- /dev/null +++ b/test/es6/module-4482-bug.js @@ -0,0 +1,15 @@ +//------------------------------------------------------------------------------------------------------- +// Copyright (C) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- + +import Thing1 from './module-4482-bug-dep1.js'; +import Thing2 from './module-4482-bug-dep2.js'; + +export { Thing1, Thing2 }; + +export default function main() +{ + Thing1(); + Thing2(); +} diff --git a/test/es6/module-functionality.js b/test/es6/module-functionality.js index f6642c0ed48..129313138a0 100644 --- a/test/es6/module-functionality.js +++ b/test/es6/module-functionality.js @@ -291,6 +291,14 @@ var tests = [ testModuleScript(functionBody); } }, + { + name:"Inter-related circular dependencies", + body: function () { + let functionBody = + `import './module-4482-bug.js';`; + testModuleScript(functionBody); + } + }, { name: "Implicitly re-exporting an import binding (import { foo } from ''; export { foo };)", body: function () {