1

Have this code:

var a = 'Start';
var b = ' here';
return (document.querySelectorAll + "").toString().toLowerCase().indexOf(a + b) == -1;

After Google Closure Compiler, this code will be:

return (document.querySelectorAll + "").toString().toLowerCase().indexOf('Start here') == -1;

How to prevent changing this string because I don't need in parameter of indexOf 'Start here', very important that will be exactly 'a + b'? Do I have specific keys above this code that will explain GCC to not compile this code/string?

3
  • If you want the paramter of indexOf to be the string a + b then why not use 'a + b' instead of a + b in indexOf ? Commented Jan 26, 2020 at 9:30
  • Because I need that my code was not be parsed by some systems. They blocking my code with regex and I can't do anything Commented Jan 26, 2020 at 9:42
  • I need to change 'Start here' to 'Start' + ' here'. But compiler returning to me previous value @NickParsons Commented Jan 26, 2020 at 9:44

1 Answer 1

2

You can use the experimental @noinline annotation which:

Denotes a function or variable that should not be inlined by the optimizations.

To keep both a and b preserved, use:

function x() {
  /** @noinline */
  var a = 'Start';
  /** @noinline */
  var b = ' here';
  return (document.querySelectorAll + "").toString().toLowerCase().indexOf(a + b) == -1;
}

Result:

function x(){var a="Start",b=" here";return-1==(document.querySelectorAll+"").toString().toLowerCase().indexOf(a+b)};

Demo

(Note that since document.querySelectorAll + "" evaluates to a string already, you don't need to call toString on it again - you can leave that part off if you want)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.