Debug Code Elimination

Potency None
Resilience High
Cost None
Tags: debug code, debug, elimination, removal, optimization

Description

Debug code main purpose is to help the developer doing code debugging. This can be done in many different ways, such as log statements or assertions. Debug Code Elimination removes statements and public variable declarations used to control the output of debugging messages that help on code debugging.

Notes:

  • Try to use (uppercase) names that do not collide with other declarations
  • Local declarations with the same name will not be removed

Code Annotation Example

// @jscrambler define debugCodeElimination {variables: [DEBUG,DEBUG_MODE]} as dce
// @jscrambler enable dce

Examples

The following example contains some debug code to be removed:

if (typeof DEBUG === 'undefined') {
  DEBUG = true;
}
// code A
if (DEBUG) {
  console.log('Collecting objects.');
}
// code B
DEBUG && console.log('In debugging mode.');

Adding DEBUG to the variables list removes any statement or public variable declaration with that name, leading to:

// code A
// code B

Option Types

Name Required Default Value Description
variables Yes N/A List of variables that are intended to be removed from the code.

Browser Compatibility

Browser Compatible Versions Tested Versions Notes
Chrome 80+ 80+
Firefox 90+ 90+
Internet Explorer 8+ 8+
Microsoft Edge 116+ 116+
Safari 13.1+ 13.1+

API Parameters

Example:

{
  "keys": {
    "accessKey": "XXXXXX",
    "secretKey": "YYYYYY"
  },
  "applicationId": "ZZZZZZ",
  "params": [
    {
      "name": "debugCodeElimination",
      "options": {
        "variables": "VALUE"
      }
    }
  ]
}