This repository was archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 419
PP0026
Dan Abramov edited this page Feb 21, 2018
·
4 revisions
Mutating an object with unknown properties, after some of those properties have already been used, is not yet supported
To a certain extent, Prepack can handle partially unknown objects.
For example, even if obj
is partially unknown, Prepack can still process code like this:
var target = {};
Object.assign(target, obj);
However, since Prepack doesn't know all the properties of obj
, it can't know what the target
object is going to look like after this call. In this case, Prepack emits Object.assign()
in the result code instead of evaluating it at compile time.
Currently, this is only safe to do if target
doesn't get mutated further down the line. For example, code like this will cause a compile error:
var target = {};
Object.assign(target, obj);
target.hello = 'world';
In the future, Prepack may be able to handle this case better by "snapshotting" the state of target
before it was passed to Object.assign
. However, this is not supported yet.