"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateBindings = generateBindings;
const utils_1 = require("../utils");
const component_1 = require("./component");
const template_1 = require("./template");
function* generateBindings(options, ctx, templateCodegenCtx) {
    if (!options.sfc.scriptSetup || !options.scriptSetupRanges) {
        return;
    }
    yield `const __VLS_bindings = {`;
    if (ctx.bypassDefineComponent) {
        yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
    }
    const templateUsageVars = (0, template_1.getTemplateUsageVars)(options, ctx);
    for (const [content, bindings] of [
        [options.sfc.scriptSetup.content, options.scriptSetupRanges.bindings],
        options.sfc.script && options.scriptRanges
            ? [options.sfc.script.content, options.scriptRanges.bindings]
            : ['', []],
    ]) {
        for (const { range } of bindings) {
            const varName = content.slice(range.start, range.end);
            if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
                continue;
            }
            const templateOffset = options.getGeneratedLength();
            yield `${varName}: ${varName} as typeof `;
            const scriptOffset = options.getGeneratedLength();
            yield `${varName},${utils_1.newLine}`;
            options.linkedCodeMappings.push({
                sourceOffsets: [scriptOffset],
                generatedOffsets: [templateOffset],
                lengths: [varName.length],
                data: undefined,
            });
        }
    }
    yield `}${utils_1.endOfLine}`;
}
//# sourceMappingURL=binding.js.map