javascript-obfuscator break Assignment without declaration.
This issue is edited after post.
function main() {
const o = {v: 1}
let v;
({v} = o);
console.log(v);
}
main();
Expected Behavior
stdout 1.
Current Behavior
stdout undefined.
Steps to Reproduce (for bugs)
yarn javascript-obfuscator src/main.js
Your Environment
- Obfuscator version used: 0.18.1
- Node version used: v9.11.2
Stack trace
None.
Minimal working example that will help to reproduce issue
src/main.js
function main() {
const o = {v: 1}
let v;
({v} = o);
console.log(v);
}
main();
command.
yarn javascript-obfuscator src/main.js
compiled.
function main() {
const _0x501e82 = { v: 0x1 };
let _0x5b6c40;
({ v } = _0x501e82);
console["log"](_0x5b6c40);
}
main();
detail
I use javascript-obfuscator.
My software is breaked.
I found small example.
function main() {
const o = {v: 1}
let v;
({v} = o);
console.log(v);
}
main();
The code at 3 of lines is standard JavaScript statement.
The round braces ( ... ) around the assignment statement is required syntax when using object literal destructuring assignment without a declaration.
{a, b} = {a: 1, b: 2} is not valid stand-alone syntax, as the {a, b} on the left-hand side is considered a block and not an object literal.
However, ({a, b} = {a: 1, b: 2}) is valid, as is var {a, b} = {a: 1, b: 2}
NOTE: Your ( ... ) expression needs to be preceded by a semicolon or it may be used to execute a function on the previous line.
Destructuring assignment - JavaScript | MDN
webpack-obfuscator or obfuscator-loader
I use webpack.config.js.
const JavaScriptObfuscator = require("webpack-obfuscator");
const path = require("path");
module.exports = {
entry: {
main: "./src/main.js"
},
output: {
path: path.resolve(__dirname, "app"),
filename: "[name].js"
},
plugins: [new JavaScriptObfuscator()]
};
yarn webpack --mode development && node app/main.js output 1 (expected).
yarn webpack --mode production && node app/main.js output undefined (error).
webpack-obfuscator in production compile code as below.
function(e, n) {
({ v: v } = { v: 1 }), console[_0xef72("0xb")](void 0);
}
This code ends of files.
I wondered whether to post to the issue of webpack-obfuscator,
Since I confirmed that the same problem will also occur in obfuscator-loader,
I decided to post a problem on javascript-obfuscator issue.
javascript-obfuscator break Assignment without declaration.
This issue is edited after post.
Expected Behavior
stdout
1.Current Behavior
stdout
undefined.Steps to Reproduce (for bugs)
yarn javascript-obfuscator src/main.jsYour Environment
Stack trace
None.
Minimal working example that will help to reproduce issue
src/main.jscommand.
compiled.
detail
I use javascript-obfuscator.
My software is breaked.
I found small example.
The code at 3 of lines is standard JavaScript statement.
webpack-obfuscator or obfuscator-loader
I use
webpack.config.js.yarn webpack --mode development && node app/main.jsoutput1(expected).yarn webpack --mode production && node app/main.jsoutputundefined(error).webpack-obfuscator in production compile code as below.
This code ends of files.
I wondered whether to post to the issue of webpack-obfuscator,
Since I confirmed that the same problem will also occur in obfuscator-loader,
I decided to post a problem on javascript-obfuscator issue.