In a JavaScript module, it is recommended to export function only so that the module is tamper proof. The function restriction ensure the following.
- There are no module wide statements other than function declarations.
- There are some functions that must be declared.
- To a particular function, the argument count can be also validated.
JavetSanitizerModuleFunctionChecker
is the one that enforces this check.
import { x } from 'x.mjs';
function main() {
// Do something.
}
const a = 1; // Variable declaration is invalid.
class A {} // Class declaration is invalid.
JSON.stringify(undefined); // Regular statement is invalid.
The default must-have function list is as follows:
main
Please refer to the tutorial for more details.