CodeSampleX

Beispiel

@vue/compiler-sfc 3.5.41: compileScript, parse

Verifiziertes Beispiel für npm @vue/compiler-sfc 3.5.41: compileScript, parse. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:31d6b26da0e966eb608e72d94dc82b5064963d249148347b8725e8a0db904941

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify @vue/compiler-sfc.parse and @vue/compiler-sfc.compileScript in pkg:npm/%40vue/compiler-sfc@3.5.41
Pakete
Symbole
  • @vue/compiler-sfc.compileScript
  • @vue/compiler-sfc.parse
Umgebung
node 22.23.2
Erstellt
2026-08-23T18:13:37Z

Contract

  1. parse parses SFC source code and returns descriptor with template, scriptSetup, and styles
  2. parse identifies scoped style blocks and custom blocks in descriptor
  3. parse collects syntax error messages in errors array when parsing malformed SFC
  4. compileScript compiles script setup block into standard JavaScript component definition
  5. compileScript extracts reactive identifier bindings and classifies their binding types
  6. compileScript resolves defineProps and defineEmits compiler macros in bindings
  7. compileScript inlines compiled template render function when inlineTemplate is enabled
  8. compileScript throws an error when descriptor contains no script or scriptSetup tags

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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-sfc.parse and @vue/compiler-sfc.compileScript in pkg:npm/%40vue/compiler-sfc@3.5.41
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vue/compiler-sfc@3.5.41
Demonstrate these symbols/APIs:
  - @vue/compiler-sfc.compileScript
  - @vue/compiler-sfc.parse
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:262262bcab17dbd02a87c4febceeb5882e306beae020777cf8a1e2ef15ff9940","constraints":{"executionContext":"node"},"contract":["parse parses SFC source code and returns descriptor with template, scriptSetup, and styles","parse identifies scoped style blocks and custom blocks in descriptor","parse collects syntax error messages in errors array when parsing malformed SFC","compileScript compiles script setup block into standard JavaScript component definition","compileScript extracts reactive identifier bindings and classifies their binding types","compileScript resolves defineProps and defineEmits compiler macros in bindings","compileScript inlines compiled template render function when inlineTemplate is enabled","compileScript throws an error when descriptor contains no script or scriptSetup tags"],"goal":"verify @vue/compiler-sfc.parse and @vue/compiler-sfc.compileScript in pkg:npm/%40vue/compiler-sfc@3.5.41","kind":"HOW","packages":["pkg:npm/%40vue/compiler-sfc@3.5.41"],"schemaVersion":1,"symbols":["@vue/compiler-sfc.compileScript","@vue/compiler-sfc.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/%40vue/compiler-sfc@3.5.41"],"schemaVersion":1,"subject":"pkg:npm/%40vue/compiler-sfc@3.5.41","symbols":["@vue/compiler-sfc.compileScript","@vue/compiler-sfc.parse"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-vue-compiler-sfc",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vue-compiler-sfc",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@vue/compiler-sfc": "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/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "license": "MIT"
    },
    "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/compiler-sfc": {
      "version": "3.5.41",
      "resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.5.41.tgz",
      "integrity": "sha512-XJhip7R2wy6vX3knCxdZN4KracFaZUef58s1KYewqluedHIJaPIVfXoYT7MF1F8nCvv6k8bWWxDC8opMkg1VTQ==",
      "license": "MIT",
      "dependencies": {
        "@babel/parser": "^7.29.8",
        "@vue/compiler-core": "3.5.41",
        "@vue/compiler-dom": "3.5.41",
        "@vue/compiler-ssr": "3.5.41",
        "@vue/shared": "3.5.41",
        "estree-walker": "^2.0.2",
        "magic-string": "^0.30.21",
        "postcss": "^8.5.19",
        "source-map-js": "^1.2.1"
      }
    },
    "node_modules/@vue/compiler-ssr": {
      "version": "3.5.41",
      "resolved": "https://registry.npmjs.org/@vue/compiler-ssr/-/compiler-ssr-3.5.41.tgz",
      "integrity": "sha512-U3v5OejKEGqOI0Wy0+Sz7hGuIFZHA4LSXzrNM3IMIeDyJEBBfTpX26n3SDgToRpP2bLc9FfI2j/kSgcJ8Emq5A==",
      "license": "MIT",
      "dependencies": {
        "@vue/compiler-dom": "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/magic-string": {
      "version": "0.30.21",
      "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
      "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "^1.5.5"
      }
    },
    "node_modules/nanoid": {
      "version": "3.3.18",
      "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz",
      "integrity": "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "bin": {
        "nanoid": "bin/nanoid.cjs"
      },
      "engines": {
        "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
      }
    },
    "node_modules/picocolors": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
      "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
      "license": "ISC"
    },
    "node_modules/postcss": {
      "version": "8.5.26",
      "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.26.tgz",
      "integrity": "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==",
      "funding": [
        {
          "type": "opencollective",
          "url": "https://opencollective.com/postcss/"
        },
        {
          "type": "tidelift",
          "url": "https://tidelift.com/funding/github/npm/postcss"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "nanoid": "^3.3.17",
        "picocolors": "^1.1.1",
        "source-map-js": "^1.2.1"
      },
      "engines": {
        "node": "^10 || ^12 || >=14"
      }
    },
    "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-sfc",
  "version": "1.0.0",
  "description": "verify @vue/compiler-sfc.parse and @vue/compiler-sfc.compileScript in pkg:npm/%40vue/compiler-sfc@3.5.41",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@vue/compiler-sfc": "3.5.41"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @vue/compiler-sfc.parse and @vue/compiler-sfc.compileScript in pkg:npm/%40vue/compiler-sfc@3.5.41",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vue/compiler-sfc@3.5.41"
  ],
  "symbols": [
    "@vue/compiler-sfc.compileScript",
    "@vue/compiler-sfc.parse"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { parse, compileScript } = require('@vue/compiler-sfc');

/**
 * Parses Vue Single File Component source code into an SFCDescriptor.
 *
 * @param {string} source - The Vue SFC source content.
 * @param {object} [options={}] - Optional parse options (e.g. filename, sourceMap).
 * @returns {object} The parse result containing descriptor and compiler errors.
 */
function parseSFC(source, options = {}) {
  const defaultOptions = {
    filename: 'anonymous.vue',
    sourceMap: true,
    ...options
  };
  return parse(source, defaultOptions);
}

/**
 * Compiles the script or script setup block of an SFC descriptor.
 *
 * @param {object} descriptor - SFCDescriptor obtained from parse.
 * @param {object} [options={}] - Compilation options such as scope id.
 * @returns {object} Compiled SFCScriptBlock with generated code, bindings, and imports.
 */
function compileSetupScript(descriptor, options = {}) {
  const defaultOptions = {
    id: 'sfc-scope-id',
    inlineTemplate: false,
    ...options
  };
  return compileScript(descriptor, defaultOptions);
}

/**
 * Compiles the script block with inline template rendering function.
 *
 * @param {object} descriptor - SFCDescriptor obtained from parse.
 * @param {object} [options={}] - Additional compilation options.
 * @returns {object} Compiled SFCScriptBlock containing inlined render function.
 */
function compileInlineScript(descriptor, options = {}) {
  return compileSetupScript(descriptor, {
    ...options,
    inlineTemplate: true
  });
}

/**
 * Parses SFC source code and compiles its script block in one step.
 *
 * @param {string} source - The Vue SFC source content.
 * @param {object} [options={}] - Combined parse and compilation options.
 * @returns {{ descriptor: object, script: object, errors: Array }} Parsed descriptor and compiled script.
 */
function parseAndCompile(source, options = {}) {
  const parsed = parseSFC(source, options);
  if (parsed.errors && parsed.errors.length > 0) {
    return { descriptor: parsed.descriptor, script: null, errors: parsed.errors };
  }
  const script = compileSetupScript(parsed.descriptor, options);
  return { descriptor: parsed.descriptor, script, errors: [] };
}

module.exports = {
  parseSFC,
  compileSetupScript,
  compileInlineScript,
  parseAndCompile
};
test/contract.js
const assert = require('assert');
const {
  parseSFC,
  compileSetupScript,
  compileInlineScript,
  parseAndCompile
} = require('../src/index');

// 1. parse parses SFC source code and returns descriptor with template, scriptSetup, and styles
{
  const sfc = `
<template>
  <div class="counter">{{ count }}</div>
</template>
<script setup>
import { ref } from 'vue';
const count = ref(0);
</script>
<style>
.counter { font-weight: bold; }
</style>
`;
  const result = parseSFC(sfc, { filename: 'Counter.vue' });
  assert(result.descriptor !== null, 'Descriptor should not be null');
  assert.strictEqual(result.descriptor.filename, 'Counter.vue', 'Filename must match provided option');
  assert(result.descriptor.template !== null, 'Template block should be present');
  assert(result.descriptor.template.content.includes('class="counter"'), 'Template content should match');
  assert(result.descriptor.scriptSetup !== null, 'Script setup block should be present');
  assert(result.descriptor.scriptSetup.content.includes('ref(0)'), 'Script content should match');
  assert.strictEqual(result.descriptor.styles.length, 1, 'Should have exactly one style block');
  assert.strictEqual(result.errors.length, 0, 'There should be no parse errors');
}

// 2. parse identifies scoped style blocks and custom blocks in descriptor
{
  const sfc = `
<template><p>test</p></template>
<style scoped>
p { color: blue; }
</style>
<i18n>
{ "en": "hello" }
</i18n>
`;
  const result = parseSFC(sfc, { filename: 'Scoped.vue' });
  assert.strictEqual(result.descriptor.styles.length, 1, 'Should have one style block');
  assert.strictEqual(result.descriptor.styles[0].scoped, true, 'Style block must be identified as scoped');
  assert.strictEqual(result.descriptor.customBlocks.length, 1, 'Custom blocks should contain one element');
  assert.strictEqual(result.descriptor.customBlocks[0].type, 'i18n', 'Custom block type must be i18n');
}

// 3. parse collects syntax error messages in errors array when parsing malformed SFC
{
  const brokenSfc = `<template><div><span>unclosed</div></template>`;
  const result = parseSFC(brokenSfc, { filename: 'Broken.vue' });
  assert(Array.isArray(result.errors), 'Errors must be an array');
  assert(result.errors.length > 0, 'Parsing unclosed tags must produce syntax errors');
  assert(result.errors.some(err => typeof err.message === 'string' && err.message.length > 0), 'Error must have descriptive message');
}

// 4. compileScript compiles script setup block into standard JavaScript component definition
{
  const sfc = `
<template><div>{{ greeting }}</div></template>
<script setup>
const greeting = 'Welcome';
function greet() { return greeting; }
</script>
`;
  const parsed = parseSFC(sfc, { filename: 'Greeting.vue' });
  const compiled = compileSetupScript(parsed.descriptor, { id: 'scope-greeting' });
  assert(compiled !== null, 'Compiled script should not be null');
  assert.strictEqual(typeof compiled.content, 'string', 'Compiled content must be a string');
  assert(compiled.content.includes('export default'), 'Compiled output must contain default export');
  assert(compiled.content.includes('setup('), 'Compiled output must define setup function');
}

// 5. compileScript extracts reactive identifier bindings and classifies their binding types
{
  const sfc = `
<script setup>
import { ref, computed } from 'vue';
const count = ref(10);
const double = computed(() => count.value * 2);
const constantVal = 'fixed';
let mutableVal = 1;
</script>
`;
  const parsed = parseSFC(sfc, { filename: 'Bindings.vue' });
  const compiled = compileSetupScript(parsed.descriptor, { id: 'scope-bindings' });
  assert(compiled.bindings !== null && typeof compiled.bindings === 'object', 'Bindings object must exist');
  assert.strictEqual(compiled.bindings.count, 'setup-ref', 'count should be classified as setup-ref');
  assert.strictEqual(compiled.bindings.double, 'setup-ref', 'double computed should be classified as setup-ref');
  assert.strictEqual(compiled.bindings.constantVal, 'literal-const', 'constantVal should be classified as literal-const');
  assert.strictEqual(compiled.bindings.mutableVal, 'setup-let', 'mutableVal should be classified as setup-let');
}

// 6. compileScript resolves defineProps and defineEmits compiler macros in bindings
{
  const sfc = `
<script setup>
const props = defineProps({
  userId: { type: Number, required: true },
  name: { type: String, default: 'Anonymous' }
});
const emit = defineEmits(['change', 'submit']);
</script>
`;
  const parsed = parseSFC(sfc, { filename: 'Macros.vue' });
  const compiled = compileSetupScript(parsed.descriptor, { id: 'scope-macros' });
  assert.strictEqual(compiled.bindings.userId, 'props', 'userId prop must be classified as props binding');
  assert.strictEqual(compiled.bindings.name, 'props', 'name prop must be classified as props binding');
  assert.strictEqual(compiled.bindings.emit, 'setup-const', 'emit must be classified as setup-const');
}

// 7. compileScript inlines compiled template render function when inlineTemplate is enabled
{
  const sfc = `
<template>
  <button @click="increment">Count: {{ count }}</button>
</template>
<script setup>
import { ref } from 'vue';
const count = ref(0);
function increment() { count.value++; }
</script>
`;
  const parsed = parseSFC(sfc, { filename: 'Inline.vue' });
  const compiled = compileInlineScript(parsed.descriptor, { id: 'scope-inline' });
  assert(compiled.content.includes('_createElementBlock') || compiled.content.includes('_toDisplayString'), 'Render helpers must be inlined');
  assert(compiled.content.includes('return (_ctx'), 'Setup function must return render function directly');
}

// 8. compileScript throws an error when descriptor contains no script or scriptSetup tags
{
  const sfc = `<template><div>Template only component</div></template>`;
  const parsed = parseSFC(sfc, { filename: 'TemplateOnly.vue' });
  assert.throws(
    () => {
      compileSetupScript(parsed.descriptor, { id: 'scope-error' });
    },
    (err) => {
      return err instanceof Error && err.message.includes('no <script> tags');
    },
    'Should throw error indicating no script tag found'
  );
}

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

Ursprungs-Seeder

anonym