CodeSampleX

示例

react-is 17.0.2: Profiler

已验证示例 — npm react-is 17.0.2: Profiler. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: Profiler export is a distinct Symbol representing the React…

sha256:fb396146aa6fb450455a3bf5f11597d1289a7a33799537936851dcecec73dcdc

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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.Profiler in pkg:npm/react-is@17.0.2
包
符号
  • react-is.Profiler
环境
node 22.23.2
创建时间
2026-09-06T09:56:03Z

契约

  1. Profiler export is a distinct Symbol representing the React Profiler component type
  2. isValidElementType evaluates to true for the Profiler symbol
  3. isProfiler returns true for React elements configured with type Profiler
  4. typeOf returns the Profiler symbol for React elements configured with type Profiler
  5. isProfiler rejects plain objects, non-profiler React elements, primitives, null, and undefined
  6. typeOf returns undefined or different symbols for non-profiler values and plain objects
  7. Profiler is a component type symbol rather than a React element instance

文件

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

Use EXACTLY these public packages and versions:
  - pkg:npm/react-is@17.0.2
Demonstrate these symbols/APIs:
  - react-is.Profiler
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:e33a60a46d90bf8f48033791a47951c5f459ebfa09388ad37e1a750daf665b50","constraints":{"executionContext":"node"},"contract":["Profiler export is a distinct Symbol representing the React Profiler component type","isValidElementType evaluates to true for the Profiler symbol","isProfiler returns true for React elements configured with type Profiler","typeOf returns the Profiler symbol for React elements configured with type Profiler","isProfiler rejects plain objects, non-profiler React elements, primitives, null, and undefined","typeOf returns undefined or different symbols for non-profiler values and plain objects","Profiler is a component type symbol rather than a React element instance"],"goal":"verify react-is.Profiler in pkg:npm/react-is@17.0.2","kind":"HOW","packages":["pkg:npm/react-is@17.0.2"],"schemaVersion":1,"symbols":["react-is.Profiler"]},"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","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/react-is@17.0.2"],"schemaVersion":1,"subject":"pkg:npm/react-is@17.0.2","symbols":["react-is.Profiler"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-profiler",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-profiler",
      "version": "1.0.0",
      "dependencies": {
        "react-is": "17.0.2"
      }
    },
    "node_modules/react-is": {
      "version": "17.0.2",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
      "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-react-is-profiler",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is.Profiler in react-is 17.0.2",
  "main": "src/index.js",
  "dependencies": {
    "react-is": "17.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.Profiler in pkg:npm/react-is@17.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@17.0.2"
  ],
  "symbols": [
    "react-is.Profiler"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const {
  Profiler,
  isProfiler,
  isElement,
  isValidElementType,
  typeOf,
} = require('react-is');

/**
 * Creates a mock React Profiler element object.
 *
 * @param {string} [id='test-profiler'] - Unique Profiler identifier.
 * @param {Function} [onRender=() => {}] - Profiler render callback.
 * @returns {object} React element with type Profiler.
 */
function createProfilerElement(id = 'test-profiler', onRender = () => {}) {
  return {
    $$typeof: Symbol.for('react.element'),
    type: Profiler,
    props: { id, onRender, children: null },
    key: null,
    ref: null,
  };
}

/**
 * Validates whether the given value is a React Profiler element.
 *
 * @param {*} value - The value to inspect.
 * @returns {boolean} True if the value is a Profiler element.
 */
function checkIsProfiler(value) {
  return isProfiler(value);
}

/**
 * Validates whether the Profiler export is a valid React element type.
 *
 * @returns {boolean} True if Profiler is a valid element type.
 */
function checkIsValidProfilerType() {
  return isValidElementType(Profiler);
}

/**
 * Identifies the element type of the given object using typeOf.
 *
 * @param {*} value - The object to inspect.
 * @returns {symbol|undefined} The matched element symbol or undefined.
 */
function identifyTypeOf(value) {
  return typeOf(value);
}

module.exports = {
  Profiler,
  isProfiler,
  isElement,
  isValidElementType,
  typeOf,
  createProfilerElement,
  checkIsProfiler,
  checkIsValidProfilerType,
  identifyTypeOf,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { Profiler, isProfiler, isElement, isValidElementType, typeOf } from 'react-is';
import sample from '../src/index.js';

const {
  createProfilerElement,
  checkIsProfiler,
  checkIsValidProfilerType,
  identifyTypeOf,
} = sample;

// 1. Profiler export is a distinct Symbol representing the React Profiler component type
assert.equal(typeof Profiler, 'symbol', 'Profiler must be a symbol');
assert.equal(Profiler, Symbol.for('react.profiler'), 'Profiler must equal Symbol.for("react.profiler")');
assert.equal(sample.Profiler, Profiler, 'Re-exported Profiler must match react-is Profiler');

// 2. isValidElementType evaluates to true for the Profiler symbol
assert.equal(isValidElementType(Profiler), true, 'isValidElementType(Profiler) must return true');
assert.equal(checkIsValidProfilerType(), true, 'checkIsValidProfilerType helper must return true');

// 3. isProfiler returns true for React elements configured with type Profiler
const profilerElement = createProfilerElement('metrics-profiler', () => {});
assert.equal(isProfiler(profilerElement), true, 'isProfiler must return true for Profiler element');
assert.equal(checkIsProfiler(profilerElement), true, 'checkIsProfiler helper must return true');

// 4. typeOf returns the Profiler symbol for React elements configured with type Profiler
assert.equal(typeOf(profilerElement), Profiler, 'typeOf(profilerElement) must return Profiler symbol');
assert.equal(identifyTypeOf(profilerElement), Profiler, 'identifyTypeOf helper must return Profiler symbol');

// 5. isProfiler rejects plain objects, non-profiler React elements, primitives, null, and undefined
const divElement = {
  $$typeof: Symbol.for('react.element'),
  type: 'div',
  props: {},
  key: null,
  ref: null,
};
assert.equal(isProfiler(divElement), false, 'div element must not be identified as Profiler');
assert.equal(checkIsProfiler(divElement), false, 'checkIsProfiler helper must return false for div element');
assert.equal(isProfiler({}), false, 'empty object is not a Profiler');
assert.equal(isProfiler(null), false, 'null is not a Profiler');
assert.equal(isProfiler(undefined), false, 'undefined is not a Profiler');
assert.equal(isProfiler('Profiler'), false, 'string is not a Profiler');
assert.equal(isProfiler(123), false, 'number is not a Profiler');

// 6. typeOf returns undefined or different symbols for non-profiler values and plain objects
assert.notEqual(typeOf(divElement), Profiler, 'typeOf(divElement) must not equal Profiler');
assert.equal(typeOf({}), undefined, 'typeOf({}) must return undefined');
assert.equal(typeOf(null), undefined, 'typeOf(null) must return undefined');
assert.equal(typeOf(undefined), undefined, 'typeOf(undefined) must return undefined');

// 7. Profiler is a component type symbol rather than a React element instance
assert.equal(isElement(Profiler), false, 'Profiler symbol itself must not be an element');
assert.equal(isElement(profilerElement), true, 'profilerElement must be a valid element');

console.log('Contract tests for react-is.Profiler passed successfully.');

原始种子者

匿名