import { store, File } from './store' import { parse, compileTemplate, compileStyleAsync, compileScript, rewriteDefault, SFCDescriptor, BindingMetadata } from '@vue/compiler-sfc' export const MAIN_FILE = 'App.vue' export const COMP_IDENTIFIER = `__sfc__` // @ts-ignore export const SANDBOX_VUE_URL = import.meta.env.PROD ? '/vue.runtime.esm-browser.js' // to be copied on build : '/src/vue-dev-proxy' export async function compileFile({ filename, code, compiled }: File) { if (!code.trim()) { return } if (filename.endsWith('.js')) { compiled.js = compiled.ssr = code return } const id = await hashId(filename) const { errors, descriptor } = parse(code, { filename, sourceMap: true }) if (errors.length) { store.errors = errors return } if ( (descriptor.script && descriptor.script.lang) || (descriptor.scriptSetup && descriptor.scriptSetup.lang) || descriptor.styles.some(s => s.lang) || (descriptor.template && descriptor.template.lang) ) { store.errors = [ 'lang="x" pre-processors are not supported in the in-browser playground.' ] return } const hasScoped = descriptor.styles.some(s => s.scoped) let clientCode = '' let ssrCode = '' const appendSharedCode = (code: string) => { clientCode += code ssrCode += code } const clientScriptResult = doCompileScript(descriptor, id, false) if (!clientScriptResult) { return } const [clientScript, bindings] = clientScriptResult clientCode += clientScript // script ssr only needs to be performed if using