charly-vm
charly-vm copied to clipboard
Export statement
Exporting variables, functions, classes
- the
exportkeyword can be used to export constants, functions and classes from a module - the compiler desugars the export statements into a class declaration that gets returned from the module function
- exporting
letdeclarations is prohibited, as to not cause the possible misconception that any future updates to the variable will be reflected in the module instance
export const bar = 25
export func do_stuff {
print("hi")
}
export class Person {
property name
property age
}
export foo
export foo.baz
Default export
- A module can export at most one default export
- The default export is the binding that is used when no specific named bindings are imported
// liba.ch
export const foo = 100
export class Person {}
export default class FooBar {}
// main.ch
import liba
liba // class FooBar
import liba as mylib
mylib // class FooBar
import { foo, Person, FooBar } from liba
foo // 100
Person // class Person
FooBar // class FooBar
liba // class FooBar
import { foo, Person, FooBar } from liba as mylib
foo // 100
Person // class Person
FooBar // class FooBar
liba // class FooBar
mylib // class FooBar