question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AssignmentRestProperty does not work without AssignmentPropertyList

See original GitHub issue

I’ve created an issue as a bug as partial ECMAScript 2019 support is declared on web site.

Expected Behavior

const { ...fields } = req.body; should be obfuscated

Current Behavior

For now seems like many features of ECMAScript 2018 is supported except at least one when AssignmentRestProperty alone is used at the LeftHandSideExpression of destructuring assignment. Example: const { ...fields } = req.body; Runing javascript-obfuscator against that string gives:

[javascript-obfuscator-cli] Error in file: playground/test.js... 

Although it works well when AssignmentPropertyList is present before the rest. This string will not cause an error: const { foo, ...fields } = req.body;

Steps to Reproduce

  1. create test.js file with a content from example below
  2. run javascript-obfuscator against it javascript-obfuscator ./test.js --output ./
  3. experience an error

Your Environment

  • Obfuscator version used: 0.28.1
  • Node version used: 12.13.1

Stack trace

/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:2226
                if (property.value.type !== Syntax.Identifier) {
                                   ^
TypeError: Cannot read property 'type' of undefined
    at CodeGenerator.ObjectPattern (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:2226:36)
    at CodeGenerator.generateExpression (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:2469:28)
    at CodeGenerator.VariableDeclarator (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:1438:26)
    at CodeGenerator.generateStatement (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:2482:33)
    at block (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:1465:38)
    at CodeGenerator.VariableDeclaration (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:1483:17)
    at CodeGenerator.generateStatement (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:2482:33)
    at /Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:1075:51
    at withIndent (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:576:9)
    at CodeGenerator.BlockStatement (/Users/lonedone/.nvm/versions/node/v12.13.1/lib/node_modules/javascript-obfuscator/node_modules/escodegen/escodegen.js:1025:13)

Minimal working example that will help to reproduce issue

const req = {
  foo: 'foo_str',
  bar: 'bar_str',
};

const { ...fields } = req;
console.log(fields);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
sanex3339commented, May 30, 2020

I created PR with fix some time ago. Please ping this PR https://github.com/estools/escodegen/pull/408

1reaction
sanex3339commented, Jun 4, 2020

Fixed and released as 0.28.5

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# property setter not called when assiging the same value
My problem is that when I assign the property ggFileName with the same value it already contains, nothing happens. The setter is not...
Read more >
Using Properties - C# Programming Guide - Microsoft Learn
A property without a set accessor is considered read-only. A property without a get accessor is considered write-only.
Read more >
CSSStyleDeclaration.setProperty() - Web APIs | MDN
The CSSStyleDeclaration.setProperty() method interface sets a new value for a property on a CSS style declaration object.
Read more >
11 Properties: assignment vs. definition - Exploring JS
Invoking setters: If there is an own or inherited setter for .prop , assignment invokes that setter. Creating properties: If there is no...
Read more >
Properties - Manual - PHP
Note: A property declared without a Visibility modifier will be declared as ... Modifications are not necessarily plain assignments, all of the following ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found