Skip to content

Commit

Permalink
Merge pull request #291 from kmvi/fix-290
Browse files Browse the repository at this point in the history
Fix template string parsing
  • Loading branch information
nilproject committed Aug 26, 2023
2 parents 97cb9ce + 9981382 commit 6221057
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions NiL.JS/Expressions/TemplateString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static Expression Parse(ParseInfo state, ref int index, TemplateStringMod
if (state.Code[pos] == '$')
{
pos += 2;
Tools.SkipSpaces(state.Code, ref pos);
expressions.Add((Expression)ExpressionTree.Parse(state, ref pos));

Tools.SkipSpaces(state.Code, ref pos);
Expand Down
12 changes: 12 additions & 0 deletions Tests/StringInterpolationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,17 @@ public void StringInterpolationAllowsSubstititions()

Assert.AreEqual("This is a string such as 1234", stringValue.Value);
}

[TestMethod]
public void StringInterpolationAllowsWhitespaces()
{
var context = new Context();
var code = @"var a=1234; `This is a string such as ${
a }`";
var stringValue = context.Eval(code);

Assert.AreEqual("This is a string such as 1234", stringValue.Value);
}
}
}

0 comments on commit 6221057

Please sign in to comment.