Skip to main content

Imports

Jade's use statement loads another .jde file and makes its top-level function and variable definitions available in the importing file.

Syntax

use "<path>"
  • <path> — a relative path to another .jde file, resolved relative to the directory of the importing file.
  • The use statement must appear at the top level (not inside a function body).
  • The imported file is executed once; all top-level bindings it produces become available in the importing scope.

Basic Example

math_lib.jde — the library:

fn add(a, b) { return a + b }
fn mul(a, b) { return a * b }

main.jde — the importer:

use "math_lib.jde"

let x = add(2, 3) // 5
let y = mul(4, 5) // 20

After the use statement executes, add and mul are defined in the importing scope exactly as if they had been written inline. They can be called, passed as values, or stored in variables.

Path Resolution

Paths in use are resolved relative to the directory containing the importing file, not the directory from which jade was invoked.

// If your project layout is:
// project/
// main.jde
// lib/
// utils.jde

// Inside main.jde:
use "lib/utils.jde"
note

Absolute paths are not supported. Always use paths relative to the importing file's location.

What Gets Imported

All top-level bindings in the imported file are brought into scope — including functions, variables, and struct definitions. The imported file runs to completion before execution of the importing file continues past the use statement.

Exported from libAvailable after use
fn add(a, b) { … }add(2, 3) works
let PI = 3.14159PI is in scope
struct Point { x, y }Point { x: 1, y: 2 } works

Multiple Imports

A file may contain multiple use statements. Each is processed in order. If two imported files define the same name, the later import wins.

use "math_lib.jde"
use "string_lib.jde"

let n = add(1, 2)
let s = concat("hello", " world")

No Re-export

Imports are not re-exported. If a.jde uses b.jde, a third file that uses a.jde does not automatically get access to what b.jde defined. Each file must import the libraries it needs directly.