CodeSampleX

サンプル

@babel/helper-module-imports 7.29.7

検証済みサンプル — npm @babel/helper-module-imports 7.29.7. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: isModule detects whether a Program AST path…

sha256:f5076c708ab2ce6c5c34de06862b8a1c614e1cb69034aa6f122f650886f3d18f

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-23

ケース

HOW
ゴール
verify pkg:npm/%40babel/helper-module-imports@7.29.7
パッケージ
作成日
2026-08-23T06:44:06Z

コントラクト

  1. isModule detects whether a Program AST path has module sourceType
  2. injectDefaultImport adds a default import declaration and returns an identifier
  3. injectNamedImport adds a named import specifier with custom nameHint
  4. injectNamespaceImport adds a namespace import (* as alias) into the AST
  5. injectSideEffectImport adds a bare import statement without specifiers
  6. ImportInjector instance methods support chained operations and reuse of injector state

ファイル

  • 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 pkg:npm/%40babel/helper-module-imports@7.29.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40babel/helper-module-imports@7.29.7

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:cbf0f7c99152935ea3109eeb2f55cc35915f4e80c5028b33aa9e61c57b5b7ff0","contract":["isModule detects whether a Program AST path has module sourceType","injectDefaultImport adds a default import declaration and returns an identifier","injectNamedImport adds a named import specifier with custom nameHint","injectNamespaceImport adds a namespace import (* as alias) into the AST","injectSideEffectImport adds a bare import statement without specifiers","ImportInjector instance methods support chained operations and reuse of injector state"],"goal":"verify pkg:npm/%40babel/helper-module-imports@7.29.7","kind":"HOW","packages":["pkg:npm/%40babel/helper-module-imports@7.29.7"],"schemaVersion":1},"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/%40babel/helper-module-imports@7.29.7"],"schemaVersion":1,"subject":"pkg:npm/%40babel/helper-module-imports@7.29.7","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-babel-helper-module-imports",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-babel-helper-module-imports",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@babel/helper-module-imports": "7.29.7"
      }
    },
    "node_modules/@babel/code-frame": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz",
      "integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==",
      "license": "MIT",
      "dependencies": {
        "@babel/helper-validator-identifier": "^7.29.7",
        "js-tokens": "^4.0.0",
        "picocolors": "^1.1.1"
      },
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/generator": {
      "version": "7.29.8",
      "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.8.tgz",
      "integrity": "sha512-gZbepsdh3WDtgZKWL+vTPh71LSBrm/Y4/QDZBVCcYfmeTEEuoOYwlSy+G1StfJg+/Zy550u/3TATbm7qDbbMtg==",
      "license": "MIT",
      "dependencies": {
        "@babel/parser": "^7.29.8",
        "@babel/types": "^7.29.8",
        "@jridgewell/gen-mapping": "^0.3.12",
        "@jridgewell/trace-mapping": "^0.3.28",
        "jsesc": "^3.0.2"
      },
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/helper-globals": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.29.7.tgz",
      "integrity": "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==",
      "license": "MIT",
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/helper-module-imports": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.29.7.tgz",
      "integrity": "sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g==",
      "license": "MIT",
      "dependencies": {
        "@babel/traverse": "^7.29.7",
        "@babel/types": "^7.29.7"
      },
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/helper-string-parser": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz",
      "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==",
      "license": "MIT",
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/helper-validator-identifier": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz",
      "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==",
      "license": "MIT",
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/parser": {
      "version": "7.29.8",
      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.8.tgz",
      "integrity": "sha512-E8lTAYNB1KW+FH+VGJuZM1ioAx2E6oVlvQFRrf5P8ZZmsiJXYAD9vTFV7yyEURNzgh1dFqMZuO6tUwcARbqFCA==",
      "license": "MIT",
      "dependencies": {
        "@babel/types": "^7.29.8"
      },
      "bin": {
        "parser": "bin/babel-parser.js"
      },
      "engines": {
        "node": ">=6.0.0"
      }
    },
    "node_modules/@babel/template": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz",
      "integrity": "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==",
      "license": "MIT",
      "dependencies": {
        "@babel/code-frame": "^7.29.7",
        "@babel/parser": "^7.29.7",
        "@babel/types": "^7.29.7"
      },
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/traverse": {
      "version": "7.29.8",
      "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.8.tgz",
      "integrity": "sha512-I5z7H3bf/41ktsNVLtpN0wAa336HkqIHQ5BuPLEhTkt1jVSyZpeNKIzTgEWmlxjdg81R0IgUCcaE+Ok3NvrfZg==",
      "license": "MIT",
      "dependencies": {
        "@babel/code-frame": "^7.29.7",
        "@babel/generator": "^7.29.8",
        "@babel/helper-globals": "^7.29.7",
        "@babel/parser": "^7.29.8",
        "@babel/template": "^7.29.7",
        "@babel/types": "^7.29.8",
        "debug": "^4.3.1"
      },
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@babel/types": {
      "version": "7.29.8",
      "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.8.tgz",
      "integrity": "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==",
      "license": "MIT",
      "dependencies": {
        "@babel/helper-string-parser": "^7.29.7",
        "@babel/helper-validator-identifier": "^7.29.7"
      },
      "engines": {
        "node": ">=6.9.0"
      }
    },
    "node_modules/@jridgewell/gen-mapping": {
      "version": "0.3.13",
      "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
      "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "^1.5.0",
        "@jridgewell/trace-mapping": "^0.3.24"
      }
    },
    "node_modules/@jridgewell/resolve-uri": {
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
      "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
      "license": "MIT",
      "engines": {
        "node": ">=6.0.0"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "license": "MIT"
    },
    "node_modules/@jridgewell/trace-mapping": {
      "version": "0.3.31",
      "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz",
      "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/resolve-uri": "^3.1.0",
        "@jridgewell/sourcemap-codec": "^1.4.14"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/js-tokens": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
      "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
      "license": "MIT"
    },
    "node_modules/jsesc": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz",
      "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==",
      "license": "MIT",
      "bin": {
        "jsesc": "bin/jsesc"
      },
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/picocolors": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
      "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-babel-helper-module-imports",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@babel/helper-module-imports": "7.29.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40babel/helper-module-imports@7.29.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/helper-module-imports@7.29.7"
  ]
}
src/index.mjs
import helperModule from "@babel/helper-module-imports";

const {
  addDefault,
  addNamed,
  addNamespace,
  addSideEffect,
  isModule,
  ImportInjector
} = helperModule;

export function checkIsModule(path) {
  return isModule(path);
}

export function injectDefaultImport(path, source, nameHint) {
  return addDefault(path, source, { nameHint });
}

export function injectNamedImport(path, name, source, nameHint) {
  return addNamed(path, name, source, { nameHint });
}

export function injectNamespaceImport(path, source, nameHint) {
  return addNamespace(path, source, { nameHint });
}

export function injectSideEffectImport(path, source) {
  return addSideEffect(path, source);
}

export function createImportInjector(path) {
  return new ImportInjector(path);
}
test/contract.mjs
import assert from "node:assert/strict";
import helperModule from "@babel/helper-module-imports";
import traverseModule from "@babel/traverse";
import {
  checkIsModule,
  injectDefaultImport,
  injectNamedImport,
  injectNamespaceImport,
  injectSideEffectImport,
  createImportInjector
} from "../src/index.mjs";

const { addDefault, addNamed, addNamespace, addSideEffect, isModule, ImportInjector } = helperModule;
const traverse = traverseModule.default || traverseModule;

function createProgramPath(sourceType = "module") {
  const ast = {
    type: "File",
    program: {
      type: "Program",
      sourceType,
      body: [],
      directives: []
    }
  };
  let programPath;
  traverse(ast, {
    Program(path) {
      programPath = path;
    }
  });
  return { ast, programPath };
}

// Contract 1: isModule detects whether a Program AST path has module sourceType
{
  const { programPath: modulePath } = createProgramPath("module");
  const { programPath: scriptPath } = createProgramPath("script");

  assert.equal(checkIsModule(modulePath), true);
  assert.equal(isModule(modulePath), true);
  assert.equal(checkIsModule(scriptPath), false);
  assert.equal(isModule(scriptPath), false);
}

// Contract 2: injectDefaultImport adds a default import declaration and returns an identifier
{
  const { ast, programPath } = createProgramPath("module");
  const id = injectDefaultImport(programPath, "lodash/map", "map");

  assert.equal(id.type, "Identifier");
  assert.equal(id.name, "_map");
  assert.equal(ast.program.body.length, 1);
  assert.equal(ast.program.body[0].type, "ImportDeclaration");
  assert.equal(ast.program.body[0].source.value, "lodash/map");
  assert.equal(ast.program.body[0].specifiers.length, 1);
  assert.equal(ast.program.body[0].specifiers[0].type, "ImportDefaultSpecifier");
  assert.equal(ast.program.body[0].specifiers[0].local.name, "_map");
}

// Contract 3: injectNamedImport adds a named import specifier with custom nameHint
{
  const { ast, programPath } = createProgramPath("module");
  const id = injectNamedImport(programPath, "join", "path", "join");

  assert.equal(id.type, "Identifier");
  assert.equal(id.name, "_join");
  assert.equal(ast.program.body.length, 1);
  assert.equal(ast.program.body[0].type, "ImportDeclaration");
  assert.equal(ast.program.body[0].source.value, "path");
  assert.equal(ast.program.body[0].specifiers.length, 1);
  assert.equal(ast.program.body[0].specifiers[0].type, "ImportSpecifier");
  assert.equal(ast.program.body[0].specifiers[0].imported.name, "join");
  assert.equal(ast.program.body[0].specifiers[0].local.name, "_join");
}

// Contract 4: injectNamespaceImport adds a namespace import (* as alias) into the AST
{
  const { ast, programPath } = createProgramPath("module");
  const id = injectNamespaceImport(programPath, "node:fs", "fs");

  assert.equal(id.type, "Identifier");
  assert.equal(id.name, "_fs");
  assert.equal(ast.program.body.length, 1);
  assert.equal(ast.program.body[0].type, "ImportDeclaration");
  assert.equal(ast.program.body[0].source.value, "node:fs");
  assert.equal(ast.program.body[0].specifiers.length, 1);
  assert.equal(ast.program.body[0].specifiers[0].type, "ImportNamespaceSpecifier");
  assert.equal(ast.program.body[0].specifiers[0].local.name, "_fs");
}

// Contract 5: injectSideEffectImport adds a bare import statement without specifiers
{
  const { ast, programPath } = createProgramPath("module");
  const result = injectSideEffectImport(programPath, "reset.css");

  assert.equal(result, null);
  assert.equal(ast.program.body.length, 1);
  assert.equal(ast.program.body[0].type, "ImportDeclaration");
  assert.equal(ast.program.body[0].source.value, "reset.css");
  assert.equal(ast.program.body[0].specifiers.length, 0);
}

// Contract 6: ImportInjector instance methods support chained operations and reuse of injector state
{
  const { ast, programPath } = createProgramPath("module");
  const injector = createImportInjector(programPath);
  assert.ok(injector instanceof ImportInjector);

  const defId = injector.addDefault("pkg-a", { nameHint: "pkgA" });
  const namedId = injector.addNamed("funcB", "pkg-a", { nameHint: "funcB" });
  const nsId = injector.addNamespace("pkg-c", { nameHint: "pkgC" });
  const sideEffect = injector.addSideEffect("pkg-d/styles.css");

  assert.equal(defId.name, "_pkgA");
  assert.equal(namedId.name, "_funcB");
  assert.equal(nsId.name, "_pkgC");
  assert.equal(sideEffect, null);

  // default and named imports from pkg-a are grouped into one declaration
  assert.equal(ast.program.body.length, 3);
  const pkgADecl = ast.program.body.find(stmt => stmt.source?.value === "pkg-a");
  assert.ok(pkgADecl);
  assert.equal(pkgADecl.specifiers.length, 2);
  assert.equal(pkgADecl.specifiers[0].type, "ImportDefaultSpecifier");
  assert.equal(pkgADecl.specifiers[1].type, "ImportSpecifier");
}

console.log("All @babel/helper-module-imports contract assertions passed.");

オリジンシーダー

匿名