CodeSampleX

示例

react-refresh 0.18.0: isLikelyComponentType

已验证示例 — npm react-refresh 0.18.0: isLikelyComponentType. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: isLikelyComponentType returns true for…

sha256:72cf2def3b6b06a9b2cd6c434db4f6d68b0524490dd22787d5f09e014b067eb8

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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-refresh.isLikelyComponentType in pkg:npm/react-refresh@0.18.0
包
符号
  • react-refresh.isLikelyComponentType
环境
node 22.23.2
创建时间
2026-09-06T15:04:47Z

契约

  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.mjs
  • 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.18.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-refresh@0.18.0
Demonstrate these symbols/APIs:
  - react-refresh.isLikelyComponentType
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:61e8c1b415c3d25be9f41d731aa5cfc9aadcab701d88a6535418c7d202e52a59","constraints":{"executionContext":"node"},"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.18.0","kind":"HOW","packages":["pkg:npm/react-refresh@0.18.0"],"schemaVersion":1,"symbols":["react-refresh.isLikelyComponentType"]},"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-refresh@0.18.0"],"schemaVersion":1,"subject":"pkg:npm/react-refresh@0.18.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",
      "license": "MIT-0",
      "dependencies": {
        "react-refresh": "0.18.0"
      }
    },
    "node_modules/react-refresh": {
      "version": "0.18.0",
      "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.18.0.tgz",
      "integrity": "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-react-refresh-is-likely-component-type",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "react-refresh": "0.18.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-refresh.isLikelyComponentType in pkg:npm/react-refresh@0.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-refresh@0.18.0"
  ],
  "symbols": [
    "react-refresh.isLikelyComponentType"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import refreshRuntimeModule from "react-refresh/runtime";

export const RefreshRuntime =
  refreshRuntimeModule && typeof refreshRuntimeModule === "object" && "default" in refreshRuntimeModule
    ? refreshRuntimeModule.default
    : refreshRuntimeModule;

export const isLikelyComponentType = RefreshRuntime.isLikelyComponentType;

/**
 * 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 RefreshRuntime.isLikelyComponentType(type);
}
test/contract.mjs
import assert from "node:assert/strict";
import refreshRuntimeModule from "react-refresh/runtime";
import {
  isLikelyComponentType,
  checkIsLikelyComponentType,
} from "../src/index.mjs";

const rawRuntime =
  refreshRuntimeModule && typeof refreshRuntimeModule === "object" && "default" in refreshRuntimeModule
    ? refreshRuntimeModule.default
    : refreshRuntimeModule;

// 1. Export verification
assert.equal(typeof isLikelyComponentType, "function", "isLikelyComponentType must be a function");
assert.equal(typeof checkIsLikelyComponentType, "function", "checkIsLikelyComponentType helper must be a function");
assert.equal(typeof rawRuntime.isLikelyComponentType, "function", "raw runtime isLikelyComponentType must be a function");

// Contract 1: isLikelyComponentType returns true for 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");
  assert.equal(rawRuntime.isLikelyComponentType(ValidComponent), true);

  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");
  assert.equal(rawRuntime.isLikelyComponentType(ArrowComponent), true);
}

// Contract 2: isLikelyComponentType returns true for 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");
  assert.equal(rawRuntime.isLikelyComponentType(anonymousFunc), true);
}

// Contract 3: isLikelyComponentType returns true for 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");
  assert.equal(rawRuntime.isLikelyComponentType(MyClassComponent), true);
}

// Contract 4: isLikelyComponentType returns true for 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");
  assert.equal(rawRuntime.isLikelyComponentType(forwardRefComponent), true);

  function BaseComponent() {
    return null;
  }
  const memoComponent = {
    $$typeof: Symbol.for("react.memo"),
    type: BaseComponent,
  };
  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");
  assert.equal(rawRuntime.isLikelyComponentType(memoComponent), true);
}

// Contract 5: isLikelyComponentType returns false for 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");
  assert.equal(rawRuntime.isLikelyComponentType(helperFunction), false);

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

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

// Contract 6: isLikelyComponentType returns false for 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");
  assert.equal(rawRuntime.isLikelyComponentType({}), false);
  assert.equal(rawRuntime.isLikelyComponentType(null), false);
}

console.log("All react-refresh.isLikelyComponentType contract tests passed successfully.");

原始种子者

匿名