Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite default export from SourceTextModule #1952

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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