CodeSampleX

샘플

@vue/compiler-dom 3.5.41: NodeTypes

검증된 샘플 — npm @vue/compiler-dom 3.5.41: NodeTypes. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert NodeTypes enum maps AST node types…

sha256:12261d503b0d76e49c8b62e8f968ec6a9beb99cb4a98b942aa032405b4e6cd7e

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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 @vue/compiler-dom.NodeTypes in pkg:npm/%40vue/compiler-dom@3.5.41
패키지
심벌
  • @vue/compiler-dom.NodeTypes
환경
node 22.23.2
생성일
2026-08-27T17:44:49Z

컨트랙트

  1. assert NodeTypes enum maps AST node types including ROOT, ELEMENT, TEXT, COMMENT, SIMPLE_EXPRESSION, INTERPOLATION, ATTRIBUTE, DIRECTIVE
  2. assert parse produces RootNode with type matching NodeTypes.ROOT and child elements matching NodeTypes.ELEMENT
  3. assert element attributes and directives are classified with NodeTypes.ATTRIBUTE and NodeTypes.DIRECTIVE
  4. assert template interpolations and comments match NodeTypes.INTERPOLATION, NodeTypes.SIMPLE_EXPRESSION, and NodeTypes.COMMENT
  5. assert AST node visitor classifies and counts all node types in template

파일

  • 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 @vue/compiler-dom.NodeTypes in pkg:npm/%40vue/compiler-dom@3.5.41
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vue/compiler-dom@3.5.41
Demonstrate these symbols/APIs:
  - @vue/compiler-dom.NodeTypes

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:de37f1ab49d552bfe919024a4c3949db4737a10973669cbca3de27a89a2e7543","constraints":{"executionContext":"node"},"contract":["assert NodeTypes enum maps AST node types including ROOT, ELEMENT, TEXT, COMMENT, SIMPLE_EXPRESSION, INTERPOLATION, ATTRIBUTE, DIRECTIVE","assert parse produces RootNode with type matching NodeTypes.ROOT and child elements matching NodeTypes.ELEMENT","assert element attributes and directives are classified with NodeTypes.ATTRIBUTE and NodeTypes.DIRECTIVE","assert template interpolations and comments match NodeTypes.INTERPOLATION, NodeTypes.SIMPLE_EXPRESSION, and NodeTypes.COMMENT","assert AST node visitor classifies and counts all node types in template"],"goal":"verify @vue/compiler-dom.NodeTypes in pkg:npm/%40vue/compiler-dom@3.5.41","kind":"HOW","packages":["pkg:npm/%40vue/compiler-dom@3.5.41"],"schemaVersion":1,"symbols":["@vue/compiler-dom.NodeTypes"]},"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/%40vue/compiler-dom@3.5.41"],"schemaVersion":1,"subject":"pkg:npm/%40vue/compiler-dom@3.5.41","symbols":["@vue/compiler-dom.NodeTypes"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-vue-compiler-dom-nodetypes",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vue-compiler-dom-nodetypes",
      "version": "1.0.0",
      "dependencies": {
        "@vue/compiler-dom": "3.5.41"
      }
    },
    "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/@vue/compiler-core": {
      "version": "3.5.41",
      "resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.5.41.tgz",
      "integrity": "sha512-q0Xtv/F9w2YO/7htQhtiL+Ev2WCJbe5N2hc+XfgyKkEKqWpSxknmT8QOuGdEKNdjPq0c3F7rNpFkTo3Kfrm7pg==",
      "license": "MIT",
      "dependencies": {
        "@babel/parser": "^7.29.8",
        "@vue/shared": "3.5.41",
        "entities": "^7.0.1",
        "estree-walker": "^2.0.2",
        "source-map-js": "^1.2.1"
      }
    },
    "node_modules/@vue/compiler-dom": {
      "version": "3.5.41",
      "resolved": "https://registry.npmjs.org/@vue/compiler-dom/-/compiler-dom-3.5.41.tgz",
      "integrity": "sha512-oKacVfNglLvGjnS6BXOlGL7EyG2h8X03pqXCjzotRZUaXGjbrTJUnVAQjrCqUnS+lyu31nwQjZY/d817GmCnfw==",
      "license": "MIT",
      "dependencies": {
        "@vue/compiler-core": "3.5.41",
        "@vue/shared": "3.5.41"
      }
    },
    "node_modules/@vue/shared": {
      "version": "3.5.41",
      "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.5.41.tgz",
      "integrity": "sha512-IOnwSCma8j+9xJT6b8H0dEYidC80NsYmNMlZxRsukYcSoGaDBohog5hDxzeUXdFeGWFA++vWvxqOmrr96VlqMA==",
      "license": "MIT"
    },
    "node_modules/entities": {
      "version": "7.0.1",
      "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
      "integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==",
      "license": "BSD-2-Clause",
      "engines": {
        "node": ">=0.12"
      },
      "funding": {
        "url": "https://github.com/fb55/entities?sponsor=1"
      }
    },
    "node_modules/estree-walker": {
      "version": "2.0.2",
      "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
      "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
      "license": "MIT"
    },
    "node_modules/source-map-js": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
      "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
      "license": "BSD-3-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-vue-compiler-dom-nodetypes",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@vue/compiler-dom": "3.5.41"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @vue/compiler-dom.NodeTypes in pkg:npm/%40vue/compiler-dom@3.5.41",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vue/compiler-dom@3.5.41"
  ],
  "symbols": [
    "@vue/compiler-dom.NodeTypes"
  ]
}
src/index.js
const { NodeTypes, parse } = require("@vue/compiler-dom");

/**
 * Maps a numeric NodeTypes value to its enum name string.
 *
 * @param {number} type - The NodeTypes numeric value.
 * @returns {string} The name of the node type (e.g. 'ROOT', 'ELEMENT', 'TEXT').
 */
function getNodeTypeName(type) {
  return NodeTypes[type] || "UNKNOWN";
}

/**
 * Checks if a given AST node matches the specified NodeTypes value.
 *
 * @param {object} node - AST node object with a type property.
 * @param {number} expectedType - Expected NodeTypes enum value.
 * @returns {boolean} True if the node's type matches expectedType.
 */
function isNodeType(node, expectedType) {
  return Boolean(node && typeof node === "object" && node.type === expectedType);
}

/**
 * Recursively walks an AST node and its children / properties, invoking a callback.
 *
 * @param {object} node - The AST node to walk.
 * @param {Function} visitor - Visitor callback invoked with each visited node.
 */
function walkAST(node, visitor) {
  if (!node || typeof node !== "object") return;
  visitor(node);

  if (Array.isArray(node.children)) {
    for (const child of node.children) {
      walkAST(child, visitor);
    }
  }

  if (Array.isArray(node.props)) {
    for (const prop of node.props) {
      walkAST(prop, visitor);
      if (prop.value) {
        walkAST(prop.value, visitor);
      }
      if (prop.exp) {
        walkAST(prop.exp, visitor);
      }
      if (prop.arg) {
        walkAST(prop.arg, visitor);
      }
    }
  }

  if (node.content && typeof node.content === "object") {
    walkAST(node.content, visitor);
  }

  if (Array.isArray(node.branches)) {
    for (const branch of node.branches) {
      walkAST(branch, visitor);
    }
  }
}

/**
 * Traverses an AST and counts occurrences of each NodeTypes value.
 *
 * @param {object} ast - The root AST or node to inspect.
 * @returns {Record<string, number>} Map of NodeTypes names to occurrence counts.
 */
function countNodeTypes(ast) {
  const counts = {};
  walkAST(ast, (node) => {
    if (typeof node.type === "number") {
      const typeName = getNodeTypeName(node.type);
      counts[typeName] = (counts[typeName] || 0) + 1;
    }
  });
  return counts;
}

/**
 * Collects all AST nodes matching a specific NodeTypes value.
 *
 * @param {object} ast - The root AST or node to search within.
 * @param {number} nodeType - NodeTypes enum value to filter by.
 * @returns {object[]} Array of matching AST nodes.
 */
function findNodesByType(ast, nodeType) {
  const matched = [];
  walkAST(ast, (node) => {
    if (node.type === nodeType) {
      matched.push(node);
    }
  });
  return matched;
}

/**
 * Parses a Vue template string and classifies root child nodes by NodeTypes.
 *
 * @param {string} template - The Vue HTML template string.
 * @returns {{ ast: object, counts: Record<string, number> }} Parsed AST and node type counts.
 */
function analyzeTemplate(template) {
  const ast = parse(template);
  const counts = countNodeTypes(ast);
  return { ast, counts };
}

module.exports = {
  NodeTypes,
  getNodeTypeName,
  isNodeType,
  walkAST,
  countNodeTypes,
  findNodesByType,
  analyzeTemplate,
};
test/contract.js
const assert = require("node:assert");
const { NodeTypes, parse } = require("@vue/compiler-dom");
const {
  getNodeTypeName,
  isNodeType,
  countNodeTypes,
  findNodesByType,
  analyzeTemplate,
} = require("../src/index.js");

// 1. Verify NodeTypes enum values and reverse mappings
assert.strictEqual(NodeTypes.ROOT, 0, "NodeTypes.ROOT should equal 0");
assert.strictEqual(NodeTypes.ELEMENT, 1, "NodeTypes.ELEMENT should equal 1");
assert.strictEqual(NodeTypes.TEXT, 2, "NodeTypes.TEXT should equal 2");
assert.strictEqual(NodeTypes.COMMENT, 3, "NodeTypes.COMMENT should equal 3");
assert.strictEqual(NodeTypes.SIMPLE_EXPRESSION, 4, "NodeTypes.SIMPLE_EXPRESSION should equal 4");
assert.strictEqual(NodeTypes.INTERPOLATION, 5, "NodeTypes.INTERPOLATION should equal 5");
assert.strictEqual(NodeTypes.ATTRIBUTE, 6, "NodeTypes.ATTRIBUTE should equal 6");
assert.strictEqual(NodeTypes.DIRECTIVE, 7, "NodeTypes.DIRECTIVE should equal 7");
assert.strictEqual(NodeTypes.COMPOUND_EXPRESSION, 8, "NodeTypes.COMPOUND_EXPRESSION should equal 8");
assert.strictEqual(NodeTypes.IF, 9, "NodeTypes.IF should equal 9");
assert.strictEqual(NodeTypes.FOR, 11, "NodeTypes.FOR should equal 11");

// Helper getNodeTypeName verification
assert.strictEqual(getNodeTypeName(NodeTypes.ROOT), "ROOT");
assert.strictEqual(getNodeTypeName(NodeTypes.ELEMENT), "ELEMENT");
assert.strictEqual(getNodeTypeName(NodeTypes.DIRECTIVE), "DIRECTIVE");

// 2. Parse template and verify root and element AST node types
const template = `<section id="container" class="layout">
  <!-- header section -->
  <h1>{{ heading }}</h1>
  <p>Paragraph text with <span data-id="nested">inner span</span></p>
  <button @click="handleClick" v-if="isEnabled">Action</button>
</section>`;

const ast = parse(template);
assert(ast, "parse should return an AST RootNode");
assert.strictEqual(ast.type, NodeTypes.ROOT, "AST root type should be NodeTypes.ROOT (0)");
assert(isNodeType(ast, NodeTypes.ROOT), "isNodeType should return true for Root node");

const rootElement = ast.children.find((child) => child.type === NodeTypes.ELEMENT);
assert(rootElement, "Root AST should contain an element child");
assert.strictEqual(rootElement.tag, "section", "Root element tag should be section");
assert(isNodeType(rootElement, NodeTypes.ELEMENT), "isNodeType should return true for Element node");

// 3. Verify attributes and directives match NodeTypes.ATTRIBUTE and NodeTypes.DIRECTIVE
const idAttr = rootElement.props.find((p) => p.name === "id");
assert(idAttr, "Element should have id attribute");
assert.strictEqual(idAttr.type, NodeTypes.ATTRIBUTE, "id prop should have type NodeTypes.ATTRIBUTE (6)");
assert(idAttr.value && idAttr.value.type === NodeTypes.TEXT, "Attribute value node should have type NodeTypes.TEXT (2)");

const buttonNode = findNodesByType(ast, NodeTypes.ELEMENT).find((el) => el.tag === "button");
assert(buttonNode, "Should find button element node");

const clickDirective = buttonNode.props.find((p) => p.name === "on");
assert(clickDirective, "Button should have @click directive");
assert.strictEqual(clickDirective.type, NodeTypes.DIRECTIVE, "Directive prop should have type NodeTypes.DIRECTIVE (7)");

const ifDirective = buttonNode.props.find((p) => p.name === "if");
assert(ifDirective, "Button should have v-if directive");
assert.strictEqual(ifDirective.type, NodeTypes.DIRECTIVE, "v-if prop should have type NodeTypes.DIRECTIVE (7)");

// 4. Verify interpolations and comments match NodeTypes.INTERPOLATION, SIMPLE_EXPRESSION, COMMENT
const comments = findNodesByType(ast, NodeTypes.COMMENT);
assert.strictEqual(comments.length, 1, "Should find 1 comment node");
assert.strictEqual(comments[0].type, NodeTypes.COMMENT, "Comment should match NodeTypes.COMMENT (3)");
assert.strictEqual(comments[0].content.trim(), "header section");

const interpolations = findNodesByType(ast, NodeTypes.INTERPOLATION);
assert.strictEqual(interpolations.length, 1, "Should find 1 interpolation node");
assert.strictEqual(interpolations[0].type, NodeTypes.INTERPOLATION, "Interpolation should match NodeTypes.INTERPOLATION (5)");
assert.strictEqual(interpolations[0].content.type, NodeTypes.SIMPLE_EXPRESSION, "Interpolation expression should be NodeTypes.SIMPLE_EXPRESSION (4)");
assert.strictEqual(interpolations[0].content.content, "heading");

// 5. Verify analyzeTemplate and countNodeTypes aggregation
const analysis = analyzeTemplate(template);
assert(analysis.ast && typeof analysis.counts === "object", "analyzeTemplate should return ast and counts");
assert(analysis.counts.ROOT >= 1, "Counts should include ROOT");
assert(analysis.counts.ELEMENT >= 4, "Counts should include multiple ELEMENTs (section, h1, p, span, button)");
assert(analysis.counts.ATTRIBUTE >= 3, "Counts should include ATTRIBUTEs (id, class, data-id)");
assert(analysis.counts.DIRECTIVE >= 2, "Counts should include DIRECTIVEs (@click, v-if)");
assert(analysis.counts.COMMENT >= 1, "Counts should include COMMENT");
assert(analysis.counts.INTERPOLATION >= 1, "Counts should include INTERPOLATION");
assert(analysis.counts.SIMPLE_EXPRESSION >= 1, "Counts should include SIMPLE_EXPRESSION");

console.log("PASS: @vue/compiler-dom NodeTypes contract assertions verified");

오리진 시더

익명