Assertions Removal
Potency None
Resilience High
Cost None
Tags: assertion, elimination, removal, optimization, assert
Description
An assertion is a statement that contains a test predicate (a true-false expression) which is expected to always be true, otherwise the assertion will fail. Typically, assertions are turned off when the code is deployed to production to avoid any side effects and reduce performance impact. This transformation can be used to remove all assertions from the production code including their function declarations.
Code Annotation Example
Example
The following example contains some assertions that will be removed by the transformation:
function assert(result, description) {
}
function a() {
}
function b() {
}
function c() {
}
var d = 1;
assert(d === 1);
d += 2;
assert(d > 1, 'd is greater than 1');
Adding assert
to the names list removes any function declaration and function call with that name:
function a() {
}
function b() {
}
function c() {
}
var d = 1;
d += 2;
Option Types
Name | Required | Default Value | Description |
names | Yes | [] | List containing the names of the assertions to be removed. Each name can be provided as a string or as a regular expression. |
Browser Compatibility
Browser | Compatible Versions | Tested Versions | Notes |
Chrome | 80+ | 80+ | |
Firefox | 80+ | 80+ | |
Internet Explorer | 8+ | 8+ | |
Microsoft Edge | 108+ | 108+ | |
Safari | 12.1+ | 12.1+ | |
API Parameters
Example:
{
"keys": {
"accessKey": "XXXXXX",
"secretKey": "YYYYYY"
},
"applicationId": "ZZZZZZ",
"params": [
{
"name": "assertionsRemoval",
"options": {
"names": []
}
}
]
}