diff --git a/src/NUglify.Tests/JavaScript/Bugs.cs b/src/NUglify.Tests/JavaScript/Bugs.cs index a6fc023..6361104 100644 --- a/src/NUglify.Tests/JavaScript/Bugs.cs +++ b/src/NUglify.Tests/JavaScript/Bugs.cs @@ -388,5 +388,10 @@ public void Bug391() TestHelper.Instance.RunTest("-rename:all"); } + [Test] + public void Bug394() + { + TestHelper.Instance.RunTest("-rename:all"); + } } } diff --git a/src/NUglify.Tests/NUglify.Tests.csproj b/src/NUglify.Tests/NUglify.Tests.csproj index 8acb02a..011aa46 100644 --- a/src/NUglify.Tests/NUglify.Tests.csproj +++ b/src/NUglify.Tests/NUglify.Tests.csproj @@ -1,4 +1,4 @@ - + @@ -575,6 +575,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -2965,6 +2968,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug201.js b/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug201.js index 19c678e..686d9f6 100644 --- a/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug201.js +++ b/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug201.js @@ -1 +1 @@ -const sum=function({t=2,n=3}){return t+n},sum2=({t=2,n=3})=>t+n \ No newline at end of file +const sum=function({foo:t=2,dummy:n=3}){return t+n},sum2=({foo2:t=2,dummy2:n=3})=>t+n \ No newline at end of file diff --git a/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug345.js b/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug345.js index e26a10e..ab3e46e 100644 --- a/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug345.js +++ b/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug345.js @@ -1 +1 @@ -"use strict";function test1({n=1,t=2}={}){console.log(n+t)}function test2(n=1,t=2){console.log(n+t)} \ No newline at end of file +"use strict";function test1({verylongname_x:n=1,verylongname_y:t=2}={}){console.log(n+t)}function test2(n=1,t=2){console.log(n+t)} \ No newline at end of file diff --git a/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug394.js b/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug394.js new file mode 100644 index 0000000..488ab2b --- /dev/null +++ b/src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug394.js @@ -0,0 +1 @@ +const someFunc=({val:t,op:n="eq"})=>{var i=n+t};var args={val:"va",op:"contains"};someFunc(args) \ No newline at end of file diff --git a/src/NUglify.Tests/TestData/JS/Input/Bugs/Bug394.js b/src/NUglify.Tests/TestData/JS/Input/Bugs/Bug394.js new file mode 100644 index 0000000..6f4ca97 --- /dev/null +++ b/src/NUglify.Tests/TestData/JS/Input/Bugs/Bug394.js @@ -0,0 +1,10 @@ +const someFunc = ({ val, op = 'eq' }) => { + var useOp = op + val; +}; + +var args = { + val: 'va', + op: 'contains' +}; + +someFunc(args); \ No newline at end of file diff --git a/src/NUglify/JavaScript/JSParser.cs b/src/NUglify/JavaScript/JSParser.cs index 94ec7ad..0df7adc 100644 --- a/src/NUglify/JavaScript/JSParser.cs +++ b/src/NUglify/JavaScript/JSParser.cs @@ -4926,10 +4926,20 @@ private ObjectLiteralProperty ParseObjectLiteralProperty(bool isBindingPattern) // just a name lookup; the property name is implicit ParsedVersion = ScriptVersion.EcmaScript6; + var fieldContext = m_currentToken.Clone(); + var fieldScanner = m_scanner.Clone(); value = ParseObjectPropertyValue(isBindingPattern); if (isBindingPattern && m_currentToken.Is(JSToken.Assign)) { + // we need to back up to properly parse the field name + if (m_settings.LocalRenaming != LocalRenaming.KeepAll) + { + m_currentToken = fieldContext; + m_scanner = fieldScanner; + field = ParseObjectLiteralFieldName(); + } + var assignContext = m_currentToken.Clone(); GetNextToken(); value = new InitializerNode(assignContext.Clone())