Skip to content

Commit

Permalink
Don't overwrite default export from SourceTextModule (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Aug 21, 2024
1 parent 1febd1b commit 2f3a801
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Jint.Tests/Runtime/ModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ public void ShouldExportDefault()
Assert.Equal("exported value", ns.Get("default").AsString());
}

[Fact]
public void ShouldExportDefaultFunctionWithoutName()
{
_engine.Modules.Add("module1", "export default function main() { return 1; }");
_engine.Modules.Add("module2", "export default function () { return 1; }");
var ns = _engine.Modules.Import("module1");

var func = ns.Get("default");
Assert.Equal(1, func.Call());

ns = _engine.Modules.Import("module2");

func = ns.Get("default");
Assert.Equal(1, func.Call());
}

[Fact]
public void ShouldExportAll()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ protected override void Initialize(EvaluationContext context)
protected override Completion ExecuteInternal(EvaluationContext context)
{
var env = context.Engine.ExecutionContext.LexicalEnvironment;
if (env.HasBinding("*default*"))
{
// We already have the default binding.
// Initialized in SourceTextModule.InitializeEnvironment.
return Completion.Empty();
}

JsValue value;
if (_classDefinition is not null)
{
Expand Down

0 comments on commit 2f3a801

Please sign in to comment.