CodeSampleX

샘플

@babel/parser 8.0.4

검증된 샘플 — npm @babel/parser 8.0.4. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: parse parses JavaScript source code into a File AST node…

sha256:ee7c5991092e0a45dd458bab157a86ad279c696b6ccef3750655a0723f901b4d

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

케이스

HOW
목표
verify pkg:npm/%40babel/parser@8.0.4
패키지
환경
node 22.23.2
생성일
2026-08-20T21:31:20Z

컨트랙트

  1. parse parses JavaScript source code into a File AST node containing a Program body with default script sourceType
  2. parse with sourceType module parses ECMAScript module import and export declarations
  3. parseExpression parses a single JavaScript expression string directly into an Expression AST node
  4. parse with jsx plugin parses JSX syntax into JSXElement AST nodes
  5. parse with tokens option set to true populates the tokens array with lexical tokens
  6. parse with ranges option set to true attaches numeric [start, end] ranges to AST nodes
  7. parse throws a SyntaxError with code BABEL_PARSER_SYNTAX_ERROR when parsing invalid JavaScript syntax
  8. tokTypes exposes standard token type descriptors including parenL, parenR, and name

파일

  • 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 pkg:npm/%40babel/parser@8.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40babel/parser@8.0.4
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:fe11af1ff1d7d0a09b62c9837c15766e7e936342ba1fce4f09ce9b13891c8f7f","constraints":{"executionContext":"node"},"contract":["parse parses JavaScript source code into a File AST node containing a Program body with default script sourceType","parse with sourceType module parses ECMAScript module import and export declarations","parseExpression parses a single JavaScript expression string directly into an Expression AST node","parse with jsx plugin parses JSX syntax into JSXElement AST nodes","parse with tokens option set to true populates the tokens array with lexical tokens","parse with ranges option set to true attaches numeric [start, end] ranges to AST nodes","parse throws a SyntaxError with code BABEL_PARSER_SYNTAX_ERROR when parsing invalid JavaScript syntax","tokTypes exposes standard token type descriptors including parenL, parenR, and name"],"goal":"verify pkg:npm/%40babel/parser@8.0.4","kind":"HOW","packages":["pkg:npm/%40babel/parser@8.0.4"],"schemaVersion":1},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40babel/parser@8.0.4"],"schemaVersion":1,"subject":"pkg:npm/%40babel/parser@8.0.4","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-babel-parser",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-babel-parser",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@babel/parser": "8.0.4"
      }
    },
    "node_modules/@babel/helper-string-parser": {
      "version": "8.0.0",
      "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.0.0.tgz",
      "integrity": "sha512-6mJgmFFFIIO82vvoLt9XtRC7/TkzXfts1t/SpRX4IHSzMgqoPYCWesVu1udUPUWioAE/2fcG6WuI8zrkE1gwrg==",
      "license": "MIT",
      "engines": {
        "node": "^22.18.0 || >=24.11.0"
      }
    },
    "node_modules/@babel/helper-validator-identifier": {
      "version": "8.0.4",
      "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-8.0.4.tgz",
      "integrity": "sha512-4wFaiLd0bVo4cIoTXI3zKI038NIWE/cr3jvBjejOVYVxV/m8Ltav1USiGzG1fmS5J2RhgEOgXNNK46cRPnRsrg==",
      "license": "MIT",
      "engines": {
        "node": "^22.18.0 || >=24.11.0"
      }
    },
    "node_modules/@babel/parser": {
      "version": "8.0.4",
      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-8.0.4.tgz",
      "integrity": "sha512-srpptsAkEbbNIC/q8nT7o+m6CQe8CJUTV/t7MYc9NnWlgYVtHOb7JH6SorxMhN0kuRJjVqXbKClG6xSbPtzz+g==",
      "license": "MIT",
      "dependencies": {
        "@babel/types": "^8.0.4"
      },
      "bin": {
        "parser": "bin/babel-parser.js"
      },
      "engines": {
        "node": "^22.18.0 || >=24.11.0"
      }
    },
    "node_modules/@babel/types": {
      "version": "8.0.4",
      "resolved": "https://registry.npmjs.org/@babel/types/-/types-8.0.4.tgz",
      "integrity": "sha512-eY+Yn3dCqTGmyiq2QRU66lA5FL8lqqqvecHt0fF3uHONIa7ToYsaCiWV8lOKqAs0Rb2SjixiKFROngnulPtt2g==",
      "license": "MIT",
      "dependencies": {
        "@babel/helper-string-parser": "^8.0.0",
        "@babel/helper-validator-identifier": "^8.0.4"
      },
      "engines": {
        "node": "^22.18.0 || >=24.11.0"
      }
    }
  }
}
package.json
{
  "name": "sample-babel-parser",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @babel/parser",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@babel/parser": "8.0.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40babel/parser@8.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/parser@8.0.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { parse, parseExpression, tokTypes } = require('@babel/parser');

/**
 * Parses JavaScript source code into an AST File node.
 * @param {string} code - The source code to parse.
 * @param {object} [options] - Parser configuration options.
 * @returns {object} The parsed AST root File node.
 */
function parseSource(code, options = {}) {
  return parse(code, options);
}

/**
 * Parses a single JavaScript expression into an AST Expression node.
 * @param {string} code - The expression code to parse.
 * @param {object} [options] - Parser configuration options.
 * @returns {object} The parsed AST Expression node.
 */
function parseExpr(code, options = {}) {
  return parseExpression(code, options);
}

/**
 * Retrieves the token type object by name.
 * @param {string} name - Name of the token type.
 * @returns {object|undefined} The token type descriptor.
 */
function getTokenType(name) {
  return tokTypes[name];
}

module.exports = {
  parseSource,
  parseExpr,
  getTokenType,
  tokTypes,
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  parseSource,
  parseExpr,
  getTokenType,
  tokTypes,
} = require('../src/index.js');

async function runContract() {
  // 1. parse parses JavaScript source code into a File AST node containing a Program body with default script sourceType
  const ast1 = parseSource('const a = 1;');
  assert.strictEqual(ast1.type, 'File', 'root node should be File');
  assert.strictEqual(ast1.program.type, 'Program', 'ast.program should be Program');
  assert.strictEqual(ast1.program.sourceType, 'script', 'default sourceType should be script');
  assert.strictEqual(ast1.program.body.length, 1, 'body should contain one statement');
  assert.strictEqual(ast1.program.body[0].type, 'VariableDeclaration', 'statement should be VariableDeclaration');

  // 2. parse with sourceType module parses ECMAScript module import and export declarations
  const ast2 = parseSource('import { x } from "y"; export const z = 2;', { sourceType: 'module' });
  assert.strictEqual(ast2.program.sourceType, 'module', 'sourceType should be module');
  assert.strictEqual(ast2.program.body[0].type, 'ImportDeclaration', 'first statement should be ImportDeclaration');
  assert.strictEqual(ast2.program.body[1].type, 'ExportNamedDeclaration', 'second statement should be ExportNamedDeclaration');

  // 3. parseExpression parses a single JavaScript expression string directly into an Expression AST node
  const expr = parseExpr('x + y * 2');
  assert.strictEqual(expr.type, 'BinaryExpression', 'expression type should be BinaryExpression');
  assert.strictEqual(expr.left.name, 'x', 'left operand should be x');
  assert.strictEqual(expr.operator, '+', 'operator should be +');
  assert.strictEqual(expr.right.type, 'BinaryExpression', 'right operand should be BinaryExpression');

  // 4. parse with jsx plugin parses JSX syntax into JSXElement AST nodes
  const ast4 = parseSource('<Button onClick={handleClick}>Click</Button>', { plugins: ['jsx'] });
  const jsxStmt = ast4.program.body[0];
  assert.strictEqual(jsxStmt.type, 'ExpressionStatement', 'statement should be ExpressionStatement');
  assert.strictEqual(jsxStmt.expression.type, 'JSXElement', 'expression should be JSXElement');
  assert.strictEqual(jsxStmt.expression.openingElement.name.name, 'Button', 'element tag should be Button');

  // 5. parse with tokens option set to true populates the tokens array with lexical tokens
  const ast5 = parseSource('let x = 10;', { tokens: true });
  assert.strictEqual(Array.isArray(ast5.tokens), true, 'ast.tokens should be an array');
  assert.strictEqual(ast5.tokens.length > 0, true, 'ast.tokens should not be empty');
  assert.strictEqual(ast5.tokens[0].type.label, 'name', 'first token label should be name');

  // 6. parse with ranges option set to true attaches numeric [start, end] ranges to AST nodes
  const ast6 = parseSource('const foo = "bar";', { ranges: true });
  assert.deepStrictEqual(ast6.program.range, [0, 18], 'program node should have [start, end] range');
  assert.deepStrictEqual(ast6.program.body[0].range, [0, 18], 'body node should have [start, end] range');

  // 7. parse throws a SyntaxError with code BABEL_PARSER_SYNTAX_ERROR when parsing invalid JavaScript syntax
  assert.throws(
    () => parseSource('const = 1;'),
    (err) => {
      return err instanceof SyntaxError && err.code === 'BABEL_PARSER_SYNTAX_ERROR';
    },
    'invalid syntax should throw SyntaxError with BABEL_PARSER_SYNTAX_ERROR'
  );

  // 8. tokTypes exposes standard token type descriptors including parenL, parenR, and name
  assert.strictEqual(typeof tokTypes, 'object', 'tokTypes should be an object');
  assert.strictEqual(getTokenType('parenL').label, '(', 'parenL token type should have label (');
  assert.strictEqual(getTokenType('parenR').label, ')', 'parenR token type should have label )');
  assert.strictEqual(getTokenType('name').label, 'name', 'name token type should have label name');

  console.log('All contract assertions passed successfully.');
}

runContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명