CodeSampleX

示例

@vue/compiler-core 3.5.41: baseParse

已验证示例 — npm @vue/compiler-core 3.5.41: baseParse. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: baseParse parses simple template and produces ROOT…

sha256:9b01a796beb4ef4d7299bf154e073b6649c616066b690440317a78755808b929

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-26

案例

HOW
目标
verify baseParse in pkg:npm/%40vue/compiler-core@3.5.41
包
符号
  • baseParse
环境
node 22.23.2
创建时间
2026-08-26T04:42:43Z

契约

  1. baseParse parses simple template and produces ROOT AST node with child elements and text
  2. baseParse parses attributes and Vue directives including v-bind, v-on, and v-model
  3. baseParse parses mustache interpolations into INTERPOLATION and SIMPLE_EXPRESSION nodes
  4. baseParse supports custom delimiters options for interpolation parsing
  5. baseParse preserves HTML comment nodes when present in template
  6. baseParse invokes onError callback with error codes when encountering unclosed or malformed tags

文件

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

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

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:04969aa589e627ee4a1803b21b1403e85e4d30b538bfbb1eb2f57f67f84d2c66","contract":["baseParse parses simple template and produces ROOT AST node with child elements and text","baseParse parses attributes and Vue directives including v-bind, v-on, and v-model","baseParse parses mustache interpolations into INTERPOLATION and SIMPLE_EXPRESSION nodes","baseParse supports custom delimiters options for interpolation parsing","baseParse preserves HTML comment nodes when present in template","baseParse invokes onError callback with error codes when encountering unclosed or malformed tags"],"goal":"verify baseParse in pkg:npm/%40vue/compiler-core@3.5.41","kind":"HOW","packages":["pkg:npm/%40vue/compiler-core@3.5.41"],"schemaVersion":1,"symbols":["baseParse"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","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-core@3.5.41"],"schemaVersion":1,"subject":"pkg:npm/%40vue/compiler-core@3.5.41","symbols":["baseParse"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-vue-compiler-core-baseparse",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vue-compiler-core-baseparse",
      "version": "1.0.0",
      "dependencies": {
        "@vue/compiler-core": "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/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-core-baseparse",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of baseParse in @vue/compiler-core",
  "main": "src/index.js",
  "dependencies": {
    "@vue/compiler-core": "3.5.41"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify baseParse in pkg:npm/%40vue/compiler-core@3.5.41",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vue/compiler-core@3.5.41"
  ],
  "symbols": [
    "baseParse"
  ]
}
src/index.js
const { baseParse, NodeTypes, ElementTypes } = require('@vue/compiler-core');

/**
 * Parse a Vue template string into an AST root node.
 * @param {string} template
 * @param {object} [options]
 * @returns {object} RootNode
 */
function parseTemplate(template, options = {}) {
  return baseParse(template, options);
}

/**
 * Extract directive props from an element AST node.
 * @param {object} elementNode
 * @returns {Array<object>}
 */
function extractDirectives(elementNode) {
  if (!elementNode || !Array.isArray(elementNode.props)) {
    return [];
  }
  return elementNode.props.filter((prop) => prop.type === NodeTypes.DIRECTIVE);
}

/**
 * Collect all interpolation expression contents in an AST.
 * @param {object} node
 * @returns {string[]}
 */
function extractInterpolations(node) {
  const expressions = [];
  function traverse(current) {
    if (!current) return;
    if (current.type === NodeTypes.INTERPOLATION && current.content) {
      expressions.push(current.content.content || current.content.loc?.source || '');
    }
    if (Array.isArray(current.children)) {
      for (const child of current.children) {
        traverse(child);
      }
    }
    if (Array.isArray(current.props)) {
      for (const prop of current.props) {
        if (prop.exp) traverse(prop.exp);
      }
    }
  }
  traverse(node);
  return expressions;
}

/**
 * Parse template using custom open/close delimiters.
 * @param {string} template
 * @param {string} open
 * @param {string} close
 * @returns {object} RootNode
 */
function parseWithCustomDelimiters(template, open, close) {
  return baseParse(template, { delimiters: [open, close] });
}

/**
 * Parse template and collect errors via onError callback.
 * @param {string} template
 * @returns {{ ast: object, errors: Array<{ code: number, message: string }> }}
 */
function collectParseErrors(template) {
  const errors = [];
  const ast = baseParse(template, {
    onError(err) {
      errors.push({
        code: err.code,
        message: err.message
      });
    }
  });
  return { ast, errors };
}

module.exports = {
  baseParse,
  NodeTypes,
  ElementTypes,
  parseTemplate,
  extractDirectives,
  extractInterpolations,
  parseWithCustomDelimiters,
  collectParseErrors
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  baseParse,
  NodeTypes,
  ElementTypes,
  parseTemplate,
  extractDirectives,
  extractInterpolations,
  parseWithCustomDelimiters,
  collectParseErrors
} = require('../src/index.js');

// 1. Export verification
assert.strictEqual(typeof baseParse, 'function', 'baseParse should be exported as a function');
assert.strictEqual(typeof parseTemplate, 'function', 'parseTemplate should be exported as a function');
assert.strictEqual(typeof extractDirectives, 'function', 'extractDirectives should be exported as a function');
assert.strictEqual(typeof extractInterpolations, 'function', 'extractInterpolations should be exported as a function');
assert.strictEqual(typeof parseWithCustomDelimiters, 'function', 'parseWithCustomDelimiters should be exported as a function');
assert.strictEqual(typeof collectParseErrors, 'function', 'collectParseErrors should be exported as a function');

// 2. baseParse parses simple template and produces ROOT AST node with child elements and text
const root = parseTemplate('<div class="container"><p>Hello World</p></div>');
assert.strictEqual(root.type, NodeTypes.ROOT, 'Root node type must be ROOT (0)');
assert.strictEqual(root.children.length, 1, 'Root should have 1 child element');

const divElement = root.children[0];
assert.strictEqual(divElement.type, NodeTypes.ELEMENT, 'Child must be an ELEMENT node');
assert.strictEqual(divElement.tag, 'div');
assert.strictEqual(divElement.tagType, ElementTypes.ELEMENT);
assert.strictEqual(divElement.children.length, 1);

const pElement = divElement.children[0];
assert.strictEqual(pElement.tag, 'p');
assert.strictEqual(pElement.children.length, 1);
assert.strictEqual(pElement.children[0].type, NodeTypes.TEXT);
assert.strictEqual(pElement.children[0].content, 'Hello World');

// 3. baseParse parses attributes and Vue directives including v-bind, v-on, and v-model
const buttonTemplate = '<button id="btn-submit" :disabled="isSubmitting" @click="handleSubmit" v-model="status">Submit</button>';
const buttonRoot = parseTemplate(buttonTemplate);
const buttonNode = buttonRoot.children[0];
assert.strictEqual(buttonNode.props.length, 4);

const attr = buttonNode.props.find((p) => p.type === NodeTypes.ATTRIBUTE);
assert.ok(attr, 'Should contain static attribute');
assert.strictEqual(attr.name, 'id');
assert.strictEqual(attr.value.content, 'btn-submit');

const directives = extractDirectives(buttonNode);
assert.strictEqual(directives.length, 3, 'Should contain 3 directives');

const bindDir = directives.find((d) => d.name === 'bind');
assert.ok(bindDir, 'Should contain bind directive (:disabled)');
assert.strictEqual(bindDir.arg.content, 'disabled');
assert.strictEqual(bindDir.exp.content, 'isSubmitting');

const onDir = directives.find((d) => d.name === 'on');
assert.ok(onDir, 'Should contain on directive (@click)');
assert.strictEqual(onDir.arg.content, 'click');
assert.strictEqual(onDir.exp.content, 'handleSubmit');

const modelDir = directives.find((d) => d.name === 'model');
assert.ok(modelDir, 'Should contain model directive (v-model)');
assert.strictEqual(modelDir.exp.content, 'status');

// 4. baseParse parses mustache interpolations into INTERPOLATION and SIMPLE_EXPRESSION nodes
const interpolationTemplate = '<section><h1>{{ title }}</h1><span>Count: {{ count + 1 }}</span></section>';
const interpRoot = parseTemplate(interpolationTemplate);
const expressions = extractInterpolations(interpRoot);
assert.deepStrictEqual(expressions, ['title', 'count + 1'], 'Should extract interpolation expressions');

const h1Node = interpRoot.children[0].children[0];
const interpNode = h1Node.children[0];
assert.strictEqual(interpNode.type, NodeTypes.INTERPOLATION);
assert.strictEqual(interpNode.content.type, NodeTypes.SIMPLE_EXPRESSION);
assert.strictEqual(interpNode.content.content, 'title');
assert.strictEqual(interpNode.content.isStatic, false);

// 5. baseParse supports custom delimiters options for interpolation parsing
const customDelimTemplate = '<div>Hello [[ user.name ]] and {{ ignored }}</div>';
const customRoot = parseWithCustomDelimiters(customDelimTemplate, '[[', ']]');
const customExpressions = extractInterpolations(customRoot);
assert.deepStrictEqual(customExpressions, ['user.name'], 'Should parse custom delimiters [[ ]]');

// 6. baseParse preserves HTML comment nodes when present in template
const commentTemplate = '<div><!-- banner notice --><span>Main content</span></div>';
const commentRoot = parseTemplate(commentTemplate, { comments: true });
const divChildren = commentRoot.children[0].children;
const commentNode = divChildren.find((c) => c.type === NodeTypes.COMMENT);
assert.ok(commentNode, 'Comment node should be present');
assert.strictEqual(commentNode.content, ' banner notice ');

// 7. baseParse invokes onError callback with error codes when encountering unclosed or malformed tags
const malformedTemplate = '<div class="broken"><span>Unclosed text';
const { errors } = collectParseErrors(malformedTemplate);
assert.ok(errors.length > 0, 'Errors should be captured on malformed template');
assert.ok(errors.some((e) => typeof e.code === 'number'), 'Error code should be numeric enum value');

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

原始种子者

匿名