Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export statement #101

Open
KCreate opened this issue Apr 3, 2022 · 0 comments
Open

Export statement #101

KCreate opened this issue Apr 3, 2022 · 0 comments
Labels

Comments

@KCreate
Copy link
Owner

KCreate commented Apr 3, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant