YahooArchive/express-state

Namespaces can be shadowed by data

jeremyruppel opened this issue · 1 comments

Right now, because express-state keeps namespaces separate from their data, it is possible that data can shadow previously defined namespaces. Given some exposed variables like:

expose('foo', {});
expose('foo.bar.baz', 'baz');

The resulting javascript looks like:

root.foo || (root.foo = {});
root.foo.bar || (root.foo.bar = {});

root.foo = {};
root.foo.bar.baz = "baz";

And the root.foo.bar namespace gets shadowed by the data in root.foo.

I see, the resulting code will throw because root.foo.bar will be undefined when it tries to assign a value to root.foo.bar.baz.