diff --git a/changelog.md b/changelog.md index b281acfb..f5305ded 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,11 @@ # Changelog ## vNext (unpublished) +- Fixes but methods called `set` or `get` on classes ## v1.11.6 (28 December 2020) -- Fixed bug with unused setter `value` parameters being removed - Fixes tagged template literals +- Fixed bug with unused setter `value` parameters being removed ## v1.11.5 (10 December 2020) - Fixes bug with `
`s when HtmlToText()ing diff --git a/src/NUglify.Tests/JavaScript/Bugs.cs b/src/NUglify.Tests/JavaScript/Bugs.cs index a8bcfbe5..172a6e13 100644 --- a/src/NUglify.Tests/JavaScript/Bugs.cs +++ b/src/NUglify.Tests/JavaScript/Bugs.cs @@ -230,13 +230,18 @@ public void Bug204() TestHelper.Instance.RunTest("-rename:all"); } - [Test] public void Bug214() { TestHelper.Instance.RunTest("-rename:all"); } + [Test] + public void Bug215() + { + TestHelper.Instance.RunErrorTest("-rename:all"); + } + [Test] public void Bug216() { diff --git a/src/NUglify.Tests/NUglify.Tests.csproj b/src/NUglify.Tests/NUglify.Tests.csproj index e11f6df8..97231e4a 100644 --- a/src/NUglify.Tests/NUglify.Tests.csproj +++ b/src/NUglify.Tests/NUglify.Tests.csproj @@ -459,6 +459,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -2750,6 +2753,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug215.js b/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug215.js new file mode 100644 index 00000000..d5efbae8 --- /dev/null +++ b/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug215.js @@ -0,0 +1 @@ +export class Loader{set(n,t,i){alert(n+t+i)}} \ No newline at end of file diff --git a/src/NUglify.Tests/TestData/JS/Input/Bugs/Bug215.js b/src/NUglify.Tests/TestData/JS/Input/Bugs/Bug215.js new file mode 100644 index 00000000..0bdd7c8b --- /dev/null +++ b/src/NUglify.Tests/TestData/JS/Input/Bugs/Bug215.js @@ -0,0 +1,5 @@ +export class Loader { + set(not, a, setter) { + alert(not + a + setter); + } +} \ No newline at end of file diff --git a/src/NUglify/JavaScript/JSParser.cs b/src/NUglify/JavaScript/JSParser.cs index 19bd15b6..4dcd89fe 100644 --- a/src/NUglify/JavaScript/JSParser.cs +++ b/src/NUglify/JavaScript/JSParser.cs @@ -3219,10 +3219,16 @@ private AstNode ParseClassElement() } // see if this is a getter/setter or a regular method - var funcType = m_currentToken.Is(JSToken.Get) - ? FunctionType.Getter - : m_currentToken.Is(JSToken.Set) ? FunctionType.Setter : FunctionType.Method; - + var funcType = FunctionType.Method; + var nextToken = PeekToken(); + if (nextToken != JSToken.LeftParenthesis) + { + if (m_currentToken.Is(JSToken.Get)) + funcType = FunctionType.Getter; + else if (m_currentToken.Is(JSToken.Set)) + funcType = FunctionType.Setter; + } + // right now the ES6 spec just has method declarations. var method = ParseFunction(funcType, m_currentToken.FlattenToStart()); if (method != null && staticContext != null)