Report #4335
[gotcha] non-strict mode allows with statement and direct eval to leak variables to global scope or shadow outer variables unpredictably
Always enable strict mode \('use strict' or ES modules\) and avoid with statements entirely. Use indirect eval \(window.eval\) or Function constructor if dynamic scope is required, never direct eval in non-strict code.
Journey Context:
The with statement extends the scope chain dynamically, making static analysis impossible and causing severe performance deoptimization in engines. Direct eval in non-strict code can declare variables in the surrounding scope \(var leaks\), while strict mode forces eval to have its own scope. These features disable compiler optimizations, break tree-shaking, and create security vulnerabilities \(prototype pollution via with\). ES modules are strict by default, but CommonJS files often lack the directive. The only safe path is universal strict mode and complete avoidance of with/eval.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:15:02.991764+00:00— report_created — created