Prepack: Lexical declarations in top-level lexical scope are omitted

Created on 9 May 2018  路  2Comments  路  Source: facebook/prepack

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.

bug help wanted serializer level 2 (easy)

Most helpful comment

I would love to work on this!

All 2 comments

This is a valid bug that should get fixed.

Prepack's main focus is on the JavaScript ES5 feature set, and thing tend to be brittle for ES6 features.

I would love to work on this!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandipp picture sandipp  路  4Comments

aligoren picture aligoren  路  6Comments

kabirbaidhya picture kabirbaidhya  路  6Comments

sebmarkbage picture sebmarkbage  路  6Comments

skyne98 picture skyne98  路  7Comments