Enforce stricter file-level closures in JavaScript code.
Review Request #9189 — Created Sept. 8, 2017 and submitted — Latest diff uploaded
With the move to ES6, we've been using
{ ... }
around files that need
to define local variables and assuming Babel would do the right thing.It doesn't.
Each resulting variable defined on a file level ran the risk of being
redefined by another file, and this would break all sorts of things in
confusing ways when that variable is accessed by any other code. The fix
to this is to go back to wrapping files with(function() { ... })()
,
which is the only way to guarantee safety.All files using simple braces around the file contents to enforce scope
have been updated. All future files will need to use the old form to
ensure safe scoping rules.
Unit tests pass.
Verified this fixed the problem found in production.