facebookarchive/prepack

Lexical declarations in top-level lexical scope are omitted

Open

#1.905 geöffnet am 8. Mai 2018

Auf GitHub ansehen
 (3 Kommentare) (1 Reaktion) (0 zugewiesene Personen)JavaScript (520 Forks)batch import
bughelp wantedlevel 2 (easy)serializer

Repository-Metriken

Stars
 (14.268 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

const f = 0; is considered by Prepack to be totally dead. But it's not: the top-level lexical scope is shared across scripts, just below the global scope. So while that may not be a global declaration, in that it does not create a property of the global object, it is available to other code on the page just as if it had been var instead of const; other scripts can write console.log(f) to print 0. In that sense it is not safe to eliminate.

This may or may not be a bug, depending on your perspective. I'm just not sure what things prepack considers dead: { const f = 0; } definitely is, var f = 0; definitely isn't, but this is kind of in-between.

Contributor Guide