Some bundlers and compilers, like the Google Closure Compiler, remove the code’s comments which can be a problem if you use code annotations and want to apply Jscrambler’s transformations after bundling. To avoid this issue you can use Jscrambler’s Annotations as strings instead of code comments.
In order to use String Annotations, simply use the same
@jscrambler directives inside a literal expression instead of a comment, in the same way you’d do to enable strict mode.
For instance, the following example using comment annotations:
Is equivalent to:
Which in turn, would produce something like the following code as a result of having enabled the
regexObfuscation transformation on the next block:
Please be aware that there are some cases where strings as annotations lead to errors or unexpected behavior:
1) Without semicolon (
2) Inside the body of ES2015 Classes
3) When mixing comment and string annotation formats
Not using semicolons in string annotations may cause the string directives to be misinterpreted by our parser which can cause the annotation to be ignored.
ES6 classes do not support strings inside the class body. The following code is syntactically invalid.
You can still use string annotations in class methods by placing the string annotation at the beginning of function’s body and then wrapping the actual function code in an additional block, like so:
Annotations in string and comment formats are parsed at different times when a protection is triggered. Mixing code annotations formats may lead to unexpected results since some of them would be parsed sooner than others and act upon different blocks of code.
Annotations like these are correct since they use a consistent format:
Annotations like these may lead to errors because they contain both comment annotations and string annotations: