Skip to content

Commit

Permalink
Refactored module import
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanenckevort committed Mar 8, 2024
1 parent e93f3f9 commit d326c4f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/AngleSharp.Js/EngineInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ public JsValue RunScript(String source, String type, JsValue context)
}
else if (type.Isi("module"))
{
return RunModule(source);
// use a unique specifier to import the module into Jint
var specifier = Guid.NewGuid().ToString();

return ImportModule(specifier, source);
}
else
{
Expand Down Expand Up @@ -173,19 +176,16 @@ private JsValue LoadImportMap(String source)
{
var moduleContent = FetchModule(import.Value);

_engine.Modules.Add(import.Key, moduleContent);
_engine.Modules.Import(import.Key);
ImportModule(import.Key, moduleContent);
}

return JsValue.Undefined;
}

private JsValue RunModule(String source)
private JsValue ImportModule(String specifier, String source)
{
var moduleIdentifier = Guid.NewGuid().ToString();

_engine.Modules.Add(moduleIdentifier, source);
_engine.Modules.Import(moduleIdentifier);
_engine.Modules.Add(specifier, source);
_engine.Modules.Import(specifier);

return JsValue.Undefined;
}
Expand Down

0 comments on commit d326c4f

Please sign in to comment.