js-confuser icon indicating copy to clipboard operation
js-confuser copied to clipboard

SyntaxError: 'return' outside of function (3:4)

Open batongprodt opened this issue 1 year ago • 3 comments

SyntaxError: 'return' outside of function (3:4)

var base_url = window.location.host; if (base_url != "example.com") return; Why did the error occur?

batongprodt avatar Dec 26 '23 03:12 batongprodt

you can only return inside a function, which you do not have.

use an IIFE:

(() => {
  var base_url = window.location.host;
  if (base_url != "example.com")
    return;
})();

Le0Developer avatar Mar 18 '24 13:03 Le0Developer

js-obfuscator supports return outside a function, it should be possible to do it, and it is useful, I am dealing with a use case where I need it

younes-zeboudj avatar Apr 28 '24 00:04 younes-zeboudj

Parse the AST yourself with acorn and add the allowReturnOutsideFunction like described in https://github.com/acornjs/acorn/issues/86

Le0Developer avatar Apr 28 '24 11:04 Le0Developer