Skip to content

Commit

Permalink
Merge pull request #144 from trullock/bug_139
Browse files Browse the repository at this point in the history
added more tests for #139 and fixed #139
  • Loading branch information
trullock authored Sep 15, 2020
2 parents 9be4bbf + 5b38eac commit 6d0abea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 33 additions & 0 deletions src/NUglify.Tests/JavaScript/Bugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,38 @@ public void Bug139()
{
TestHelper.Instance.RunTest();
}

[Test]
public void Bug139_A()
{
// previously these would throw exceptions because the closing backtick was skipped, creating an invalid ast
// manually define cr and lfs to be sure we dont have platform sillynes

var uglifyResult = Uglify.Js(@"var testString = `
`;
testString += `} async init(){ }`;");
Assert.AreEqual("var testString=`\n`+`} async init(){ }`", uglifyResult.Code);

// CR
uglifyResult = Uglify.Js("var testString = `"+ (char)13 +@"`;
testString += `} async init(){ }`;");
Assert.AreEqual("var testString=`\r`+`} async init(){ }`", uglifyResult.Code);

// LF
uglifyResult = Uglify.Js("var testString = `" + (char)10 + @"`;
testString += `} async init(){ }`;");
Assert.AreEqual("var testString=`\n`+`} async init(){ }`", uglifyResult.Code);

// CRLF
uglifyResult = Uglify.Js("var testString = `" + (char)13 + (char)10 + @"`;
testString += `} async init(){ }`;");
Assert.AreEqual("var testString=`\r\n`+`} async init(){ }`", uglifyResult.Code);

//LFCR
uglifyResult = Uglify.Js("var testString = `" + (char)10 + (char)13 + @"`;
testString += `} async init(){ }`;");
Assert.AreEqual("var testString=`\n\r`+`} async init(){ }`", uglifyResult.Code);

}
}
}
3 changes: 1 addition & 2 deletions src/NUglify/JavaScript/JSScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2897,10 +2897,9 @@ private JSToken ScanTemplateLiteral(char ch)
// save the start of the next run (if any)
startOfRun = m_currentPosition + 1;
}
else if (IsLineTerminator(ch, 0))
else if (IsLineTerminator(ch, 1))
{
// we'll just keep this as part of the unescaped run
++m_currentPosition;
++m_currentLine;
m_startLinePosition = m_currentPosition + 1;
}
Expand Down

0 comments on commit 6d0abea

Please sign in to comment.