CodeSampleX

Пример

react-refresh 0.17.0: isLikelyComponentType

Проверенный пример — npm react-refresh 0.17.0: isLikelyComponentType. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден.

sha256:3864b45b2729f5daf211e4cf1397710648b5356526408e1c507a858b5da790eb

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

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

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

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

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

Окружение Контракт Этапы Запуск
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-04

Кейс

HOW
Цель
verify react-refresh.isLikelyComponentType in pkg:npm/react-refresh@0.17.0
Пакеты
Символы
  • react-refresh.isLikelyComponentType
Создан
2026-09-04T18:52:58Z

Контракт

  1. isLikelyComponentType returns true for PascalCase function components and arrow functions
  2. isLikelyComponentType returns true for components with uppercase displayName
  3. isLikelyComponentType returns true for class components with isReactComponent on prototype
  4. isLikelyComponentType returns true for React forwardRef and memo objects
  5. isLikelyComponentType returns false for lowercase functions and regular classes
  6. isLikelyComponentType returns false for plain objects, non-component elements, primitives, and nullish values

Файлы

  • 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 react-refresh.isLikelyComponentType in pkg:npm/react-refresh@0.17.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-refresh@0.17.0
Demonstrate these symbols/APIs:
  - react-refresh.isLikelyComponentType

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:e845f2386faaf115cd0bd9e3efef61028dbbc42c70ba68d70155c18efe9a4ede","contract":["isLikelyComponentType returns true for PascalCase function components and arrow functions","isLikelyComponentType returns true for components with uppercase displayName","isLikelyComponentType returns true for class components with isReactComponent on prototype","isLikelyComponentType returns true for React forwardRef and memo objects","isLikelyComponentType returns false for lowercase functions and regular classes","isLikelyComponentType returns false for plain objects, non-component elements, primitives, and nullish values"],"goal":"verify react-refresh.isLikelyComponentType in pkg:npm/react-refresh@0.17.0","kind":"HOW","packages":["pkg:npm/react-refresh@0.17.0"],"schemaVersion":1,"symbols":["react-refresh.isLikelyComponentType"]},"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/react-refresh@0.17.0"],"schemaVersion":1,"subject":"pkg:npm/react-refresh@0.17.0","symbols":["react-refresh.isLikelyComponentType"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-refresh-is-likely-component-type",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-refresh-is-likely-component-type",
      "version": "1.0.0",
      "dependencies": {
        "react-refresh": "0.17.0"
      }
    },
    "node_modules/react-refresh": {
      "version": "0.17.0",
      "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
      "integrity": "sha512-z6F7K9bV85EfseRCp2bzrpyQ0Gkw1uLoCel9XBVWPg/TjRj94SkJzUTGfOa4bs7iJvBWtQG0Wq7wnI0syw3EBQ==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-react-refresh-is-likely-component-type",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-refresh isLikelyComponentType",
  "type": "module",
  "main": "src/index.js",
  "dependencies": {
    "react-refresh": "0.17.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-refresh.isLikelyComponentType in pkg:npm/react-refresh@0.17.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-refresh@0.17.0"
  ],
  "symbols": [
    "react-refresh.isLikelyComponentType"
  ]
}
src/index.js
import { isLikelyComponentType } from 'react-refresh';

/**
 * Check if the given value is likely a React component type.
 *
 * @param {*} type - The value to inspect.
 * @returns {boolean} True if the value is likely a component type.
 */
export function checkIsLikelyComponentType(type) {
  return isLikelyComponentType(type);
}

export { isLikelyComponentType };
test/contract.mjs
import assert from 'node:assert/strict';
import {
  isLikelyComponentType,
  checkIsLikelyComponentType,
} from '../src/index.js';

// 1. Export verification
assert.equal(typeof isLikelyComponentType, 'function', 'isLikelyComponentType must be a function');
assert.equal(typeof checkIsLikelyComponentType, 'function', 'checkIsLikelyComponentType helper must be a function');

// 2. PascalCase function components and arrow functions
function ValidComponent() {
  return null;
}
assert.equal(isLikelyComponentType(ValidComponent), true, 'PascalCase function must be recognized as component type');
assert.equal(checkIsLikelyComponentType(ValidComponent), true, 'checkIsLikelyComponentType returns true for PascalCase function');

const ArrowComponent = () => null;
assert.equal(isLikelyComponentType(ArrowComponent), true, 'Arrow function with PascalCase name must be recognized as component type');
assert.equal(checkIsLikelyComponentType(ArrowComponent), true, 'checkIsLikelyComponentType returns true for PascalCase arrow function');

// 3. Components with uppercase displayName
const anonymousFunc = (() => function() {
  return null;
})();
Object.defineProperty(anonymousFunc, 'name', { value: '' });
anonymousFunc.displayName = 'NamedComponent';
assert.equal(isLikelyComponentType(anonymousFunc), true, 'Function with uppercase displayName must be recognized as component type');
assert.equal(checkIsLikelyComponentType(anonymousFunc), true, 'checkIsLikelyComponentType returns true for function with uppercase displayName');

// 4. Class components with isReactComponent on prototype
class MyClassComponent {}
MyClassComponent.prototype.isReactComponent = true;
assert.equal(isLikelyComponentType(MyClassComponent), true, 'Class component with isReactComponent must be recognized as component type');
assert.equal(checkIsLikelyComponentType(MyClassComponent), true, 'checkIsLikelyComponentType returns true for class component');

// 5. React forwardRef and memo objects
const forwardRefComponent = {
  $$typeof: Symbol.for('react.forward_ref'),
  render: () => null,
};
assert.equal(isLikelyComponentType(forwardRefComponent), true, 'React forwardRef object must be recognized as component type');
assert.equal(checkIsLikelyComponentType(forwardRefComponent), true, 'checkIsLikelyComponentType returns true for forwardRef');

const memoComponent = {
  $$typeof: Symbol.for('react.memo'),
  type: ValidComponent,
};
assert.equal(isLikelyComponentType(memoComponent), true, 'React memo object must be recognized as component type');
assert.equal(checkIsLikelyComponentType(memoComponent), true, 'checkIsLikelyComponentType returns true for memo object');

// 6. Lowercase functions and regular classes
function helperFunction() {
  return false;
}
assert.equal(isLikelyComponentType(helperFunction), false, 'lowercase function must not be recognized as component type');
assert.equal(checkIsLikelyComponentType(helperFunction), false, 'checkIsLikelyComponentType returns false for lowercase function');

const lowercaseArrow = () => false;
assert.equal(isLikelyComponentType(lowercaseArrow), false, 'lowercase arrow function must not be recognized as component type');

class RegularClass {
  method() {}
}
assert.equal(isLikelyComponentType(RegularClass), false, 'regular class without isReactComponent must not be recognized as component type');

// 7. Plain objects, non-component elements, primitives, and nullish values
assert.equal(isLikelyComponentType({}), false, 'plain object must not be recognized as component type');
assert.equal(isLikelyComponentType({ $$typeof: Symbol.for('react.element') }), false, 'React element object must not be recognized as component type');
assert.equal(isLikelyComponentType(null), false, 'null must not be recognized as component type');
assert.equal(isLikelyComponentType(undefined), false, 'undefined must not be recognized as component type');
assert.equal(isLikelyComponentType(42), false, 'number primitive must not be recognized as component type');
assert.equal(isLikelyComponentType('MyComponent'), false, 'string primitive must not be recognized as component type');
assert.equal(isLikelyComponentType(true), false, 'boolean primitive must not be recognized as component type');

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

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

аноним