As any other syntactic feature, it should be evaluated in order to be detected. Since eval
can be restricted, this may be impossible when CSP is enabled:
let isAsync = true;
try {
eval('async () => {}');
} catch (e) {
if (e instanceof SyntaxError)
isAsync = false;
else
throw e; // throws CSP error
}
If there's a chance that target browsers don't support a feature, the code should be transpiled.
The alternative that allows to avoid CSP restrictions on eval
is to use external script to detect syntactic features, as described here.