"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const vfs_1 = require("@previewjs/vfs");
const path_1 = __importDefault(require("path"));
const vitest_1 = require("vitest");
const vue_reader_1 = require("./vue-reader");
(0, vitest_1.describe)("createVueTypeScriptReader", () => {
    let memoryReader;
    let reader;
    (0, vitest_1.beforeEach)(() => {
        memoryReader = (0, vfs_1.createMemoryReader)();
        reader = (0, vue_reader_1.createVueTypeScriptReader)(memoryReader);
    });
    (0, vitest_1.it)("extracts from script", async () => {
        memoryReader.updateFile(path_1.default.join(__dirname, "virtual", "App.vue"), `
<template>
  <h1>{{ msg }}</h1>
</template>
<script lang="ts">
export default {
  name: 'App',
  props: {}
}
</script>

    `);
        const virtualFile = await reader.read(path_1.default.join(__dirname, "virtual", "App.vue.ts"));
        if ((virtualFile === null || virtualFile === void 0 ? void 0 : virtualFile.kind) !== "file") {
            throw new Error();
        }
        (0, vitest_1.expect)(await virtualFile.read()).toEqual(`
const pjs_component = {
    name: "App",
    props: {}
} as const;


import type {Prop as PJS_Prop} from 'vue/types/options';

type PJS_TypeOrUnion<T> = PJS_Prop<T> | ReadonlyArray<PJS_Prop<T>>;
type PJS_OptionalPropType<T> = PJS_TypeOrUnion<T> | {type: PJS_TypeOrUnion<T>; required?: false};
type PJS_RequiredPropType<T> = {type: PJS_TypeOrUnion<T>; required: true};
type PJS_OptionalPropsKeys<T> = {
  [K in keyof T]: T[K] extends PJS_OptionalPropType<any> ? K : never;
}[keyof T];
type PJS_RequiredPropsKeys<T> = {
  [K in keyof T]: T[K] extends PJS_RequiredPropType<any> ? K : never;
}[keyof T];
type PJS_CombinedProps<T> = T extends readonly [...any] ? {
  [K in T[number]]: unknown
} : ({
  [K in PJS_OptionalPropsKeys<T>]?: T[K] extends PJS_OptionalPropType<infer S> ? S : never;
} & {
  [K in PJS_RequiredPropsKeys<T>]: T[K] extends PJS_RequiredPropType<infer S> ? S : never;
});
type PJS_ExtractProps<T> = T extends { props: any } ? PJS_CombinedProps<T['props']> : {}
type PJS_Props = PJS_ExtractProps<typeof pjs_component>;
`);
    });
    (0, vitest_1.it)("ignores incompatible script lang", async () => {
        memoryReader.updateFile(path_1.default.join(__dirname, "virtual", "App.vue"), `
<template>
  <h1>{{ msg }}</h1>
</template>
<script lang="coffee">
foo
</script>
    `);
        const virtualFile = await reader.read(path_1.default.join(__dirname, "virtual", "App.vue.ts"));
        if ((virtualFile === null || virtualFile === void 0 ? void 0 : virtualFile.kind) !== "file") {
            throw new Error();
        }
        (0, vitest_1.expect)(await virtualFile.read()).toEqual(``);
    });
});
