Clarify tsetse's isLiteral documentation. PiperOrigin-RevId: 261407997
diff --git a/internal/tsetse/util/is_literal.ts b/internal/tsetse/util/is_literal.ts index 8b7209c..2f44ce2 100644 --- a/internal/tsetse/util/is_literal.ts +++ b/internal/tsetse/util/is_literal.ts
@@ -2,7 +2,21 @@ import {findInChildren} from './ast_tools'; /** - * Determines if the given ts.Node is literal enough for security purposes. + * Determines if the given ts.Node is literal enough for security purposes. This + * is true when the value is built from compile-time constants, with a certain + * tolerance for indirection in order to make this more user-friendly. + * + * This considers a few different things. We accept + * - What TS deems literal (literal strings, literal numbers, literal booleans, + * enum literals), + * - Binary operations of two expressions that we accept (including + * concatenation), + * - Template interpolations of what we accept, + * - `x?y:z` constructions, if we accept `y` and `z` + * - Variables that are const, and initialized with an expression we accept + * + * And to prevent bypasses, expressions that include casts are not accepted, and + * this checker does not follow imports. */ export function isLiteral(typeChecker: ts.TypeChecker, node: ts.Node): boolean { if (ts.isBinaryExpression(node) &&