diff --git a/Jint.Tests/Runtime/ModuleTests.cs b/Jint.Tests/Runtime/ModuleTests.cs index cc0a6f513..65b580457 100644 --- a/Jint.Tests/Runtime/ModuleTests.cs +++ b/Jint.Tests/Runtime/ModuleTests.cs @@ -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() { diff --git a/Jint/Runtime/Interpreter/Statements/JintExportDefaultDeclaration.cs b/Jint/Runtime/Interpreter/Statements/JintExportDefaultDeclaration.cs index b40772ad3..3d0d5dd04 100644 --- a/Jint/Runtime/Interpreter/Statements/JintExportDefaultDeclaration.cs +++ b/Jint/Runtime/Interpreter/Statements/JintExportDefaultDeclaration.cs @@ -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) {