CodeSampleX

Ejemplo

@webassemblyjs/wast-printer 1.14.1: print WebAssembly AST to wast format

Muestra verificada para npm @webassemblyjs/wast-printer 1.14.1: print WebAssembly AST to wast format. El contrato se ejecutó en node 22 · linux alpine/x64 …

sha256:b56953cc384bdf2d615dbf6372c32cfbdbb1521e537c2a60652f0e8912f8450c

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Caso

HOW
Objetivo
print WebAssembly AST to wast format
Paquetes
Símbolos
  • print
Entorno
node 22.23.2
Creado
2026-08-27T23:33:16Z

Contrato

  1. print converts a WebAssembly Program AST node into formatted wast string
  2. print supports printing module declarations, functions, signatures, instructions, and exports
  3. print throws an error when called with a non-Program AST node

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • test/contract.mjs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: print WebAssembly AST to wast format
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40webassemblyjs/wast-printer@1.14.1
Demonstrate these symbols/APIs:
  - print

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:c9e015b45f517ba43aff68683f6cc387512c15206f93995139239457863fb38e","contract":["print converts a WebAssembly Program AST node into formatted wast string","print supports printing module declarations, functions, signatures, instructions, and exports","print throws an error when called with a non-Program AST node"],"goal":"print WebAssembly AST to wast format","kind":"HOW","packages":["pkg:npm/%40webassemblyjs/wast-printer@1.14.1"],"schemaVersion":1,"symbols":["print"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40webassemblyjs/wast-printer@1.14.1"],"schemaVersion":1,"subject":"pkg:npm/%40webassemblyjs/wast-printer@1.14.1","symbols":["print"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-wast-printer",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-wast-printer",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@webassemblyjs/wast-printer": "1.14.1"
      }
    },
    "node_modules/@webassemblyjs/ast": {
      "version": "1.14.1",
      "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.14.1.tgz",
      "integrity": "sha512-nuBEDgQfm1ccRp/8bCQrx1frohyufl4JlbMMZ4P1wpeOfDhF6FQkxZJ1b/e+PLwr6X1Nhw6OLme5usuBWYBvuQ==",
      "license": "MIT",
      "dependencies": {
        "@webassemblyjs/helper-numbers": "1.13.2",
        "@webassemblyjs/helper-wasm-bytecode": "1.13.2"
      }
    },
    "node_modules/@webassemblyjs/floating-point-hex-parser": {
      "version": "1.13.2",
      "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.13.2.tgz",
      "integrity": "sha512-6oXyTOzbKxGH4steLbLNOu71Oj+C8Lg34n6CqRvqfS2O71BxY6ByfMDRhBytzknj9yGUPVJ1qIKhRlAwO1AovA==",
      "license": "MIT"
    },
    "node_modules/@webassemblyjs/helper-api-error": {
      "version": "1.13.2",
      "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.13.2.tgz",
      "integrity": "sha512-U56GMYxy4ZQCbDZd6JuvvNV/WFildOjsaWD3Tzzvmw/mas3cXzRJPMjP83JqEsgSbyrmaGjBfDtV7KDXV9UzFQ==",
      "license": "MIT"
    },
    "node_modules/@webassemblyjs/helper-numbers": {
      "version": "1.13.2",
      "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.13.2.tgz",
      "integrity": "sha512-FE8aCmS5Q6eQYcV3gI35O4J789wlQA+7JrqTTpJqn5emA4U2hvwJmvFRC0HODS+3Ye6WioDklgd6scJ3+PLnEA==",
      "license": "MIT",
      "dependencies": {
        "@webassemblyjs/floating-point-hex-parser": "1.13.2",
        "@webassemblyjs/helper-api-error": "1.13.2",
        "@xtuc/long": "4.2.2"
      }
    },
    "node_modules/@webassemblyjs/helper-wasm-bytecode": {
      "version": "1.13.2",
      "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.13.2.tgz",
      "integrity": "sha512-3QbLKy93F0EAIXLh0ogEVR6rOubA9AoZ+WRYhNbFyuB70j3dRdwH9g+qXhLAO0kiYGlg3TxDV+I4rQTr/YNXkA==",
      "license": "MIT"
    },
    "node_modules/@webassemblyjs/wast-printer": {
      "version": "1.14.1",
      "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.14.1.tgz",
      "integrity": "sha512-kPSSXE6De1XOR820C90RIo2ogvZG+c3KiHzqUoO/F34Y2shGzesfqv7o57xrxovZJH/MetF5UjroJ/R/3isoiw==",
      "license": "MIT",
      "dependencies": {
        "@webassemblyjs/ast": "1.14.1",
        "@xtuc/long": "4.2.2"
      }
    },
    "node_modules/@xtuc/long": {
      "version": "4.2.2",
      "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz",
      "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==",
      "license": "Apache-2.0"
    }
  }
}
package.json
{
  "name": "sample-wast-printer",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@webassemblyjs/wast-printer": "1.14.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "print WebAssembly AST to wast format",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40webassemblyjs/wast-printer@1.14.1"
  ],
  "symbols": [
    "print"
  ]
}
src/index.mjs
import { print } from "@webassemblyjs/wast-printer";

export function printAst(ast) {
  return print(ast);
}

export function createSampleProgram(moduleName, funcName) {
  return {
    type: "Program",
    body: [
      {
        type: "Module",
        id: moduleName,
        fields: [
          {
            type: "Func",
            name: { type: "Identifier", value: funcName },
            signature: {
              type: "Signature",
              params: [
                { id: "a", valtype: "i32" },
                { id: "b", valtype: "i32" }
              ],
              results: ["i32"]
            },
            body: [
              {
                type: "Instr",
                id: "i32.add",
                args: [
                  { type: "Instr", id: "get_local", args: [{ type: "Identifier", value: "a" }] },
                  { type: "Instr", id: "get_local", args: [{ type: "Identifier", value: "b" }] }
                ]
              }
            ]
          },
          {
            type: "ModuleExport",
            name: funcName,
            descr: {
              exportType: "Func",
              id: { type: "Identifier", value: funcName }
            }
          }
        ]
      }
    ]
  };
}
test/contract.mjs
import assert from "node:assert/strict";
import { print } from "@webassemblyjs/wast-printer";
import { printAst, createSampleProgram } from "../src/index.mjs";

// Test 1: print converts a WebAssembly Program AST node into formatted wast string
{
  const ast = createSampleProgram("math_module", "add");
  const output = print(ast);
  assert.equal(typeof output, "string");
  assert.ok(output.includes("(module math_module"));
  assert.ok(output.includes("(func $add (param $a i32) (param $b i32) (result i32)"));
  assert.ok(output.includes("(i32.add (get_local $a) (get_local $b))"));
  assert.ok(output.includes("(export \"add\" (func $add))"));
}

// Test 2: printAst helper correctly delegates to print
{
  const emptyProgram = {
    type: "Program",
    body: [
      {
        type: "Module",
        id: "empty_mod",
        fields: []
      }
    ]
  };
  const result = printAst(emptyProgram);
  assert.equal(typeof result, "string");
  assert.ok(result.includes("(module empty_mod"));
}

// Test 3: print throws an error when called with a non-Program AST node
{
  assert.throws(
    () => {
      print({ type: "Module", id: "invalid", fields: [] });
    },
    {
      name: "Error",
      message: /Unsupported node in print of type: Module/
    }
  );
}

console.log("All contract tests passed successfully.");

Seeder de origen

anónimo