Obfuscate error.

Hi, I'm been working on a project for some time now with no errors til now.

It compiles ok under debug, but when I select Release in the Obfuscate part I get errors.

Any hints?

Thanks in advance,

Omar Zelaya

Obfuscate errors:

Parse error at D:\ISAT\WebAdmin\TMSWeb\Release\ISWebAdmin.js:24140,33
const userAgentData = window?.navigator?.userAgentData?.brands;
^
ERROR: Unexpected token: punc (.)
at pos (C:\snapshot\Terser\node_modules\terser\lib\parse.js:373:35)
at c (C:\snapshot\Terser\node_modules\terser\lib\parse.js:1069:18)
at type (C:\snapshot\Terser\node_modules\terser\lib\parse.js:1079:28)
at token (C:\snapshot\Terser\node_modules\terser\lib\parse.js:1082:27)
at val (C:\snapshot\Terser\node_modules\terser\lib\parse.js:2273:25)
at ge (C:\snapshot\Terser\node_modules\terser\lib\parse.js:2978:17)
at AST_Conditional (C:\snapshot\Terser\node_modules\terser\lib\parse.js:3037:13)
at left (C:\snapshot\Terser\node_modules\terser\lib\parse.js:3037:24)
at AST_Sequence (C:\snapshot\Terser\node_modules\terser\lib\parse.js:3113:41)
at qe (C:\snapshot\Terser\node_modules\terser\lib\parse.js:3137:51)

[Fatal Error] Parse error at D:\ISAT\WebAdmin\TMSWeb\Release\ISWebAdmin.js:24140,33
const userAgentData = window?.navigator?.userAgentData?.brands;
^
ERROR: Unexpected token: punc (.)
at pos (C:\snapshot\Terser\node_modules\terser\lib\parse.js:373:35)
at c (C:\snapshot\Terser\node_modules\terser\lib\parse.js:1069:18)
at type (C:\snapshot\Terser\node_modules\terser\lib\parse.js:1079:28)
at token (C:\snapshot\Terser\node_modules\terser\lib\parse.js:1082:27)
at val (C:\snapshot\Terser\node_modules\terser\lib\parse.js:2273:25)
at ge (C:\snapshot\Terser\node_modules\terser\lib\parse.js:2978:17)
at AST_Conditional (C:\snapshot\Terser\node_modules\terser\lib\parse.js:3037:13)
at left (C:\snapshot\Terser\node_modules\terser\lib\parse.js:3037:24)
at AST_Sequence (C:\snapshot\Terser\node_modules\terser\lib\parse.js:3113:41)
at qe (C:\snapshot\Terser\node_modules\terser\lib\parse.js:3137:51)

Is this line of code

const userAgentData = window?.navigator?.userAgentData?.brands;

a line of code you wrote yourself and if so, why these questionmarks?

@brunofierens

?. is called an "Optional Chaining Operator" in JavaScript.

It's super handy. I use it all the time, but I haven't tried it in TMS WEB Core yet.

Here's some info on it: Optional chaining (?.) - JavaScript | MDN

@Zelaya_Omar

You could write that line as:

const userAgentData = window.navigator && window.navigator.userAgentData && window.navigator.userAgentData.brands;

instead of:

const userAgentData = window?.navigator?.userAgentData?.brands;

Using the logical AND (&&) operator to check each property was the old way of doing it before ?. was introduced.


@brunofierens

But ideally, the optional chaining operator (?.) should be fixed and work in TMS WEB Core (or PAS2JS) in my opinion. It's a very useful operator!

Possibly, the terser obfuscator tool we use (GitHub - terser/terser: 🗜 JavaScript parser, mangler and compressor toolkit for ES6+) does not support this yet. We'll need to investigate.

@brunofierens Seems like there are a couple of issues regarding optional chaining for the terser obfuscator tool: Issues · terser/terser · GitHub

Most of them are marked as Completed and Closed though.

We'll look if we might have to update the terser tool in the TMS WEB Core distribution.

Thanks for the hint. It worked.

Omar Zelaya