CodeSampleX

Пример

react-is 19.2.8: Fragment

Проверенный пример — npm react-is 19.2.8: Fragment. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: react-is exports Fragment matching…

sha256:2c12e150c1fe0fefdb130a5c3e4c8c43392d81d036f6c09c6f15b58724cd6d59

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

Кейс

HOW
Цель
verify react-is.Fragment in pkg:npm/react-is@19.2.8
Пакеты
Символы
  • react-is.Fragment
Создан
2026-09-06T04:00:24Z

Контракт

  1. react-is exports Fragment matching Symbol.for('react.fragment')
  2. isValidElementType identifies Fragment as a valid React element type
  3. isFragment detects valid React 19 Fragment elements
  4. isFragment returns false for Fragment symbol itself, non-fragment elements, and primitives
  5. typeOf returns Fragment symbol for valid fragment elements and undefined for non-elements

Файлы

  • 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-is.Fragment in pkg:npm/react-is@19.2.8
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-is@19.2.8
Demonstrate these symbols/APIs:
  - react-is.Fragment

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:b16ffc8f8fac189d5f28f04e9a2f1b866480a204249f2a1e388e359316385c83","contract":["react-is exports Fragment matching Symbol.for('react.fragment')","isValidElementType identifies Fragment as a valid React element type","isFragment detects valid React 19 Fragment elements","isFragment returns false for Fragment symbol itself, non-fragment elements, and primitives","typeOf returns Fragment symbol for valid fragment elements and undefined for non-elements"],"goal":"verify react-is.Fragment in pkg:npm/react-is@19.2.8","kind":"HOW","packages":["pkg:npm/react-is@19.2.8"],"schemaVersion":1,"symbols":["react-is.Fragment"]},"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-is@19.2.8"],"schemaVersion":1,"subject":"pkg:npm/react-is@19.2.8","symbols":["react-is.Fragment"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-fragment",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-fragment",
      "version": "1.0.0",
      "dependencies": {
        "react-is": "19.2.8"
      }
    },
    "node_modules/react-is": {
      "version": "19.2.8",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-19.2.8.tgz",
      "integrity": "sha512-s5un28nYxKJw5gvUHyW5PCC28CvBqLu9r3cWgzHT4Vo/5fqqkFcdRYsGcKf50WMPpjjFZS5d76fn3YCo2njKwQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-react-is-fragment",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is.Fragment in React 19",
  "type": "module",
  "main": "src/index.js",
  "dependencies": {
    "react-is": "19.2.8"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.Fragment in pkg:npm/react-is@19.2.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@19.2.8"
  ],
  "symbols": [
    "react-is.Fragment"
  ]
}
src/index.js
import {
  Fragment,
  isFragment,
  typeOf,
  isValidElementType,
  Element,
} from 'react-is';

export { Fragment, Element };

/**
 * Creates a React 19 element representation.
 *
 * @param {*} type - The element type.
 * @param {Object} [props={}] - Element properties.
 * @returns {Object} React element object.
 */
export function createElement(type, props = {}) {
  return {
    $$typeof: Element || Symbol.for('react.transitional.element'),
    type,
    props,
    key: null,
    ref: null,
  };
}

/**
 * Creates a React 19 Fragment element representation.
 *
 * @param {*} [children] - Children to include in props.
 * @returns {Object} React Fragment element object.
 */
export function createFragmentElement(children) {
  const props = children !== undefined ? { children } : {};
  return createElement(Fragment, props);
}

/**
 * Checks whether a given object is a React Fragment element.
 *
 * @param {*} value - The value to test.
 * @returns {boolean} True if the value is a Fragment element.
 */
export function checkIsFragment(value) {
  return isFragment(value);
}

/**
 * Checks whether a given type is a valid React element type.
 *
 * @param {*} type - The type to test.
 * @returns {boolean} True if the type is valid.
 */
export function checkIsValidElementType(type) {
  return isValidElementType(type);
}

/**
 * Inspects the React type of a given value.
 *
 * @param {*} value - The value to inspect.
 * @returns {*|undefined} Type symbol or undefined.
 */
export function inspectTypeOf(value) {
  return typeOf(value);
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Fragment,
  Element,
  createElement,
  createFragmentElement,
  checkIsFragment,
  checkIsValidElementType,
  inspectTypeOf,
} from '../src/index.js';
import reactIs from 'react-is';

// Contract 1: react-is exports Fragment matching Symbol.for('react.fragment')
assert.equal(typeof Fragment, 'symbol', 'Fragment must be a symbol');
assert.equal(Fragment, Symbol.for('react.fragment'), 'Fragment must match Symbol.for("react.fragment")');
assert.equal(reactIs.Fragment, Fragment, 'Default import Fragment must match named import Fragment');

// Contract 2: isValidElementType identifies Fragment as a valid React element type
assert.equal(checkIsValidElementType(Fragment), true, 'Fragment must be recognized as a valid element type');
assert.equal(reactIs.isValidElementType(Fragment), true, 'react-is.isValidElementType must return true for Fragment');
assert.equal(checkIsValidElementType('div'), true, 'String tag must be a valid element type');
assert.equal(checkIsValidElementType(() => null), true, 'Function component must be a valid element type');
assert.equal(checkIsValidElementType(123), false, 'Number must not be a valid element type');
assert.equal(checkIsValidElementType(null), false, 'null must not be a valid element type');
assert.equal(checkIsValidElementType(undefined), false, 'undefined must not be a valid element type');

// Contract 3: isFragment detects valid React 19 Fragment elements
const fragmentWithChildren = createFragmentElement(['child1', 'child2']);
assert.equal(checkIsFragment(fragmentWithChildren), true, 'Fragment element with children must be detected by checkIsFragment');
assert.equal(reactIs.isFragment(fragmentWithChildren), true, 'Fragment element with children must be detected by reactIs.isFragment');

const emptyFragment = createFragmentElement();
assert.equal(checkIsFragment(emptyFragment), true, 'Empty Fragment element must be detected by checkIsFragment');
assert.equal(reactIs.isFragment(emptyFragment), true, 'Empty Fragment element must be detected by reactIs.isFragment');

// Contract 4: isFragment returns false for Fragment symbol itself, non-fragment elements, and primitives
assert.equal(checkIsFragment(Fragment), false, 'Fragment symbol itself is not an element instance');
assert.equal(reactIs.isFragment(Fragment), false, 'Fragment symbol itself must return false from isFragment');

const divElement = createElement('div', { id: 'root' });
assert.equal(checkIsFragment(divElement), false, 'Plain div element must not be identified as a Fragment');
assert.equal(reactIs.isFragment(divElement), false, 'Plain div element must return false from isFragment');

const suspenseElement = createElement(Symbol.for('react.suspense'));
assert.equal(checkIsFragment(suspenseElement), false, 'Suspense element must not be identified as a Fragment');

const legacyFragment = {
  $$typeof: Symbol.for('react.element'),
  type: Fragment,
  props: {},
  key: null,
  ref: null,
};
assert.equal(checkIsFragment(legacyFragment), false, 'Legacy React element $$typeof is not recognized by React 19 react-is');

assert.equal(checkIsFragment(null), false, 'null must return false');
assert.equal(checkIsFragment(undefined), false, 'undefined must return false');
assert.equal(checkIsFragment({}), false, 'Plain object must return false');
assert.equal(checkIsFragment('react.fragment'), false, 'String must return false');
assert.equal(checkIsFragment(42), false, 'Number must return false');

// Contract 5: typeOf returns Fragment symbol for valid fragment elements and undefined for non-elements
assert.equal(inspectTypeOf(fragmentWithChildren), Fragment, 'inspectTypeOf must return Fragment symbol for fragment element');
assert.equal(reactIs.typeOf(fragmentWithChildren), Fragment, 'reactIs.typeOf must return Fragment symbol for fragment element');
assert.equal(inspectTypeOf(emptyFragment), Fragment, 'inspectTypeOf must return Fragment symbol for empty fragment element');

assert.equal(inspectTypeOf(divElement), Element, 'inspectTypeOf returns Element symbol for plain element');
assert.equal(inspectTypeOf(suspenseElement), Symbol.for('react.suspense'), 'inspectTypeOf returns Suspense symbol');
assert.equal(inspectTypeOf(Fragment), undefined, 'inspectTypeOf returns undefined for Fragment symbol');
assert.equal(inspectTypeOf(null), undefined, 'inspectTypeOf returns undefined for null');
assert.equal(inspectTypeOf(undefined), undefined, 'inspectTypeOf returns undefined for undefined');
assert.equal(inspectTypeOf({}), undefined, 'inspectTypeOf returns undefined for plain object');
assert.equal(inspectTypeOf(legacyFragment), undefined, 'inspectTypeOf returns undefined for legacy element');

console.log('All react-is.Fragment contract assertions passed.');

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

аноним