CodeSampleX

示例

react-is 17.0.2: Memo

已验证示例 — npm react-is 17.0.2: Memo. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: Memo exports the react.memo symbol identifier in React 17

sha256:95efd4aac94b6fd2679e88ba4d29b9d54e1660aa58f713712919b53e9f0bb74c

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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.Memo in pkg:npm/react-is@17.0.2
包
符号
  • react-is.Memo
创建时间
2026-09-06T08:32:12Z

契约

  1. Memo exports the react.memo symbol identifier in React 17
  2. isMemo returns true for React 17 elements wrapping memo component types
  3. typeOf returns Memo symbol for valid memo elements
  4. isMemo returns false for React 19 transitional element symbols
  5. isMemo returns false for unmounted memo component definition objects
  6. isValidElementType recognizes memo component definitions
  7. isMemo returns false for standard DOM elements and primitives

文件

  • 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.Memo 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.Memo

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:53e507641f944a15e9d75eb4dbeb6da8ca0468f7601fae57e8c930fd589302e1","contract":["Memo exports the react.memo symbol identifier in React 17","isMemo returns true for React 17 elements wrapping memo component types","typeOf returns Memo symbol for valid memo elements","isMemo returns false for React 19 transitional element symbols","isMemo returns false for unmounted memo component definition objects","isValidElementType recognizes memo component definitions","isMemo returns false for standard DOM elements and primitives"],"goal":"verify react-is.Memo in pkg:npm/react-is@17.0.2","kind":"HOW","packages":["pkg:npm/react-is@17.0.2"],"schemaVersion":1,"symbols":["react-is.Memo"]},"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@17.0.2"],"schemaVersion":1,"subject":"pkg:npm/react-is@17.0.2","symbols":["react-is.Memo"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-memo",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-memo",
      "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-memo",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is.Memo in React 17",
  "type": "module",
  "main": "src/index.js",
  "dependencies": {
    "react-is": "17.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.Memo in pkg:npm/react-is@17.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@17.0.2"
  ],
  "symbols": [
    "react-is.Memo"
  ]
}
src/index.js
import { Memo, isMemo, typeOf, isValidElementType } from 'react-is';

/**
 * Symbol used by React 17 for elements.
 */
export const REACT_ELEMENT_TYPE = Symbol.for('react.element');

/**
 * Symbol used by React 19 for transitional elements (not recognized by React 17).
 */
export const REACT_TRANSITIONAL_ELEMENT_TYPE = Symbol.for('react.transitional.element');

/**
 * Check if the provided value is a React memo element using react-is.
 *
 * @param {*} value - Value to inspect.
 * @returns {boolean} True if the value is a memo element.
 */
export function checkIsMemo(value) {
  return isMemo(value);
}

/**
 * Check if the provided value is a valid memo component definition.
 *
 * @param {*} value - Value to inspect.
 * @returns {boolean} True if the value is a valid memo component type.
 */
export function checkIsValidMemoType(value) {
  return (
    typeof value === 'object' &&
    value !== null &&
    value.$$typeof === Memo &&
    isValidElementType(value)
  );
}

/**
 * Create a mock React 17 element wrapping a memo component.
 *
 * @param {Function} [renderFn] - Inner render component.
 * @returns {object} Mock element.
 */
export function createMemoElement(renderFn = () => null) {
  const memoType = {
    $$typeof: Memo,
    type: renderFn,
    compare: null,
  };
  return {
    $$typeof: REACT_ELEMENT_TYPE,
    type: memoType,
    props: {},
    key: null,
    ref: null,
  };
}

/**
 * Create a mock React 19 transitional element wrapping a memo component.
 *
 * @param {Function} [renderFn] - Inner render component.
 * @returns {object} Mock transitional element.
 */
export function createTransitionalMemoElement(renderFn = () => null) {
  const memoType = {
    $$typeof: Memo,
    type: renderFn,
    compare: null,
  };
  return {
    $$typeof: REACT_TRANSITIONAL_ELEMENT_TYPE,
    type: memoType,
    props: {},
    key: null,
    ref: null,
  };
}

export {
  Memo,
  isMemo,
  typeOf,
  isValidElementType,
};
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Memo,
  isMemo,
  typeOf,
  isValidElementType,
  REACT_ELEMENT_TYPE,
  REACT_TRANSITIONAL_ELEMENT_TYPE,
  checkIsMemo,
  checkIsValidMemoType,
  createMemoElement,
  createTransitionalMemoElement,
} from '../src/index.js';

// 1. Symbol and Function exports verification
assert.equal(typeof Memo, 'symbol', 'Memo should export a symbol');
assert.equal(Memo, Symbol.for('react.memo'), 'Memo must match Symbol.for("react.memo")');
assert.equal(typeof isMemo, 'function', 'isMemo should be a function');
assert.equal(typeof typeOf, 'function', 'typeOf should be a function');
assert.equal(typeof isValidElementType, 'function', 'isValidElementType should be a function');
assert.equal(typeof checkIsMemo, 'function', 'checkIsMemo helper should be a function');
assert.equal(typeof checkIsValidMemoType, 'function', 'checkIsValidMemoType helper should be a function');

// 2. React 17 Memo Element verification
const memoElem = createMemoElement(() => null);
assert.equal(isMemo(memoElem), true, 'isMemo must return true for React 17 memo elements');
assert.equal(checkIsMemo(memoElem), true, 'checkIsMemo helper must return true for React 17 memo elements');
assert.equal(typeOf(memoElem), Memo, 'typeOf must return Memo symbol for valid memo elements');

// 3. React 19 Transitional Element verification (not recognized in React 17)
const transitionalMemoElem = createTransitionalMemoElement(() => null);
assert.equal(isMemo(transitionalMemoElem), false, 'React 17 react-is does not match React 19 transitional element symbol for isMemo');
assert.notEqual(typeOf(transitionalMemoElem), Memo, 'typeOf does not return Memo for React 19 transitional element symbols');

// 4. Raw Memo Component Type Object (unmounted definition) verification
const rawMemoComponent = {
  $$typeof: Memo,
  type: () => null,
  compare: null,
};
assert.equal(isMemo(rawMemoComponent), false, 'isMemo must return false for raw memo component definitions without element envelope');
assert.equal(isValidElementType(rawMemoComponent), true, 'isValidElementType must recognize raw memo component definitions');
assert.equal(checkIsValidMemoType(rawMemoComponent), true, 'checkIsValidMemoType helper must return true for valid memo component types');

// 5. Negative assertions for non-memo elements and invalid values
const plainElement = {
  $$typeof: REACT_ELEMENT_TYPE,
  type: 'div',
  props: {},
  key: null,
  ref: null,
};
assert.equal(isMemo(plainElement), false, 'plain element is not a memo element');
assert.equal(isMemo(null), false, 'null is not a memo element');
assert.equal(isMemo(undefined), false, 'undefined is not a memo element');
assert.equal(isMemo({}), false, 'empty object is not a memo element');
assert.equal(isMemo('div'), false, 'primitive string is not a memo element');
assert.equal(isMemo(123), false, 'primitive number is not a memo element');
assert.equal(isMemo(() => null), false, 'plain function component is not a memo element');
assert.equal(isMemo(Memo), false, 'Memo symbol itself is not a memo element');

// 6. isValidElementType negative checks
assert.equal(isValidElementType(null), false, 'isValidElementType returns false for null');
assert.equal(isValidElementType(undefined), false, 'isValidElementType returns false for undefined');
assert.equal(isValidElementType(Memo), false, 'isValidElementType returns false for raw Memo symbol');

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

原始种子者

匿名