Fork me on GitHub

Shift Fuzzer

generates random valid Shift ASTs


The Shift Fuzzer generates a random, valid Shift AST, and may generate any JavaScript program up to a given complexity (AST depth) with a non-zero probability. Additional APIs exist for generating only certain node types and for integrating a custom pseudo-random number generator for deterministic and reproducible fuzzing.


This demo uses the fuzzer to generate a random Shift AST and renders it using the Shift Code Generator. Press the green button in the upper right corner of the demo to begin cycling through random programs. If the fuzzer finds a program that cannot be parsed, you will be prompted to open an issue on GitHub because at least one of the fuzzer, the code generator, or the parser will have a bug.


npm install shift-fuzzer


import fuzzProgram, {FuzzerState, fuzzFunctionDeclaration} from "shift-fuzzer";
import render from "shift-codegen";

// generate random program
let randomProgramAst = fuzzProgram();
let randomProgram = render(randomProgramAst);

// generate random FunctionDeclaration
let randomFunctionAst = fuzzFunctionDeclaration(new FuzzerState({maxDepth: 7}));
let randomFunction = render(randomFunctionAst);

// generate random program from a seed
const RNG_SEED = 0xBADBE1BE1;
let prng =
    return function nextDouble() {
      // implementation left as an exercise for the reader
let seededRandomProgramAst = fuzzProgram(new FuzzerState({rng: prng, maxDepth: 7}));
let seededRandomProgram = render(seededRandomProgramAst);