Language reference · section 18
18. Classes and modules
Feature: Classes
Scenario: A class extends another class
Given the code "class B extends A:"
Then B inherits the methods of A
Scenario: A class has fields, a constructor, and methods
Given a class with a field n, a constructor, and a method
When the code writes new B(2)
Then the constructor runs with 2
Scenario: A class field can have a type
Given the code "n: number = 1" in a class body
Then n is a number field
Scenario: An async method returns a promise
Given an async class method
Then the method returns a Promise
Scenario: Class methods use this
Given a class method that reads this.name
Then the method reads the name of the object it belongs to
Scenario: new takes a dotted name
Given the code "new ns.Thing(1)"
Then the code constructs ns.Thing
Feature: Modules
Scenario: A named import brings in names
Given the code 'from "mod" import a, b'
Then the code can use a and b
Scenario: export makes a name visible to other modules
Given the code "export x = 1"
Then other modules can import x
Scenario: export default sets the default export
Given the code "export default f"
Then other modules can import the default value
Scenario: export can mark a decorated function
Given the code "@worker" above "export fn f(n: int): int:"
Then other modules can import f and call it on a worker
Pin modules compile to ES module syntax.