CodeSampleX

示例

@vue/compiler-core 3.5.41: compile template string to render function code with baseCompile

已验证示例 — npm @vue/compiler-core 3.5.41: compile template string to render function code with baseCompile. contract 在 node 22 · linux alpine/x64 · docker…

sha256:c90983380b24b4c0122cf4989fa8c3846e159da1670cdaf84c541fa4c03c072f

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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-23

案例

HOW
目标
compile template string to render function code with baseCompile
包
符号
  • baseCompile
环境
node 22.23.2
创建时间
2026-08-23T18:11:18Z

契约

  1. assert baseCompile in default mode returns AST root and render function code
  2. assert baseCompile in module mode with prefixIdentifiers produces ES export and prefixed identifiers
  3. assert baseCompile with comments option generates comment VNodes
  4. assert baseCompile onError handler captures syntax and parsing errors

文件

  • 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: compile template string to render function code with baseCompile
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vue/compiler-core@3.5.41
Demonstrate these symbols/APIs:
  - baseCompile
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:c05907926258b33db62a6e902af811e6f22a1f25cb8a65b5d1ea3febf66be3f6","constraints":{"executionContext":"node"},"contract":["assert baseCompile in default mode returns AST root and render function code","assert baseCompile in module mode with prefixIdentifiers produces ES export and prefixed identifiers","assert baseCompile with comments option generates comment VNodes","assert baseCompile onError handler captures syntax and parsing errors"],"goal":"compile template string to render function code with baseCompile","kind":"HOW","packages":["pkg:npm/%40vue/compiler-core@3.5.41"],"schemaVersion":1,"symbols":["baseCompile"]},"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-core@3.5.41"],"schemaVersion":1,"subject":"pkg:npm/%40vue/compiler-core@3.5.41","symbols":["baseCompile"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-vue-compiler-core-basecompile",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vue-compiler-core-basecompile",
      "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-basecompile",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@vue/compiler-core": "3.5.41"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "compile template string to render function code with baseCompile",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vue/compiler-core@3.5.41"
  ],
  "symbols": [
    "baseCompile"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { baseCompile, NodeTypes } = require("@vue/compiler-core");

function compileTemplate(template, options = {}) {
  return baseCompile(template, options);
}

function compileModule(template, options = {}) {
  return baseCompile(template, {
    ...options,
    mode: "module",
    prefixIdentifiers: true,
  });
}

function compileWithErrors(template, options = {}) {
  const errors = [];
  const warnings = [];
  const result = baseCompile(template, {
    ...options,
    onError: (err) => errors.push(err),
    onWarn: (warn) => warnings.push(warn),
  });
  return { result, errors, warnings };
}

module.exports = {
  compileTemplate,
  compileModule,
  compileWithErrors,
  NodeTypes,
};
test/contract.js
const assert = require("node:assert");
const {
  compileTemplate,
  compileModule,
  compileWithErrors,
  NodeTypes,
} = require("../src/index.js");

// 1. Verify default function mode compilation produces AST and render function code
const defaultResult = compileTemplate("<div><p>{{ message }}</p></div>");
assert(defaultResult && typeof defaultResult === "object", "compileTemplate should return an object");
assert(typeof defaultResult.code === "string", "result.code should be a string");
assert(defaultResult.ast && typeof defaultResult.ast === "object", "result.ast should be an object");
assert.strictEqual(defaultResult.ast.type, NodeTypes.ROOT, "AST root should have type ROOT (0)");
assert(defaultResult.code.includes("return function render"), "default compilation should produce function render");
assert(defaultResult.code.includes("toDisplayString(message)"), "code should contain display string helper for message");

// 2. Verify module mode compilation with prefixIdentifiers produces ES module export
const moduleResult = compileModule('<button @click="handleClick">{{ label }}</button>');
assert(typeof moduleResult.code === "string", "moduleResult.code should be a string");
assert(moduleResult.code.includes("export function render"), "module mode should produce export function render");
assert(moduleResult.code.includes("_ctx.handleClick"), "prefixIdentifiers should prefix variables with _ctx");
assert(moduleResult.code.includes("_ctx.label"), "prefixIdentifiers should prefix expressions with _ctx");
assert(moduleResult.code.includes("import {"), "module mode should generate import statement from vue");

// 3. Verify comments option preserves template comments in generated render function
const commentResult = compileTemplate("<div><!-- header section --><span>Content</span></div>", {
  comments: true,
});
assert(commentResult.code.includes("createCommentVNode"), "comments option should generate createCommentVNode");

// 4. Verify onError handler captures syntax and parsing errors without unhandled crashes
const errorCapture = compileWithErrors('<div :class=""><span>Unclosed tag');
assert(Array.isArray(errorCapture.errors), "errors should be an array");
assert(errorCapture.errors.length > 0, "onError handler should catch syntax errors");
assert(errorCapture.errors[0].code !== undefined, "compiler errors should have an error code");

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

原始种子者

匿名