-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaScript Object Destructuring with default values does not work after minification #394
Comments
The fix requires parsing the same token twice... It doesn't look like there is a way to back up the SourceContext or JSScanner... so I cloned them before ParseObjectPropertyValue, then if it's a binding pattern and the current token is Assign, I replace m_currentToken and m_scanner with the clones, and call ParseObjectPropertyValue... This doesn't feel right, but it feels better than creating the ObjectLiteralField directly using the value.Context...
JSParser line 4923
|
Sounds sensible enough |
…pt object destructuring with default values and property renaming (trullock#394)
Fixes issue with default values and javascript destructuring (#394)
JavaScript object destructuring with default values does not work after minification, the original parameter name is not maintained, so the value is never extracted from the source object and always has the default value.
Code
Actual
const someFunc=({val:t,n="eq"})=>{var i=n+t};var args={val:"va",op:"contains"};someFunc(args)
Expected
const someFunc=({val:t,op:n="eq"})=>{var i=n+t};var args={val:"va",op:"contains"};someFunc(args)
My current fix of setting the Field property of the ObjectLiteralProperty in ParseObjectLiteralProperty when isBindingPattern is true and the current token is Assign causes the tests for Bugs 201 and 345 to fail... although, in both cases, I believe the new results are correct.
Bug 201:
Code
Expected
const sum=function({t=2,n=3}){return t+n},sum2=({t=2,n=3})=>t+n
Actual
const sum=function({foo:t=2,dummy:n=3}){return t+n},sum2=({foo2:t=2,dummy2:n=3})=>t+n
Bug 345:
Code
Expected
"use strict";function test1({n=1,t=2}={}){console.log(n+t)}function test2(n=1,t=2){console.log(n+t)}
Actual
"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)}
If you agree with the results, I have some questions so that I can generate the ObjectLiteralField in the intended way instead of the way I'm doing it now, which just doesn't feel right.
In Bug 390 you mentioned that the code in that section gets confused with two different types of notations/types, would you be able to describe those issues when you get a chance?
The text was updated successfully, but these errors were encountered: