CodeSampleX

Exemple

acorn 8.18.0: parseExpressionAt

Échantillon vérifié pour npm acorn 8.18.0: parseExpressionAt. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:09d1876f21b3e3e2b52b152f2f9b00ac4e3390c2c79cdbb48e6721c4aad5da1b

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
2
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 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-26
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-07

Cas

HOW
Objectif
verify acorn.parseExpressionAt in pkg:npm/acorn@8.18.0
Paquets
Symboles
  • acorn.parseExpressionAt
Créé
2026-08-26T11:02:16Z

Contrat

  1. acorn.parseExpressionAt(input, offset, options) parses a single JavaScript expression starting at the given offset and returns an AST Node
  2. acorn.parseExpressionAt returns node with correct type, start, end, and expression-specific fields
  3. acorn.parseExpressionAt supports locations and ranges options for source mapping
  4. acorn.parseExpressionAt supports ecmaVersion option for modern ECMAScript syntax features
  5. acorn.parseExpressionAt throws SyntaxError when given invalid JavaScript syntax at the offset

Fichiers

  • PROMPT.md
  • csx.json
  • 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 acorn.parseExpressionAt in pkg:npm/acorn@8.18.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/acorn@8.18.0
Demonstrate these symbols/APIs:
  - acorn.parseExpressionAt

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:2454e3b22563855d5dbe8f805a449826580cfcb69ad5d80c0f363f44f5ecdea8","contract":["acorn.parseExpressionAt(input, offset, options) parses a single JavaScript expression starting at the given offset and returns an AST Node","acorn.parseExpressionAt returns node with correct type, start, end, and expression-specific fields","acorn.parseExpressionAt supports locations and ranges options for source mapping","acorn.parseExpressionAt supports ecmaVersion option for modern ECMAScript syntax features","acorn.parseExpressionAt throws SyntaxError when given invalid JavaScript syntax at the offset"],"goal":"verify acorn.parseExpressionAt in pkg:npm/acorn@8.18.0","kind":"HOW","packages":["pkg:npm/acorn@8.18.0"],"schemaVersion":1,"symbols":["acorn.parseExpressionAt"]},"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/acorn@8.18.0"],"schemaVersion":1,"subject":"pkg:npm/acorn@8.18.0","symbols":["acorn.parseExpressionAt"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-acorn-parse-expression-at",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-acorn-parse-expression-at",
      "version": "1.0.0",
      "dependencies": {
        "acorn": "8.18.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"
      }
    }
  }
}
package.json
{
  "name": "sample-acorn-parse-expression-at",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "acorn": "8.18.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify acorn.parseExpressionAt in pkg:npm/acorn@8.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/acorn@8.18.0"
  ],
  "symbols": [
    "acorn.parseExpressionAt"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import * as acorn from 'acorn';

// 1. Basic expression parsing at offset 0
{
  const code = '1 + 2';
  const node = acorn.parseExpressionAt(code, 0, { ecmaVersion: 2020 });
  assert.equal(node.type, 'BinaryExpression');
  assert.equal(node.start, 0);
  assert.equal(node.end, 5);
  assert.equal(node.operator, '+');
  assert.equal(node.left.type, 'Literal');
  assert.equal(node.left.value, 1);
  assert.equal(node.right.type, 'Literal');
  assert.equal(node.right.value, 2);
}

// 2. Parsing expression starting at arbitrary offset
{
  const code = 'const msg = "hello " + name;';
  const offset = 12; // Start of `"hello " + name`
  const node = acorn.parseExpressionAt(code, offset, { ecmaVersion: 2020 });
  assert.equal(node.type, 'BinaryExpression');
  assert.equal(node.start, 12);
  assert.equal(node.end, 27);
  assert.equal(node.left.type, 'Literal');
  assert.equal(node.left.value, 'hello ');
  assert.equal(node.right.type, 'Identifier');
  assert.equal(node.right.name, 'name');
}

// 3. Options: locations and ranges
{
  const code = 'foo.bar(42)';
  const node = acorn.parseExpressionAt(code, 0, {
    ecmaVersion: 2020,
    locations: true,
    ranges: true
  });
  assert.equal(node.type, 'CallExpression');
  assert.deepEqual(node.range, [0, 11]);
  assert.ok(node.loc);
  assert.equal(node.loc.start.line, 1);
  assert.equal(node.loc.start.column, 0);
  assert.equal(node.loc.end.line, 1);
  assert.equal(node.loc.end.column, 11);
}

// 4. Modern syntax with optional chaining and nullish coalescing
{
  const code = 'user?.profile?.name ?? "Anonymous"';
  const node = acorn.parseExpressionAt(code, 0, { ecmaVersion: 2022 });
  assert.equal(node.type, 'LogicalExpression');
  assert.equal(node.operator, '??');
  assert.equal(node.left.type, 'ChainExpression');
  assert.equal(node.right.value, 'Anonymous');
}

// 5. Syntax error handling
{
  assert.throws(
    () => {
      acorn.parseExpressionAt('1 +', 0, { ecmaVersion: 2020 });
    },
    (err) => {
      assert.ok(err instanceof SyntaxError);
      assert.ok(typeof err.pos === 'number');
      return true;
    }
  );
}

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

Seeder d'origine

anonyme