Skip to main content

Module expr

Module expr 

Source
Expand description

The !!js expression subset evaluated at config hand-off.

Upstream evaluates !!js scalars with real JavaScript against the loader context. The expressions that actually appear in the shipped bundles only reference process.*, so this module evaluates that subset synchronously — at the same hand-off point as the ${{ env.NAME }} interpolation (crate::interpolate) — with a hand-written lexer and parser. Expressions referencing injected context (ctx.*, dshHomePath(…)) are deferred to the owning plugin’s lazy evaluation and fail here with a clear subset error.

Supported syntax (JavaScript precedence):

  • the ternary cond ? then : else
  • ??, ||, && with JavaScript truthiness (empty strings and zero are falsy); like JavaScript, ?? may not be mixed with ||/&& without parentheses
  • strict equality === / !== (loose ==/!= is outside the subset)
  • unary !
  • string literals in single or double quotes, decimal integers and floats, true/false/null/undefined
  • member access limited to process.platform, process.env.NAME (unset variables are undefined), and process.cwd()

Values are Nodes directly; null and undefined both map to Node::Null, which is also what ?? triggers on.

Functions§

evaluate
Evaluate one !!js expression, reading environment variables from the process environment.
evaluate_node
Recursively evaluate every Node::Expr in a value tree, leaving all other nodes untouched — the expression twin of crate::interpolate::interpolate_node, applied when config is handed to a plugin.
evaluate_node_with
evaluate_node with a caller-supplied environment lookup.
evaluate_with
Evaluate one !!js expression against a caller-supplied environment lookup, which maps a variable name to its value (None when unset).