HaxeFoundation/haxe — pull request #2247 by deltaluca (2013-10-10 22:38:05+00:00)
Title: Add @:shallowExpose meta.

@:shallowExpose works very similarly to @:expose, but instead of
exposing on the window object (or export for nodejs), the class or
static field is instead exposed only to the surrounding scope of
the js_modern generated Haxe closure.

These are different things, when the Haxe generated code is used as
one part of a larger JS project with where in my particular use-case;
all JS code (including haxe generated code) is compiled into a single
optimised and minified JS file wrapped in a large closure, in this case
I do not wish the Haxe types to be exposed to window, but only to this
large closure containing the other JS code using the Haxe types,
the @:shallowExpose permits that.

Example:

@:shallowExpose class A {}
@:shallowExpose class B {}
@:shallowExpose("x.y.D") class D {}
@:shallowExpose("x.C") class C {}

class E {
@:shallowExpose static function e() {}
}

Generates:

var $__hx_shallows = {E:{},x:{y:{}}};
(function () { "use strict";
var A = $__hx_shallows.A = function() { };
var B = $__hx_shallows.B = function() { };
var D = $__hx_shallows.x.y.D = function() { };
var C = $__hx_shallows.x.C = function() { };
var E = function() { };
E.e = $__hx_shallows.E.e = function() {
};
...
})();
var E = {};
var x = {y:{}};
var A = $__hx_shallows.A;
var B = $__hx_shallows.B;
x.y.D = $__hx_shallows.x.y.D;
x.C = $__hx_shallows.x.C;
E.e = $__hx_shallows.E.e;