-
Notifications
You must be signed in to change notification settings - Fork 103
Minification and export rules
JSX supports minification as of commit dc3f7cc.
This document describes how to use the feature.
Minification is turned on by using the --minify compiler flag.
jsx --release --minify myapp.jsx
It is possible to export a JSX class to JavaScript by using the export attribute. Exported functions cannot be overloaded; others should be marked as noexport.
// the class is exported
__export__ class ExportedClass {
// only one constructor can be exported
function constructor() {
}
// other constructors should be marked __noexport__
__noexport__ function constructor(a : number) {
}
// properties not starting with "_" of a exported class are exported by default
function f() {
}
// properties that need not be exported can be marked as such
__noexport__ var n : number;
// properties starting with "_" can also be exported by explicitly specifying as such
__export__ var _n2 : number;
}
_Main.main(args : string[]) and _Test.test*() are automatically marked as __export__.
Code generated by the JSX compiler is stored in a single object called JSX. The object has a property called require that returns an object that maps the name of classes and their bodies given a name of a source file.
The following JavaScript code loads a class called ExportedClass defined in file exported.jsx, instantiates an object, and calls its method named f.
var ExportedClass = JSX.require("exported.jsx").ExportedClass;
var obj = new ExportedClass;
obj.f();