emscripten-library-decorator
Advanced tools
Comparing version 0.1.0 to 0.1.1
47
index.ts
// @dep decorator. | ||
// Apply to a function, to export other variables whenever it's used. | ||
// Arguments can be functions to export or names of global variables. | ||
function dep(...depList: any[]) { | ||
@@ -33,2 +36,4 @@ return((target: Object, functionName: string) => { | ||
// @exportLibrary decorator. | ||
// Apply to a class with static methods, to export them as functions. | ||
function exportLibrary(target: any) { | ||
@@ -38,30 +43,30 @@ mergeInto(LibraryManager.library, target); | ||
var namespaceList: string[] = []; | ||
// @exportNamespace decorator. | ||
// Apply to a class named "_" and defined at the end of the namespace, | ||
// to export the entire namespace. | ||
function _initNamespaces() { | ||
var namespaceList = $NAMESPACELIST; | ||
for(var i = 0; i < namespaceList.length; ++i) { | ||
var space = namespaceList[i]; | ||
if(space) space.init(space); | ||
} | ||
} | ||
// @exportNamespace decorator. | ||
function exportNamespace(name: string) { | ||
return((target: any) => { | ||
var exportName = name.substr(1); | ||
var body = '(' + __decorate.caller.caller.toString().replace(/var +_ *= *[^]*/, '}') + ')'; | ||
eval(name + ' = { init: ' + body + ' };'); | ||
eval(name + '={};'); | ||
namespaceList.push(name); | ||
var lib: _Library = { | ||
_extends: __extends, | ||
_decorate: __decorate, | ||
defineHidden: _defineHidden | ||
}; | ||
var safeList = namespaceList.map((name: string) => ("typeof(" + name + ")=='object'&&" + name)); | ||
lib[exportName + '__deps'] = Object.keys(lib); | ||
lib[exportName + '__postset'] = body + '(' + name + ')'; | ||
mergeInto(LibraryManager.library, { | ||
initNamespaces: eval('(' + _initNamespaces.toString().replace('$NAMESPACELIST', '[' + safeList.join(',') + ']') + ')') | ||
}); | ||
mergeInto(LibraryManager.library, lib); | ||
}); | ||
} | ||
// @_defineHidden decorator. | ||
// Apply to a property to protect it from modifications and hide it. | ||
function _defineHidden(value: any) { | ||
@@ -78,6 +83,2 @@ return((target: any, key: string) => { | ||
// Placeholder variable replaced in code with array contents. | ||
declare var $NAMESPACELIST: any[]; | ||
// Typescript internal shim functions. | ||
@@ -90,3 +91,3 @@ | ||
interface _Library {} | ||
interface _Library { [name: string]: any } | ||
@@ -101,3 +102,3 @@ interface _LibraryManager { | ||
declare function mergeInto(lib: _Library, proto: any): void; | ||
declare function mergeInto(target: _Library, extension: _Library): void; | ||
@@ -104,0 +105,0 @@ // The HEAP* arrays are the main way to access the C++ heap. |
{ | ||
"name": "emscripten-library-decorator", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Decorators for writing Emscripten libraries", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/charto/emscripten-library-decorator", |
5944
82