CodeSampleX

Exemple

espree 10.4.0: supportedEcmaVersions

Échantillon vérifié pour npm espree 10.4.0: supportedEcmaVersions. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:97a36af6f71da68aaa2e39c906129f5ffa15f43359132f71f35db365c153e857

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é linux 24 · ubuntu · glibc 2.39 x64 npm

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-17

Cas

HOW
Objectif
verify espree.supportedEcmaVersions in pkg:npm/espree@10.4.0
Paquets
Symboles
  • espree.supportedEcmaVersions
Créé
2026-09-16T23:45:49Z

Contrat

  1. espree.supportedEcmaVersions is an array of supported ECMAScript edition numbers
  2. espree.supportedEcmaVersions contains edition numbers starting at 3 and ending at 17, excluding version 4
  3. espree.supportedEcmaVersions aligns with espree.latestEcmaVersion
  4. espree.parse accepts all editions listed in espree.supportedEcmaVersions
  5. espree.parse throws Error with message Invalid ecmaVersion when ecmaVersion is not present in espree.supportedEcmaVersions

Fichiers

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 espree.supportedEcmaVersions in pkg:npm/espree@10.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/espree@10.4.0
Demonstrate these symbols/APIs:
  - espree.supportedEcmaVersions

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:7f39faa347ed687a8fd771e54960a8e060feeef98e76cf05ef942a6732a5d702","contract":["espree.supportedEcmaVersions is an array of supported ECMAScript edition numbers","espree.supportedEcmaVersions contains edition numbers starting at 3 and ending at 17, excluding version 4","espree.supportedEcmaVersions aligns with espree.latestEcmaVersion","espree.parse accepts all editions listed in espree.supportedEcmaVersions","espree.parse throws Error with message Invalid ecmaVersion when ecmaVersion is not present in espree.supportedEcmaVersions"],"goal":"verify espree.supportedEcmaVersions in pkg:npm/espree@10.4.0","kind":"HOW","packages":["pkg:npm/espree@10.4.0"],"schemaVersion":1,"symbols":["espree.supportedEcmaVersions"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/espree@10.4.0"],"schemaVersion":1,"subject":"pkg:npm/espree@10.4.0","symbols":["espree.supportedEcmaVersions"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const espree = require('espree');

export const supportedEcmaVersions = espree.supportedEcmaVersions;
export const parse = espree.parse;
export const latestEcmaVersion = espree.latestEcmaVersion;
export default espree;
package-lock.json
{
  "name": "sample-espree-supportedecmaversions",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-espree-supportedecmaversions",
      "version": "1.0.0",
      "dependencies": {
        "espree": "10.4.0"
      }
    },
    "node_modules/acorn": {
      "version": "8.18.0",
      "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz",
      "integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==",
      "license": "MIT",
      "bin": {
        "acorn": "bin/acorn"
      },
      "engines": {
        "node": ">=0.4.0"
      }
    },
    "node_modules/acorn-jsx": {
      "version": "5.3.2",
      "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz",
      "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==",
      "license": "MIT",
      "peerDependencies": {
        "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
      }
    },
    "node_modules/eslint-visitor-keys": {
      "version": "4.2.1",
      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz",
      "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==",
      "license": "Apache-2.0",
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/eslint"
      }
    },
    "node_modules/espree": {
      "version": "10.4.0",
      "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz",
      "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "acorn": "^8.15.0",
        "acorn-jsx": "^5.3.2",
        "eslint-visitor-keys": "^4.2.1"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/eslint"
      }
    }
  }
}
package.json
{
  "name": "sample-espree-supportedecmaversions",
  "version": "1.0.0",
  "type": "module",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "espree": "10.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify espree.supportedEcmaVersions in pkg:npm/espree@10.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/espree@10.4.0"
  ],
  "symbols": [
    "espree.supportedEcmaVersions"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const espree = require('espree');

// 1. espree.supportedEcmaVersions is an array of supported ECMAScript edition numbers
{
  assert.ok(Array.isArray(espree.supportedEcmaVersions), 'supportedEcmaVersions must be an array');
  assert.ok(espree.supportedEcmaVersions.length > 0, 'supportedEcmaVersions must not be empty');
  assert.ok(
    espree.supportedEcmaVersions.every((v) => typeof v === 'number' && Number.isInteger(v)),
    'every version in supportedEcmaVersions must be an integer'
  );
}

// 2. espree.supportedEcmaVersions contains edition numbers starting at 3 and ending at 17, excluding version 4
{
  assert.equal(espree.supportedEcmaVersions[0], 3, 'first supported version must be 3');
  assert.equal(
    espree.supportedEcmaVersions[espree.supportedEcmaVersions.length - 1],
    17,
    'latest supported version must be 17'
  );
  assert.equal(espree.supportedEcmaVersions.includes(4), false, 'version 4 must be excluded');
  assert.deepEqual(
    espree.supportedEcmaVersions,
    [3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
    'supportedEcmaVersions must match known edition list'
  );
}

// 3. espree.supportedEcmaVersions aligns with espree.latestEcmaVersion
{
  assert.equal(
    espree.latestEcmaVersion,
    espree.supportedEcmaVersions[espree.supportedEcmaVersions.length - 1],
    'latestEcmaVersion must match the last entry in supportedEcmaVersions'
  );
}

// 4. espree.parse accepts all editions listed in espree.supportedEcmaVersions
{
  for (const version of espree.supportedEcmaVersions) {
    const code = version >= 6 ? 'const x = 1;' : 'var x = 1;';
    const ast = espree.parse(code, { ecmaVersion: version, sourceType: 'script' });
    assert.equal(ast.type, 'Program', `parsing with ecmaVersion ${version} must return Program node`);
  }
}

// 5. espree.parse throws Error with message Invalid ecmaVersion when ecmaVersion is not present in espree.supportedEcmaVersions
{
  const invalidVersions = [0, 1, 2, 4, 18, 99];
  for (const inv of invalidVersions) {
    assert.throws(
      () => espree.parse('var x = 1;', { ecmaVersion: inv }),
      {
        name: 'Error',
        message: 'Invalid ecmaVersion.'
      },
      `ecmaVersion ${inv} must be rejected with Invalid ecmaVersion error`
    );
  }
}

console.log('All espree.supportedEcmaVersions contract assertions passed.');

Seeder d'origine

anonyme