CodeSampleX

샘플

@babel/generator 7.29.7: generator

검증된 샘플 — npm @babel/generator 7.29.7: generator. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: generate converts AST Program node containing…

sha256:c35187ec344ead2a9ece1adcf16accc9213ce4e009410d39545299b40a5c4264

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-02

케이스

HOW
목표
verify @babel/generator in pkg:npm/%40babel/generator@7.29.7
패키지
심벌
  • @babel/generator
생성일
2026-09-02T13:45:58Z

컨트랙트

  1. generate converts AST Program node containing variable declarations into formatted JavaScript code
  2. generate formats FunctionDeclaration with parameters and binary expression return statement
  3. generate produces minified code without redundant whitespace when minified option is enabled
  4. generate generates source maps with version 3 mappings when sourceMaps option is enabled
  5. generate controls comment emission via comments configuration option
  6. generate formats code using CodeGenerator class with custom generator options
  7. generate throws an Error when passed an unknown AST node type

파일

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

Use EXACTLY these public packages and versions:
  - pkg:npm/%40babel/generator@7.29.7
Demonstrate these symbols/APIs:
  - @babel/generator

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:c781635bdbc3e780e1c27a1e9832d1d730001a03dd46d43366d1506ffcde643f","contract":["generate converts AST Program node containing variable declarations into formatted JavaScript code","generate formats FunctionDeclaration with parameters and binary expression return statement","generate produces minified code without redundant whitespace when minified option is enabled","generate generates source maps with version 3 mappings when sourceMaps option is enabled","generate controls comment emission via comments configuration option","generate formats code using CodeGenerator class with custom generator options","generate throws an Error when passed an unknown AST node type"],"goal":"verify @babel/generator in pkg:npm/%40babel/generator@7.29.7","kind":"HOW","packages":["pkg:npm/%40babel/generator@7.29.7"],"schemaVersion":1,"symbols":["@babel/generator"]},"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/generator@7.29.7"],"schemaVersion":1,"subject":"pkg:npm/%40babel/generator@7.29.7","symbols":["@babel/generator"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-babel-generator",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-babel-generator",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@babel/generator": "7.29.7"
      }
    },
    "node_modules/@babel/generator": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.7.tgz",
      "integrity": "sha512-DkXD5OJQaAQIdZ1bt3UZdEnHAn9Imd3IVBdX03UFe+ony9Ojw5pzr9YVKGDY1jt+Gcn/FnGkNf8r+Vj5NOJWtQ==",
      "license": "MIT",
      "dependencies": {
        "@babel/parser": "^7.29.7",
        "@babel/types": "^7.29.7",
        "@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-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/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/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"
      }
    }
  }
}
package.json
{
  "name": "sample-babel-generator",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@babel/generator": "7.29.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @babel/generator in pkg:npm/%40babel/generator@7.29.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/generator@7.29.7"
  ],
  "symbols": [
    "@babel/generator"
  ]
}
src/index.mjs
import generatorPkg from "@babel/generator";

const generateFn = typeof generatorPkg.default === "function"
  ? generatorPkg.default
  : (generatorPkg.default?.default || generatorPkg.generate || generatorPkg);

export const CodeGenerator = generatorPkg.CodeGenerator;

export function generateCode(ast, options = {}) {
  return generateFn(ast, options);
}

export function generateMinified(ast) {
  return generateFn(ast, { minified: true });
}

export function generateWithSourceMap(ast, sourceFileName) {
  return generateFn(ast, {
    sourceMaps: true,
    sourceFileName
  });
}

export function generateWithCommentsOption(ast, comments) {
  return generateFn(ast, { comments });
}

export function generateWithCustomGenerator(ast, options = {}) {
  const customGenerator = new CodeGenerator(ast, options);
  return customGenerator.generate();
}
test/contract.mjs
import assert from "node:assert/strict";
import {
  CodeGenerator,
  generateCode,
  generateMinified,
  generateWithSourceMap,
  generateWithCommentsOption,
  generateWithCustomGenerator
} from "../src/index.mjs";

// 1. generate converts AST Program node containing variable declarations into formatted JavaScript code
{
  const ast = {
    type: "Program",
    body: [
      {
        type: "VariableDeclaration",
        kind: "const",
        declarations: [
          {
            type: "VariableDeclarator",
            id: { type: "Identifier", name: "greeting" },
            init: { type: "StringLiteral", value: "hello" }
          }
        ]
      }
    ]
  };
  const result = generateCode(ast);
  assert.equal(typeof result.code, "string");
  assert.equal(result.code, 'const greeting = "hello";');
}

// 2. generate formats FunctionDeclaration with parameters and binary expression return statement
{
  const ast = {
    type: "FunctionDeclaration",
    id: { type: "Identifier", name: "multiply" },
    params: [
      { type: "Identifier", name: "a" },
      { type: "Identifier", name: "b" }
    ],
    body: {
      type: "BlockStatement",
      body: [
        {
          type: "ReturnStatement",
          argument: {
            type: "BinaryExpression",
            operator: "*",
            left: { type: "Identifier", name: "a" },
            right: { type: "Identifier", name: "b" }
          }
        }
      ]
    }
  };
  const result = generateCode(ast);
  assert.match(result.code, /function multiply\(a, b\)/);
  assert.match(result.code, /return a \* b;/);
}

// 3. generate produces minified code without redundant whitespace when minified option is enabled
{
  const ast = {
    type: "FunctionDeclaration",
    id: { type: "Identifier", name: "fn" },
    params: [],
    body: {
      type: "BlockStatement",
      body: [
        {
          type: "ReturnStatement",
          argument: { type: "NumericLiteral", value: 1 }
        }
      ]
    }
  };
  const result = generateMinified(ast);
  assert.equal(result.code, "function fn(){return 1}");
}

// 4. generate generates source maps with version 3 mappings when sourceMaps option is enabled
{
  const ast = {
    type: "Identifier",
    name: "myVar",
    loc: {
      start: { line: 1, column: 0 },
      end: { line: 1, column: 5 },
      filename: "test.js"
    }
  };
  const result = generateWithSourceMap(ast, "test.js");
  assert.ok(result.map, "Expected sourcemap object to be present");
  assert.equal(result.map.version, 3);
}

// 5. generate controls comment emission via comments configuration option
{
  const ast = {
    type: "ExpressionStatement",
    expression: { type: "Identifier", name: "x" },
    leadingComments: [
      {
        type: "CommentLine",
        value: " important comment"
      }
    ]
  };
  const withComments = generateWithCommentsOption(ast, true);
  assert.match(withComments.code, /\/\/ important comment/);

  const withoutComments = generateWithCommentsOption(ast, false);
  assert.equal(withoutComments.code.includes("important comment"), false);
}

// 6. generate formats code using CodeGenerator class with custom generator options
{
  const ast = {
    type: "ReturnStatement",
    argument: { type: "BooleanLiteral", value: true }
  };
  const result = generateWithCustomGenerator(ast, { concise: true });
  assert.equal(result.code, "return true;");
}

// 7. generate throws an Error when passed an unknown AST node type
{
  assert.throws(
    () => {
      generateCode({ type: "UnknownCustomInvalidNodeType" });
    },
    Error
  );
}

console.log("All @babel/generator contract tests passed successfully.");

오리진 시더

익명