[
  {
    "path": ".eslintignore",
    "content": "dist\nnode_modules\n*.vue\n"
  },
  {
    "path": ".eslintrc.json",
    "content": "{\n  \"extends\": \"@antfu\"\n}\n"
  },
  {
    "path": ".github/FUNDING.yml",
    "content": "github: [antfu]\n"
  },
  {
    "path": ".github/workflows/release.yml",
    "content": "name: Release\n\non:\n  push:\n    tags:\n      - 'v*'\n\njobs:\n  release:\n    runs-on: ubuntu-latest\n    permissions:\n      contents: write\n    steps:\n      - uses: actions/checkout@v2\n        with:\n          fetch-depth: 0\n      - uses: actions/setup-node@v2\n        with:\n          node-version: lts/*\n          registry-url: https://registry.npmjs.org/\n      - run: npm i -g pnpm @antfu/ni\n      - run: nci\n      - run: nr test --if-present\n      # - run: npm publish --access public\n      #   env:\n      #     NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}\n      - run: npx conventional-github-releaser -p angular\n        env:\n          CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{secrets.GITHUB_TOKEN}}\n"
  },
  {
    "path": ".github/workflows/test.yml",
    "content": "name: Test\n\non:\n  push:\n    branches:\n      - main\n      - master\n\n  pull_request:\n    branches:\n      - main\n      - master\n\njobs:\n  build:\n    runs-on: ${{ matrix.os }}\n\n    strategy:\n      matrix:\n        node: [18.x]\n        os: [ubuntu-latest, windows-latest, macos-latest]\n      fail-fast: false\n\n    steps:\n      - uses: actions/checkout@v2\n\n      - name: Install pnpm\n        uses: pnpm/action-setup@v2\n\n      - name: Set node version to ${{ matrix.node }}\n        uses: actions/setup-node@v2\n        with:\n          node-version: ${{ matrix.node }}\n          cache: pnpm\n\n      - uses: actions/checkout@v2\n\n      - name: Install\n        run: pnpm i\n\n      - name: Lint\n        run: pnpm run lint\n\n      - name: Build\n        run: pnpm run build\n\n      - name: Test\n        run: pnpm run test\n\n      - name: Build Examples\n        run: pnpm run build:examples\n"
  },
  {
    "path": ".gitignore",
    "content": "# Created by .ignore support plugin (hsz.mobi)\n### Node template\n# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Bower dependency directory (https://bower.io/)\nbower_components\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (https://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules/\njspm_packages/\n\n# TypeScript v1 declaration files\ntypings/\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Optional REPL history\n.node_repl_history\n\n# Output of 'npm pack'\n*.tgz\n\n# Yarn Integrity file\n.yarn-integrity\n\n# dotenv environment variables file\n.env\n\n# parcel-bundler cache (https://parceljs.org/)\n.cache\n\n# next.js build output\n.next\n\n# nuxt.js build output\n.nuxt\n\n# Nuxt generate\ndist\n\n# vuepress build output\n.vuepress/dist\n\n# Serverless directories\n.serverless\n\n# IDE\n.idea\n\ntemp.ts\n.output\n"
  },
  {
    "path": ".npmrc",
    "content": "ignore-workspace-root-check=true\nstrict-peer-dependencies=false\n"
  },
  {
    "path": ".tazerc.json",
    "content": "{\n  \"exclude\": [\n    \"vue\",\n    \"htmlparser2\"\n  ]\n}\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2021 Anthony Fu <https://github.com/antfu>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# unplugin-vue2-script-setup\n\n[![NPM version](https://img.shields.io/npm/v/unplugin-vue2-script-setup?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-vue2-script-setup)\n\nBring [`<script setup>`](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to Vue 2. Works for Vite, Nuxt, Vue CLI, Webpack, esbuild and more, powered by [unplugin](https://github.com/unjs/unplugin).\n\n> ⚠️ With the release of [Vue 2.7](https://blog.vuejs.org/posts/vue-2-7-naruto.html), which has Composition API and `<script setup>` built-in, **you no longer need this plugin**. Thereby this plugin has entered maintenance mode and will only support Vue 2.6 or earlier. This project will reach End of Life by the end of 2022.\n\n## Install\n\n```bash\nnpm i -D unplugin-vue2-script-setup\nnpm i @vue/composition-api\n```\n\nInstall [`@vue/composition-api`](https://github.com/vuejs/composition-api) in your App's entry (it enables the `setup()` hook):\n\n```ts\nimport Vue from 'vue'\nimport VueCompositionAPI from '@vue/composition-api'\n\nVue.use(VueCompositionAPI)\n```\n\n<details>\n<summary>Vite</summary><br>\n\n```ts\n// vite.config.ts\nimport { defineConfig } from 'vite'\nimport { createVuePlugin as Vue2 } from 'vite-plugin-vue2'\nimport ScriptSetup from 'unplugin-vue2-script-setup/vite'\n\nexport default defineConfig({\n  plugins: [\n    Vue2(),\n    ScriptSetup({ /* options */ }),\n  ],\n})\n```\n\nExample: [`playground/`](./playground/)\n\n<br></details>\n\n<details>\n<summary>Nuxt</summary><br>\n\n> It's built-in in [Nuxt Bridge](https://github.com/nuxt/bridge).\n\n</details>\n\n<details>\n<summary>Vue CLI</summary><br>\n\n```ts\n// vue.config.js\nconst ScriptSetup = require('unplugin-vue2-script-setup/webpack').default\n\nmodule.exports = {\n  parallel: false, // disable thread-loader, which is not compactible with this plugin\n  configureWebpack: {\n    plugins: [\n      ScriptSetup({ /* options */ }),\n    ],\n  },\n}\n```\n\nExample: [`examples/vue-cli`](./examples/vue-cli)\n\n###### TypeScript\n\nTo use TypeScript with Vue CLI, install `@vue/cli-plugin-typescript` but disable the type check:\n\n```bash\nnpm i -D @vue/cli-plugin-typescript vue-tsc\n```\n\n```ts\nconst ScriptSetup = require('unplugin-vue2-script-setup/webpack').default\n\nmodule.exports = {\n  parallel: false,\n  configureWebpack: {\n    plugins: [\n      ScriptSetup({ /* options */ }),\n    ],\n  },\n  chainWebpack(config) {\n    // disable type check and let `vue-tsc` handles it\n    config.plugins.delete('fork-ts-checker')\n  },\n}\n```\n\nAnd then use [`vue-tsc`](https://github.com/johnsoncodehk/volar) to do the type check at build time:\n\n```jsonc\n// package.json\n{\n  \"scripts\": {\n    \"dev\": \"vue-cli-service serve\",\n    \"build\": \"vue-tsc --noEmit && vue-cli-service build\"\n  }\n}\n```\n\n<br></details>\n\n<details>\n<summary>Webpack</summary><br>\n\n```ts\n// webpack.config.js\nconst ScriptSetup = require('unplugin-vue2-script-setup/webpack').default\n\nmodule.exports = {\n  /* ... */\n  plugins: [\n    ScriptSetup({ /* options */ }),\n  ]\n}\n```\n\n<br></details>\n\n<details>\n<summary>Rollup</summary><br>\n\n```ts\n// rollup.config.js\nimport Vue from 'rollup-plugin-vue'\nimport ScriptSetup from 'unplugin-vue2-script-setup/rollup'\n\nexport default {\n  plugins: [\n    Vue(),\n    ScriptSetup({ /* options */ }),\n  ]\n}\n```\n\n<br></details>\n\n<details>\n<summary>esbuild</summary><br>\n\n```ts\n// esbuild.config.js\nimport { build } from 'esbuild'\nimport ScriptSetup from 'unplugin-vue2-script-setup/esbuild'\n\nbuild({\n  /* ... */\n  plugins: [\n    ScriptSetup({\n      /* options */\n    }),\n  ],\n})\n```\n\n<br></details>\n\n<details>\n<summary>Jest</summary><br>\n\n```bash\nnpm i -D vue-jest\n```\n\n```ts\n// jest.config.js\nmodule.exports = {\n  transform: {\n    '.*\\\\.(vue)$': 'unplugin-vue2-script-setup/jest',\n  },\n}\n```\n\n<br></details>\n\n<details>\n<summary>JavaScript API</summary><br>\n\n```ts\nimport { transform } from 'unplugin-vue2-script-setup'\n\nconst Vue2SFC = await transform(`\n<template>\n  <!-- ... -->\n</template>\n\n<script setup>\n  // ...\n</script>\n`)\n```\n\n<br></details>\n\n## IDE\n\nWe recommend using [VS Code](https://code.visualstudio.com/) with [Volar](https://github.com/johnsoncodehk/volar) to get the best experience (You might want to disable Vetur if you have it).\n\nWhen using Volar, you need to install `@vue/runtime-dom` as devDependencies to make it work on Vue 2.\n\n```bash\nnpm i -D @vue/runtime-dom\n```\n\n[Learn more](https://github.com/johnsoncodehk/volar#using)\n\n###### Global Types\n\nIf the global types are missing for your IDE, update your `tsconfig.json` with:\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"types\": [\n      \"unplugin-vue2-script-setup/types\"\n    ]\n  }\n}\n```\n\n###### Support Vue 2 template\n\nVolar preferentially supports Vue 3. Vue 3 and Vue 2 template has some different. You need to set the `experimentalCompatMode` option to support Vue 2 template.\n\n```jsonc\n{\n  \"compilerOptions\": {\n    // ...\n  },\n  \"vueCompilerOptions\": {\n    \"target\": 2\n  }\n}\n```\n\n###### ESLint\n\nIf you are using ESLint, you might get `@typescript-eslint/no-unused-vars` warning with `<script setup>`. You can disable it and add `noUnusedLocals: true` in your `tsconfig.json`, Volar will infer the real missing locals correctly for you. \n\n## Configurations\n\n<details>\n  <summary>\n    Ref Sugar (take 2)\n  </summary>\n\nIn v0.5.x, we shipped the **experimental** [Ref Sugar (take 2)](https://github.com/vuejs/rfcs/discussions/369) implementation based on Vue 3's [`@vue/reactivity-transform`](https://github.com/vuejs/vue-next/tree/master/packages/reactivity-transform) package. Notice the syntax is not settled yet and might be changed in the future updates. **Use at your own risk!**\n\nTo enabled it, pass the option:\n\n```ts\nScriptSetup({\n  reactivityTransform: true\n})\n```\n\nTo get TypeScript support, update your `tsconfig.json` with:\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"types\": [\n      \"unplugin-vue2-script-setup/types\",\n      \"unplugin-vue2-script-setup/ref-macros\"\n    ]\n  }\n}\n```\n\n</details>\n\n## Recommendations\n\nIf you enjoy using `<script setup>`, you might also want to try [`unplugin-auto-import`](https://github.com/antfu/unplugin-auto-import) to improve the DX even further.\n\n## Progress\n\n- [x] PoC\n- [x] Components registration\n- [x] Compile time macros `defineProps` `defineEmits` `withDefaults` `defineExpose`\n- [x] Global types\n- [x] Merge with normal scripts\n- [x] [Ref Sugar (take 2)](https://github.com/vuejs/rfcs/discussions/369)\n- [x] `<template lang=\"pug\">` support\n- [x] Vite plugin\n- [x] Webpack plugin\n- [x] Nuxt module\n- [ ] ~~Top-level await~~ (not supported)\n\n## How?\n\n<details>\n  <summary>\n    👀\n  </summary>\n\n![image](https://user-images.githubusercontent.com/11247099/130307245-20f9342e-377b-4565-b55d-1b91741b5c0f.png)\n\nIt's made possible by transforming the `<script setup>` syntax back to normal `<script>` and let the Vue 2 SFC compiler handle the rest.\n\n<br></details>\n\n## Sponsors\n\n<p align=\"center\">\n  <a href=\"https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg\">\n    <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>\n  </a>\n</p>\n\n## License\n\n[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)\n"
  },
  {
    "path": "esbuild.d.ts",
    "content": "export { default } from './dist/esbuild'\n"
  },
  {
    "path": "examples/vue-cli/.npmrc",
    "content": "shamefully-hoist=true\n"
  },
  {
    "path": "examples/vue-cli/babel.config.js",
    "content": "module.exports = {\n  presets: [\n    '@vue/cli-plugin-babel/preset',\n  ],\n}\n"
  },
  {
    "path": "examples/vue-cli/package.json",
    "content": "{\n  \"name\": \"vue-cli\",\n  \"private\": true,\n  \"scripts\": {\n    \"type-check\": \"vue-tsc --noEmit\",\n    \"dev\": \"vue-cli-service serve\",\n    \"build\": \"vue-cli-service build\",\n    \"lint\": \"vue-cli-service lint\"\n  },\n  \"dependencies\": {\n    \"@vue/composition-api\": \"^1.7.1\",\n    \"core-js\": \"^3.32.0\",\n    \"vue\": \"~2.6.14\"\n  },\n  \"devDependencies\": {\n    \"@vue/cli-plugin-babel\": \"^5.0.8\",\n    \"@vue/cli-plugin-typescript\": \"^5.0.8\",\n    \"@vue/cli-service\": \"^5.0.8\",\n    \"typescript\": \"^5.1.6\",\n    \"unplugin-vue2-script-setup\": \"workspace:*\",\n    \"vue-template-compiler\": \"~2.6.14\",\n    \"vue-tsc\": \"^1.8.8\"\n  }\n}\n"
  },
  {
    "path": "examples/vue-cli/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"\">\n  <head>\n    <meta charset=\"utf-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\">\n    <title><%= htmlWebpackPlugin.options.title %></title>\n  </head>\n  <body>\n    <noscript>\n      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>\n    </noscript>\n    <div id=\"app\"></div>\n    <!-- built files will be auto injected -->\n  </body>\n</html>\n"
  },
  {
    "path": "examples/vue-cli/src/App.vue",
    "content": "<script setup lang=\"ts\">\nimport HelloWorld from './components/HelloWorld.vue'\n</script>\n<template>\n  <div id=\"app\">\n    <HelloWorld msg=\"Welcome to Your Vue.js App\" />\n  </div>\n</template>\n<style>\n#app {\n  font-family: Avenir, Helvetica, Arial, sans-serif;\n  -webkit-font-smoothing: antialiased;\n  -moz-osx-font-smoothing: grayscale;\n  text-align: center;\n  color: #2c3e50;\n  margin-top: 60px;\n}\n</style>\n"
  },
  {
    "path": "examples/vue-cli/src/components/HelloWorld.vue",
    "content": "<script setup lang=\"ts\">\ndefineProps<{\n  msg: string\n}>()\n</script>\n<template>\n  <div class=\"hello\">\n    <h1>{{ msg }}</h1>\n    <p>\n      For a guide and recipes on how to configure / customize this project,<br>\n      check out the\n      <a href=\"https://cli.vuejs.org\" target=\"_blank\" rel=\"noopener\">vue-cli documentation</a>.\n    </p>\n    <h3>Installed CLI Plugins</h3>\n    <ul>\n      <li><a href=\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript\" target=\"_blank\" rel=\"noopener\">typescript</a></li>\n    </ul>\n    <h3>Essential Links</h3>\n    <ul>\n      <li><a href=\"https://vuejs.org\" target=\"_blank\" rel=\"noopener\">Core Docs</a></li>\n      <li><a href=\"https://forum.vuejs.org\" target=\"_blank\" rel=\"noopener\">Forum</a></li>\n      <li><a href=\"https://chat.vuejs.org\" target=\"_blank\" rel=\"noopener\">Community Chat</a></li>\n      <li><a href=\"https://twitter.com/vuejs\" target=\"_blank\" rel=\"noopener\">Twitter</a></li>\n      <li><a href=\"https://news.vuejs.org\" target=\"_blank\" rel=\"noopener\">News</a></li>\n    </ul>\n    <h3>Ecosystem</h3>\n    <ul>\n      <li><a href=\"https://router.vuejs.org\" target=\"_blank\" rel=\"noopener\">vue-router</a></li>\n      <li><a href=\"https://vuex.vuejs.org\" target=\"_blank\" rel=\"noopener\">vuex</a></li>\n      <li><a href=\"https://github.com/vuejs/vue-devtools#vue-devtools\" target=\"_blank\" rel=\"noopener\">vue-devtools</a></li>\n      <li><a href=\"https://vue-loader.vuejs.org\" target=\"_blank\" rel=\"noopener\">vue-loader</a></li>\n      <li><a href=\"https://github.com/vuejs/awesome-vue\" target=\"_blank\" rel=\"noopener\">awesome-vue</a></li>\n    </ul>\n  </div>\n</template>\n<style scoped>\nh3 {\n  margin: 40px 0 0;\n}\nul {\n  list-style-type: none;\n  padding: 0;\n}\nli {\n  display: inline-block;\n  margin: 0 10px;\n}\na {\n  color: #42b983;\n}\n</style>\n"
  },
  {
    "path": "examples/vue-cli/src/main.ts",
    "content": "import Vue from 'vue'\nimport VueCompositionAPI, { createApp, h } from '@vue/composition-api'\nimport App from './App.vue'\n\nVue.config.productionTip = false\nVue.use(VueCompositionAPI)\n\nconst app = createApp({\n  render: () => h(App),\n})\n\napp.mount('#app')\n"
  },
  {
    "path": "examples/vue-cli/src/shims-vue.d.ts",
    "content": "/// <reference types=\"unplugin-vue2-script-setup/shims.js\" />\n"
  },
  {
    "path": "examples/vue-cli/tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"esnext\",\n    \"module\": \"esnext\",\n    \"strict\": true,\n    \"jsx\": \"preserve\",\n    \"importHelpers\": true,\n    \"moduleResolution\": \"node\",\n    \"skipLibCheck\": false,\n    \"esModuleInterop\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"sourceMap\": true,\n    \"types\": [\n      \"webpack-env\"\n    ],\n    \"lib\": [\n      \"esnext\",\n      \"dom\",\n      \"dom.iterable\"\n    ]\n  },\n  \"include\": [\n    \"src\"\n  ],\n  \"exclude\": [\n    \"node_modules\"\n  ],\n  \"vueCompilerOptions\": {\n    \"target\": 2\n  }\n}\n"
  },
  {
    "path": "examples/vue-cli/vue.config.cjs",
    "content": "const { defineConfig } = require('@vue/cli-service')\nconst ScriptSetup = require('unplugin-vue2-script-setup/webpack').default\n\nmodule.exports = defineConfig({\n  configureWebpack: {\n    plugins: [\n      ScriptSetup({\n        reactivityTransform: true,\n      }),\n    ],\n  },\n  parallel: false,\n  chainWebpack(config) {\n    // disable type check and let `vue-tsc` handles it\n    config.plugins.delete('fork-ts-checker')\n\n    // disable cache for testing, you should remove this in production\n    config.module.rule('vue').uses.delete('cache-loader')\n    config.module.rule('js').uses.delete('cache-loader')\n    config.module.rule('ts').uses.delete('cache-loader')\n    config.module.rule('tsx').uses.delete('cache-loader')\n  },\n})\n"
  },
  {
    "path": "index.d.ts",
    "content": "export { default } from './dist/index'\n"
  },
  {
    "path": "jest.js",
    "content": "const { transform } = require('./dist/index')\n\nfunction requireVueJest() {\n  const names = ['@vue/vue2-jest', 'vue-jest']\n  for (const name of names) {\n    try {\n      return require(name)\n    }\n    catch (e) {\n      // Try next module\n    }\n  }\n  throw new Error(`Cannot find a Jest transformer for Vue SFC, you should install one of these packages: ${names.join(', ')}`)\n}\n\nmodule.exports = {\n  async process(source, filename, ...args) {\n    const transformed = await transform(source, filename)\n    const code = transformed ? transformed.code : source\n    return requireVueJest().process.call(this, code, filename, ...args)\n  },\n}\n"
  },
  {
    "path": "nuxt.d.ts",
    "content": "export { default } from './dist/nuxt'\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"unplugin-vue2-script-setup\",\n  \"version\": \"0.11.4\",\n  \"packageManager\": \"pnpm@8.6.11\",\n  \"description\": \"Bring <script setup> to Vue 2\",\n  \"author\": \"Anthony Fu <anthonyfu117@hotmail.com>\",\n  \"license\": \"MIT\",\n  \"funding\": \"https://github.com/sponsors/antfu\",\n  \"homepage\": \"https://github.com/unplugin/unplugin-vue2-script-setup#readme\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/unplugin/unplugin-vue2-script-setup.git\"\n  },\n  \"bugs\": {\n    \"url\": \"https://github.com/unplugin/unplugin-vue2-script-setup/issues\"\n  },\n  \"exports\": {\n    \".\": {\n      \"import\": \"./dist/index.mjs\",\n      \"require\": \"./dist/index.js\"\n    },\n    \"./*\": \"./*\",\n    \"./esbuild\": {\n      \"import\": \"./dist/esbuild.mjs\",\n      \"require\": \"./dist/esbuild.js\"\n    },\n    \"./jest\": \"./jest.js\",\n    \"./nuxt\": {\n      \"import\": \"./dist/nuxt.mjs\",\n      \"require\": \"./dist/nuxt.js\"\n    },\n    \"./rollup\": {\n      \"import\": \"./dist/rollup.mjs\",\n      \"require\": \"./dist/rollup.js\"\n    },\n    \"./types\": {\n      \"import\": \"./dist/types.mjs\",\n      \"require\": \"./dist/types.js\"\n    },\n    \"./vite\": {\n      \"import\": \"./dist/vite.mjs\",\n      \"require\": \"./dist/vite.js\"\n    },\n    \"./webpack\": {\n      \"import\": \"./dist/webpack.mjs\",\n      \"require\": \"./dist/webpack.js\"\n    }\n  },\n  \"main\": \"dist/index.js\",\n  \"files\": [\n    \"dist\",\n    \"jest.js\",\n    \"*.d.ts\"\n  ],\n  \"scripts\": {\n    \"build\": \"rimraf dist && rollup -c\",\n    \"dev\": \"rollup -c --watch\",\n    \"lint\": \"eslint .\",\n    \"lint:fix\": \"eslint . --fix\",\n    \"build:examples\": \"pnpm -r --filter=!unplugin-vue2-script-setup run build\",\n    \"play\": \"npm -C playground run dev\",\n    \"prepublishOnly\": \"nr build\",\n    \"release\": \"bumpp --commit --push --tag && pnpm publish\",\n    \"test\": \"vitest\",\n    \"test:update\": \"vitest -u\"\n  },\n  \"peerDependencies\": {\n    \"@vue/composition-api\": \"*\",\n    \"@vue/runtime-dom\": \"^3.2.31\",\n    \"pug\": \"^3.0.2\"\n  },\n  \"peerDependenciesMeta\": {\n    \"pug\": {\n      \"optional\": true\n    }\n  },\n  \"dependencies\": {\n    \"@antfu/utils\": \"^0.7.5\",\n    \"@babel/core\": \"^7.22.9\",\n    \"@babel/generator\": \"^7.22.9\",\n    \"@babel/parser\": \"^7.22.7\",\n    \"@babel/traverse\": \"^7.22.8\",\n    \"@babel/types\": \"^7.22.5\",\n    \"@rollup/pluginutils\": \"^5.0.2\",\n    \"@vue/compiler-core\": \"^3.3.4\",\n    \"@vue/compiler-dom\": \"^3.3.4\",\n    \"@vue/reactivity-transform\": \"^3.3.4\",\n    \"@vue/shared\": \"^3.3.4\",\n    \"defu\": \"^6.1.2\",\n    \"magic-string\": \"^0.30.2\",\n    \"unplugin\": \"^1.4.0\"\n  },\n  \"devDependencies\": {\n    \"@antfu/eslint-config\": \"^0.40.0\",\n    \"@antfu/ni\": \"^0.21.5\",\n    \"@rollup/plugin-alias\": \"^5.0.0\",\n    \"@rollup/plugin-commonjs\": \"^25.0.3\",\n    \"@rollup/plugin-json\": \"^6.0.0\",\n    \"@rollup/plugin-node-resolve\": \"^15.1.0\",\n    \"@types/babel__core\": \"^7.20.1\",\n    \"@types/estree\": \"^1.0.1\",\n    \"@types/node\": \"^18.17.1\",\n    \"@types/pug\": \"^2.0.6\",\n    \"@types/ws\": \"^8.5.5\",\n    \"@vue/composition-api\": \"^1.7.1\",\n    \"@vue/runtime-dom\": \"^3.3.4\",\n    \"bumpp\": \"^9.1.1\",\n    \"esbuild\": \"^0.18.17\",\n    \"eslint\": \"^8.46.0\",\n    \"fast-glob\": \"^3.3.1\",\n    \"pug\": \"^3.0.2\",\n    \"rimraf\": \"^5.0.1\",\n    \"rollup\": \"^3.27.0\",\n    \"rollup-plugin-dts\": \"^5.3.1\",\n    \"rollup-plugin-esbuild\": \"^5.0.0\",\n    \"rollup-plugin-typescript2\": \"^0.35.0\",\n    \"typescript\": \"^5.1.6\",\n    \"vite\": \"^4.4.8\",\n    \"vitest\": \"^0.33.0\",\n    \"webpack\": \"^5.88.2\"\n  },\n  \"pnpm\": {\n    \"overrides\": {\n      \"unplugin-vue2-script-setup\": \"workspace:*\"\n    }\n  }\n}\n"
  },
  {
    "path": "playground/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <link rel=\"icon\" href=\"/favicon.ico\" />\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  <title>Vite App</title>\n</head>\n<body>\n  <div id=\"app\"></div>\n  <script type=\"module\" src=\"./src/main.ts\"></script>\n</body>\n</html>\n"
  },
  {
    "path": "playground/package.json",
    "content": "{\n  \"private\": true,\n  \"scripts\": {\n    \"dev\": \"vite --open\",\n    \"build\": \"vite build\"\n  },\n  \"dependencies\": {\n    \"@vue/composition-api\": \"^1.7.1\",\n    \"vue\": \"^2.6.14\"\n  },\n  \"devDependencies\": {\n    \"vite\": \"^4.4.8\",\n    \"vite-plugin-inspect\": \"^0.7.35\",\n    \"vite-plugin-vue2\": \"^2.0.3\",\n    \"vue-template-compiler\": \"~2.6.14\"\n  }\n}\n"
  },
  {
    "path": "playground/src/App.vue",
    "content": "<script setup lang=\"ts\">\nimport { defineAsyncComponent } from '@vue/composition-api'\nimport ButtonTest from './ButtonTest.vue';\nimport HelloWorld from './HelloWorld.vue'\n\nconst AsyncComponent = defineAsyncComponent(() => import('./Async.vue'))\n\nfunction onUpdate(e: any) {\n  // eslint-disable-next-line no-console\n  console.log(e)\n}\n</script>\n<template>\n  <div>\n    <ButtonTest />\n\n    <HelloWorld name=\"Vue 2\" @update=\"onUpdate\" />\n\n    <AsyncComponent />\n  </div>\n</template>\n"
  },
  {
    "path": "playground/src/Async.vue",
    "content": "<template>\n  <div>Async Component</div>\n</template>\n"
  },
  {
    "path": "playground/src/Bar.vue",
    "content": "<template>\n  <div>Bar</div>\n</template>\n"
  },
  {
    "path": "playground/src/ButtonTest.vue",
    "content": "<script setup lang=\"ts\">\nimport Button from './Foo.vue';\nimport button from './Foo.vue';\n</script>\n\n<template>\n  <div>\n    <button>{{ Button }}</button>\n    <Button>{{ button }}</Button>\n  </div>\n</template>\n"
  },
  {
    "path": "playground/src/Foo.vue",
    "content": "<script setup lang=\"ts\">\n\n</script>\n<template>\n  <div>\n    Button Component: <slot></slot>\n  </div>\n</template>\n"
  },
  {
    "path": "playground/src/HelloWorld.vue",
    "content": "<script lang=\"ts\">\n/* eslint-disable import/first */\nexport default {\n  name: 'App',\n}\n</script>\n<script setup lang=\"ts\">\nimport { watch } from '@vue/composition-api'\nimport Foo from './Foo.vue'\nimport Bar from './Bar.vue'\n\nwithDefaults(defineProps<{ msg: string; name: string | number }>(), { msg: 'Hello' })\nconst emit = defineEmits<{\n  (event: 'update', value: number): void\n}>()\n\nlet count = $ref(0)\n// eslint-disable-next-line prefer-const\nlet doubled = $computed(() => count * 2)\n\nfunction inc() {\n  count += 1\n}\nfunction dec() {\n  count -= 1\n}\n\nconst decText = '<b>Dec</b>'\n\nwatch(count, value => emit('update', value))\n</script>\n<template>\n  <div>\n    <h3>{{ msg }}, {{ name }}</h3>\n    <button @click=\"inc\">\n      Inc\n    </button>\n    <div>{{ count }} x 2 = {{ doubled }}</div>\n    <button @click=\"dec()\" v-html=\"decText\" />\n    <component :is=\"count > 2 ? Foo : Bar\" />\n  </div>\n</template>\n"
  },
  {
    "path": "playground/src/main.ts",
    "content": "import Vue from 'vue'\nimport VueCompositionAPI, { createApp, h } from '@vue/composition-api'\nimport App from './App.vue'\n\nVue.use(VueCompositionAPI)\n\nconst app = createApp({ render: () => h(App) })\n\napp.mount('#app')\n"
  },
  {
    "path": "playground/src/shims-vue.d.ts",
    "content": "/// <reference types=\"unplugin-vue2-script-setup/shims.js\" />\n/// <reference types=\"unplugin-vue2-script-setup/ref-macros.js\" />\n"
  },
  {
    "path": "playground/tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"esnext\",\n    \"module\": \"esnext\",\n    \"strict\": true,\n    \"jsx\": \"preserve\",\n    \"importHelpers\": true,\n    \"moduleResolution\": \"node\",\n    \"skipLibCheck\": false,\n    \"esModuleInterop\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"sourceMap\": true,\n    \"types\": [\n      \"webpack-env\"\n    ],\n    \"lib\": [\n      \"esnext\",\n      \"dom\",\n      \"dom.iterable\"\n    ]\n  },\n  \"include\": [\n    \"src\"\n  ],\n  \"exclude\": [\n    \"node_modules\"\n  ],\n  \"vueCompilerOptions\": {\n    \"experimentalCompatMode\": 2\n  }\n}\n"
  },
  {
    "path": "playground/vite.config.ts",
    "content": "import { defineConfig } from 'vite'\nimport { createVuePlugin as Vue2 } from 'vite-plugin-vue2'\nimport Inspect from 'vite-plugin-inspect'\nimport { unplugin } from '../src'\n\nconst ScriptSetup = unplugin.vite\n\nexport default defineConfig({\n  plugins: [\n    Vue2(),\n    Inspect(),\n    ScriptSetup({\n      reactivityTransform: true,\n    }),\n  ],\n})\n"
  },
  {
    "path": "pnpm-workspace.yaml",
    "content": "- packages\n  - playground\n  - examples/*\n"
  },
  {
    "path": "ref-macros.d.ts",
    "content": "import type {\n  ComputedRef,\n  Ref,\n  ShallowUnwrapRef,\n  UnwrapRef,\n  WritableComputedOptions,\n  WritableComputedRef,\n} from '@vue/composition-api'\n\ndeclare const RefMarker: unique symbol\n  type RefValue<T> = T & { [RefMarker]?: any }\n\ndeclare const ComputedRefMarker: unique symbol\n  type ComputedRefValue<T> = T & { [ComputedRefMarker]?: any }\n\ndeclare const WritableComputedRefMarker: unique symbol\n  type WritableComputedRefValue<T> = T & { [WritableComputedRefMarker]?: any }\n\n  type ToRawRefs<T extends object> = {\n    [K in keyof T]: T[K] extends ComputedRefValue<infer V>\n      ? ComputedRefValue<V>\n      : T[K] extends WritableComputedRefValue<infer V>\n        ? WritableComputedRef<V>\n        : T[K] extends RefValue<infer V>\n          ? Ref<V>\n          : T[K] extends object\n            ? T[K] extends\n            | Function\n            | Map<any, any>\n            | Set<any>\n            | WeakMap<any, any>\n            | WeakSet<any>\n              ? T[K]\n              : ToRawRefs<T[K]>\n            : T[K];\n  }\n\n/**\n   * Vue ref transform macro for binding refs as reactive variables.\n   */\ndeclare function _$<T>(arg: ComputedRef<T>): ComputedRefValue<T>\ndeclare function _$<T>(\n  arg: WritableComputedRef<T>\n): WritableComputedRefValue<T>\ndeclare function _$<T>(arg: Ref<T>): RefValue<T>\ndeclare function _$<T extends object>(arg?: T): ShallowUnwrapRef<T>\n\n/**\n   * Vue ref transform macro for accessing underlying refs of reactive varaibles.\n   */\ndeclare function _$$<T>(value: T): ComputedRef<T>\ndeclare function _$$<T>(\n  value: WritableComputedRefValue<T>\n): WritableComputedRef<T>\ndeclare function _$$<T>(value: RefValue<T>): Ref<T>\ndeclare function _$$<T extends object>(arg: T): ToRawRefs<T>\n\ndeclare function _$ref<T>(arg?: T | Ref<T>): RefValue<UnwrapRef<T>>\n\ndeclare function _$shallowRef<T>(arg?: T): RefValue<T>\n\ndeclare function _$computed<T>(\n  getter: () => T,\n  // debuggerOptions?: DebuggerOptions\n): ComputedRefValue<T>\ndeclare function _$computed<T>(\n  options: WritableComputedOptions<T>,\n  // debuggerOptions?: DebuggerOptions\n): WritableComputedRefValue<T>\n\ndeclare global {\n  const $: typeof _$\n  const $$: typeof _$$\n  const $ref: typeof _$ref\n  const $shallowRef: typeof _$shallowRef\n  const $computed: typeof _$computed\n}\n"
  },
  {
    "path": "rollup.config.mjs",
    "content": "// @ts-check\nimport * as fs from 'node:fs'\nimport ts from 'rollup-plugin-esbuild'\nimport dts from 'rollup-plugin-dts'\nimport resolve from '@rollup/plugin-node-resolve'\nimport commonjs from '@rollup/plugin-commonjs'\nimport json from '@rollup/plugin-json'\nimport alias from '@rollup/plugin-alias'\n\n/** @type {import('./package.json')} */\nconst pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))\n\nconst entries = {\n  index: 'src/index.ts',\n  webpack: 'src/webpack.ts',\n  vite: 'src/vite.ts',\n  rollup: 'src/rollup.ts',\n  esbuild: 'src/esbuild.ts',\n  nuxt: 'src/nuxt.ts',\n  types: 'src/types.ts',\n}\n\nconst external = [\n  ...Object.keys(pkg.dependencies),\n  ...Object.keys(pkg.peerDependencies),\n  'esbuild',\n  'rollup',\n  'vite',\n  'webpack',\n  '@nuxt/kit',\n]\n\n\n/** @type {import('rollup').RollupOptions[]} */\nexport default [\n  {\n    input: entries,\n    external,\n    plugins: [\n      alias({\n        entries: [\n          { find: /^node:(.+)$/, replacement: '$1' },\n        ],\n      }),\n      resolve({\n        preferBuiltins: true,\n      }),\n      json(),\n      commonjs(),\n      ts(),\n    ],\n    onwarn({ code, message }) {\n      if(code === 'EMPTY_BUNDLE') return\n      console.error(message)\n    },\n    output:[\n      {\n        dir: 'dist',\n        format: 'esm',\n        sourcemap: 'inline',\n        entryFileNames: \"[name].mjs\",\n      },\n      {\n        dir: 'dist',\n        format: 'cjs',\n        exports: 'named',\n        sourcemap: 'inline',\n        entryFileNames: \"[name].js\",\n      },\n    ]\n  },\n  {\n    input: entries,\n    external,\n    plugins: [\n      dts({ respectExternal: true }),\n    ],\n    output: [\n      {\n        dir: 'dist',\n        entryFileNames: \"[name].d.mts\",\n      },\n      {\n        dir: 'dist',\n        entryFileNames: \"[name].d.ts\",\n      },\n    ],\n  },\n]\n"
  },
  {
    "path": "rollup.d.ts",
    "content": "export { default } from './dist/rollup'\n"
  },
  {
    "path": "scripts/postbuild.ts",
    "content": "import { basename, resolve } from 'node:path'\nimport { promises as fs } from 'node:fs'\nimport fg from 'fast-glob'\n\nasync function run() {\n  // fix cjs exports\n  const files = await fg('*.js', {\n    ignore: ['chunk-*'],\n    absolute: true,\n    cwd: resolve(__dirname, '../dist'),\n  })\n  for (const file of files) {\n    console.log('[postbuild]', basename(file))\n    const name = basename(file, '.js')\n    let code = await fs.readFile(file, 'utf8')\n    code = code.replace('exports.default =', 'module.exports =')\n    code += 'exports.default = module.exports;'\n    await fs.writeFile(file, code)\n    await fs.writeFile(`${name}.d.ts`, `import './shims'\\nexport { default } from './dist/${name}'\\n`)\n  }\n}\n\nrun()\n"
  },
  {
    "path": "shims.d.ts",
    "content": "// workaround for Volar to infer the ref type in <template>\n// https://github.com/johnsoncodehk/volar/issues/404\ndeclare module '@vue/runtime-dom' {\n  export * from '@vue/runtime-dom/dist/runtime-dom'\n  export { defineComponent, PropType, ObjectDirective, FunctionDirective } from '@vue/composition-api'\n}\n"
  },
  {
    "path": "src/core/babel.ts",
    "content": "import * as babel from '@babel/core'\nimport { parse, parseExpression } from '@babel/parser'\nimport g from '@babel/generator'\nimport * as babel_traverse from '@babel/traverse'\n\nexport const t: typeof babel['types'] = ((babel as any).default || babel).types\nexport const generate: typeof g = ((g as any).default || g)\nexport const traverse = ((babel_traverse as any)?.default?.default as null) ?? babel_traverse?.default ?? babel_traverse\nexport { parseExpression, parse }\n"
  },
  {
    "path": "src/core/identifiers.ts",
    "content": "import type {\n  Expression,\n  File,\n  PrivateName,\n  SpreadElement,\n  Statement,\n  TSType,\n} from '@babel/types'\nimport type { ParseResult } from '@babel/parser'\nimport { t, traverse } from './babel'\n\nexport function getIdentifierDeclarations(nodes: Statement[]) {\n  let result!: Set<string>\n  let programScopeUid: number\n  traverse(t.file(t.program(nodes)), {\n    Program(path) {\n      result = new Set(Object.keys(path.scope.bindings))\n      programScopeUid = (path.scope as any).uid\n    },\n    // FIXME: babel bug, temporary add TSEnumDeclaration and TSModuleDeclaration logic\n    TSEnumDeclaration(path) {\n      if ((path.scope as any).uid === programScopeUid)\n        result.add(path.node.id.name)\n    },\n    TSModuleDeclaration(path) {\n      if ((path.scope as any).uid === programScopeUid) {\n        const id = path.node.id\n        if (id.type === 'Identifier')\n          result.add(id.name)\n      }\n    },\n  })\n  return Array.from(result)\n}\n\n/**\n * @deprecated use `getFileGlobals` instead\n */\nexport function getIdentifierUsages(node?: Expression | TSType | SpreadElement | PrivateName | Statement | null, identifiers = new Set<string>()) {\n  if (!node)\n    return identifiers\n\n  if (node.type === 'BlockStatement') {\n    node.body.forEach(child => getIdentifierUsages(child, identifiers))\n  }\n  else if (node.type === 'ExpressionStatement') {\n    getIdentifierUsages(node.expression, identifiers)\n  }\n  else if (node.type === 'Identifier') {\n    identifiers.add(node.name)\n  }\n  else if (node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression') {\n    getIdentifierUsages(node.object, identifiers)\n    if (node.computed)\n      getIdentifierUsages(node.property, identifiers)\n  }\n  else if (node.type === 'CallExpression' || node.type === 'OptionalCallExpression') {\n    getIdentifierUsages(node.callee as Expression, identifiers)\n    node.arguments.forEach(arg => getIdentifierUsages(arg as Expression, identifiers))\n  }\n  else if (node.type === 'BinaryExpression' || node.type === 'LogicalExpression') {\n    getIdentifierUsages(node.left, identifiers)\n    getIdentifierUsages(node.right, identifiers)\n  }\n  else if (node.type === 'UnaryExpression') {\n    getIdentifierUsages(node.argument, identifiers)\n  }\n  else if (node.type === 'ForOfStatement' || node.type === 'ForInStatement') {\n    getIdentifierUsages(node.right, identifiers)\n  }\n  else if (node.type === 'ConditionalExpression') {\n    getIdentifierUsages(node.test, identifiers)\n    getIdentifierUsages(node.consequent, identifiers)\n    getIdentifierUsages(node.alternate, identifiers)\n  }\n  else if (node.type === 'ObjectExpression') {\n    node.properties.forEach((prop) => {\n      if (prop.type === 'ObjectProperty') {\n        if (prop.computed)\n          getIdentifierUsages(prop.key, identifiers)\n        getIdentifierUsages(prop.value as Expression, identifiers)\n      }\n      else if (prop.type === 'SpreadElement') {\n        getIdentifierUsages(prop, identifiers)\n      }\n    })\n  }\n  else if (node.type === 'ArrayExpression') {\n    node.elements.forEach(element => getIdentifierUsages(element, identifiers))\n  }\n  else if (node.type === 'SpreadElement' || node.type === 'ReturnStatement') {\n    getIdentifierUsages(node.argument, identifiers)\n  }\n  else if (node.type === 'NewExpression') {\n    getIdentifierUsages(node.callee as Expression, identifiers)\n    node.arguments.forEach(arg => getIdentifierUsages(arg as Expression, identifiers))\n  }\n  else if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {\n    getIdentifierUsages(node.body, identifiers)\n  }\n  else if (node.type === 'TemplateLiteral') {\n    node.expressions.forEach(expr => getIdentifierUsages(expr, identifiers))\n  }\n  // else {\n  //   console.log(node)\n  // }\n  return identifiers\n}\n\nexport function getFileGlobals(result: ParseResult<File>) {\n  let globals!: Set<string>\n  let programScopeUid: number\n  traverse(result, {\n    Program(path) {\n      globals = new Set(Object.keys((path.scope as any).globals))\n      programScopeUid = (path.scope as any).uid\n    },\n    // FIXME: babel bug, temporary add TSEnumDeclaration and TSModuleDeclaration logic\n    TSEnumDeclaration(path) {\n      if ((path.scope as any).uid === programScopeUid)\n        globals.delete(path.node.id.name)\n    },\n    TSModuleDeclaration(path) {\n      if ((path.scope as any).uid === programScopeUid) {\n        const id = path.node.id\n        if (id.type === 'Identifier')\n          globals.delete(id.name)\n      }\n    },\n  })\n  return Array.from(globals)\n}\n"
  },
  {
    "path": "src/core/index.ts",
    "content": "export * from './transform'\nexport * from './transformScriptSetup'\nexport * from '../types'\n"
  },
  {
    "path": "src/core/macros.ts",
    "content": "// modified from https://github.com/vuejs/vue-next/blob/main/packages/compiler-sfc/src/compileScript.ts\n\nimport type {\n  CallExpression,\n  Node,\n  ObjectExpression,\n  ObjectProperty,\n  Statement,\n  TSFunctionType,\n  TSInterfaceBody,\n  TSType,\n  TSTypeLiteral,\n} from '@babel/types'\nimport { parseExpression, t } from './babel'\n\n// Special compiler macros\nconst DEFINE_PROPS = 'defineProps'\nconst DEFINE_EMITS = 'defineEmits'\nconst DEFINE_EXPOSE = 'defineExpose'\nconst WITH_DEFAULTS = 'withDefaults'\nconst DEFINE_SLOTS = 'defineSlots'\n\nexport interface PropTypeData {\n  key: string\n  type: string[] | string\n  required: boolean\n}\n\nexport function applyMacros(nodes: Statement[]) {\n  let hasDefinePropsCall = false\n  let hasDefineEmitCall = false\n  let hasDefineSlotsCall = false\n  let propsRuntimeDecl: Node | undefined\n  let propsRuntimeDefaults: Node | undefined\n  let propsTypeDecl: TSTypeLiteral | TSInterfaceBody | undefined\n  let propsTypeDeclRaw: Node | undefined\n  let emitsRuntimeDecl: Node | undefined\n  let emitsTypeDecl:\n  | TSFunctionType\n  | TSTypeLiteral\n  | TSInterfaceBody\n  | undefined\n  let emitsTypeDeclRaw: Node | undefined\n  let exposeDecl: CallExpression['arguments'][number] | undefined\n\n  // props/emits declared via types\n  const typeDeclaredProps: Record<string, PropTypeData> = {}\n  // record declared types for runtime props type generation\n  const declaredTypes: Record<string, string[]> = {}\n\n  function error(\n    msg: string,\n\n    _node: Node,\n  ): never {\n    throw new Error(msg)\n  }\n\n  function processDefineProps(node: Node): boolean {\n    if (!isCallOf(node, DEFINE_PROPS))\n      return false\n\n    if (hasDefinePropsCall)\n      error(`duplicate ${DEFINE_PROPS}() call`, node)\n\n    hasDefinePropsCall = true\n\n    propsRuntimeDecl = node.arguments[0]\n\n    // call has type parameters - infer runtime types from it\n    if (node.typeParameters) {\n      if (propsRuntimeDecl) {\n        error(\n          `${DEFINE_PROPS}() cannot accept both type and non-type arguments `\n            + 'at the same time. Use one or the other.',\n          node,\n        )\n      }\n\n      propsTypeDeclRaw = node.typeParameters.params[0]\n      propsTypeDecl = resolveQualifiedType(\n        propsTypeDeclRaw,\n        node => node.type === 'TSTypeLiteral',\n      ) as TSTypeLiteral | TSInterfaceBody | undefined\n\n      if (!propsTypeDecl) {\n        error(\n          `type argument passed to ${DEFINE_PROPS}() must be a literal type, `\n            + 'or a reference to an interface or literal type.',\n          propsTypeDeclRaw,\n        )\n      }\n    }\n\n    return true\n  }\n\n  function processWithDefaults(node: Node): boolean {\n    if (!isCallOf(node, WITH_DEFAULTS))\n      return false\n\n    if (processDefineProps(node.arguments[0])) {\n      if (propsRuntimeDecl) {\n        error(\n          `${WITH_DEFAULTS} can only be used with type-based `\n            + `${DEFINE_PROPS} declaration.`,\n          node,\n        )\n      }\n      propsRuntimeDefaults = node.arguments[1]\n    }\n    else {\n      error(\n        `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`,\n        node.arguments[0] || node,\n      )\n    }\n    return true\n  }\n\n  function processDefineEmits(node: Node): boolean {\n    if (!isCallOf(node, DEFINE_EMITS))\n      return false\n\n    if (hasDefineEmitCall)\n      error(`duplicate ${DEFINE_EMITS}() call`, node)\n\n    hasDefineEmitCall = true\n    emitsRuntimeDecl = node.arguments[0]\n    if (node.typeParameters) {\n      if (emitsRuntimeDecl) {\n        error(\n          `${DEFINE_EMITS}() cannot accept both type and non-type arguments `\n            + 'at the same time. Use one or the other.',\n          node,\n        )\n      }\n\n      emitsTypeDeclRaw = node.typeParameters.params[0]\n      emitsTypeDecl = resolveQualifiedType(\n        emitsTypeDeclRaw,\n        node => node.type === 'TSFunctionType' || node.type === 'TSTypeLiteral',\n      ) as TSFunctionType | TSTypeLiteral | TSInterfaceBody | undefined\n\n      if (!emitsTypeDecl) {\n        error(\n          `type argument passed to ${DEFINE_EMITS}() must be a function type, `\n            + 'a literal type with call signatures, or a reference to the above types.',\n          emitsTypeDeclRaw,\n        )\n      }\n    }\n    return true\n  }\n\n  function resolveQualifiedType(\n    node: Node,\n    qualifier: (node: Node) => boolean,\n  ) {\n    if (qualifier(node))\n      return node\n\n    if (\n      node.type === 'TSTypeReference'\n      && node.typeName.type === 'Identifier'\n    ) {\n      const refName = node.typeName.name\n      const isQualifiedType = (node: Node): Node | undefined => {\n        if (\n          node.type === 'TSInterfaceDeclaration'\n          && node.id.name === refName\n        )\n          return node.body\n\n        else if (\n          node.type === 'TSTypeAliasDeclaration'\n          && node.id.name === refName\n          && qualifier(node.typeAnnotation)\n        )\n          return node.typeAnnotation\n\n        else if (node.type === 'ExportNamedDeclaration' && node.declaration)\n          return isQualifiedType(node.declaration)\n      }\n\n      for (const node of nodes) {\n        const qualified = isQualifiedType(node)\n        if (qualified)\n          return qualified\n      }\n    }\n  }\n\n  function processDefineExpose(node: Node): boolean {\n    if (!isCallOf(node, DEFINE_EXPOSE))\n      return false\n\n    if (exposeDecl)\n      error(`duplicate ${DEFINE_EXPOSE}() call`, node)\n\n    if (node.arguments.length !== 1)\n      error(`${DEFINE_EXPOSE}() requires one argument`, node)\n\n    exposeDecl = node.arguments[0]\n\n    return true\n  }\n\n  function processDefineSlots(\n    node: Node,\n  ): boolean {\n    if (!isCallOf(node, DEFINE_SLOTS))\n      return false\n\n    if (hasDefineSlotsCall)\n      error(`duplicate ${DEFINE_SLOTS}() call`, node)\n\n    hasDefineSlotsCall = true\n\n    if (node.arguments.length > 0)\n      error(`${DEFINE_SLOTS}() cannot accept arguments`, node)\n\n    return true\n  }\n\n  function genRuntimeProps(props: Record<string, PropTypeData>) {\n    const keys = Object.keys(props)\n    if (!keys.length)\n      return undefined\n\n    // check defaults. If the default object is an object literal with only\n    // static properties, we can directly generate more optimzied default\n    // decalrations. Otherwise we will have to fallback to runtime merging.\n    const hasStaticDefaults = propsRuntimeDefaults\n      && propsRuntimeDefaults.type === 'ObjectExpression'\n      && propsRuntimeDefaults.properties.every(\n        node => node.type === 'ObjectProperty' && !node.computed,\n      )\n\n    return t.objectExpression(\n      Object.entries(props).map(([key, value]) => {\n        const prop = hasStaticDefaults\n          ? (propsRuntimeDefaults as ObjectExpression).properties.find((node: any) => node.key.name === key) as ObjectProperty\n          : undefined\n\n        if (prop)\n          value.required = false\n\n        const entries = Object.entries(value).map(([key, value]) => key === 'type'\n          ? t.objectProperty(t.identifier(key), typeof value === 'string' ? t.identifier(value) : t.arrayExpression(value.map((i: any) => t.identifier(i))) as any)\n          : t.objectProperty(t.identifier(key), parseExpression(JSON.stringify(value)) as any),\n        )\n\n        if (prop)\n          entries.push(t.objectProperty(t.identifier('default'), prop.value as any))\n\n        return t.objectProperty(\n          t.identifier(key),\n          t.objectExpression(entries),\n        )\n      }),\n    )\n  }\n\n  function getProps() {\n    if (propsRuntimeDecl)\n      return propsRuntimeDecl\n\n    if (propsTypeDecl) {\n      extractRuntimeProps(propsTypeDecl, typeDeclaredProps, declaredTypes)\n      return genRuntimeProps(typeDeclaredProps)\n    }\n  }\n\n  function throwIfAwait(node: Node) {\n    if (node.type === 'AwaitExpression')\n      error('top-level await is not supported in Vue 2', node)\n  }\n\n  nodes = nodes\n    .map((raw: Node) => {\n      let node = raw\n      if (raw.type === 'ExpressionStatement')\n        node = raw.expression\n\n      if (node.type === 'VariableDeclaration' && !node.declare) {\n        const total = node.declarations.length\n        for (let i = 0; i < total; i++) {\n          const decl = node.declarations[i]\n          if (decl.init) {\n            if (processDefineEmits(decl.init))\n              decl.init = t.memberExpression(t.identifier('__ctx'), t.identifier('emit'))\n            else if (processDefineSlots(decl.init))\n              decl.init = t.memberExpression(t.identifier('__ctx'), t.identifier('slots'))\n            else if (processDefineProps(decl.init) || processWithDefaults(decl.init))\n              decl.init = t.identifier('__props') as any\n            else\n              throwIfAwait(decl.init)\n          }\n        }\n      }\n\n      if (processWithDefaults(node) || processDefineEmits(node) || processDefineProps(node) || processDefineExpose(node) || processDefineSlots(node))\n        return null\n\n      throwIfAwait(node)\n\n      return raw\n    })\n    .filter(Boolean) as Statement[]\n\n  return {\n    nodes,\n    props: getProps(),\n    expose: exposeDecl,\n  }\n}\n\nfunction isCallOf(\n  node: Node | null | undefined,\n  test: string | ((id: string) => boolean),\n): node is CallExpression {\n  return !!(\n    node\n    && node.type === 'CallExpression'\n    && node.callee.type === 'Identifier'\n    && (typeof test === 'string'\n      ? node.callee.name === test\n      : test(node.callee.name))\n  )\n}\n\nfunction extractRuntimeProps(\n  node: TSTypeLiteral | TSInterfaceBody,\n  props: Record<string, PropTypeData>,\n  declaredTypes: Record<string, string[]>,\n) {\n  const members = node.type === 'TSTypeLiteral' ? node.members : node.body\n  for (const m of members) {\n    if (\n      (m.type === 'TSPropertySignature' || m.type === 'TSMethodSignature')\n      && m.key.type === 'Identifier'\n    ) {\n      let type: string[] | undefined\n      if (m.type === 'TSMethodSignature') {\n        type = ['Function']\n      }\n      else if (m.typeAnnotation) {\n        type = inferRuntimeType(\n          m.typeAnnotation.typeAnnotation,\n          declaredTypes,\n        )\n      }\n      props[m.key.name] = {\n        key: m.key.name,\n        required: !m.optional,\n        type: type?.length === 1 ? type[0] : type || 'null',\n      }\n    }\n  }\n}\n\nfunction inferRuntimeType(\n  node: TSType,\n  declaredTypes: Record<string, string[]>,\n): string[] {\n  switch (node.type) {\n    case 'TSStringKeyword':\n      return ['String']\n    case 'TSNumberKeyword':\n      return ['Number']\n    case 'TSBooleanKeyword':\n      return ['Boolean']\n    case 'TSObjectKeyword':\n      return ['Object']\n    case 'TSTypeLiteral':\n      // TODO (nice to have) generate runtime property validation\n      return ['Object']\n    case 'TSFunctionType':\n      return ['Function']\n    case 'TSArrayType':\n    case 'TSTupleType':\n      // TODO (nice to have) generate runtime element type/length checks\n      return ['Array']\n\n    case 'TSLiteralType':\n      switch (node.literal.type) {\n        case 'StringLiteral':\n          return ['String']\n        case 'BooleanLiteral':\n          return ['Boolean']\n        case 'NumericLiteral':\n        case 'BigIntLiteral':\n          return ['Number']\n        default:\n          return ['null']\n      }\n\n    case 'TSTypeReference':\n      if (node.typeName.type === 'Identifier') {\n        if (declaredTypes[node.typeName.name])\n          return declaredTypes[node.typeName.name]\n\n        switch (node.typeName.name) {\n          case 'Array':\n          case 'Function':\n          case 'Object':\n          case 'Set':\n          case 'Map':\n          case 'WeakSet':\n          case 'WeakMap':\n            return [node.typeName.name]\n          case 'Record':\n          case 'Partial':\n          case 'Readonly':\n          case 'Pick':\n          case 'Omit':\n          case 'Exclude':\n          case 'Extract':\n          case 'Required':\n          case 'InstanceType':\n            return ['Object']\n        }\n      }\n      return ['null']\n\n    case 'TSParenthesizedType':\n      return inferRuntimeType(node.typeAnnotation, declaredTypes)\n    case 'TSUnionType':\n      return [\n        ...new Set(\n          [].concat(\n            ...(node.types.map(t => inferRuntimeType(t, declaredTypes)) as any),\n          ),\n        ),\n      ]\n    case 'TSIntersectionType':\n      return ['Object']\n\n    default:\n      return ['null'] // no runtime check\n  }\n}\n"
  },
  {
    "path": "src/core/options.ts",
    "content": "import type { ResolvedOptions, ScriptSetupTransformOptions } from '../types'\n\nexport function resolveOptions(options: ScriptSetupTransformOptions = {}): ResolvedOptions {\n  return Object.assign(\n    {},\n    {\n      sourceMap: true,\n      reactivityTransform: false,\n      importHelpersFrom: '@vue/composition-api',\n      astTransforms: {},\n    },\n    options,\n  )\n}\n"
  },
  {
    "path": "src/core/parseSFC.ts",
    "content": "/* eslint-disable one-var */\n/* eslint-disable @typescript-eslint/no-namespace */\nimport { notNullish, partition } from '@antfu/utils'\nimport type { Program } from '@babel/types'\nimport type { ParserPlugin } from '@babel/parser'\nimport type {\n  AttributeNode,\n  DirectiveNode,\n  ExpressionNode,\n  PlainElementNode,\n  RootNode,\n  TemplateChildNode,\n} from '@vue/compiler-core'\nimport { baseParse } from '@vue/compiler-core'\nimport { parserOptions } from '@vue/compiler-dom'\nimport { camelize } from '@vue/shared'\nimport type {\n  ParsedSFC,\n  ScriptSetupTransformOptions,\n  ScriptTagMeta,\n} from '../types'\nimport { getFileGlobals } from './identifiers'\nimport { parse } from './babel'\nimport { exhaustiveCheckReturnUndefined, pascalize } from './utils'\n\nnamespace NodeTypes {\n  export const ROOT = 0,\n    ELEMENT = 1,\n    TEXT = 2,\n    COMMENT = 3,\n    SIMPLE_EXPRESSION = 4,\n    INTERPOLATION = 5,\n    ATTRIBUTE = 6,\n    DIRECTIVE = 7,\n    COMPOUND_EXPRESSION = 8,\n    IF = 9,\n    IF_BRANCH = 10,\n    FOR = 11,\n    TEXT_CALL = 12,\n    VNODE_CALL = 13,\n    JS_CALL_EXPRESSION = 14,\n    JS_OBJECT_EXPRESSION = 15,\n    JS_PROPERTY = 16,\n    JS_ARRAY_EXPRESSION = 17,\n    JS_FUNCTION_EXPRESSION = 18,\n    JS_CONDITIONAL_EXPRESSION = 19,\n    JS_CACHE_EXPRESSION = 20,\n    JS_BLOCK_STATEMENT = 21,\n    JS_TEMPLATE_LITERAL = 22,\n    JS_IF_STATEMENT = 23,\n    JS_ASSIGNMENT_EXPRESSION = 24,\n    JS_SEQUENCE_EXPRESSION = 25,\n    JS_RETURN_STATEMENT = 26\n}\n\nnamespace ElementTypes {\n  export const ELEMENT = 0,\n    COMPONENT = 1,\n    SLOT = 2,\n    TEMPLATE = 3\n}\n\nconst BUILD_IN_DIRECTIVES = new Set([\n  'if',\n  'else',\n  'else-if',\n  'for',\n  'once',\n  'model',\n  'on',\n  'bind',\n  'slot',\n  'slot-scope',\n  'key',\n  'ref',\n  'text',\n  'html',\n  'show',\n  'pre',\n  'cloak',\n  // 'el',\n  // 'ref',\n])\n\nfunction getComponents(node: TemplateChildNode): string[] {\n  const current\n    = node.type === NodeTypes.ELEMENT && node.tagType === ElementTypes.COMPONENT\n      ? [node.tag]\n      : node.type === NodeTypes.ELEMENT && node.tagType === ElementTypes.ELEMENT\n        ? [node.tag]\n        : []\n\n  const children\n    = node.type === NodeTypes.IF\n      ? node.branches\n      : node.type === NodeTypes.ELEMENT\n        || node.type === NodeTypes.IF_BRANCH\n        || node.type === NodeTypes.FOR\n        ? node.children\n        : node.type === NodeTypes.TEXT\n        || node.type === NodeTypes.COMMENT\n        || node.type === NodeTypes.COMPOUND_EXPRESSION\n        || node.type === NodeTypes.TEXT_CALL\n        || node.type === NodeTypes.INTERPOLATION\n          ? []\n          : exhaustiveCheckReturnUndefined(node) ?? []\n\n  return [...current, ...children.flatMap(getComponents)]\n}\n\nfunction getDirectiveNames(node: TemplateChildNode): string[] {\n  if (node.type === NodeTypes.ELEMENT) {\n    const directives = node.props.flatMap(x =>\n      x.type === NodeTypes.DIRECTIVE ? [x.name] : [],\n    )\n    return [...directives, ...node.children.flatMap(getDirectiveNames)]\n  }\n  else if (node.type === NodeTypes.IF) {\n    return node.branches.flatMap(getDirectiveNames)\n  }\n  else if (node.type === NodeTypes.IF_BRANCH || node.type === NodeTypes.FOR) {\n    return node.children.flatMap(getDirectiveNames)\n  }\n  else if (\n    node.type === NodeTypes.INTERPOLATION\n    || node.type === NodeTypes.COMPOUND_EXPRESSION\n    || node.type === NodeTypes.TEXT\n    || node.type === NodeTypes.COMMENT\n    || node.type === NodeTypes.TEXT_CALL\n  ) {\n    return []\n  }\n  else {\n    exhaustiveCheckReturnUndefined(node)\n    return []\n  }\n}\n\nfunction getFreeVariablesForText(input: string): string[] {\n  const inputWithPrefix = input.trimStart()[0] === '{' ? `(${input})` : input\n  return getFileGlobals(parse(inputWithPrefix))\n}\n\nfunction getFreeVariablesForPropsNode(\n  node: AttributeNode | DirectiveNode,\n): string[] {\n  if (node.type === NodeTypes.DIRECTIVE) {\n    const arg = node.arg === undefined ? [] : getFreeVariablesForNode(node.arg)\n    const exp = node.exp === undefined ? [] : getFreeVariablesForNode(node.exp)\n    return [...arg, ...exp]\n  }\n  return []\n}\n\nfunction getFreeVariablesForNode(\n  node: TemplateChildNode | ExpressionNode,\n): string[] {\n  if (node.type === NodeTypes.SIMPLE_EXPRESSION) {\n    return node.isStatic ? [] : getFreeVariablesForText(node.content)\n  }\n  else if (node.type === NodeTypes.COMPOUND_EXPRESSION) {\n    return node.children.flatMap(x =>\n      typeof x !== 'object' ? [] : getFreeVariablesForNode(x),\n    )\n  }\n  else if (node.type === NodeTypes.INTERPOLATION) {\n    return getFreeVariablesForNode(node.content)\n  }\n  else if (node.type === NodeTypes.ELEMENT) {\n    const children = node.children.flatMap(getFreeVariablesForNode)\n\n    const directiveProps = node.props.flatMap(x =>\n      x.type === NodeTypes.DIRECTIVE ? [x] : [],\n    )\n    const attributeProps = node.props.flatMap(x =>\n      x.type === NodeTypes.ATTRIBUTE ? [x] : [],\n    )\n\n    const refNode = attributeProps.find(\n      node => node.name === 'ref' && node.value !== undefined,\n    )\n    const refIdentifier = refNode?.value?.content\n\n    const vSlotNode = directiveProps.find(node => node.name === 'slot')\n    const vSlotArgIdentifiers\n      = vSlotNode?.arg === undefined ? [] : getFreeVariablesForNode(vSlotNode.arg)\n    // TODO: Variable shadowing\n    const vSlotExpVariableShadowingIdentifiers: string[] = []\n\n    const vForNode = directiveProps.find(node => node.name === 'for')\n    const vForIdentifiers\n      = vForNode?.exp?.type === NodeTypes.SIMPLE_EXPRESSION\n        ? getFreeVariablesForText(\n          vForNode.exp.content.replace(/^.*\\s(?:in|of)\\s/, ''),\n        )\n        : []\n    // TODO: Variable shadowing\n    const vForExpVariableShadowingIdentifiers: string[] = []\n\n    const props = directiveProps\n      .filter(({ name }) => name !== 'slot' && name !== 'for')\n      .flatMap(getFreeVariablesForPropsNode)\n\n    const shadowingIdentifiers = new Set([\n      ...vSlotExpVariableShadowingIdentifiers,\n      ...vForExpVariableShadowingIdentifiers,\n    ])\n    return [\n      ...vSlotArgIdentifiers,\n      refIdentifier,\n      ...vForIdentifiers,\n      ...[...children, ...props].filter(x => !shadowingIdentifiers.has(x)),\n    ].filter(notNullish)\n  }\n  else if (node.type === NodeTypes.FOR) {\n    // If we use `baseCompiler`, we need add variable shadowing here\n    // But we use `baseParse` now. So this branch will never be reached.\n    // `NodeTypes.IF` and `NodeTypes.IF_BRANCH` will never be reached, also.\n\n    // const { keyAlias, valueAlias } = node\n    return [node.source, ...node.children].flatMap(getFreeVariablesForNode)\n  }\n  else if (node.type === NodeTypes.IF) {\n    return (node.branches ?? []).flatMap(getFreeVariablesForNode)\n  }\n  else if (node.type === NodeTypes.IF_BRANCH) {\n    return [node.condition, ...node.children]\n      .filter(notNullish)\n      .flatMap(getFreeVariablesForNode)\n  }\n  else if (\n    node.type === NodeTypes.TEXT\n    || node.type === NodeTypes.COMMENT\n    || node.type === NodeTypes.TEXT_CALL\n  ) {\n    return []\n  }\n  else {\n    exhaustiveCheckReturnUndefined(node)\n    return []\n  }\n}\n\nexport function findReferencesForSFC(\n  templateNode: RootNode | PlainElementNode | undefined,\n) {\n  const components = templateNode?.children.flatMap(getComponents) ?? []\n  const directives = templateNode?.children.flatMap(getDirectiveNames) ?? []\n  const identifiers\n    = templateNode?.children.flatMap(getFreeVariablesForNode) ?? []\n\n  return {\n    components,\n    directives,\n    identifiers,\n  }\n}\n\nfunction getBabelParserOptions(lang: string | null | undefined) {\n  lang = lang || 'js'\n  const pluginsDict: Record<string, Array<ParserPlugin>> = {\n    js: [],\n    ts: ['typescript'],\n    jsx: ['jsx'],\n    tsx: ['jsx', 'typescript'],\n  }\n  const plugins = pluginsDict[lang]\n  if (plugins === undefined)\n    throw new SyntaxError(`Unsupported script language: ${lang}`)\n  return {\n    sourceType: 'module' as const,\n    plugins,\n  }\n}\nexport async function parseSFC(\n  code: string,\n  id?: string,\n  options?: ScriptSetupTransformOptions,\n): Promise<ParsedSFC> {\n  const elementChildren = baseParse(code, parserOptions).children.flatMap(x =>\n    x.type === NodeTypes.ELEMENT && x.tagType === ElementTypes.ELEMENT\n      ? [x]\n      : [],\n  )\n  const templateNode = elementChildren.find(x => x.tag === 'template')\n\n  const [scriptSetupChildNodes, scriptChildNodes] = partition(\n    elementChildren.filter(x => x.tag === 'script'),\n    x => x.props.some(p => p.type === NodeTypes.ATTRIBUTE && p.name === 'setup'),\n  )\n\n  const getScriptTagMeta = (\n    n: PlainElementNode | undefined,\n    astTransforms: (ast: Program) => Program = x => x,\n  ): ScriptTagMeta => {\n    if (n === undefined) {\n      const content = ''\n      const ast = parse(content, {\n        sourceType: 'module',\n        plugins: [],\n      }).program\n      return {\n        start: 0,\n        end: 0,\n        contentStart: 0,\n        contentEnd: 0,\n        content,\n        attrs: {},\n        found: false,\n        ast,\n      }\n    }\n    const attrs = Object.fromEntries(\n      n.props.flatMap(x =>\n        !(\n          x.type === NodeTypes.ATTRIBUTE && typeof x.value?.content === 'string'\n        )\n          ? []\n          : [[x.name, x.value.content]],\n      ),\n    )\n    const content = n.children[0]?.loc.source ?? ''\n    const contentStart = n.children[0]?.loc.start.offset ?? 0\n    const contentEnd = n.children[0]?.loc.end.offset ?? 0\n    const ast = astTransforms(\n      parse(content, getBabelParserOptions(attrs.lang)).program,\n    )\n    return {\n      start: n.loc.start.offset,\n      end: n.loc.end.offset,\n      contentStart,\n      contentEnd,\n      content,\n      attrs,\n      found: true,\n      ast,\n    }\n  }\n  const scriptSetup = getScriptTagMeta(\n    scriptSetupChildNodes[0],\n    options?.astTransforms?.scriptSetup,\n  )\n  const script = getScriptTagMeta(\n    scriptChildNodes[0],\n    options?.astTransforms?.script,\n  )\n\n  if (\n    script.found\n    && scriptSetup.found\n    && scriptSetup.attrs.lang !== script.attrs.lang\n  ) {\n    throw new SyntaxError(\n      '<script setup> language must be the same as <script>',\n    )\n  }\n\n  const codeOfTemplate\n    = templateNode == null\n      ? undefined\n      : templateNode.props.some(\n        p =>\n          p.type === NodeTypes.ATTRIBUTE\n            && p.name === 'lang'\n            && p.value?.type === NodeTypes.TEXT\n            && p.value.content === 'pug',\n      )\n        ? baseParse(\n          (await import('pug')).compile(\n            templateNode.children.map(x => x.loc.source).join(''),\n            {\n              filename: id,\n            },\n          )(),\n          parserOptions,\n        )\n        : templateNode\n\n  const result = codeOfTemplate\n    ? findReferencesForSFC(codeOfTemplate)\n    : undefined\n\n  return {\n    id,\n    template: {\n      tags: new Set(result?.components),\n      components: new Set(result?.components.map(pascalize)),\n      directives: new Set(\n        result?.directives\n          .filter(x => !BUILD_IN_DIRECTIVES.has(x))\n          .map(camelize),\n      ),\n      identifiers: new Set(result?.identifiers),\n    },\n    scriptSetup,\n    script,\n    parserOptions: getBabelParserOptions(\n      script.attrs.lang ?? scriptSetup.attrs.lang,\n    ),\n    extraDeclarations: [],\n  }\n}\n"
  },
  {
    "path": "src/core/transform.ts",
    "content": "import MagicString from 'magic-string'\nimport { shouldTransform as shouldTransformRefSugar, transform as transformRef } from '@vue/reactivity-transform'\nimport type { ResolvedOptions, ScriptSetupTransformOptions, TransformResult } from '../types'\nimport { parseSFC } from './parseSFC'\nimport { transformScriptSetup } from './transformScriptSetup'\nimport { transformSfcRefSugar } from './transformSfcRefSugar'\nimport { resolveOptions } from './options'\n\nexport const scriptSetupRE = /<script\\s+(.*\\s+)?setup(\\s+.*)?\\s*>/\n\nexport function shouldTransform(code: string, id: string, options?: ScriptSetupTransformOptions): boolean {\n  // avoid transforming twice\n  if (code.includes('export default __sfc_main'))\n    return false\n  return (options?.reactivityTransform && shouldTransformRefSugar(code)) || scriptSetupRE.test(code)\n}\n\nexport async function transform(input: string, id: string, options?: ScriptSetupTransformOptions): Promise<TransformResult> {\n  if (!shouldTransform(input, id, options))\n    return null\n  const resolved = resolveOptions(options)\n  if (id.endsWith('.vue') || id.includes('.vue?vue'))\n    return await transformVue(input, id, resolved)\n  else\n    return transformNonVue(input, id, resolved)\n}\n\nfunction transformNonVue(input: string, id: string, options: ResolvedOptions): TransformResult {\n  if (options.reactivityTransform && shouldTransformRefSugar(input)) {\n    return transformRef(input, {\n      filename: id,\n      sourceMap: options.sourceMap,\n      importHelpersFrom: options.importHelpersFrom,\n    }) as any\n  }\n  return null\n}\n\nasync function transformVue(input: string, id: string, options: ResolvedOptions): Promise<TransformResult> {\n  const s = new MagicString(input)\n\n  const sfc = await parseSFC(input, id)\n\n  if (options.reactivityTransform)\n    transformSfcRefSugar(sfc, options)\n\n  const { code } = transformScriptSetup(sfc, options)\n\n  const attributes = {\n    ...sfc.script.attrs,\n    ...sfc.scriptSetup.attrs,\n  }\n  delete attributes.setup\n  const attr = Object.entries(attributes)\n    .map(([key, value]) => value ? `${key}=\"${value}\"` : key)\n    .join(' ')\n\n  if (code) {\n    const block = `<script ${attr}>\\n${code}\\n</script>`\n\n    s.remove(sfc.script.start, sfc.script.end)\n    if (sfc.scriptSetup.start !== sfc.scriptSetup.end) {\n      s.overwrite(\n        sfc.scriptSetup.start,\n        sfc.scriptSetup.end,\n        block,\n      )\n    }\n    else {\n      s.prependLeft(0, `${block}\\n`)\n    }\n  }\n  return {\n    code: s.toString(),\n    map: options.sourceMap\n      ? s.generateMap({\n        source: id,\n        includeContent: true,\n      }) as any\n      : null,\n  }\n}\n"
  },
  {
    "path": "src/core/transformScriptSetup.ts",
    "content": "import { capitalize } from '@vue/shared'\nimport type { Node, ObjectExpression, Statement } from '@babel/types'\nimport { notNullish, partition, uniq } from '@antfu/utils'\nimport { parserOptions } from '@vue/compiler-dom'\nimport type { ParsedSFC, ScriptSetupTransformOptions } from '../types'\nimport { applyMacros } from './macros'\nimport { getIdentifierDeclarations } from './identifiers'\nimport { generate, t } from './babel'\nimport { pascalize } from './utils'\n\nfunction isAsyncImport(node: Statement) {\n  if (t.isVariableDeclaration(node)) {\n    const declaration = node.declarations[0]\n\n    return (\n      declaration !== undefined\n      && t.isCallExpression(declaration.init)\n      && t.isIdentifier(declaration.init.callee)\n      && declaration.init.callee.name === 'defineAsyncComponent'\n    )\n  }\n\n  return false\n}\n\nexport function transformScriptSetup(\n  sfc: ParsedSFC,\n  options?: ScriptSetupTransformOptions,\n) {\n  const { scriptSetup, script, template } = sfc\n\n  const { nodes: body, props, expose } = applyMacros(scriptSetup.ast.body)\n\n  const [hoisted, setupBody] = partition(\n    body,\n    n =>\n      isAsyncImport(n)\n      || t.isImportDeclaration(n)\n      || t.isExportNamedDeclaration(n)\n      || n.type.startsWith('TS'),\n  )\n\n  // get all identifiers in `<script setup>` and `<script>`\n  const declarationArray = uniq([\n    ...getIdentifierDeclarations(hoisted),\n    ...getIdentifierDeclarations(setupBody),\n    ...getIdentifierDeclarations(script.ast.body),\n  ]).filter(notNullish)\n\n  // filter out identifiers that are used in `<template>`\n  const returns: ObjectExpression['properties'] = declarationArray\n    .filter(i => template.identifiers.has(i))\n    .map((i) => {\n      const id = t.identifier(i)\n      return t.objectProperty(id, id, false, true)\n    })\n\n  const nonNativeTags = new Set(\n    Array.from(template.tags)\n      .filter(tag => !parserOptions.isNativeTag!(tag))\n      .map(pascalize),\n  )\n\n  const components = Array.from(nonNativeTags)\n    .map(\n      component =>\n        declarationArray.find(declare => declare === component)\n        ?? declarationArray.find(declare => pascalize(declare) === component),\n    )\n    .filter(notNullish)\n\n  const directiveDeclaration = Array.from(template.directives)\n    .map((directive) => {\n      const identifier = declarationArray.find(\n        declaration => declaration === `v${capitalize(directive)}`,\n      )\n      if (identifier === undefined)\n        return undefined\n\n      return { identifier, directive }\n    })\n    .filter(notNullish)\n\n  // append `<script setup>` imports to `<script>`\n\n  const __sfc = t.identifier('__sfc_main')\n\n  let hasBody = false\n\n  const bodyNodes = script.ast.body.map((node: Node) => {\n    // replace `export default` with a temproray variable\n    // `const __sfc_main = { ... }`\n    if (node.type === 'ExportDefaultDeclaration') {\n      hasBody = true\n      return t.variableDeclaration('const', [\n        t.variableDeclarator(__sfc, node.declaration as any),\n      ])\n    }\n    return node\n  })\n\n  let ast = t.program([\n    ...sfc.extraDeclarations,\n    ...hoisted,\n    ...bodyNodes,\n  ] as Statement[])\n\n  // inject `const __sfc_main = {}` if `<script>` has default export\n  if (!hasBody) {\n    ast.body.push(\n      t.variableDeclaration('const', [\n        t.variableDeclarator(__sfc, t.objectExpression([])),\n      ]),\n    )\n  }\n\n  // inject props function\n  // `__sfc_main.props = { ... }`\n  if (props) {\n    hasBody = true\n    ast.body.push(\n      t.expressionStatement(\n        t.assignmentExpression(\n          '=',\n          t.memberExpression(__sfc, t.identifier('props')),\n          props as any,\n        ),\n      ) as any,\n    )\n  }\n\n  // inject setup function\n  // `__sfc_main.setup = () => {}`\n  if (body.length) {\n    hasBody = true\n    const returnExpr = expose\n      ? t.callExpression(\n        t.memberExpression(t.identifier('Object'), t.identifier('assign')),\n        [t.objectExpression(returns), expose],\n      )\n      : t.objectExpression(returns)\n    const returnStatement = t.returnStatement(returnExpr)\n\n    ast.body.push(\n      t.expressionStatement(\n        t.assignmentExpression(\n          '=',\n          t.memberExpression(__sfc, t.identifier('setup')),\n          t.arrowFunctionExpression(\n            [t.identifier('__props'), t.identifier('__ctx')],\n            t.blockStatement([...setupBody, returnStatement as any]),\n          ),\n        ),\n      ) as any,\n    )\n  }\n\n  // inject components\n  // `__sfc_main.components = Object.assign({ ... }, __sfc_main.components)`\n  if (components.length) {\n    hasBody = true\n    const componentsObject = t.objectExpression(\n      components.map((i) => {\n        const id = t.identifier(i)\n        return t.objectProperty(id, id, false, true)\n      }),\n    )\n\n    ast.body.push(\n      t.expressionStatement(\n        t.assignmentExpression(\n          '=',\n          t.memberExpression(__sfc, t.identifier('components')),\n          t.callExpression(\n            t.memberExpression(t.identifier('Object'), t.identifier('assign')),\n            [\n              componentsObject,\n              t.memberExpression(__sfc, t.identifier('components')),\n            ],\n          ),\n        ),\n      ) as any,\n    )\n  }\n\n  // inject directives\n  // `__sfc_main.directives = Object.assign({ ... }, __sfc_main.directives)`\n  if (directiveDeclaration.length) {\n    hasBody = true\n    const directivesObject = t.objectExpression(\n      directiveDeclaration.map(({ directive, identifier }) =>\n        t.objectProperty(\n          t.identifier(directive),\n          t.identifier(identifier),\n          false,\n          false,\n        ),\n      ),\n    )\n\n    ast.body.push(\n      t.expressionStatement(\n        t.assignmentExpression(\n          '=',\n          t.memberExpression(__sfc, t.identifier('directives')),\n          t.callExpression(\n            t.memberExpression(t.identifier('Object'), t.identifier('assign')),\n            [\n              directivesObject,\n              t.memberExpression(__sfc, t.identifier('directives')),\n            ],\n          ),\n        ),\n      ) as any,\n    )\n  }\n\n  if (!hasBody && !options?.astTransforms) {\n    return {\n      ast: null,\n      code: '',\n    }\n  }\n\n  // re-export\n  // `export default __sfc_main`\n  ast.body.push(t.exportDefaultDeclaration(__sfc) as any)\n\n  ast = options?.astTransforms?.post?.(ast, sfc) || ast\n\n  return {\n    ast,\n    code: generate(ast).code,\n  }\n}\n"
  },
  {
    "path": "src/core/transformSfcRefSugar.ts",
    "content": "import { shouldTransform, transformAST } from '@vue/reactivity-transform'\nimport MagicString from 'magic-string'\nimport type { ParsedSFC, ResolvedOptions } from '../types'\nimport { parse, t } from './babel'\n\nexport function transformSfcRefSugar(sfc: ParsedSFC, options: ResolvedOptions) {\n  const importedHelpers = new Set<string>()\n\n  for (const script of [sfc.script, sfc.scriptSetup]) {\n    if (shouldTransform(script.content)) {\n      const s = new MagicString(script.content)\n      const { importedHelpers: imports } = transformAST(script.ast, s)\n      Array.from(imports).forEach(helper => importedHelpers.add(helper))\n      script.content = s.toString()\n      script.ast = parse(script.content, sfc.parserOptions).program\n    }\n  }\n\n  if (importedHelpers.size) {\n    sfc.extraDeclarations = [\n      t.importDeclaration(\n        Array.from(importedHelpers).map(i => t.importSpecifier(t.identifier(`_${i}`), t.identifier(i))),\n        t.stringLiteral(options.importHelpersFrom),\n      ),\n    ]\n  }\n}\n"
  },
  {
    "path": "src/core/utils.ts",
    "content": "import { camelize, capitalize } from '@vue/shared'\n\nexport const pascalize = (str: string) => capitalize(camelize(str))\n\nexport const isNotNil = <T>(value: T): value is NonNullable<T> => value != null\n\nexport function exhaustiveCheckReturnUndefined(_param: never) {\n  return undefined as never\n}\n"
  },
  {
    "path": "src/esbuild.ts",
    "content": "import unplugin from '.'\n\nexport default unplugin.esbuild\n"
  },
  {
    "path": "src/index.ts",
    "content": "import { createUnplugin } from 'unplugin'\nimport { createFilter } from '@rollup/pluginutils'\nimport type { PluginOptions } from './types'\nimport { transform } from './core'\n\nexport * from './core'\n\nexport const unplugin = createUnplugin<PluginOptions>((options = {}) => {\n  const filter = createFilter(\n    options.include || (options.reactivityTransform ? [/\\.vue$/, /\\.vue\\?vue/, /\\.[jt]sx?$/] : [/\\.vue$/, /\\.vue\\?vue/]),\n    options.exclude || [/node_modules/, /\\.git/, /\\.nuxt/],\n  )\n\n  return {\n    name: 'unplugin-vue2-script-setup',\n    enforce: 'pre',\n    transformInclude(id) {\n      return filter(id)\n    },\n    async transform(code, id) {\n      try {\n        return await transform(code, id, options)\n      }\n      catch (e: any) {\n        this.error(e)\n      }\n    },\n  }\n})\n\nexport default unplugin\n"
  },
  {
    "path": "src/lib.ts",
    "content": "export * from './core'\n"
  },
  {
    "path": "src/nuxt.ts",
    "content": "import defu from 'defu'\nimport type { PluginOptions } from './types'\nimport unplugin from '.'\n\nfunction scriptSetupModule(this: any, inlineOptions: PluginOptions = {}) {\n  const options = defu(inlineOptions, this.nuxt.options.scriptSetup)\n\n  // install webpack plugin\n  this.extendBuild((config: any) => {\n    config.plugins = config.plugins || []\n    config.plugins.unshift(unplugin.webpack(options))\n  })\n\n  // install vite plugin\n  this.nuxt.hook('vite:extend', async (vite: any) => {\n    vite.config.plugins = vite.config.plugins || []\n    vite.config.plugins.push(unplugin.vite(options))\n  })\n}\n\nexport default scriptSetupModule\n"
  },
  {
    "path": "src/rollup.ts",
    "content": "import unplugin from '.'\n\nexport default unplugin.rollup\n"
  },
  {
    "path": "src/types.ts",
    "content": "import type { ParserOptions } from '@babel/parser'\nimport type { Node, Program } from '@babel/types'\nimport type { FilterPattern } from '@rollup/pluginutils'\n\nexport interface ScriptTagMeta {\n  start: number\n  end: number\n  contentStart: number\n  contentEnd: number\n  content: string\n  attrs: Record<string, string>\n  found: boolean\n  ast: Program\n}\n\nexport interface ParsedSFC {\n  id?: string\n  template: {\n    /** foo-bar -> FooBar */\n    components: Set<string>\n    tags: Set<string>\n    /** v-foo-bar -> fooBar */\n    directives: Set<string>\n    identifiers: Set<string>\n  }\n  scriptSetup: ScriptTagMeta\n  script: ScriptTagMeta\n  parserOptions: ParserOptions\n  extraDeclarations: Node[]\n}\n\nexport interface ScriptSetupTransformOptions {\n  astTransforms?: {\n    script?: (ast: Program) => Program\n    scriptSetup?: (ast: Program) => Program\n    post?: (ast: Program, sfc: ParsedSFC) => Program\n  }\n  reactivityTransform?: boolean\n  importHelpersFrom?: string\n  sourceMap?: boolean\n}\n\nexport interface PluginOptions extends ScriptSetupTransformOptions {\n  include?: FilterPattern\n  exclude?: FilterPattern\n}\n\nexport type ResolvedOptions = Required<ScriptSetupTransformOptions>\n\nexport interface SourceMap {\n  file: string\n  mappings: string\n  names: string[]\n  sources: string[]\n  sourcesContent: string[]\n  version: number\n  toString(): string\n  toUrl(): string\n}\n\nexport type TransformResult = {\n  code: string\n  readonly map: SourceMap | null\n} | null\n"
  },
  {
    "path": "src/vite.ts",
    "content": "import unplugin from '.'\n\nexport default unplugin.vite\n"
  },
  {
    "path": "src/webpack.ts",
    "content": "import unplugin from '.'\n\nexport default unplugin.webpack\n"
  },
  {
    "path": "test/__snapshots__/transform.test.ts.snap",
    "content": "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html\n\nexports[`transform > fixtures > playground/src/App.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nimport { defineAsyncComponent } from '@vue/composition-api';\nimport ButtonTest from './ButtonTest.vue';\nimport HelloWorld from './HelloWorld.vue';\nconst AsyncComponent = defineAsyncComponent(() => import('./Async.vue'));\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  function onUpdate(e: any) {\n    // eslint-disable-next-line no-console\n    console.log(e);\n  }\n  return {\n    onUpdate\n  };\n};\n__sfc_main.components = Object.assign({\n  ButtonTest,\n  HelloWorld,\n  AsyncComponent\n}, __sfc_main.components);\nexport default __sfc_main;\n</script>\n<template>\n  <div>\n    <ButtonTest />\n\n    <HelloWorld name=\\\\\"Vue 2\\\\\" @update=\\\\\"onUpdate\\\\\" />\n\n    <AsyncComponent />\n  </div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > playground/src/Async.vue 1`] = `\n\"<template>\n  <div>Async Component</div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > playground/src/Bar.vue 1`] = `\n\"<template>\n  <div>Bar</div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > playground/src/ButtonTest.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nimport Button from './Foo.vue';\nimport button from './Foo.vue';\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  return {\n    Button,\n    button\n  };\n};\n__sfc_main.components = Object.assign({\n  Button\n}, __sfc_main.components);\nexport default __sfc_main;\n</script>\n\n<template>\n  <div>\n    <button>{{ Button }}</button>\n    <Button>{{ button }}</Button>\n  </div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > playground/src/Foo.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\nexport default __sfc_main;\n</script>\n<template>\n  <div>\n    Button Component: <slot></slot>\n  </div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > playground/src/HelloWorld.vue 1`] = `\n\"\n<script lang=\\\\\"ts\\\\\">\nimport { ref as _ref, computed as _computed } from \\\\\"@vue/composition-api\\\\\";\nimport { watch } from '@vue/composition-api';\nimport Foo from './Foo.vue';\nimport Bar from './Bar.vue';\nconst __sfc_main = {\n  name: 'App'\n};\n__sfc_main.props = {\n  msg: {\n    key: \\\\\"msg\\\\\",\n    required: false,\n    type: String,\n    default: 'Hello'\n  },\n  name: {\n    key: \\\\\"name\\\\\",\n    required: true,\n    type: [String, Number]\n  }\n};\n__sfc_main.setup = (__props, __ctx) => {\n  const emit = __ctx.emit;\n  let count = _ref(0);\n  // eslint-disable-next-line prefer-const\n  let doubled = _computed(() => count.value * 2);\n  function inc() {\n    count.value += 1;\n  }\n  function dec() {\n    count.value -= 1;\n  }\n  const decText = '<b>Dec</b>';\n  watch(count.value, value => emit('update', value));\n  return {\n    Foo,\n    Bar,\n    count,\n    doubled,\n    inc,\n    dec,\n    decText\n  };\n};\nexport default __sfc_main;\n</script>\n<template>\n  <div>\n    <h3>{{ msg }}, {{ name }}</h3>\n    <button @click=\\\\\"inc\\\\\">\n      Inc\n    </button>\n    <div>{{ count }} x 2 = {{ doubled }}</div>\n    <button @click=\\\\\"dec()\\\\\" v-html=\\\\\"decText\\\\\" />\n    <component :is=\\\\\"count > 2 ? Foo : Bar\\\\\" />\n  </div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > playground/src/main.ts 1`] = `\n\"import Vue from 'vue'\nimport VueCompositionAPI, { createApp, h } from '@vue/composition-api'\nimport App from './App.vue'\n\nVue.use(VueCompositionAPI)\n\nconst app = createApp({ render: () => h(App) })\n\napp.mount('#app')\n\"\n`;\n\nexports[`transform > fixtures > playground/src/shims-vue.d.ts 1`] = `\n\"/// <reference types=\\\\\"unplugin-vue2-script-setup/shims.js\\\\\" />\n/// <reference types=\\\\\"unplugin-vue2-script-setup/ref-macros.js\\\\\" />\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/AsyncImport.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nimport { defineAsyncComponent } from '@vue/composition-api';\nconst ScriptOnly = defineAsyncComponent(() => import('./ScriptOnly.vue'));\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  return {};\n};\n__sfc_main.components = Object.assign({\n  ScriptOnly\n}, __sfc_main.components);\nexport default __sfc_main;\n</script>\n\n<template>\n  <ScriptOnly />\n</template>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/ComponentsDirectives.vue 1`] = `\n\"<template>\n  <div>\n    <FooView\n      v-if=\\\\\"now > 0\\\\\"\n      ref=\\\\\"fooView\\\\\"\n      v-foo-bar=\\\\\"message0\\\\\"\n      v-d0-demo:foo.a.b=\\\\\"message1\\\\\"\n      v-d1-modifiers.a=\\\\\"message2\\\\\"\n      v-d2-modifiers-no-value.b.c\n      v-d3-arg:click=\\\\\"message3\\\\\"\n      v-d4-arg-no-value:click\n      v-d5-arg-dynamic:[direction1+direction2.length].c=\\\\\"message4\\\\\"\n      v-d6-arg-dynamic-no-value:[direction3]\n      v-d6-arg-dynamic-no-value:shouldNotUsed\n    >\n      <template #[slotName]=\\\\\"{ foo = 1 }\\\\\">\n        <div>\n          good {{ foo }}\n        </div>\n      </template>\n      <template v-slot:default=\\\\\"bar\\\\\">\n        <div>\n          good {{ bar }}\n        </div>\n      </template>\n    </FooView>\n    <button v-else-if=\\\\\"now === 0\\\\\" :[propNamePrefix+propName]=\\\\\"1\\\\\" @[eventPrefix.value+eventName]=\\\\\"console.log($event)\\\\\"></button>\n    <router-view v-else></router-view>\n    <img src=\\\\\"https://vuejs.org/images/logo.svg\\\\\">\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nimport { ref } from '@vue/runtime-dom';\nimport FooView from './FooView.vue';\nimport { vFooBar, vDemo as vD0Demo, vD1Modifiers, vD2ModifiersNoValue, vD3Arg, vD4ArgNoValue, vD5ArgDynamic, vD6ArgDynamicNoValue } from './directive';\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const fooView = ref<null | InstanceType<typeof FooView>>(null);\n  const message0 = ref('hello');\n  const message1 = ref('hello');\n  const message2 = ref('hello');\n  const message3 = ref('hello');\n  const message4 = ref('hello');\n  const direction1 = ref('top');\n  const direction2 = ref('top');\n  const direction3 = ref('top');\n  const shouldNotUsed = ref('');\n  const propNamePrefix = 'vue-';\n  const propName = 'color';\n  const eventPrefix = {\n    value: 'vue-'\n  };\n  const eventName = '';\n  const console = globalThis.console;\n  const now = Date.now();\n  const slotName = 'footer';\n  return {\n    fooView,\n    message0,\n    message1,\n    message2,\n    message3,\n    message4,\n    direction1,\n    direction2,\n    direction3,\n    propNamePrefix,\n    propName,\n    eventPrefix,\n    eventName,\n    console,\n    now,\n    slotName\n  };\n};\n__sfc_main.components = Object.assign({\n  FooView\n}, __sfc_main.components);\n__sfc_main.directives = Object.assign({\n  fooBar: vFooBar,\n  d0Demo: vD0Demo,\n  d1Modifiers: vD1Modifiers,\n  d2ModifiersNoValue: vD2ModifiersNoValue,\n  d3Arg: vD3Arg,\n  d4ArgNoValue: vD4ArgNoValue,\n  d5ArgDynamic: vD5ArgDynamic,\n  d6ArgDynamicNoValue: vD6ArgDynamicNoValue\n}, __sfc_main.directives);\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/ComponentsDirectivesLocal.vue 1`] = `\n\"\n<script lang=\\\\\"ts\\\\\">\nimport type { ObjectDirective } from '@vue/composition-api';\n// enables v-focus in templates\nconst vFocus: ObjectDirective<HTMLInputElement, null> = {\n  inserted: (el, binding, vnode, oldVnode) => {\n    el.focus();\n  }\n};\nconst __sfc_main = {};\n__sfc_main.directives = Object.assign({\n  focus: vFocus\n}, __sfc_main.directives);\nexport default __sfc_main;\n</script>\n<template>\n  <input v-focus=\\\\\"null\\\\\">\n</template>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/ComponentsLocal.vue 1`] = `\n\"\n<script lang=\\\\\"tsx\\\\\">\nconst HelloComponent = ({\n  name\n}: {\n  name: string;\n}) => <span>Hello, {name}</span>;\nconst __sfc_main = {};\n__sfc_main.components = Object.assign({\n  HelloComponent\n}, __sfc_main.components);\nexport default __sfc_main;\n</script>\n<template>\n  <HelloComponent name=\\\\\"Evan You\\\\\" />\n</template>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/DynamicStyle.vue 1`] = `\n\"<template>\n  <div :style=\\\\\"{ color, border: '1px' }\\\\\" />\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const color = computed(() => 'red');\n  return {\n    color\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/Empty.vue 1`] = `\"\"`;\n\nexports[`transform > fixtures > test/fixtures/Enum.vue 1`] = `\n\"<template>\n  <div>{{ MyEnum }}</div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nenum MyEnum {\n  test = 'true',\n}\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  return {\n    MyEnum\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/HtmlTag.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nimport Enum from './Enum.vue';\nimport { ref } from '@vue/composition-api';\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  let p = \\\\\"hello word\\\\\";\n  let Div = ref(\\\\\"hello word\\\\\");\n  let h3 = 'test';\n  let H3 = '';\n  return {\n    p,\n    Div,\n    h3,\n    H3\n  };\n};\n__sfc_main.components = Object.assign({\n  Enum\n}, __sfc_main.components);\nexport default __sfc_main;\n</script>\n\n<template>\n  <div>\n    <Enum />\n    <h3></h3>\n    {{ H3 }}\n    {{ h3 }}\n    {{ Div }}\n    <p>{{ p }}</p>\n  </div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/HtmlTag2.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nimport Button from './DynamicStyle.vue';\nimport button from './DynamicStyle.vue';\nimport { defineAsyncComponent } from '@vue/composition-api';\nconst footer = defineAsyncComponent(() => import('./ScriptOnly.vue'));\nimport { ref } from '@vue/composition-api';\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const p = ref(\\\\\"hello word\\\\\");\n  return {\n    Button,\n    button,\n    p\n  };\n};\n__sfc_main.components = Object.assign({\n  Button\n}, __sfc_main.components);\nexport default __sfc_main;\n</script>\n\n<template>\n  <div>\n    <p>{{ p }}</p>\n    <button>{{ Button }}</button>\n    <Button>{{ button }}</Button>\n    <footer>FOOTER</footer>\n  </div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/JSLongComment.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const a = 1;\n  ////////////////\n  return {\n    a\n  };\n};\nexport default __sfc_main;\n</script>\n<template>\n  <div>{{ a }}</div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/Macros.vue 1`] = `\n\"<template>\n  <div @click=\\\\\"emit(props.msg)\\\\\">{{ msg }}</div>\n</template>\n\n<script lang=\\\\\"js\\\\\">\nconst __sfc_main = {};\n__sfc_main.props = {\n  msg: String\n};\n__sfc_main.setup = (__props, __ctx) => {\n  const props = __props;\n  const emit = __ctx.emit;\n  return {\n    props,\n    emit\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosDefineExpose.vue 1`] = `\n\"<template>\n  <div>{{ a }}</div>\n  <div>{{ text?.length ?? textLengthDefault }}</div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nimport { ref } from '@vue/composition-api';\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const a = ref(1);\n  const b = 1;\n  const text = 'hello';\n  const textLengthDefault = 0;\n  return Object.assign({\n    a,\n    text,\n    textLengthDefault\n  }, {\n    b\n  });\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosPure.vue 1`] = `\n\"<template>\n  <div>{{ msg }}</div>\n</template>\n\n<script >\nconst __sfc_main = {};\n__sfc_main.props = {\n  msg: String\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosType.vue 1`] = `\n\"<template>\n  <div @click=\\\\\"emit('update', props.msg)\\\\\">\n    {{ msg }}\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.props = {\n  msg: {\n    key: \\\\\"msg\\\\\",\n    required: false,\n    type: String,\n    default: 'Hello'\n  },\n  value: {\n    key: \\\\\"value\\\\\",\n    required: true,\n    type: [Number, String]\n  },\n  data: {\n    key: \\\\\"data\\\\\",\n    required: false,\n    type: Object\n  }\n};\n__sfc_main.setup = (__props, __ctx) => {\n  const props = __props;\n  const emit = __ctx.emit;\n  return {\n    props,\n    emit\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosType2.vue 1`] = `\n\"<template>\n  <div @click=\\\\\"emit(props.msg)\\\\\">\n    {{ msg }}\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nexport interface Props {\n  msg: string;\n  value: number | string;\n  data?: {\n    value: boolean;\n  };\n  arr?: [number, string, {}];\n  any: any;\n}\nconst __sfc_main = {};\n__sfc_main.props = {\n  msg: {\n    key: \\\\\"msg\\\\\",\n    required: false,\n    type: String,\n    default: 'Hello'\n  },\n  value: {\n    key: \\\\\"value\\\\\",\n    required: true,\n    type: [Number, String]\n  },\n  data: {\n    key: \\\\\"data\\\\\",\n    required: false,\n    type: Object\n  },\n  arr: {\n    key: \\\\\"arr\\\\\",\n    required: false,\n    type: Array\n  },\n  any: {\n    key: \\\\\"any\\\\\",\n    required: true,\n    type: null\n  }\n};\n__sfc_main.setup = (__props, __ctx) => {\n  const props = __props;\n  const emit = __ctx.emit;\n  return {\n    props,\n    emit\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosType3.vue 1`] = `\n\"<template>\n  <div @click=\\\\\"emit('update', msg);emit('update', msg + value);\\\\\">\n    {{ msg }}\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.props = {\n  msg: {\n    key: \\\\\"msg\\\\\",\n    required: false,\n    type: String,\n    default: 'Hello'\n  },\n  value: {\n    key: \\\\\"value\\\\\",\n    required: true,\n    type: [Number, String]\n  },\n  data: {\n    key: \\\\\"data\\\\\",\n    required: false,\n    type: Object\n  }\n};\n__sfc_main.setup = (__props, __ctx) => {\n  const emit = __ctx.emit;\n  const value = 'bar';\n  return {\n    emit,\n    value\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosType4.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\ntype Test = number[];\nconst __sfc_main = {};\n__sfc_main.props = {\n  test: {\n    key: \\\\\"test\\\\\",\n    required: false,\n    type: null,\n    default: () => []\n  }\n};\n__sfc_main.setup = (__props, __ctx) => {\n  return {};\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosType5.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosType6.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const slots = __ctx.slots;\n  return {\n    slots\n  };\n};\nexport default __sfc_main;\n</script>\n<template>\n  <template v-if=\\\\\"slots.default\\\\\">\n    <slot name=\\\\\"default\\\\\" msg=\\\\\"hello\\\\\"></slot>\n  </template>\n  <div v-else>\n    fallback\n  </div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/MacrosTypeAny.vue 1`] = `\n\"<template>\n  <div>\n    {{ value }}\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.props = {\n  value: {\n    key: \\\\\"value\\\\\",\n    required: true,\n    type: null\n  }\n};\n__sfc_main.setup = (__props, __ctx) => {\n  const props = __props;\n  return {};\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/Object1.vue 1`] = `\n\"<template>\n  <div>\n    {{ data }} {{ title }}\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const data = {\n    title: 'Template Only'\n  };\n  return {\n    data\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/ObjectDestructure.vue 1`] = `\n\"<template>\n  <div></div>\n</template>\n\n<script >\nimport { toRefs, reactive } from 'vue';\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const state = reactive({\n    data: 'hello'\n  });\n  const {\n    data\n  } = toRefs(state);\n  return {};\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/Pug1.vue 1`] = `\n\"<template lang=\\\\\"pug\\\\\">\n.root\n  span {{ data }} {{ title }}\n  .p-1(@click=\\\\\"foo\\\\\")\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const data = {\n    title: 'Template Only'\n  };\n  function foo() {}\n  return {\n    data,\n    foo\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/RefSugar.ts 1`] = `\n\"import { ref as _ref, computed as _computed } from '@vue/composition-api'\n/* eslint-disable unused-imports/no-unused-vars */\n/* eslint-disable prefer-const */\nimport { ref } from '@vue/composition-api'\n\nlet ref1 = (ref('hello'))\nref1.value = 'world'\nlet ref1Raw = (ref1)\n\nlet ref2 = _ref('hello')\nref2.value = 'world'\nlet ref2Raw = (ref2)\n\nlet computed1 = _computed(() => ref2.value += ' str')\nlet computed1Raw = (computed1)\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/RefSugar.vue 1`] = `\n\"<template>\n  <div>\n    {{ msg }}\n    {{ msg2 }}\n    {{ a }}\n  </div>\n</template>\n\n\n\n<script lang=\\\\\"ts\\\\\">\nimport { ref as _ref } from \\\\\"@vue/composition-api\\\\\";\n/* eslint-disable prefer-const */\nimport { defineComponent, ref } from '@vue/composition-api';\nconst __sfc_main = defineComponent({\n  setup() {\n    let msg = ref('hello world');\n    return {\n      msg: msg.value,\n      msgRef: msg\n    };\n  }\n});\n__sfc_main.setup = (__props, __ctx) => {\n  let msg2 = _ref('hello world');\n  let a: number;\n  a = 2;\n  return {\n    msg2,\n    a\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/RefSugarScriptSetup.vue 1`] = `\n\"<template>\n  <div>\n    {{ msg }}\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nimport { ref as _ref } from \\\\\"@vue/composition-api\\\\\";\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  /* eslint-disable prefer-const */\n\n  let msg = _ref('hello world');\n  return {\n    msg\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/ScriptLessThanOrEqualTo.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const val: boolean = 1 <= 2;\n  return {\n    val\n  };\n};\nexport default __sfc_main;\n</script>\n\n<template>\n  <div>{{ val }}</div>\n</template>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/ScriptOnly.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\n// <script setup> in comment should not be matched\nimport { defineComponent } from '@vue/composition-api';\nconst __sfc_main = defineComponent({\n  name: 'Hi'\n});\nexport default __sfc_main;\n</script>\n\n\n<!-- <script setup> -->\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/TemplateOnly.vue 1`] = `\n\"<template>\n  <div>\n    <div v-for=\\\\\"(item, index) in items\\\\\" :key=\\\\\"item\\\\\">\n      {{ index }}: {{ item }}\n    </div>\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const items = [{\n    name: 'Item 1',\n    value: 1\n  }, {\n    name: 'Item 2',\n    value: 2\n  }, {\n    name: 'Item 3',\n    value: 3\n  }, {\n    name: 'Item 4',\n    value: 4\n  }];\n  return {\n    items\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/TemplateOptionalChaining.vue 1`] = `\n\"<template>\n  <div @click=\\\\\"callback?.()\\\\\">\n    {{ text?.length ?? textLengthDefault?.[index] }}\n    {{ classes?.[0] }}\n    {{ arrayObj.data.value[i] }}\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nimport { ref } from '@vue/composition-api';\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const text = 'hello';\n  const textLengthDefault = '';\n  const index = ref(0);\n  const callback = (undefined as undefined | (() => void));\n  const classes = (undefined as undefined | string[]);\n  const arrayObj = {\n    data: {\n      value: [1, 2, 3]\n    }\n  };\n  const i = 0;\n  return {\n    text,\n    textLengthDefault,\n    index,\n    callback,\n    classes,\n    arrayObj,\n    i\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/VFor.vue 1`] = `\n\"<template>\n  <div>\n    <div v-for=\\\\\"(item, index) in items\\\\\" :key=\\\\\"item\\\\\">\n      {{ item }}\n    </div>\n    <div v-for=\\\\\"{ cargo_key, in_of } in items2\\\\\">\n      {{ cargo_key }}\n    </div>\n  </div>\n</template>\n\n<script lang=\\\\\"ts\\\\\">\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const items = [{\n    name: 'Item 1',\n    value: 1\n  }, {\n    name: 'Item 2',\n    value: 2\n  }, {\n    name: 'Item 3',\n    value: 3\n  }, {\n    name: 'Item 4',\n    value: 4\n  }];\n  const items2 = [{\n    cargo_key: 'cargo_key',\n    in_of: 'in'\n  }];\n  const index = 0;\n  return {\n    items,\n    items2\n  };\n};\nexport default __sfc_main;\n</script>\n\"\n`;\n\nexports[`transform > fixtures > test/fixtures/VariableBinding.vue 1`] = `\n\"<script lang=\\\\\"ts\\\\\">\n/* eslint-disable no-console */\nimport { reactive } from '@vue/composition-api';\nconst __sfc_main = {};\n__sfc_main.setup = (__props, __ctx) => {\n  const state = reactive({\n    value: ''\n  });\n  function showEvent(event: MouseEvent) {\n    console.log(event);\n  }\n  const emit = __ctx.emit;\n  return {\n    state,\n    showEvent,\n    emit\n  };\n};\nexport default __sfc_main;\n</script>\n<template>\n  <div\n    @click=\\\\\"\n      state.value = \\`x: \\${$event.x}\\`\n      showEvent($event)\n      emit('foo')\n    \\\\\"\n  >\n    2333\n  </div>\n</template>\n\"\n`;\n"
  },
  {
    "path": "test/errors.test.ts",
    "content": "import { describe, expect, it, vi } from 'vitest'\nimport { transform as t } from '../src'\n\ndescribe('errors', () => {\n  it('langs', async () => {\n    await expect(() =>\n      t(`\n<script setup>\nconst a = 1\n</script>\n\n<script lang=\"ts\">\nexport default {}\n</script>\n`, 'Lang.vue')).rejects.toThrowError('<script setup> language must be the same as <script>')\n  })\n\n  it('defineProps', async () => {\n    await expect(() =>\n      t(`\n<script setup>\ndefineProps()\nconst a = defineProps()\n</script>\n`, 'DefineProps.vue'))\n      .rejects.toThrowError('duplicate defineProps() call')\n  })\n\n  it('top-level await', async () => {\n    await expect(() =>\n      t(`\n<script setup>\ndefineProps()\nawait something()\n</script>\n`, 'TopLevel.vue'))\n      .rejects.toThrowError('top-level await is not supported in Vue 2')\n\n    await expect(() =>\n      t(`\n<script setup>\ndefineProps()\nconst {data} = await something()\n</script>\n`, 'TopLevel.vue'))\n      .rejects.toThrowError('top-level await is not supported in Vue 2')\n  })\n\n  it('ref sugar', async () => {\n    const consoleWarnMock = vi.spyOn(console, 'warn')\n\n    await t(`\n<script setup>\ndefineProps()\nconst a = async () => {\n  await something()\n}\n</script>\n    `, 'App.vue')\n\n    consoleWarnMock.mockRestore()\n  })\n})\n"
  },
  {
    "path": "test/fixtures/AsyncImport.vue",
    "content": "<script setup lang=\"ts\">\nimport { defineAsyncComponent } from '@vue/composition-api'\nconst ScriptOnly = defineAsyncComponent(() => import('./ScriptOnly.vue'))\n</script>\n\n<template>\n  <ScriptOnly />\n</template>\n"
  },
  {
    "path": "test/fixtures/ComponentsDirectives.vue",
    "content": "<template>\n  <div>\n    <FooView\n      v-if=\"now > 0\"\n      ref=\"fooView\"\n      v-foo-bar=\"message0\"\n      v-d0-demo:foo.a.b=\"message1\"\n      v-d1-modifiers.a=\"message2\"\n      v-d2-modifiers-no-value.b.c\n      v-d3-arg:click=\"message3\"\n      v-d4-arg-no-value:click\n      v-d5-arg-dynamic:[direction1+direction2.length].c=\"message4\"\n      v-d6-arg-dynamic-no-value:[direction3]\n      v-d6-arg-dynamic-no-value:shouldNotUsed\n    >\n      <template #[slotName]=\"{ foo = 1 }\">\n        <div>\n          good {{ foo }}\n        </div>\n      </template>\n      <template v-slot:default=\"bar\">\n        <div>\n          good {{ bar }}\n        </div>\n      </template>\n    </FooView>\n    <button v-else-if=\"now === 0\" :[propNamePrefix+propName]=\"1\" @[eventPrefix.value+eventName]=\"console.log($event)\"></button>\n    <router-view v-else></router-view>\n    <img src=\"https://vuejs.org/images/logo.svg\">\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref } from '@vue/runtime-dom'\nimport FooView from './FooView.vue'\nimport { vFooBar, vDemo as vD0Demo, vD1Modifiers, vD2ModifiersNoValue, vD3Arg, vD4ArgNoValue, vD5ArgDynamic, vD6ArgDynamicNoValue } from './directive'\n\nconst fooView = ref<null | InstanceType<typeof FooView>>(null)\nconst message0 = ref('hello')\nconst message1 = ref('hello')\nconst message2 = ref('hello')\nconst message3 = ref('hello')\nconst message4 = ref('hello')\nconst direction1 = ref('top')\nconst direction2 = ref('top')\nconst direction3 = ref('top')\nconst shouldNotUsed = ref('')\n\nconst propNamePrefix = 'vue-'\nconst propName = 'color'\nconst eventPrefix = { value: 'vue-' }\nconst eventName = ''\n\nconst console = globalThis.console\nconst now = Date.now()\nconst slotName = 'footer'\n</script>\n"
  },
  {
    "path": "test/fixtures/ComponentsDirectivesLocal.vue",
    "content": "<script lang=\"ts\">\nimport type { ObjectDirective } from '@vue/composition-api'\n// enables v-focus in templates\nconst vFocus: ObjectDirective<HTMLInputElement, null> = {\n  inserted: (el, binding, vnode, oldVnode) => {\n    el.focus()\n  },\n}\n</script>\n<script setup lang=\"ts\"></script>\n<template>\n  <input v-focus=\"null\">\n</template>\n"
  },
  {
    "path": "test/fixtures/ComponentsLocal.vue",
    "content": "<script lang=\"tsx\">\nconst HelloComponent = ({ name }: { name: string }) => <span>Hello, {name}</span>\n</script>\n<script setup lang=\"tsx\"></script>\n<template>\n  <HelloComponent name=\"Evan You\" />\n</template>\n"
  },
  {
    "path": "test/fixtures/DynamicStyle.vue",
    "content": "<template>\n  <div :style=\"{ color, border: '1px' }\" />\n</template>\n\n<script setup lang=\"ts\">\nconst color = computed(() => 'red')\n</script>\n"
  },
  {
    "path": "test/fixtures/Empty.vue",
    "content": ""
  },
  {
    "path": "test/fixtures/Enum.vue",
    "content": "<template>\n  <div>{{ MyEnum }}</div>\n</template>\n\n<script setup lang=\"ts\">\nenum MyEnum {\n  test = 'true',\n}\n</script>\n"
  },
  {
    "path": "test/fixtures/HtmlTag.vue",
    "content": "<script setup lang=\"ts\">\nimport Enum from './Enum.vue'\nimport { ref } from '@vue/composition-api';\n\nlet p = \"hello word\";\nlet Div = ref(\"hello word\");\nlet h3 = 'test'\nlet H3 = ''\n</script>\n\n<template>\n  <div>\n    <Enum />\n    <h3></h3>\n    {{ H3 }}\n    {{ h3 }}\n    {{ Div }}\n    <p>{{ p }}</p>\n  </div>\n</template>\n"
  },
  {
    "path": "test/fixtures/HtmlTag2.vue",
    "content": "<script setup lang=\"ts\">\nimport Button from './DynamicStyle.vue';\nimport button from './DynamicStyle.vue';\nimport { defineAsyncComponent } from '@vue/composition-api'\nconst footer = defineAsyncComponent(() => import('./ScriptOnly.vue'))\n\nimport { ref } from '@vue/composition-api';\n\nconst p = ref(\"hello word\");\n\n</script>\n\n<template>\n  <div>\n    <p>{{ p }}</p>\n    <button>{{ Button }}</button>\n    <Button>{{ button }}</Button>\n    <footer>FOOTER</footer>\n  </div>\n</template>\n"
  },
  {
    "path": "test/fixtures/JSLongComment.vue",
    "content": "<script setup lang=\"ts\">\nconst a = 1\n////////////////\n</script>\n<template>\n  <div>{{ a }}</div>\n</template>\n"
  },
  {
    "path": "test/fixtures/Macros.vue",
    "content": "<template>\n  <div @click=\"emit(props.msg)\">{{ msg }}</div>\n</template>\n\n<script setup lang=\"js\">\nconst props = defineProps({\n  msg: String,\n})\n\nconst emit = defineEmits(['msg', 'update'])\n</script>\n"
  },
  {
    "path": "test/fixtures/MacrosDefineExpose.vue",
    "content": "<template>\n  <div>{{ a }}</div>\n  <div>{{ text?.length ?? textLengthDefault }}</div>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref } from '@vue/composition-api'\n\nconst a = ref(1)\nconst b = 1\nconst text = 'hello'\nconst textLengthDefault = 0\ndefineExpose({ b })\n</script>\n"
  },
  {
    "path": "test/fixtures/MacrosPure.vue",
    "content": "<template>\n  <div>{{ msg }}</div>\n</template>\n\n<script setup>\ndefineEmits()\ndefineProps({\n  msg: String,\n})\n</script>\n"
  },
  {
    "path": "test/fixtures/MacrosType.vue",
    "content": "<template>\n  <div @click=\"emit('update', props.msg)\">\n    {{ msg }}\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nconst props = withDefaults(\n  defineProps<{ msg: string; value: number | string; data?: { value: boolean } }>(),\n  { msg: 'Hello' },\n)\n\nconst emit = defineEmits(['update'])\n</script>\n"
  },
  {
    "path": "test/fixtures/MacrosType2.vue",
    "content": "<template>\n  <div @click=\"emit(props.msg)\">\n    {{ msg }}\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nexport interface Props {\n  msg: string\n  value: number | string\n  data?: { value: boolean }\n  arr?: [number, string, {}]\n  any: any\n}\n\nconst props = withDefaults(\n  defineProps<Props>(),\n  { msg: 'Hello' },\n)\n\nconst emit = defineEmits<{\n  (msg: string): void\n  (msg: number): number\n}>()\n</script>\n"
  },
  {
    "path": "test/fixtures/MacrosType3.vue",
    "content": "<template>\n  <div @click=\"emit('update', msg);emit('update', msg + value);\">\n    {{ msg }}\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nwithDefaults(\n  defineProps<{ msg: string; value: number | string; data?: { value: boolean } }>(),\n  { msg: 'Hello' },\n)\n\nconst emit = defineEmits(['update'])\nconst value = 'bar'\n</script>\n"
  },
  {
    "path": "test/fixtures/MacrosType4.vue",
    "content": "<script setup lang=\"ts\">\ntype Test = number[]\nwithDefaults(\n  defineProps<{ test: Test }>(),\n  { test: () => [] },\n)\n</script>\n"
  },
  {
    "path": "test/fixtures/MacrosType5.vue",
    "content": "<script setup lang=\"ts\">\ndefineSlots<{\n  default: { msg: string }\n}>()\n</script>\n"
  },
  {
    "path": "test/fixtures/MacrosType6.vue",
    "content": "<script setup lang=\"ts\">\nconst slots = defineSlots<{\n  default: { msg: string }\n}>()\n</script>\n<template>\n  <template v-if=\"slots.default\">\n    <slot name=\"default\" msg=\"hello\"></slot>\n  </template>\n  <div v-else>\n    fallback\n  </div>\n</template>\n"
  },
  {
    "path": "test/fixtures/MacrosTypeAny.vue",
    "content": "<template>\n  <div>\n    {{ value }}\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nconst props = defineProps<{ value: any }>()\n</script>\n"
  },
  {
    "path": "test/fixtures/Object1.vue",
    "content": "<template>\n  <div>\n    {{ data }} {{ title }}\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nconst data = {\n  title: 'Template Only',\n}\n</script>\n"
  },
  {
    "path": "test/fixtures/ObjectDestructure.vue",
    "content": "<template>\n  <div></div>\n</template>\n\n<script setup>\nimport { toRefs, reactive } from 'vue'\nconst state = reactive({ data: 'hello' })\nconst { data } = toRefs(state)\n</script>\n"
  },
  {
    "path": "test/fixtures/Pug1.vue",
    "content": "<template lang=\"pug\">\n.root\n  span {{ data }} {{ title }}\n  .p-1(@click=\"foo\")\n</template>\n\n<script setup lang=\"ts\">\nconst data = {\n  title: 'Template Only',\n}\n\nfunction foo() {}\n</script>\n"
  },
  {
    "path": "test/fixtures/RefSugar.ts",
    "content": "/* eslint-disable unused-imports/no-unused-vars */\n/* eslint-disable prefer-const */\nimport { ref } from '@vue/composition-api'\n\nlet ref1 = $(ref('hello'))\nref1 = 'world'\nlet ref1Raw = $$(ref1)\n\nlet ref2 = $ref('hello')\nref2 = 'world'\nlet ref2Raw = $$(ref2)\n\nlet computed1 = $computed(() => ref2 += ' str')\nlet computed1Raw = $$(computed1)\n"
  },
  {
    "path": "test/fixtures/RefSugar.vue",
    "content": "<template>\n  <div>\n    {{ msg }}\n    {{ msg2 }}\n    {{ a }}\n  </div>\n</template>\n\n<script lang=\"ts\">\n/* eslint-disable prefer-const */\nimport { defineComponent, ref } from '@vue/composition-api'\n\nexport default defineComponent({\n  setup() {\n    let msg = $(ref('hello world'))\n\n    return {\n      msg,\n      msgRef: $$(msg),\n    }\n  },\n})\n</script>\n\n<script setup lang=\"ts\">\nlet msg2 = $ref('hello world')\n\nlet a: number\n\na = 2\n</script>\n"
  },
  {
    "path": "test/fixtures/RefSugarScriptSetup.vue",
    "content": "<template>\n  <div>\n    {{ msg }}\n  </div>\n</template>\n\n<script setup lang=\"ts\">\n/* eslint-disable prefer-const */\n\nlet msg = $ref('hello world')\n</script>\n"
  },
  {
    "path": "test/fixtures/ScriptLessThanOrEqualTo.vue",
    "content": "<script setup lang=\"ts\">\nconst val: boolean = 1 <= 2\n</script>\n\n<template>\n  <div>{{ val }}</div>\n</template>\n"
  },
  {
    "path": "test/fixtures/ScriptOnly.vue",
    "content": "<script lang=\"ts\">\n// <script setup> in comment should not be matched\nimport { defineComponent } from '@vue/composition-api'\n\nexport default defineComponent({\n  name: 'Hi',\n})\n</script>\n\n<!-- <script setup> -->\n"
  },
  {
    "path": "test/fixtures/TemplateOnly.vue",
    "content": "<template>\n  <div>\n    <div v-for=\"(item, index) in items\" :key=\"item\">\n      {{ index }}: {{ item }}\n    </div>\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nconst items = [\n  { name: 'Item 1', value: 1 },\n  { name: 'Item 2', value: 2 },\n  { name: 'Item 3', value: 3 },\n  { name: 'Item 4', value: 4 },\n]\n</script>\n"
  },
  {
    "path": "test/fixtures/TemplateOptionalChaining.vue",
    "content": "<template>\n  <div @click=\"callback?.()\">\n    {{ text?.length ?? textLengthDefault?.[index] }}\n    {{ classes?.[0] }}\n    {{ arrayObj.data.value[i] }}\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref } from '@vue/composition-api'\nconst text = 'hello'\nconst textLengthDefault = ''\nconst index = ref(0)\n\nconst callback = undefined as undefined | (() => void)\nconst classes = undefined as undefined | string[]\nconst arrayObj = { data: { value: [1, 2, 3] } }\nconst i = 0\n</script>\n"
  },
  {
    "path": "test/fixtures/VFor.vue",
    "content": "<template>\n  <div>\n    <div v-for=\"(item, index) in items\" :key=\"item\">\n      {{ item }}\n    </div>\n    <div v-for=\"{ cargo_key, in_of } in items2\">\n      {{ cargo_key }}\n    </div>\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nconst items = [\n  { name: 'Item 1', value: 1 },\n  { name: 'Item 2', value: 2 },\n  { name: 'Item 3', value: 3 },\n  { name: 'Item 4', value: 4 },\n]\n\nconst items2 = [\n  { cargo_key: 'cargo_key', in_of: 'in' },\n]\n\nconst index = 0\n</script>\n"
  },
  {
    "path": "test/fixtures/VariableBinding.vue",
    "content": "<script setup lang=\"ts\">\n/* eslint-disable no-console */\nimport { reactive } from '@vue/composition-api'\nconst state = reactive({ value: '' })\nfunction showEvent(event: MouseEvent) {\n  console.log(event)\n}\nconst emit = defineEmits<{\n  (event: 'foo'): void\n}>()\n</script>\n<template>\n  <div\n    @click=\"\n      state.value = `x: ${$event.x}`\n      showEvent($event)\n      emit('foo')\n    \"\n  >\n    2333\n  </div>\n</template>\n"
  },
  {
    "path": "test/identifiers.test.ts",
    "content": "/* eslint-disable no-template-curly-in-string */\nimport { parse } from '@babel/parser'\nimport { describe, expect, it } from 'vitest'\nimport { getIdentifierDeclarations, getIdentifierUsages } from '../src/core/identifiers'\n\ndescribe('identifiers', () => {\n  describe('should identifier declarations', () => {\n    const cases: [string, string[]][] = [\n      ['var a = 1', ['a']],\n      ['import { foo, t as bar } from \"z\"', ['foo', 'bar']],\n      ['import foo from \"z\"', ['foo']],\n      ['import Button from \\'./DynamicStyle.vue\\'', ['Button']],\n      ['import button from \\'./DynamicStyle.vue\\'', ['button']],\n      ['import * as foo from \"z\"', ['foo']],\n      ['function foo(bar) {const a = z}', ['foo']],\n      ['console.log(foo)', []],\n      ['var { data } = toRefs(state)', ['data']],\n      ['const { data, ...args } = bar', ['data', 'args']],\n      ['const { foo: bar } = bar', ['bar']],\n      ['const { foo: { a, b: c, d: { e: [f] } } } = { bar }', ['a', 'c', 'f']],\n      ['let [a, b,, ...c] = bar', ['a', 'b', 'c']],\n      ['let [a, b, [c, {d}],, ...e] = bar', ['a', 'b', 'c', 'd', 'e']],\n      ['class A extends B {}', ['A']],\n    ]\n\n    for (const [input, output] of cases) {\n      it(input, () => {\n        const ast = parse(input, {\n          sourceType: 'module',\n        })\n\n        expect(new Set(getIdentifierDeclarations(ast.program.body))).toEqual(new Set(output))\n      })\n    }\n  })\n\n  describe('should identifier usages', () => {\n    const cases: [string, string[]][] = [\n      ['foo', ['foo']],\n      ['foo.bar', ['foo']],\n      ['foo(bar, console.log, ...args)', ['foo', 'bar', 'console', 'args']],\n      ['foo(bar())', ['foo', 'bar']],\n      ['for (let x in foo) {}', ['foo']],\n      ['for (let [x, idx] of foo) {}', ['foo']],\n      ['a + b', ['a', 'b']],\n      ['a ? \"\" : b < c', ['a', 'b', 'c']],\n      ['a == b && a === c || d != e', ['a', 'b', 'c', 'd', 'e']],\n      ['({ a, b, ...args, [c]: 1, d: e, f: { g } })', ['a', 'b', 'args', 'c', 'e', 'g']],\n      ['!a', ['a']],\n      ['!!c', ['c']],\n      ['[a,b,[c,{d}],...args]', ['a', 'b', 'c', 'd', 'args']],\n      ['new Foo(a,[b,,c])', ['Foo', 'a', 'b', 'c']],\n      ['new RC.Foo()', ['RC']],\n      ['() => foo(bar)', ['foo', 'bar']],\n      ['() => { foo() + bar; a }', ['foo', 'bar', 'a']],\n      ['(function () { foo() + bar })', ['foo', 'bar']],\n      ['function foobar() { return foo() + bar }', ['foo', 'bar']],\n      ['`${foo}bar`', ['foo']],\n      ['`${foo(zag)}` + bar', ['foo', 'zag', 'bar']],\n    ]\n\n    for (const [input, output] of cases) {\n      it(input, () => {\n        const nodes = parse(input).program.body\n        const i = new Set<string>()\n        nodes.forEach(node => getIdentifierUsages(node, i))\n        expect(i).toEqual(new Set(output))\n      })\n    }\n  })\n})\n"
  },
  {
    "path": "test/nativeTag.test.ts",
    "content": "import { describe, expect, it } from 'vitest'\nimport { transform } from '../src'\n\ndescribe('filter native tags as vue components', () => {\n  describe('no components output', () => {\n    const cases: string[] = [\n      `\n      <script setup lang=\"ts\">\n      import button from './DynamicStyle.vue';\n      </script>\n      \n      <template>\n        <button>{{ Button }}</button>\n      </template>\n      `,\n      `\n      <script setup lang=\"ts\">\n      let p='hello'\n      let Div='hello'\n      </script>\n      \n      <template>\n        <div>\n          <p>{{ p }}</p>\n          <Button>{{ Div }}</Button>\n        </div>\n      </template>\n      `,\n      `\n      <script setup lang=\"ts\">\n      let svg='hello'\n      </script>\n      \n      <template>\n        <div>\n          <p>{{ svg }}</p>\n          <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 283.46 283.46\">\n            <defs>\n              <style>\n                .cls-1{fill:#231815;}\n                @media (prefers-color-scheme: dark) { .cls-1{fill:#ffffff;} }\n              </style>\n            </defs>\n            <path class=\"cls-1\" d=\"M144.89,89.86c-33.46,0-54.44,14.56-66.14,26.76a86,86,0,0,0-23.69,58.94c0,22.64,8.81,43.48,24.8,58.67,15.7,14.92,36.9,23.14,59.68,23.14,23.81,0,46-8.49,62.49-23.91,17-15.9,26.37-37.93,26.37-62C228.4,120.37,185.94,89.86,144.89,89.86Zm.49,153.67a61.49,61.49,0,0,1-46.45-20.4c-12.33-13.76-18.85-32.64-18.85-54.62,0-20.7,6.07-37.67,17.57-49.07,10.11-10,24.39-15.62,40.19-15.74,19,0,35.22,6.56,46.76,19,12.6,13.58,19.27,34,19.27,58.95C203.87,224.39,174.49,243.53,145.38,243.53Z\"/>\n            <polygon class=\"cls-1\" points=\"198.75 74.96 179.45 74.96 142.09 37.83 104.51 74.96 86.14 74.96 138.09 24.25 146.81 24.25 198.75 74.96\"/>\n          </svg>\n        </div>\n      </template>\n      `,\n    ]\n\n    for (const input of cases) {\n      it(input, async () => {\n        const result = await transform(input, 'Lang.vue', { reactivityTransform: true })\n        expect(result?.code.includes('__sfc_main.components')).toEqual(false)\n      })\n    }\n  })\n\n  it('capitalized native tags as components', async () => {\n    const input = `\n    <script setup lang=\"ts\">\n    import Button from './DynamicStyle.vue';\n    </script>\n    \n    <template>\n      <Button>{{ Button }}</Button>\n    </template>\n    `\n    const result = await transform(input, 'Lang.vue', { reactivityTransform: true })\n    expect(result?.code.includes('__sfc_main.components = Object.assign({\\n  Button\\n}, __sfc_main.components);')).toEqual(true)\n  })\n\n  it('keep non-native components', async () => {\n    const input = `\n    <script setup lang=\"ts\">\n    import Button from './DynamicStyle.vue';\n    import DynamicStyle from './DynamicStyle.vue';\n    let p='hello'\n    </script>\n    \n    <template>\n      <dynamic-style/>\n      <p>{{ p }}</p>\n      <button>{{ Button }}</button>\n    </template>\n    `\n    const result = await transform(input, 'Lang.vue', { reactivityTransform: true })\n    expect(result?.code.includes('__sfc_main.components = Object.assign({\\n  DynamicStyle\\n}, __sfc_main.components);')).toEqual(true)\n  })\n})\n"
  },
  {
    "path": "test/transform.test.ts",
    "content": "import { resolve } from 'node:path'\nimport { promises as fs } from 'node:fs'\nimport fg from 'fast-glob'\nimport { describe, expect, it } from 'vitest'\nimport { transform } from '../src'\n\ndescribe('transform', () => {\n  describe('fixtures', () => {\n    const root = resolve(__dirname, '..')\n    const files = fg.sync([\n      'test/fixtures/*.{vue,js,ts}',\n      'playground/src/*.{vue,js,ts}',\n    ], {\n      cwd: root,\n      onlyFiles: true,\n    })\n\n    for (const file of files) {\n      it(file.replace(/\\\\/g, '/'), async () => {\n        const fixture = await fs.readFile(resolve(root, file), 'utf-8')\n        const result = (await transform(fixture, file, { reactivityTransform: true }))?.code || fixture\n        expect(result).toMatchSnapshot()\n\n        const result2 = (await transform(result, file, { reactivityTransform: true }))?.code || result\n        expect(result).toEqual(result2)\n      })\n    }\n  })\n})\n"
  },
  {
    "path": "test/transform_filter.test.ts",
    "content": "import { } from 'node:test'\nimport { describe, expect, it } from 'vitest'\nimport { scriptSetupRE } from '../src/core'\n\ndescribe('transform filter', () => {\n  describe('look for what needs to be converted by regular ', () => {\n    const cases: string[] = [\n      `<script  lang=\"tsx\"\n      setup>\n      import HelloWorld from './HelloWorld.vue'\n      </setup>`,\n      '<script  lang=\"ts\" setup>',\n      `<script \n       lang=\"ts\"\n        setup>\n        import HelloWorld from './HelloWorld.vue'\n        </script>`,\n        `<script \n        setup>\n        import HelloWorld from './HelloWorld.vue'\n        </script>`,\n        `<script setup>\n        import HelloWorld from './HelloWorld.vue'\n        </script>`,\n        `<script setup lang=\"tsx\"      >\n        import HelloWorld from './HelloWorld.vue'\n        </script>\n        `,\n        `<script setup \n        lang=\"ts\">\n        import HelloWorld from './HelloWorld.vue'\n        </script>\n        `,\n        `<script \n        setup \n                lang=\"ts\">\n        import HelloWorld from './HelloWorld.vue'\n        </script>\n                `,\n       `<script setup \n                lang=\"ts\">\n         import HelloWorld from './HelloWorld.vue'\n        </script>`,\n    ]\n\n    for (const input of cases) {\n      it(input, () => {\n        expect(scriptSetupRE.test(input)).toEqual(true)\n      })\n    }\n  })\n\n  describe('filter what is not needed by regular ', () => {\n    const cases: string[] = [\n      `<scriptlang=\"ts\"\n      setup>\n      import HelloWorld from './HelloWorld.vue'\n      </script>\n      `,\n      `<script lang=\"ts\">\n      import HelloWorld from './HelloWorld.vue'\n      </script>`,\n      `<script>\n      import HelloWorld from './HelloWorld.vue'\n      </script>\n      `,\n    ]\n\n    for (const input of cases) {\n      it(input, () => {\n        expect(scriptSetupRE.test(input)).toEqual(false)\n      })\n    }\n  })\n})\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"es2017\",\n    \"module\": \"esnext\",\n    \"lib\": [\"esnext\", \"dom\"],\n    \"moduleResolution\": \"node\",\n    \"esModuleInterop\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"strict\": true,\n    \"jsx\": \"preserve\",\n    \"strictNullChecks\": true,\n    \"isolatedModules\": true,\n    \"resolveJsonModule\": true\n  }\n}\n"
  },
  {
    "path": "types.d.ts",
    "content": "export { default } from './dist/types'\n"
  },
  {
    "path": "vite.d.ts",
    "content": "export { default } from './dist/vite'\n"
  },
  {
    "path": "webpack.d.ts",
    "content": "export { default } from './dist/webpack'\n"
  }
]