GooberScript Compiler

raw JSON →
1.2.0 verified Fri May 01 auth: no javascript

A self-contained compiler, lexer, parser, and transpiler for the GooberScript language, a friendly syntax that compiles to clean ES2020 JavaScript. Version 1.2.0 targets browser and Node.js environments, distributed via npm and CDN (jsDelivr). Key differentiators: includes a complete toolchain in a single file (goobc.js), exposes a global `Goobc` object for browser script tags, enforces mandatory file structure and unique syntax rules like the `yippee;` check marker. Ideal for educational platforms like CodeHS, with no external dependencies.

error Goobc is not defined
cause Package not loaded or imported incorrectly in Node.js (require not supported).
fix
Use CDN script tag: <script src="https://cdn.jsdelivr.net/npm/gooberscript-compiler@1/goobc.js"></script> or in Node.js: import Goobc from 'gooberscript-compiler'
error TypeError: Goobc.compile is not a function
cause Attempted to use a named import `{ compile }` instead of default import.
fix
Use import Goobc from 'gooberscript-compiler' then Goobc.compile(source).
error Missing mandatory header 'dear goober;'
cause GooberScript source is missing the required file header.
fix
Start every GooberScript program with exactly dear goober; on its own line.
error Missing mandatory check 'yippee;'
cause A function body lacks the required `yippee;` statement.
fix
Add yippee; as the first statement inside each function body.
gotcha GooberScript source must include the mandatory `dear goober;` header and `thanks, goober;` footer, plus a `yippee;` statement in every function body.
fix Ensure source begins with `dear goober;\n` and ends with `\nthanks, goober;` and each function contains `yippee;` once.
gotcha All statements must end with `ya;` (equivalent to semicolon), including function calls, variable declarations, and control flow.
fix Append `ya;` after every statement, e.g., `holler("Hello") ya;`
gotcha The compiler runs client-side and can execute arbitrary JavaScript via `new Function()`. Ensure source is trusted to avoid XSS.
fix Only compile and run GooberScript from trusted sources; validate or sandbox if user-provided.
breaking v1.2.0 changed the return shape of Goobc.compile(): errors are now in an array instead of an object property `error`.
fix Access `result.errors` (array) instead of `result.error` (string).
npm install gooberscript-compiler
yarn add gooberscript-compiler
pnpm add gooberscript-compiler

Demonstrates loading the compiler via CDN, compiling a simple GooberScript program, and executing the transpiled JavaScript.

// Load via CDN in HTML: <script src="https://cdn.jsdelivr.net/npm/gooberscript-compiler@1/goobc.js"></script>

const gooberSource = `
dear goober;
heck name iskinda "World" ya;
goober greet() {
  yippee;
  holler("Hello, " + name + "!") ya;
} ya;
greet() ya;
thanks, goober;
`;

const result = Goobc.compile(gooberSource);

if (result.errors && result.errors.length > 0) {
  console.error('Compilation failed:', result.errors);
} else {
  console.log('Transpiled JS:', result.js);
  new Function(result.js)();
}