Skip to content

Export statement #101

Description

@KCreate

Exporting variables, functions, classes

  • the export keyword 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 let declarations 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions