Modules#

Nonstraightforward supports JavaScript modules. Currently, only ES modules are supported, however CommonJS support will come sometime in the future.

Importing JavaScript modules#

Importing a JavaScript module can be done with

from module "./my_module.js" request defaultExport;
from module "./my_module2.js" request { factorial, fibonacci, system_shredder };
from module "node:fs/promises" request everything as fs;

The first form is a default import, which in JavaScript is

import defaultExport from "./my_module.js";

The second form is an import list (or whatever it’s called) which compiles to

import { factorial, fibonacci, system_shredder } from “./my_module2.js”;

The third form (other than importing a Node.js module) is a library import which always requires an alias to be provided.

import * as fs from "node:fs/promises";

Importing Nonstraightforward modules#

Importing Nonstraightforward modules is as simple as replacing .js with .nstrfwd, as shown below.

The top of src/main.nstrfwd as of C9 2026.05.16#
from module "./tokenizer.nstrfwd" request tokenize;
from module "./parser.nstrfwd" request { parse };
from module "./codegen.nstrfwd" request { emit_script };
from module "./errors.nstrfwd" request { nonstraightforward_shut_up, nonstraightforward_dont_care, nonstraightforward_error_count };
from module "node:fs/promises" request everything as fs;
from module "node:util" request everything as util;

In the example above, tokenizer.nstrfwd, parser.nstrfwd, codegen.nstrfwd, and errors.nstrfwd are Nonstraightforward modules. They used to require the .nstrfwd.js extension (the file extension used by the compiler for output files) but as of C9 2026.05.16, the code generator replaces .nstrfwd.js automatically.