pub fn check_early_errors(stmts: &[Stmt]) -> Result<(), String>Expand description
Reject a duplicate lexical declaration before anything runs, as node does.
let a = 1; let a = 2; is a SyntaxError at PARSE time in node, and this
engine ran it — the second declaration simply won. That is the gap that lets
a genuine double-declaration bug through silently, and it bit three test
files in this repo whose collisions node rejected and this accepted.
Deliberately narrow, since a false positive REJECTS a program that works:
only the three collisions the spec is unambiguous about are reported —
two lexical declarations of one name in the same statement list, a lexical
name that a var in the same subtree hoists onto, and a lexical name
colliding with a function declaration beside it. Repeated vars, and the
same name in nested scopes, stay legal.
V8 finds a collision while parsing, when the second of the two
declarations is reached, so the one reported is the collision whose later
declaration comes first in the source, and the report’s arrow underlines
that declaration’s name (parser::note_error_span).