CodeSampleX

샘플

regjsparser 0.13.2: parse

검증된 샘플 — npm regjsparser 0.13.2: parse. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: parse parses regular expression patterns into abstract…

sha256:74d424cec7cf39bc550dee8741d8dacb68c44c65b6709eeb7f673ad01b07ebbf

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

실행 증거

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

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

검증 실행 환경

환경 컨트랙트 단계 실행일
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-27

케이스

HOW
목표
verify pkg:npm/regjsparser@0.13.2
패키지
심벌
  • regjsparser.parse
환경
node 22.23.2
생성일
2026-08-27T20:52:19Z

컨트랙트

  1. parse parses regular expression patterns into abstract syntax tree nodes including anchors, values, and character classes
  2. parse parses capturing and non-capturing groups with quantifiers
  3. parse supports named capturing groups when the namedGroups feature flag is enabled
  4. parse supports lookbehind assertions when the lookbehind feature flag is enabled
  5. parse supports unicode property escapes when the unicodePropertyEscape feature flag is enabled
  6. parse supports unicode set intersection and subtraction syntax under the v flag with unicodeSet feature enabled
  7. parse supports inline modifier flags when the modifiers feature flag is enabled
  8. parse throws SyntaxError on invalid regular expression syntax

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

소스 아티팩트 내려받기 (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/regjsparser@0.13.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/regjsparser@0.13.2
Demonstrate these symbols/APIs:
  - regjsparser.parse

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:c52d3171b93297f419a3b3f2afc9ea34d5f07049ea4cc9d6d97b03ad61f380a6","contract":["parse parses regular expression patterns into abstract syntax tree nodes including anchors, values, and character classes","parse parses capturing and non-capturing groups with quantifiers","parse supports named capturing groups when the namedGroups feature flag is enabled","parse supports lookbehind assertions when the lookbehind feature flag is enabled","parse supports unicode property escapes when the unicodePropertyEscape feature flag is enabled","parse supports unicode set intersection and subtraction syntax under the v flag with unicodeSet feature enabled","parse supports inline modifier flags when the modifiers feature flag is enabled","parse throws SyntaxError on invalid regular expression syntax"],"goal":"verify pkg:npm/regjsparser@0.13.2","kind":"HOW","packages":["pkg:npm/regjsparser@0.13.2"],"schemaVersion":1,"symbols":["regjsparser.parse"]},"contractCommand":["node","test/contract.js"],"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/regjsparser@0.13.2"],"schemaVersion":1,"subject":"pkg:npm/regjsparser@0.13.2","symbols":["regjsparser.parse"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-regjsparser",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-regjsparser",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "regjsparser": "0.13.2"
      }
    },
    "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/regjsparser": {
      "version": "0.13.2",
      "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.13.2.tgz",
      "integrity": "sha512-NgRBy2Nx/bE+9F27nVHnqcN5HjyLmecqsqx2PJHu3/IEtADD4WuxuXIVExD5PoSDFVrl78dOonfcOe5O+5nbzQ==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "jsesc": "~3.1.0"
      },
      "bin": {
        "regjsparser": "bin/parser"
      }
    }
  }
}
package.json
{
  "name": "sample-regjsparser",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for regjsparser",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "regjsparser": "0.13.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/regjsparser@0.13.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/regjsparser@0.13.2"
  ],
  "symbols": [
    "regjsparser.parse"
  ]
}
src/index.js
const regjsparser = require('regjsparser');

/**
 * Parses a regular expression pattern string into an AST.
 * @param {string} pattern - Regular expression pattern without enclosing slashes.
 * @param {string} [flags=''] - Regular expression flags (e.g. 'u', 'v', 'i', 'g').
 * @param {object} [features={}] - Optional feature flags for parser capabilities.
 * @returns {object} Root AST node representing the parsed regular expression.
 */
function parsePattern(pattern, flags = '', features = {}) {
  return regjsparser.parse(pattern, flags, features);
}

/**
 * Parses a regular expression pattern with named capturing groups enabled.
 * @param {string} pattern - Regular expression pattern.
 * @param {string} [flags=''] - Regular expression flags.
 * @returns {object} Root AST node.
 */
function parseWithNamedGroups(pattern, flags = '') {
  return regjsparser.parse(pattern, flags, { namedGroups: true });
}

/**
 * Parses a regular expression pattern with lookbehind assertions enabled.
 * @param {string} pattern - Regular expression pattern.
 * @param {string} [flags=''] - Regular expression flags.
 * @returns {object} Root AST node.
 */
function parseWithLookbehind(pattern, flags = '') {
  return regjsparser.parse(pattern, flags, { lookbehind: true });
}

/**
 * Parses a regular expression pattern with Unicode property escapes enabled.
 * @param {string} pattern - Regular expression pattern.
 * @param {string} [flags=''] - Regular expression flags.
 * @returns {object} Root AST node.
 */
function parseWithUnicodeProps(pattern, flags = '') {
  return regjsparser.parse(pattern, flags, { unicodePropertyEscape: true });
}

/**
 * Parses a regular expression pattern with Unicode set operations (intersection/subtraction) enabled.
 * @param {string} pattern - Regular expression pattern (e.g. '[[a-z]--[d]]').
 * @param {string} [flags='v'] - Regular expression flags (typically 'v').
 * @returns {object} Root AST node.
 */
function parseWithUnicodeSets(pattern, flags = 'v') {
  return regjsparser.parse(pattern, flags, { unicodeSet: true });
}

/**
 * Parses a regular expression pattern with inline modifier groups enabled.
 * @param {string} pattern - Regular expression pattern (e.g. '(?i-m:hello)').
 * @param {string} [flags=''] - Regular expression flags.
 * @returns {object} Root AST node.
 */
function parseWithModifiers(pattern, flags = '') {
  return regjsparser.parse(pattern, flags, { modifiers: true });
}

module.exports = {
  regjsparser,
  parsePattern,
  parseWithNamedGroups,
  parseWithLookbehind,
  parseWithUnicodeProps,
  parseWithUnicodeSets,
  parseWithModifiers
};
test/contract.js
const assert = require('node:assert');
const regjsparser = require('regjsparser');
const {
  parsePattern,
  parseWithNamedGroups,
  parseWithLookbehind,
  parseWithUnicodeProps,
  parseWithUnicodeSets,
  parseWithModifiers
} = require('../src/index.js');

// Direct export check
assert.strictEqual(typeof regjsparser.parse, 'function', 'regjsparser.parse must be a function');

// 1. parse parses regular expression patterns into abstract syntax tree nodes including anchors, values, and character classes
const basicAst = parsePattern('^a[0-9]+$', 'u');
assert.strictEqual(basicAst.type, 'alternative', 'root node of sequence is alternative');
assert.strictEqual(basicAst.raw, '^a[0-9]+$', 'raw property matches input');
assert.deepStrictEqual(basicAst.range, [0, 9], 'root range covers full string');
assert.strictEqual(basicAst.body.length, 4, 'alternative contains four subnodes');

const startAnchor = basicAst.body[0];
assert.strictEqual(startAnchor.type, 'anchor', 'first node is anchor');
assert.strictEqual(startAnchor.kind, 'start', 'anchor kind is start');
assert.strictEqual(startAnchor.raw, '^', 'start anchor raw is ^');

const charValue = basicAst.body[1];
assert.strictEqual(charValue.type, 'value', 'second node is value');
assert.strictEqual(charValue.kind, 'symbol', 'value kind is symbol');
assert.strictEqual(charValue.codePoint, 97, 'character codePoint for "a" is 97');

const charClass = basicAst.body[2];
assert.strictEqual(charClass.type, 'quantifier', 'third node is quantifier wrapping characterClass');
assert.strictEqual(charClass.symbol, '+', 'quantifier symbol is +');
assert.strictEqual(charClass.min, 1, 'quantifier min is 1');
assert.strictEqual(charClass.greedy, true, 'quantifier is greedy');
assert.strictEqual(charClass.body[0].type, 'characterClass', 'quantifier body is characterClass');
assert.strictEqual(charClass.body[0].negative, false, 'characterClass is not negated');
assert.strictEqual(charClass.body[0].body[0].type, 'characterClassRange', 'characterClass contains range');
assert.strictEqual(charClass.body[0].body[0].min.codePoint, 48, 'range min is "0" (codePoint 48)');
assert.strictEqual(charClass.body[0].body[0].max.codePoint, 57, 'range max is "9" (codePoint 57)');

const endAnchor = basicAst.body[3];
assert.strictEqual(endAnchor.type, 'anchor', 'fourth node is anchor');
assert.strictEqual(endAnchor.kind, 'end', 'anchor kind is end');

// 2. parse parses capturing and non-capturing groups with quantifiers
const groupAst = parsePattern('(abc)(?:def)*', 'u');
assert.strictEqual(groupAst.type, 'alternative', 'top level alternative');
const capGroup = groupAst.body[0];
assert.strictEqual(capGroup.type, 'group', 'first node is group');
assert.strictEqual(capGroup.behavior, 'normal', 'capturing group behavior is normal');
assert.strictEqual(capGroup.raw, '(abc)', 'capturing group raw string');

const nonCapQuant = groupAst.body[1];
assert.strictEqual(nonCapQuant.type, 'quantifier', 'second node is quantifier');
assert.strictEqual(nonCapQuant.symbol, '*', 'quantifier symbol is *');
assert.strictEqual(nonCapQuant.min, 0, 'quantifier min is 0');
const nonCapGroup = nonCapQuant.body[0];
assert.strictEqual(nonCapGroup.type, 'group', 'quantifier wraps non-capturing group');
assert.strictEqual(nonCapGroup.behavior, 'ignore', 'non-capturing group behavior is ignore');

// 3. parse supports named capturing groups when the namedGroups feature flag is enabled
const namedAst = parseWithNamedGroups('(?<year>\\d{4})-(?<month>\\d{2})', 'u');
assert.strictEqual(namedAst.type, 'alternative', 'named groups top level alternative');
const yearGroup = namedAst.body[0];
assert.strictEqual(yearGroup.type, 'group', 'year group is a group node');
assert.strictEqual(yearGroup.behavior, 'normal', 'year group behavior is normal');
assert.ok(yearGroup.name, 'year group has name node');
assert.strictEqual(yearGroup.name.type, 'identifier', 'name node is an identifier');
assert.strictEqual(yearGroup.name.value, 'year', 'name value is "year"');

const monthGroup = namedAst.body[2];
assert.strictEqual(monthGroup.type, 'group', 'month group is a group node');
assert.strictEqual(monthGroup.name.value, 'month', 'name value is "month"');

// 4. parse supports lookbehind assertions when the lookbehind feature flag is enabled
const posLookbehind = parseWithLookbehind('(?<=@)\\w+', 'u');
assert.strictEqual(posLookbehind.type, 'alternative', 'lookbehind alternative');
const posLbGroup = posLookbehind.body[0];
assert.strictEqual(posLbGroup.type, 'group', 'lookbehind node is group');
assert.strictEqual(posLbGroup.behavior, 'lookbehind', 'positive lookbehind behavior');

const negLookbehind = parseWithLookbehind('(?<![0-9])foo', 'u');
const negLbGroup = negLookbehind.body[0];
assert.strictEqual(negLbGroup.type, 'group', 'negative lookbehind node is group');
assert.strictEqual(negLbGroup.behavior, 'negativeLookbehind', 'negative lookbehind behavior');

// 5. parse supports unicode property escapes when the unicodePropertyEscape feature flag is enabled
const unicodePropAst = parseWithUnicodeProps('\\p{Letter}+', 'u');
assert.strictEqual(unicodePropAst.type, 'quantifier', 'root node is quantifier');
const propEscape = unicodePropAst.body[0];
assert.strictEqual(propEscape.type, 'unicodePropertyEscape', 'node type is unicodePropertyEscape');
assert.strictEqual(propEscape.value, 'Letter', 'unicode property value is Letter');
assert.strictEqual(propEscape.negative, false, 'positive property escape');

const negPropAst = parseWithUnicodeProps('\\P{Number}', 'u');
assert.strictEqual(negPropAst.type, 'unicodePropertyEscape', 'negative property escape type');
assert.strictEqual(negPropAst.value, 'Number', 'property name is Number');
assert.strictEqual(negPropAst.negative, true, 'negative property escape flag');

// 6. parse supports unicode set intersection and subtraction syntax under the v flag with unicodeSet feature enabled
const setSubtractionAst = parseWithUnicodeSets('[[a-z]--[d-g]]', 'v');
assert.strictEqual(setSubtractionAst.type, 'characterClass', 'set subtraction produces characterClass');
assert.strictEqual(setSubtractionAst.kind, 'subtraction', 'characterClass kind is subtraction');
assert.strictEqual(setSubtractionAst.body.length, 2, 'subtraction has 2 operands');

const setIntersectionAst = parseWithUnicodeSets('[[a-z]&&[d-g]]', 'v');
assert.strictEqual(setIntersectionAst.type, 'characterClass', 'set intersection produces characterClass');
assert.strictEqual(setIntersectionAst.kind, 'intersection', 'characterClass kind is intersection');

// 7. parse supports inline modifier flags when the modifiers feature flag is enabled
const modAst = parseWithModifiers('(?i-m:hello)', 'u');
assert.strictEqual(modAst.type, 'group', 'modifier root node is group');
assert.strictEqual(modAst.behavior, 'ignore', 'modifier group behavior is ignore');
assert.deepStrictEqual(modAst.modifierFlags, { enabling: 'i', disabling: 'm' }, 'modifierFlags captures enabled/disabled flags');

// 8. parse throws SyntaxError on invalid regular expression syntax
assert.throws(
  () => {
    parsePattern('*', 'u');
  },
  {
    name: 'SyntaxError'
  },
  'leading quantifier without atom throws SyntaxError'
);

assert.throws(
  () => {
    parsePattern('(?<1invalid>abc)', 'u', { namedGroups: true });
  },
  {
    name: 'SyntaxError'
  },
  'invalid group identifier throws SyntaxError'
);

console.log('All regjsparser contract tests passed successfully.');

오리진 시더

익명