-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix switch's case block lexical scope handling (#1392)
fixes #1391
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace Jint.Tests.Runtime; | ||
|
||
public class JintFailureTest | ||
{ | ||
[Fact] | ||
public void ShouldHandleCaseBlockLexicalScopeCorrectly() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("switchVal", 1); | ||
engine.SetValue("getCoffee", new Func<string>(() => "coffee")); | ||
|
||
engine.Execute(@" | ||
function myFunc() { | ||
switch(switchVal) { | ||
case 0: | ||
const text = getCoffee(); | ||
return text; | ||
break; | ||
case 1: | ||
const line = getCoffee(); | ||
return line; | ||
break; | ||
} | ||
} | ||
"); | ||
|
||
Assert.Equal("coffee", engine.Evaluate("myFunc()")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters