Prevent properties with get and set kinds from extraction with transformObjectKeys option. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/707

This commit is contained in:
sanex
2020-08-14 20:52:53 +03:00
parent 85e8e6c852
commit 9ff565f4e3
8 changed files with 67 additions and 10 deletions
@@ -1820,5 +1820,34 @@ describe('ObjectExpressionKeysTransformer', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('Variant #11: `get` and `set` property kinds', () => {
const match: string = `` +
`const ${variableMatch} *= *{ *` +
`get \'baz\' *\\(\\) *{ *return 0x2; *}, *` +
`set \'bark\' *\\(${variableMatch}\\) *{ *this\\[\'bark\'] *= *${variableMatch}; *} *` +
`}; *` +
`${variableMatch}\\[\'bar\'] *= *0x1;` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/get-set-property-kind.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
).getObfuscatedCode();
});
it('should keep property nodes with `get` and `set` kind in the object', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
});
@@ -0,0 +1,7 @@
(function(){
const foo = {
bar: 1,
get baz() { return 2; },
set bark(value) { this.bark = value; }
};
})();