This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index at /llms.txt, or add .md to any page's URL.
Files, indentation, and literals
Top-level declarations start in column 1. Use spaces for indentation; two spaces
per level is the formatter's style. Blank lines and // comments are ignored.
There are no semicolons or braces around declaration bodies.
The top-level forms are component, shape, fn, style, decoration, atom,
keyframes, timeline, font, sound, theme, color-profile, routes,
members, use, and test. A file can contain multiple declarations. Used files
may supply reusable declarations; the importing file's first component remains
its root.
text
use Card, Badge as StatusBadge from "./parts.contract"
use Item, pulse from "./models.contract"
Each file has its own names (LLP 1091): its own declarations, and the names its
use lines list. Nothing comes along unnamed: if parts.contract uses Icon,
Card still works, but this file writes Icon() only after naming it too,
from ./icons.contract or from ./parts.contract, which passes on what it
names. The refusal names the lines a file lacks, and contract fmt --uses app.contract writes them in every file of the app. as renames one name in
this file. Any component, shape, fn, style,
keyframes or timeline can be named; there is no export keyword.
Two files may declare the same name: each file's references mean its own
declaration. One name brought into a file twice from two files' declarations
(two however alike their text), or brought and also declared, is refused;
declare it once and use it from that file, or rename one with as. Fonts stay
app-wide, like CSS's @font-face.
A use names one of three things:
•
a file of the app: ./parts.contract, or ../lib/row.contract, as long as
it stays inside the app's directory;
•
a built-in: use Activity from "exact:motion" is the one app-wide timeline
for loading indicators, so every spinner keeps one rhythm;
•
a package: use Card from "@acme/ui" reads an installed package's
.contract files, found in node_modules as Node finds JavaScript. Its
package.json exports maps . (and any subpaths) to .contract files;
without exports, index.contract. A local library is a dependency too:
"@me/ui": "file:../ui" in the app's package.json, or a Bun workspace.
A build installs a file: package again (bun install --frozen-lockfile)
when its directory no longer matches what node_modules holds, so an edit
to it reaches the next build. A package's own relative uses stay inside the
package.
A library can supply components, shapes, functions, styles, keyframes and
timelines. Its components may own resources and mutations using sources declared
by its own package's module, with the app supplying the required grants. They may
also own tasks at bounded uses, or take data through props, inject and slots.
Fonts it names are the app's to supply.
Contract never imports JavaScript or TypeScript. Import cycles and unknown names
are refused. Keep external work behind the data interface.
Identifiers start with an ASCII letter or underscore. Letters, digits, and
underscores can follow. A hyphen followed by a letter is part of the identifier:
background-color is one name. Consequently, a-b is a name; write a - b for
subtraction. x-1 is still subtraction, but spaces make the intention clearer.
Literal | Examples |
|---|---|
Number | 0, 12, 0.5, -8 |
String | "Hello", "line\nbreak" |
Template | `Hello, ${name}` |
Boolean | true, false |
Empty option | none |
Present option | some(value) |
Empty list | [], with its element type determined by context |
Use ordinary decimal numbers, double-quoted strings, and backtick templates.
Exponent notation is a number (1e3 is 1000). Single-quoted strings, digit
separators, null, and undefined are not the language's literal forms.
Strings and template text accept the escapes \n, \t, \", \\, \` and \$, and a Unicode code
point as JavaScript writes it, \u{2011} or \u2011. Templates can contain
expressions, quoted strings, and nested templates. Keep an individual string or template on one
source line.
Newlines inside parentheses, brackets, and expression braces continue the same
logical line. Element attributes may continue on deeper-indented lines:
text
text title
role="heading"
aria-level=2
color="-exact-secondary-label"
An attribute continuation starts with name=. A child starts with a tag or a
component use. Use contract fmt --stdout file.contract to preview canonical
formatting, or contract fmt file.contract to write it.
Is this helpful
Last updated November 30, 2026