TypeScript Language Specification v1.5
TypeScript Language Specification v1.5
TypeScript Language Specification v1.5
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
where ModuleName is the name of the module and ModuleStatements is the code generated for the<br />
statements in the module body. The ModuleName function parameter may be prefixed with one or more<br />
underscore characters to ensure the name is unique within the function body. Note that the entire module<br />
is emitted as an anonymous function that is immediately executed. This ensures that local variables are in<br />
their own lexical environment isolated from the surrounding context. Also note that the generated<br />
function doesn't create and return a module instance, but rather it extends the existing instance (which<br />
may have just been created in the function call). This ensures that internal modules can extend each other.<br />
An import statement generates code of the form<br />
var = ;<br />
This code is emitted only if the imported entity is referenced as a PrimaryExpression somewhere in the<br />
body of the importing module. If an imported entity is referenced only as a TypeName or ModuleName,<br />
nothing is emitted. This ensures that types declared in one internal module can be referenced through an<br />
import alias in another internal module with no run-time overhead.<br />
When a variable is exported, all references to the variable in the body of the module are replaced with<br />
.<br />
This effectively promotes the variable to be a property on the module instance and ensures that all<br />
references to the variable become references to the property.<br />
When a function, class, enum, or module is exported, the code generated for the entity is followed by an<br />
assignment statement of the form<br />
. = ;<br />
This copies a reference to the entity into a property on the module instance.<br />
142