CodeSampleX

Пример

@babel/helper-validator-identifier 8.0.4: isReservedWord

Проверенный пример — npm @babel/helper-validator-identifier 8.0.4: isReservedWord. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден.

sha256:dd1af10a4aacd8c34c91e3cb4174eefa190b26fa8dd522aefca93671893e8666

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20
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

Кейс

HOW
Цель
verify @babel/helper-validator-identifier.isReservedWord in pkg:npm/%40babel/helper-validator-identifier@8.0.4
Пакеты
Символы
  • @babel/helper-validator-identifier.isReservedWord
Окружение
node 22.23.2
Создан
2026-08-20T21:13:29Z

Контракт

  1. isReservedWord returns true for enum regardless of whether inModule is true or false
  2. isReservedWord returns true for await when inModule is true
  3. isReservedWord returns false for await when inModule is false or omitted
  4. isReservedWord returns false for regular identifier names and standard keywords when checking reserved word status
  5. isReservedWord returns false for uppercase or mixed-case variants of enum and await

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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/helper-validator-identifier.isReservedWord in pkg:npm/%40babel/helper-validator-identifier@8.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40babel/helper-validator-identifier@8.0.4
Demonstrate these symbols/APIs:
  - @babel/helper-validator-identifier.isReservedWord
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - runtime: node@22.23.2

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:6b15007a3a3abf52ad46da43752780d043f01b741dd708bb4e379156ac78158e","constraints":{"executionContext":"node"},"contract":["isReservedWord returns true for enum regardless of whether inModule is true or false","isReservedWord returns true for await when inModule is true","isReservedWord returns false for await when inModule is false or omitted","isReservedWord returns false for regular identifier names and standard keywords when checking reserved word status","isReservedWord returns false for uppercase or mixed-case variants of enum and await"],"goal":"verify @babel/helper-validator-identifier.isReservedWord in pkg:npm/%40babel/helper-validator-identifier@8.0.4","kind":"HOW","packages":["pkg:npm/%40babel/helper-validator-identifier@8.0.4"],"schemaVersion":1,"symbols":["@babel/helper-validator-identifier.isReservedWord"]},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40babel/helper-validator-identifier@8.0.4"],"schemaVersion":1,"subject":"pkg:npm/%40babel/helper-validator-identifier@8.0.4","symbols":["@babel/helper-validator-identifier.isReservedWord"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-babel-helper-validator-identifier",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-babel-helper-validator-identifier",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@babel/helper-validator-identifier": "8.0.4"
      }
    },
    "node_modules/@babel/helper-validator-identifier": {
      "version": "8.0.4",
      "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-8.0.4.tgz",
      "integrity": "sha512-4wFaiLd0bVo4cIoTXI3zKI038NIWE/cr3jvBjejOVYVxV/m8Ltav1USiGzG1fmS5J2RhgEOgXNNK46cRPnRsrg==",
      "license": "MIT",
      "engines": {
        "node": "^22.18.0 || >=24.11.0"
      }
    }
  }
}
package.json
{
  "name": "sample-babel-helper-validator-identifier",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @babel/helper-validator-identifier.isReservedWord",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@babel/helper-validator-identifier": "8.0.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @babel/helper-validator-identifier.isReservedWord in pkg:npm/%40babel/helper-validator-identifier@8.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/helper-validator-identifier@8.0.4"
  ],
  "symbols": [
    "@babel/helper-validator-identifier.isReservedWord"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { isReservedWord } = require('@babel/helper-validator-identifier');

/**
 * Checks whether a given word is a JavaScript reserved word in the specified module context.
 * @param {string} word - The identifier string to check.
 * @param {boolean} [inModule=false] - Whether the context is inside an ES module.
 * @returns {boolean} True if the word is a reserved word.
 */
function checkIsReservedWord(word, inModule = false) {
  return isReservedWord(word, inModule);
}

/**
 * Filters a list of words and returns only those that are reserved words.
 * @param {string[]} words - Array of words to check.
 * @param {boolean} [inModule=false] - Whether the context is inside an ES module.
 * @returns {string[]} Array containing only reserved words.
 */
function filterReservedWords(words, inModule = false) {
  if (!Array.isArray(words)) {
    return [];
  }
  return words.filter((word) => typeof word === 'string' && isReservedWord(word, inModule));
}

module.exports = {
  checkIsReservedWord,
  filterReservedWords,
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { checkIsReservedWord, filterReservedWords } = require('../src/index.js');
const { isReservedWord } = require('@babel/helper-validator-identifier');

async function runContract() {
  // 1. isReservedWord returns true for enum regardless of whether inModule is true or false
  assert.strictEqual(isReservedWord('enum', true), true, 'expected isReservedWord("enum", true) to be true');
  assert.strictEqual(isReservedWord('enum', false), true, 'expected isReservedWord("enum", false) to be true');
  assert.strictEqual(isReservedWord('enum'), true, 'expected isReservedWord("enum") to be true');
  assert.strictEqual(checkIsReservedWord('enum', true), true, 'expected wrapper checkIsReservedWord("enum", true) to be true');
  assert.strictEqual(checkIsReservedWord('enum', false), true, 'expected wrapper checkIsReservedWord("enum", false) to be true');
  assert.strictEqual(checkIsReservedWord('enum'), true, 'expected wrapper checkIsReservedWord("enum") to be true');

  // 2. isReservedWord returns true for await when inModule is true
  assert.strictEqual(isReservedWord('await', true), true, 'expected isReservedWord("await", true) to be true');
  assert.strictEqual(checkIsReservedWord('await', true), true, 'expected wrapper checkIsReservedWord("await", true) to be true');

  // 3. isReservedWord returns false for await when inModule is false or omitted
  assert.strictEqual(Boolean(isReservedWord('await', false)), false, 'expected isReservedWord("await", false) to be false');
  assert.strictEqual(Boolean(isReservedWord('await')), false, 'expected isReservedWord("await") to be false');
  assert.strictEqual(Boolean(checkIsReservedWord('await', false)), false, 'expected wrapper checkIsReservedWord("await", false) to be false');
  assert.strictEqual(Boolean(checkIsReservedWord('await')), false, 'expected wrapper checkIsReservedWord("await") to be false');

  // 4. isReservedWord returns false for regular identifier names and standard keywords when checking reserved word status
  const nonReservedWords = [
    'foo',
    'bar',
    'identifier',
    'myVar',
    'if',
    'while',
    'const',
    'let',
    'function',
    'class',
    'return',
    'import',
    'export',
  ];

  for (const word of nonReservedWords) {
    assert.strictEqual(Boolean(isReservedWord(word, true)), false, `expected isReservedWord("${word}", true) to be false`);
    assert.strictEqual(Boolean(isReservedWord(word, false)), false, `expected isReservedWord("${word}", false) to be false`);
    assert.strictEqual(Boolean(checkIsReservedWord(word, true)), false, `expected checkIsReservedWord("${word}", true) to be false`);
    assert.strictEqual(Boolean(checkIsReservedWord(word, false)), false, `expected checkIsReservedWord("${word}", false) to be false`);
  }

  // 5. isReservedWord returns false for uppercase or mixed-case variants of enum and await
  const casedVariants = [
    'ENUM',
    'Enum',
    'eNum',
    'AWAIT',
    'Await',
    'aWait',
  ];

  for (const word of casedVariants) {
    assert.strictEqual(Boolean(isReservedWord(word, true)), false, `expected cased variant "${word}" with inModule=true to return false`);
    assert.strictEqual(Boolean(isReservedWord(word, false)), false, `expected cased variant "${word}" with inModule=false to return false`);
    assert.strictEqual(Boolean(checkIsReservedWord(word, true)), false, `expected checkIsReservedWord("${word}", true) to return false`);
    assert.strictEqual(Boolean(checkIsReservedWord(word, false)), false, `expected checkIsReservedWord("${word}", false) to return false`);
  }

  // Helper validation: filterReservedWords
  const testList = ['foo', 'enum', 'bar', 'await', 'if', 'const'];
  const filteredModule = filterReservedWords(testList, true);
  assert.deepStrictEqual(filteredModule, ['enum', 'await']);

  const filteredScript = filterReservedWords(testList, false);
  assert.deepStrictEqual(filteredScript, ['enum']);

  assert.deepStrictEqual(filterReservedWords([]), []);
  assert.deepStrictEqual(filterReservedWords(null), []);

  console.log('Contract tests passed successfully.');
}

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

Исходный сидер

аноним