CodeSampleX

Exemple

@babel/types 7.29.7: numericLiteral

Échantillon vérifié pour npm @babel/types 7.29.7: numericLiteral. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:8c58390f9cd42c4020a199e387ba5bf9cf94003fd2b7904554e574dcf071f549

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-05

Cas

HOW
Objectif
verify @babel/types.numericLiteral in pkg:npm/%40babel/types@7.29.7
Paquets
Symboles
  • @babel/types.numericLiteral
Environnement
node 22.23.2
Créé
2026-09-05T21:24:19Z

Contrat

  1. types.numericLiteral creates a NumericLiteral AST node with the specified number value and type 'NumericLiteral'
  2. types.numericLiteral throws a TypeError when called with a non-number argument
  3. types.isNumericLiteral returns true for NumericLiteral nodes with optional value matching and false for other nodes
  4. types.assertNumericLiteral succeeds for valid NumericLiteral nodes and throws an Error for non-NumericLiteral nodes
  5. NumericLiteral nodes created with types.numericLiteral integrate into compound AST structures like BinaryExpression and ArrayExpression
  6. types.cloneNode produces an independent equivalent copy of a NumericLiteral node

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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: verify @babel/types.numericLiteral in pkg:npm/%40babel/types@7.29.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40babel/types@7.29.7
Demonstrate these symbols/APIs:
  - @babel/types.numericLiteral

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:f56447539b5042b499ddb505118ec78e9b6808e33b48d49a92a0dcf8b6af29ae","constraints":{"executionContext":"node"},"contract":["types.numericLiteral creates a NumericLiteral AST node with the specified number value and type 'NumericLiteral'","types.numericLiteral throws a TypeError when called with a non-number argument","types.isNumericLiteral returns true for NumericLiteral nodes with optional value matching and false for other nodes","types.assertNumericLiteral succeeds for valid NumericLiteral nodes and throws an Error for non-NumericLiteral nodes","NumericLiteral nodes created with types.numericLiteral integrate into compound AST structures like BinaryExpression and ArrayExpression","types.cloneNode produces an independent equivalent copy of a NumericLiteral node"],"goal":"verify @babel/types.numericLiteral in pkg:npm/%40babel/types@7.29.7","kind":"HOW","packages":["pkg:npm/%40babel/types@7.29.7"],"schemaVersion":1,"symbols":["@babel/types.numericLiteral"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40babel/types@7.29.7"],"schemaVersion":1,"subject":"pkg:npm/%40babel/types@7.29.7","symbols":["@babel/types.numericLiteral"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-babel-types-numericliteral",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-babel-types-numericliteral",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@babel/types": "7.29.7"
      }
    },
    "node_modules/@babel/helper-string-parser": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz",
      "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==",
      "license": "MIT",
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/helper-validator-identifier": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz",
      "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==",
      "license": "MIT",
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/types": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.7.tgz",
      "integrity": "sha512-4zBIxpPzowiZpusoFkyGVwakdRJUyuH5PxQ/PrqghfdFWWasvnCdPfQXHrenDai+gyLARulZjZowCOj6fjT4pA==",
      "license": "MIT",
      "dependencies": {
        "@babel/helper-string-parser": "^7.29.7",
        "@babel/helper-validator-identifier": "^7.29.7"
      },
      "engines": {
        "node": ">=6.9.0"
      }
    }
  }
}
package.json
{
  "name": "sample-babel-types-numericliteral",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @babel/types.numericLiteral",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@babel/types": "7.29.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @babel/types.numericLiteral in pkg:npm/%40babel/types@7.29.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/types@7.29.7"
  ],
  "symbols": [
    "@babel/types.numericLiteral"
  ]
}
src/index.js
const t = require('@babel/types');

/**
 * Creates a NumericLiteral AST node with the given number value.
 * @param {number} value
 * @returns {object}
 */
function createNumericLiteral(value) {
  return t.numericLiteral(value);
}

/**
 * Checks if a node is a NumericLiteral, optionally matching properties.
 * @param {object} node
 * @param {object} [opts]
 * @returns {boolean}
 */
function isNumericLiteralNode(node, opts) {
  return t.isNumericLiteral(node, opts);
}

/**
 * Asserts that a node is a NumericLiteral, throwing if not.
 * @param {object} node
 * @param {object} [opts]
 */
function assertNumericLiteralNode(node, opts) {
  t.assertNumericLiteral(node, opts);
}

/**
 * Creates a BinaryExpression AST node with two NumericLiteral operands.
 * @param {string} operator
 * @param {number} leftValue
 * @param {number} rightValue
 * @returns {object}
 */
function createBinaryNumericExpression(operator, leftValue, rightValue) {
  const left = t.numericLiteral(leftValue);
  const right = t.numericLiteral(rightValue);
  return t.binaryExpression(operator, left, right);
}

/**
 * Creates an ArrayExpression AST node containing NumericLiteral elements.
 * @param {number[]} values
 * @returns {object}
 */
function createNumericArrayExpression(values) {
  const elements = values.map((val) => t.numericLiteral(val));
  return t.arrayExpression(elements);
}

/**
 * Clones a NumericLiteral AST node.
 * @param {object} node
 * @returns {object}
 */
function cloneNumericLiteral(node) {
  return t.cloneNode(node);
}

module.exports = {
  t,
  createNumericLiteral,
  isNumericLiteralNode,
  assertNumericLiteralNode,
  createBinaryNumericExpression,
  createNumericArrayExpression,
  cloneNumericLiteral,
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  t,
  createNumericLiteral,
  isNumericLiteralNode,
  assertNumericLiteralNode,
  createBinaryNumericExpression,
  createNumericArrayExpression,
  cloneNumericLiteral,
} = require('../src/index.js');

async function runContract() {
  // 1. types.numericLiteral creates a NumericLiteral AST node with the specified number value and type 'NumericLiteral'
  const intNode = createNumericLiteral(42);
  assert.strictEqual(intNode.type, 'NumericLiteral');
  assert.strictEqual(intNode.value, 42);

  const floatNode = createNumericLiteral(3.14159);
  assert.strictEqual(floatNode.type, 'NumericLiteral');
  assert.strictEqual(floatNode.value, 3.14159);

  const zeroNode = t.numericLiteral(0);
  assert.strictEqual(zeroNode.type, 'NumericLiteral');
  assert.strictEqual(zeroNode.value, 0);

  const negNode = t.numericLiteral(-250);
  assert.strictEqual(negNode.type, 'NumericLiteral');
  assert.strictEqual(negNode.value, -250);

  // 2. types.numericLiteral throws a TypeError when called with a non-number argument
  assert.throws(
    () => createNumericLiteral('42'),
    (err) => err instanceof TypeError || err.message.includes('expected type of number'),
    'types.numericLiteral must throw when value is a string'
  );
  assert.throws(
    () => createNumericLiteral(null),
    (err) => err instanceof TypeError || err.message.includes('expected type of number'),
    'types.numericLiteral must throw when value is null'
  );
  assert.throws(
    () => createNumericLiteral(undefined),
    (err) => err instanceof TypeError || err.message.includes('expected type of number'),
    'types.numericLiteral must throw when value is undefined'
  );
  assert.throws(
    () => createNumericLiteral(true),
    (err) => err instanceof TypeError || err.message.includes('expected type of number'),
    'types.numericLiteral must throw when value is boolean'
  );

  // 3. types.isNumericLiteral returns true for NumericLiteral nodes with optional value matching and false for other nodes
  assert.strictEqual(isNumericLiteralNode(intNode), true);
  assert.strictEqual(isNumericLiteralNode(intNode, { value: 42 }), true);
  assert.strictEqual(isNumericLiteralNode(intNode, { value: 100 }), false);

  const identNode = t.identifier('count');
  assert.strictEqual(isNumericLiteralNode(identNode), false);
  assert.strictEqual(isNumericLiteralNode(null), false);
  assert.strictEqual(isNumericLiteralNode(undefined), false);

  // 4. types.assertNumericLiteral succeeds for valid NumericLiteral nodes and throws an Error for non-NumericLiteral nodes
  assertNumericLiteralNode(intNode);
  assertNumericLiteralNode(intNode, { value: 42 });
  assert.throws(
    () => assertNumericLiteralNode(identNode),
    (err) => err instanceof Error,
    'assertNumericLiteral on non-NumericLiteral node must throw'
  );
  assert.throws(
    () => assertNumericLiteralNode(intNode, { value: 999 }),
    (err) => err instanceof Error,
    'assertNumericLiteral with mismatching value option must throw'
  );

  // 5. NumericLiteral nodes created with types.numericLiteral integrate into compound AST structures like BinaryExpression and ArrayExpression
  const binExpr = createBinaryNumericExpression('+', 10, 20);
  assert.strictEqual(binExpr.type, 'BinaryExpression');
  assert.strictEqual(binExpr.operator, '+');
  assert.strictEqual(binExpr.left.type, 'NumericLiteral');
  assert.strictEqual(binExpr.left.value, 10);
  assert.strictEqual(binExpr.right.type, 'NumericLiteral');
  assert.strictEqual(binExpr.right.value, 20);

  const arrExpr = createNumericArrayExpression([1, 2, 3]);
  assert.strictEqual(arrExpr.type, 'ArrayExpression');
  assert.strictEqual(arrExpr.elements.length, 3);
  assert.strictEqual(arrExpr.elements[0].type, 'NumericLiteral');
  assert.strictEqual(arrExpr.elements[0].value, 1);
  assert.strictEqual(arrExpr.elements[1].type, 'NumericLiteral');
  assert.strictEqual(arrExpr.elements[1].value, 2);
  assert.strictEqual(arrExpr.elements[2].type, 'NumericLiteral');
  assert.strictEqual(arrExpr.elements[2].value, 3);

  // 6. types.cloneNode produces an independent equivalent copy of a NumericLiteral node
  const cloned = cloneNumericLiteral(intNode);
  assert.notStrictEqual(cloned, intNode, 'cloned node should have separate object identity');
  assert.strictEqual(cloned.type, 'NumericLiteral');
  assert.strictEqual(cloned.value, 42);
  assert.strictEqual(t.isNodesEquivalent(cloned, intNode), true);

  console.log('All contract assertions passed successfully.');
}

runContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Seeder d'origine

anonyme