├── .prettierignore ├── .gitignore ├── .prettierrc ├── src ├── core │ ├── constants.ts │ ├── transform.ts │ ├── magic-string.ts │ └── utils.ts ├── vite.ts ├── rollup.ts ├── esbuild.ts ├── webpack.ts └── index.ts ├── .eslintignore ├── tests ├── fixtures │ ├── index3.ts │ ├── index5.ts │ ├── typescriptNormal.vue │ ├── typescript.vue │ ├── typescript5.vue │ ├── typescript7.vue │ ├── typescript6.vue │ ├── typescript10.vue │ ├── typescript-global.vue │ ├── index4.ts │ ├── typescript1.vue │ ├── typescript2.vue │ ├── typescript3.vue │ ├── index1.ts │ ├── index2.ts │ ├── typescript14.vue │ ├── typescript4.vue │ ├── typescript12.vue │ ├── typescript.vue.NotSupport │ ├── typescript13.vue │ ├── typescript11.vue │ └── index.ts ├── types │ └── index.ts ├── tsconfig.json ├── rollup.test.ts └── __snapshots__ │ └── rollup.test.ts.snap ├── playground ├── .vscode │ └── extensions.json ├── src │ ├── main.ts │ ├── vite-env.d.ts │ ├── assets │ │ └── vue.svg │ ├── App.vue │ ├── components │ │ └── HelloWorld.vue │ └── style.css ├── vite.config.ts ├── tsconfig.node.json ├── .gitignore ├── index.html ├── package.json ├── tsconfig.json ├── README.md ├── public │ └── vite.svg └── yarn.lock ├── .editorconfig ├── .eslintrc.js ├── tsup.config.ts ├── tsconfig.json ├── vite.config.ts ├── scripts └── postbuild.mts ├── LICENSE ├── package.json ├── README.md └── pnpm-lock.yaml /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | pnpm-lock.yaml 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .DS_Store 4 | .pnpm-debug.log* 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true 4 | } 5 | -------------------------------------------------------------------------------- /src/core/constants.ts: -------------------------------------------------------------------------------- 1 | export const DEFINE_PROPS_NAME = 'defineProps' 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | pnpm-lock.yaml 4 | tests/fixtures 5 | -------------------------------------------------------------------------------- /src/vite.ts: -------------------------------------------------------------------------------- 1 | import unplugin from '.' 2 | 3 | export default unplugin.vite 4 | -------------------------------------------------------------------------------- /src/rollup.ts: -------------------------------------------------------------------------------- 1 | import unplugin from '.' 2 | 3 | export default unplugin.rollup 4 | -------------------------------------------------------------------------------- /tests/fixtures/index3.ts: -------------------------------------------------------------------------------- 1 | export interface Haha { 2 | haha: string 3 | } 4 | -------------------------------------------------------------------------------- /playground/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["Vue.volar"] 3 | } 4 | -------------------------------------------------------------------------------- /src/esbuild.ts: -------------------------------------------------------------------------------- 1 | import unplugin from '.' 2 | 3 | export default unplugin.esbuild 4 | -------------------------------------------------------------------------------- /src/webpack.ts: -------------------------------------------------------------------------------- 1 | import unplugin from '.' 2 | 3 | export default unplugin.webpack 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_size = 2 5 | end_of_line = lf 6 | insert_final_newline = true 7 | -------------------------------------------------------------------------------- /tests/fixtures/index5.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | name: string 3 | age: number 4 | msg: string 5 | labels: unknown 6 | } 7 | -------------------------------------------------------------------------------- /playground/src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import './style.css' 3 | import App from './App.vue' 4 | 5 | createApp(App).mount('#app') 6 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | const { defineConfig } = require('eslint-define-config') 2 | 3 | module.exports = defineConfig({ 4 | extends: ['@sxzz/eslint-config-vue', '@sxzz/eslint-config-prettier'], 5 | }) 6 | -------------------------------------------------------------------------------- /playground/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [vue()] 7 | }) 8 | -------------------------------------------------------------------------------- /tests/types/index.ts: -------------------------------------------------------------------------------- 1 | interface Foo { 2 | name: string; 3 | } 4 | 5 | type Test = { 6 | age: number; 7 | } 8 | 9 | // export default interface Foo1 { 10 | // name: string; 11 | // } 12 | 13 | 14 | -------------------------------------------------------------------------------- /playground/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module '*.vue' { 4 | import type { DefineComponent } from 'vue' 5 | const component: DefineComponent<{}, {}, any> 6 | export default component 7 | } 8 | -------------------------------------------------------------------------------- /tests/fixtures/typescriptNormal.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | -------------------------------------------------------------------------------- /tests/fixtures/typescript.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /tests/fixtures/typescript5.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /playground/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "allowSyntheticDefaultImports": true 7 | }, 8 | "include": ["vite.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /tests/fixtures/typescript7.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /tests/fixtures/typescript6.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /tests/fixtures/typescript10.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/fixtures/typescript-global.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 19 | -------------------------------------------------------------------------------- /tests/fixtures/index4.ts: -------------------------------------------------------------------------------- 1 | export type Foo = { 2 | name: string 3 | age: number 4 | msg: string 5 | labels: unknown 6 | } 7 | 8 | // not support 9 | // export type Foo = foo 10 | 11 | // interface foo { 12 | // name: string; 13 | // age: number 14 | // } 15 | -------------------------------------------------------------------------------- /tests/fixtures/typescript1.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /tests/fixtures/typescript2.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /tests/fixtures/typescript3.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /tests/fixtures/index1.ts: -------------------------------------------------------------------------------- 1 | interface Foo { 2 | gender: string 3 | } 4 | 5 | // don't support Subsequent property declarations 6 | // 不支持后续属性声明 7 | interface Foo { 8 | age: number 9 | } 10 | 11 | export default Foo 12 | 13 | export function foo() { 14 | console.log('foo') 15 | } 16 | -------------------------------------------------------------------------------- /tests/fixtures/index2.ts: -------------------------------------------------------------------------------- 1 | // don't support 2 | // export { Haha } from "./index3" 3 | import { Haha } from "./index3" 4 | 5 | export interface Foo { 6 | name: string 7 | } 8 | 9 | export interface Test { 10 | age: number 11 | } 12 | 13 | // don't support 14 | export type haha = Haha 15 | -------------------------------------------------------------------------------- /tests/fixtures/typescript14.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 20 | -------------------------------------------------------------------------------- /tests/fixtures/typescript4.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 16 | -------------------------------------------------------------------------------- /tests/fixtures/typescript12.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/fixtures/typescript.vue.NotSupport: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /tests/fixtures/typescript13.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/fixtures/typescript11.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup' 2 | 3 | const isDev = process.env.MODE === 'dev' 4 | 5 | export default defineConfig({ 6 | entry: ['./src/**/*.ts'], 7 | format: ['cjs', 'esm'], 8 | target: 'node14', 9 | splitting: true, 10 | dts: !isDev, 11 | watch: isDev, 12 | shims: true, // https://tsup.egoist.dev/#inject-cjs-and-esm-shims 13 | }) 14 | -------------------------------------------------------------------------------- /playground/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /tests/fixtures/index.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | name: string, 3 | } 4 | 5 | // don't support Subsequent property declarations 6 | // 不支持后续属性声明 7 | export interface Foo { 8 | age: number, 9 | } 10 | 11 | interface Hoo { 12 | name: string, 13 | } 14 | 15 | export function foo() { 16 | console.log('foo') 17 | } 18 | 19 | export default interface Test { 20 | age: number 21 | } 22 | -------------------------------------------------------------------------------- /playground/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + Vue + TS 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "target": "ES2019", 5 | "module": "ESNext", 6 | "lib": ["ES2019"], 7 | "moduleResolution": "Node", 8 | "allowSyntheticDefaultImports": true, 9 | "types": ["vitest/globals"], 10 | "forceConsistentCasingInFileNames": true, 11 | "skipLibCheck": true 12 | }, 13 | "include": ["src", "tests", "scripts"], 14 | "exclude": ["tests/fixtures"] 15 | } 16 | -------------------------------------------------------------------------------- /tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "target": "ES2019", 5 | "module": "ESNext", 6 | "lib": ["ES2019"], 7 | "moduleResolution": "Node", 8 | "allowSyntheticDefaultImports": true, 9 | "types": ["vitest/globals"], 10 | "forceConsistentCasingInFileNames": true, 11 | "skipLibCheck": true, 12 | "typeRoots": ["./types"] 13 | }, 14 | "include": ["./"], 15 | "exclude": [] 16 | } 17 | -------------------------------------------------------------------------------- /playground/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "import-props-playground", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vue-tsc && vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "vue": "^3.2.41" 13 | }, 14 | "devDependencies": { 15 | "@vitejs/plugin-vue": "^3.2.0", 16 | "typescript": "^4.6.4", 17 | "vite": "^3.2.0", 18 | "vue-tsc": "^1.0.9" 19 | } 20 | } -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { defineConfig } from 'vite' 3 | 4 | export default defineConfig({ 5 | test: { 6 | globals: true, 7 | }, 8 | optimizeDeps: { 9 | include: [ 10 | '@babel/generator', 11 | '@babel/parser', 12 | '@vue/compiler-sfc', 13 | '@vue/compiler-core', 14 | '@vue/compiler-dom', 15 | '@rollup/pluginutils', 16 | 'magic-string', 17 | 'unplugin', 18 | 'typescript', 19 | ] 20 | } 21 | }) 22 | -------------------------------------------------------------------------------- /playground/src/assets/vue.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /playground/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "moduleResolution": "Node", 7 | "strict": true, 8 | "jsx": "preserve", 9 | "resolveJsonModule": true, 10 | "isolatedModules": true, 11 | "esModuleInterop": true, 12 | "lib": ["ESNext", "DOM"], 13 | "skipLibCheck": true, 14 | "noEmit": true 15 | }, 16 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], 17 | "references": [{ "path": "./tsconfig.node.json" }] 18 | } 19 | -------------------------------------------------------------------------------- /scripts/postbuild.mts: -------------------------------------------------------------------------------- 1 | import { basename, dirname, resolve } from 'path' 2 | import { readFile, writeFile } from 'fs/promises' 3 | import { fileURLToPath } from 'url' 4 | import fg from 'fast-glob' 5 | 6 | // fix cjs exports 7 | const files = await fg('*.js', { 8 | ignore: ['index.js', 'chunk-*'], 9 | absolute: true, 10 | cwd: resolve(dirname(fileURLToPath(import.meta.url)), '../dist'), 11 | }) 12 | for (const file of files) { 13 | // eslint-disable-next-line no-console 14 | console.log('[postbuild]', basename(file)) 15 | let code = await readFile(file, 'utf8') 16 | code = code.replace('exports.default =', 'module.exports =') 17 | code += 'exports.default = module.exports;' 18 | await writeFile(file, code) 19 | } 20 | -------------------------------------------------------------------------------- /src/core/transform.ts: -------------------------------------------------------------------------------- 1 | import { MagicString } from '@vue/compiler-sfc' 2 | import { DEFINE_PROPS_NAME } from './constants' 3 | import { 4 | parseSFC, 5 | } from './utils' 6 | import type { TransformResult } from 'unplugin' 7 | 8 | export const transform = async (code: string, id: string, alias: { [x: string]: string }, configPath: string): Promise => { 9 | if (!code.includes(DEFINE_PROPS_NAME)) return 10 | 11 | const sfc = await parseSFC(code, id, alias, configPath) 12 | if (!sfc) return 13 | if (!sfc.scriptSetup) return 14 | 15 | const { source } = sfc 16 | 17 | const s = new MagicString(source) 18 | // console.log(s.toString()) 19 | 20 | return { 21 | code: s.toString(), 22 | get map() { 23 | return s.generateMap({ 24 | source: id, 25 | includeContent: true, 26 | }) 27 | }, 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /playground/src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 18 | 19 | 32 | -------------------------------------------------------------------------------- /playground/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 33 | 34 | 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Albert Liu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/core/magic-string.ts: -------------------------------------------------------------------------------- 1 | import MagicStringBase from 'magic-string' 2 | import type { OverwriteOptions } from 'magic-string' 3 | import type { Node } from '@babel/types' 4 | 5 | export class MagicString extends MagicStringBase { 6 | removeNode(node: Node, { offset = 0 }: { offset?: number } = {}) { 7 | this.remove(offset + node.start!, offset + node.end!) 8 | return this 9 | } 10 | 11 | moveNode( 12 | node: Node, 13 | index: number, 14 | { offset = 0 }: { offset?: number } = {} 15 | ) { 16 | this.move(offset + node.start!, offset + node.end!, index) 17 | return this 18 | } 19 | 20 | sliceNode(node: Node, { offset = 0 }: { offset?: number } = {}) { 21 | return this.slice(offset + node.start!, offset + node.end!) 22 | } 23 | 24 | sliceNodes(nodes: Node[], { offset = 0 }: { offset?: number } = {}) { 25 | return this.slice( 26 | offset + nodes[0].start!, 27 | offset + nodes.slice(-1)[0].end! 28 | ) 29 | } 30 | 31 | overwriteNode( 32 | node: Node, 33 | content: string | Node, 34 | { offset = 0, ...options }: OverwriteOptions & { offset?: number } = {} 35 | ) { 36 | const _content = 37 | typeof content === 'string' ? content : this.sliceNode(content) 38 | this.overwrite(offset + node.start!, offset + node.end!, _content, options) 39 | return this 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /playground/README.md: -------------------------------------------------------------------------------- 1 | # Vue 3 + TypeScript + Vite 2 | 3 | This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 ` 17 | ``` 18 | app.ts 19 | ```typescript 20 | export interface Test { 21 | name: string 22 | } 23 | ``` 24 | 25 |
26 | Output 27 | 28 | ```vue 29 | 33 | ``` 34 | 35 |
36 | 37 | app.vue 38 | ```vue 39 | 43 | ``` 44 | app.ts 45 | ```typescript 46 | export interface Foo { 47 | name: string 48 | } 49 | ``` 50 | 51 |
52 | Output 53 | 54 | ```vue 55 | 59 | ``` 60 | 61 |
62 | 63 | ## Installation 64 | 65 | ```bash 66 | npm i unplugin-vue-import-props -D 67 | ``` 68 | 69 | If you want use `typeRoot` to set global types path, please add configPath like: 70 | 71 | ```ts 72 | // vite.config.ts 73 | import ImportProps from 'unplugin-vue-import-props/vite' 74 | import Vue from '@vitejs/plugin-vue' 75 | import { resolve } from 'path' 76 | 77 | export default defineConfig({ 78 | plugins: [Vue(), ImportProps({ 79 | configPath: resolve(__dirname, './tsconfig.json') 80 | })], 81 | }) 82 | ``` 83 | 84 | now you can use global types. 85 | 86 |
87 | Vite
88 | 89 | ```ts 90 | // vite.config.ts 91 | import ImportProps from 'unplugin-vue-import-props/vite' 92 | import Vue from '@vitejs/plugin-vue' 93 | 94 | export default defineConfig({ 95 | plugins: [Vue(), ImportProps()], 96 | }) 97 | ``` 98 | 99 |
100 | 101 |
102 | Rollup
103 | 104 | ```ts 105 | // rollup.config.js 106 | import ImportProps from 'unplugin-vue-import-props/rollup' 107 | 108 | export default { 109 | plugins: [ImportProps()], // Must be before Vue plugin! 110 | } 111 | ``` 112 | 113 |
114 | 115 |
116 | esbuild
117 | 118 | ```ts 119 | // esbuild.config.js 120 | import { build } from 'esbuild' 121 | 122 | build({ 123 | plugins: [ 124 | require('unplugin-vue-import-props/esbuild')(), // Must be before Vue plugin! 125 | ], 126 | }) 127 | ``` 128 | 129 |
130 | 131 |
132 | Webpack
133 | 134 | ```ts 135 | // webpack.config.js 136 | module.exports = { 137 | /* ... */ 138 | plugins: [require('unplugin-vue-import-props/webpack')()], 139 | } 140 | ``` 141 | 142 |
143 | 144 |
145 | Vue CLI
146 | 147 | ```ts 148 | // vue.config.js 149 | module.exports = { 150 | configureWebpack: { 151 | plugins: [require('unplugin-vue-import-props/webpack')()], 152 | }, 153 | } 154 | ``` 155 | 156 |
157 | 158 | #### TypeScript Support 159 | 160 | ```jsonc 161 | // tsconfig.json 162 | { 163 | "compilerOptions": { 164 | // ... 165 | "types": ["unplugin-vue-import-props" /* ... */] 166 | } 167 | } 168 | ``` 169 | #### Related articles 170 | 171 | https://www.yuque.com/docs/share/4bd70f56-a3e2-4296-843c-08550288c70f?# 172 | 173 | 174 | Plugin Template: [unplugin-vue-macros](https://github.com/sxzz/unplugin-vue-macros) 175 | 176 | > With great appreciation to this project [unplugin-vue-macros](https://github.com/sxzz/unplugin-vue-macros) and its owners [三咲智子](https://github.com/sxzz) and [contributors](https://github.com/sxzz/unplugin-vue-macros/graphs/contributors), this project was created using this project as a template 177 | 178 | -------------------------------------------------------------------------------- /tests/__snapshots__/rollup.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Vitest Snapshot v1 2 | 3 | exports[`transform > fixtures > tests/fixtures/typescript.vue 1`] = ` 4 | "var typescript = \` 9 | 10 | 15 | \`; 16 | 17 | export { typescript as default }; 18 | " 19 | `; 20 | 21 | exports[`transform > fixtures > tests/fixtures/typescript-global.vue 1`] = ` 22 | "var typescriptGlobal = \` 34 | 35 | 40 | \`; 41 | 42 | export { typescriptGlobal as default }; 43 | " 44 | `; 45 | 46 | exports[`transform > fixtures > tests/fixtures/typescript1.vue 1`] = ` 47 | "var typescript1 = \` 54 | 55 | 60 | \`; 61 | 62 | export { typescript1 as default }; 63 | " 64 | `; 65 | 66 | exports[`transform > fixtures > tests/fixtures/typescript2.vue 1`] = ` 67 | "var typescript2 = \` 74 | 75 | 80 | \`; 81 | 82 | export { typescript2 as default }; 83 | " 84 | `; 85 | 86 | exports[`transform > fixtures > tests/fixtures/typescript3.vue 1`] = ` 87 | "var typescript3 = \` 94 | 95 | 100 | \`; 101 | 102 | export { typescript3 as default }; 103 | " 104 | `; 105 | 106 | exports[`transform > fixtures > tests/fixtures/typescript4.vue 1`] = ` 107 | "var typescript4 = \` 116 | 117 | 122 | \`; 123 | 124 | export { typescript4 as default }; 125 | " 126 | `; 127 | 128 | exports[`transform > fixtures > tests/fixtures/typescript5.vue 1`] = ` 129 | "var typescript5 = \` 134 | 135 | 140 | \`; 141 | 142 | export { typescript5 as default }; 143 | " 144 | `; 145 | 146 | exports[`transform > fixtures > tests/fixtures/typescript6.vue 1`] = ` 147 | "var typescript6 = \` 152 | 153 | 158 | \`; 159 | 160 | export { typescript6 as default }; 161 | " 162 | `; 163 | 164 | exports[`transform > fixtures > tests/fixtures/typescript7.vue 1`] = ` 165 | "var typescript7 = \` 170 | 171 | 176 | \`; 177 | 178 | export { typescript7 as default }; 179 | " 180 | `; 181 | 182 | exports[`transform > fixtures > tests/fixtures/typescript10.vue 1`] = ` 183 | "var typescript10 = \` 186 | 187 | 192 | 193 | 194 | \`; 195 | 196 | export { typescript10 as default }; 197 | " 198 | `; 199 | 200 | exports[`transform > fixtures > tests/fixtures/typescript11.vue 1`] = ` 201 | "var typescript11 = \` 204 | 205 | 213 | 214 | 215 | \`; 216 | 217 | export { typescript11 as default }; 218 | " 219 | `; 220 | 221 | exports[`transform > fixtures > tests/fixtures/typescript12.vue 1`] = ` 222 | "var typescript12 = \` 225 | 226 | 233 | 234 | 235 | \`; 236 | 237 | export { typescript12 as default }; 238 | " 239 | `; 240 | 241 | exports[`transform > fixtures > tests/fixtures/typescript13.vue 1`] = ` 242 | "var typescript13 = \` 245 | 246 | 253 | 254 | 255 | \`; 256 | 257 | export { typescript13 as default }; 258 | " 259 | `; 260 | 261 | exports[`transform > fixtures > tests/fixtures/typescript14.vue 1`] = ` 262 | "var typescript14 = \` 275 | 276 | 281 | \`; 282 | 283 | export { typescript14 as default }; 284 | " 285 | `; 286 | 287 | exports[`transform > fixtures > tests/fixtures/typescriptNormal.vue 1`] = ` 288 | "var typescriptNormal = \` 294 | 295 | 300 | \`; 301 | 302 | export { typescriptNormal as default }; 303 | " 304 | `; 305 | -------------------------------------------------------------------------------- /playground/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@babel/parser@^7.16.4": 6 | version "7.20.1" 7 | resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.20.1.tgz#3e045a92f7b4623cafc2425eddcb8cf2e54f9cc5" 8 | integrity sha512-hp0AYxaZJhxULfM1zyp7Wgr+pSUKBcP3M+PHnSzWGdXOzg/kHWIgiUWARvubhUKGOEw3xqY4x+lyZ9ytBVcELw== 9 | 10 | "@esbuild/android-arm@0.15.13": 11 | version "0.15.13" 12 | resolved "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.15.13.tgz#ce11237a13ee76d5eae3908e47ba4ddd380af86a" 13 | integrity sha512-RY2fVI8O0iFUNvZirXaQ1vMvK0xhCcl0gqRj74Z6yEiO1zAUa7hbsdwZM1kzqbxHK7LFyMizipfXT3JME+12Hw== 14 | 15 | "@esbuild/linux-loong64@0.15.13": 16 | version "0.15.13" 17 | resolved "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.15.13.tgz#64e8825bf0ce769dac94ee39d92ebe6272020dfc" 18 | integrity sha512-+BoyIm4I8uJmH/QDIH0fu7MG0AEx9OXEDXnqptXCwKOlOqZiS4iraH1Nr7/ObLMokW3sOCeBNyD68ATcV9b9Ag== 19 | 20 | "@vitejs/plugin-vue@^3.2.0": 21 | version "3.2.0" 22 | resolved "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-3.2.0.tgz#a1484089dd85d6528f435743f84cdd0d215bbb54" 23 | integrity sha512-E0tnaL4fr+qkdCNxJ+Xd0yM31UwMkQje76fsDVBBUCoGOUPexu2VDUYHL8P4CwV+zMvWw6nlRw19OnRKmYAJpw== 24 | 25 | "@volar/language-core@1.0.9": 26 | version "1.0.9" 27 | resolved "https://registry.npmjs.org/@volar/language-core/-/language-core-1.0.9.tgz#d12456b294d1e5b3928b22e5214c8e7141ee2ce1" 28 | integrity sha512-5Fty3slLet6svXiJw2YxhYeo6c7wFdtILrql5bZymYLM+HbiZtJbryW1YnUEKAP7MO9Mbeh+TNH4Z0HFxHgIqw== 29 | dependencies: 30 | "@volar/source-map" "1.0.9" 31 | "@vue/reactivity" "^3.2.40" 32 | muggle-string "^0.1.0" 33 | 34 | "@volar/source-map@1.0.9": 35 | version "1.0.9" 36 | resolved "https://registry.npmjs.org/@volar/source-map/-/source-map-1.0.9.tgz#00aa951d3d7f9b842f84e28ab2a1831ab3b5b95a" 37 | integrity sha512-fazB/vy5ZEJ3yKx4fabJyGNI3CBkdLkfEIRVu6+1P3VixK0Mn+eqyUIkLBrzGYaeFM3GybhCLCvsVdNz0Fu/CQ== 38 | dependencies: 39 | muggle-string "^0.1.0" 40 | 41 | "@volar/typescript@1.0.9": 42 | version "1.0.9" 43 | resolved "https://registry.npmjs.org/@volar/typescript/-/typescript-1.0.9.tgz#9c0a8b5d79c0a03413755499d211c1c8001ac0cc" 44 | integrity sha512-dVziu+ShQUWuMukM6bvK2v2O446/gG6l1XkTh2vfkccw1IzjfbiP1TWQoNo1ipTfZOtu5YJGYAx+o5HNrGXWfQ== 45 | dependencies: 46 | "@volar/language-core" "1.0.9" 47 | 48 | "@volar/vue-language-core@1.0.9": 49 | version "1.0.9" 50 | resolved "https://registry.npmjs.org/@volar/vue-language-core/-/vue-language-core-1.0.9.tgz#9eb7c30652c80f210fca071aeeea794873835eda" 51 | integrity sha512-tofNoR8ShPFenHT1YVMuvoXtXWwoQE+fiXVqSmW0dSKZqEDjWQ3YeXSd0a6aqyKaIbvR7kWWGp34WbpQlwf9Ww== 52 | dependencies: 53 | "@volar/language-core" "1.0.9" 54 | "@volar/source-map" "1.0.9" 55 | "@vue/compiler-dom" "^3.2.40" 56 | "@vue/compiler-sfc" "^3.2.40" 57 | "@vue/reactivity" "^3.2.40" 58 | "@vue/shared" "^3.2.40" 59 | minimatch "^5.1.0" 60 | vue-template-compiler "^2.7.10" 61 | 62 | "@volar/vue-typescript@1.0.9": 63 | version "1.0.9" 64 | resolved "https://registry.npmjs.org/@volar/vue-typescript/-/vue-typescript-1.0.9.tgz#47ae4424283ec42c0b3321a4efbd4c505de3fe16" 65 | integrity sha512-ZLe4y9YNbviACa7uAMCilzxA76gbbSlKfjspXBzk6fCobd8QCIig+VyDYcjANIlm2HhgSCX8jYTzhCKlegh4mw== 66 | dependencies: 67 | "@volar/typescript" "1.0.9" 68 | "@volar/vue-language-core" "1.0.9" 69 | 70 | "@vue/compiler-core@3.2.41": 71 | version "3.2.41" 72 | resolved "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.2.41.tgz#fb5b25f23817400f44377d878a0cdead808453ef" 73 | integrity sha512-oA4mH6SA78DT+96/nsi4p9DX97PHcNROxs51lYk7gb9Z4BPKQ3Mh+BLn6CQZBw857Iuhu28BfMSRHAlPvD4vlw== 74 | dependencies: 75 | "@babel/parser" "^7.16.4" 76 | "@vue/shared" "3.2.41" 77 | estree-walker "^2.0.2" 78 | source-map "^0.6.1" 79 | 80 | "@vue/compiler-dom@3.2.41", "@vue/compiler-dom@^3.2.40": 81 | version "3.2.41" 82 | resolved "https://registry.npmjs.org/@vue/compiler-dom/-/compiler-dom-3.2.41.tgz#dc63dcd3ce8ca8a8721f14009d498a7a54380299" 83 | integrity sha512-xe5TbbIsonjENxJsYRbDJvthzqxLNk+tb3d/c47zgREDa/PCp6/Y4gC/skM4H6PIuX5DAxm7fFJdbjjUH2QTMw== 84 | dependencies: 85 | "@vue/compiler-core" "3.2.41" 86 | "@vue/shared" "3.2.41" 87 | 88 | "@vue/compiler-sfc@3.2.41", "@vue/compiler-sfc@^3.2.40": 89 | version "3.2.41" 90 | resolved "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.2.41.tgz#238fb8c48318408c856748f4116aff8cc1dc2a73" 91 | integrity sha512-+1P2m5kxOeaxVmJNXnBskAn3BenbTmbxBxWOtBq3mQTCokIreuMULFantBUclP0+KnzNCMOvcnKinqQZmiOF8w== 92 | dependencies: 93 | "@babel/parser" "^7.16.4" 94 | "@vue/compiler-core" "3.2.41" 95 | "@vue/compiler-dom" "3.2.41" 96 | "@vue/compiler-ssr" "3.2.41" 97 | "@vue/reactivity-transform" "3.2.41" 98 | "@vue/shared" "3.2.41" 99 | estree-walker "^2.0.2" 100 | magic-string "^0.25.7" 101 | postcss "^8.1.10" 102 | source-map "^0.6.1" 103 | 104 | "@vue/compiler-ssr@3.2.41": 105 | version "3.2.41" 106 | resolved "https://registry.npmjs.org/@vue/compiler-ssr/-/compiler-ssr-3.2.41.tgz#344f564d68584b33367731c04ffc949784611fcb" 107 | integrity sha512-Y5wPiNIiaMz/sps8+DmhaKfDm1xgj6GrH99z4gq2LQenfVQcYXmHIOBcs5qPwl7jaW3SUQWjkAPKMfQemEQZwQ== 108 | dependencies: 109 | "@vue/compiler-dom" "3.2.41" 110 | "@vue/shared" "3.2.41" 111 | 112 | "@vue/reactivity-transform@3.2.41": 113 | version "3.2.41" 114 | resolved "https://registry.npmjs.org/@vue/reactivity-transform/-/reactivity-transform-3.2.41.tgz#9ff938877600c97f646e09ac1959b5150fb11a0c" 115 | integrity sha512-mK5+BNMsL4hHi+IR3Ft/ho6Za+L3FA5j8WvreJ7XzHrqkPq8jtF/SMo7tuc9gHjLDwKZX1nP1JQOKo9IEAn54A== 116 | dependencies: 117 | "@babel/parser" "^7.16.4" 118 | "@vue/compiler-core" "3.2.41" 119 | "@vue/shared" "3.2.41" 120 | estree-walker "^2.0.2" 121 | magic-string "^0.25.7" 122 | 123 | "@vue/reactivity@3.2.41", "@vue/reactivity@^3.2.40": 124 | version "3.2.41" 125 | resolved "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.2.41.tgz#0ad3bdf76d76822da1502dc9f394dafd02642963" 126 | integrity sha512-9JvCnlj8uc5xRiQGZ28MKGjuCoPhhTwcoAdv3o31+cfGgonwdPNuvqAXLhlzu4zwqavFEG5tvaoINQEfxz+l6g== 127 | dependencies: 128 | "@vue/shared" "3.2.41" 129 | 130 | "@vue/runtime-core@3.2.41": 131 | version "3.2.41" 132 | resolved "https://registry.npmjs.org/@vue/runtime-core/-/runtime-core-3.2.41.tgz#775bfc00b3fadbaddab77138f23322aee3517a76" 133 | integrity sha512-0LBBRwqnI0p4FgIkO9q2aJBBTKDSjzhnxrxHYengkAF6dMOjeAIZFDADAlcf2h3GDALWnblbeprYYpItiulSVQ== 134 | dependencies: 135 | "@vue/reactivity" "3.2.41" 136 | "@vue/shared" "3.2.41" 137 | 138 | "@vue/runtime-dom@3.2.41": 139 | version "3.2.41" 140 | resolved "https://registry.npmjs.org/@vue/runtime-dom/-/runtime-dom-3.2.41.tgz#cdf86be7410f7b15c29632a96ce879e5b4c9ab92" 141 | integrity sha512-U7zYuR1NVIP8BL6jmOqmapRAHovEFp7CSw4pR2FacqewXNGqZaRfHoNLQsqQvVQ8yuZNZtxSZy0FFyC70YXPpA== 142 | dependencies: 143 | "@vue/runtime-core" "3.2.41" 144 | "@vue/shared" "3.2.41" 145 | csstype "^2.6.8" 146 | 147 | "@vue/server-renderer@3.2.41": 148 | version "3.2.41" 149 | resolved "https://registry.npmjs.org/@vue/server-renderer/-/server-renderer-3.2.41.tgz#ca64552c05878f94e8d191ac439141c06c0fb2ad" 150 | integrity sha512-7YHLkfJdTlsZTV0ae5sPwl9Gn/EGr2hrlbcS/8naXm2CDpnKUwC68i1wGlrYAfIgYWL7vUZwk2GkYLQH5CvFig== 151 | dependencies: 152 | "@vue/compiler-ssr" "3.2.41" 153 | "@vue/shared" "3.2.41" 154 | 155 | "@vue/shared@3.2.41", "@vue/shared@^3.2.40": 156 | version "3.2.41" 157 | resolved "https://registry.npmjs.org/@vue/shared/-/shared-3.2.41.tgz#fbc95422df654ea64e8428eced96ba6ad555d2bb" 158 | integrity sha512-W9mfWLHmJhkfAmV+7gDjcHeAWALQtgGT3JErxULl0oz6R6+3ug91I7IErs93eCFhPCZPHBs4QJS7YWEV7A3sxw== 159 | 160 | balanced-match@^1.0.0: 161 | version "1.0.2" 162 | resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" 163 | integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== 164 | 165 | brace-expansion@^2.0.1: 166 | version "2.0.1" 167 | resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" 168 | integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== 169 | dependencies: 170 | balanced-match "^1.0.0" 171 | 172 | csstype@^2.6.8: 173 | version "2.6.21" 174 | resolved "https://registry.npmjs.org/csstype/-/csstype-2.6.21.tgz#2efb85b7cc55c80017c66a5ad7cbd931fda3a90e" 175 | integrity sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w== 176 | 177 | de-indent@^1.0.2: 178 | version "1.0.2" 179 | resolved "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d" 180 | integrity sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg== 181 | 182 | esbuild-android-64@0.15.13: 183 | version "0.15.13" 184 | resolved "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.15.13.tgz#5f25864055dbd62e250f360b38b4c382224063af" 185 | integrity sha512-yRorukXBlokwTip+Sy4MYskLhJsO0Kn0/Fj43s1krVblfwP+hMD37a4Wmg139GEsMLl+vh8WXp2mq/cTA9J97g== 186 | 187 | esbuild-android-arm64@0.15.13: 188 | version "0.15.13" 189 | resolved "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.15.13.tgz#d8820f999314efbe8e0f050653a99ff2da632b0f" 190 | integrity sha512-TKzyymLD6PiVeyYa4c5wdPw87BeAiTXNtK6amWUcXZxkV51gOk5u5qzmDaYSwiWeecSNHamFsaFjLoi32QR5/w== 191 | 192 | esbuild-darwin-64@0.15.13: 193 | version "0.15.13" 194 | resolved "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.15.13.tgz#99ae7fdaa43947b06cd9d1a1c3c2c9f245d81fd0" 195 | integrity sha512-WAx7c2DaOS6CrRcoYCgXgkXDliLnFv3pQLV6GeW1YcGEZq2Gnl8s9Pg7ahValZkpOa0iE/ojRVQ87sbUhF1Cbg== 196 | 197 | esbuild-darwin-arm64@0.15.13: 198 | version "0.15.13" 199 | resolved "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.13.tgz#bafa1814354ad1a47adcad73de416130ef7f55e3" 200 | integrity sha512-U6jFsPfSSxC3V1CLiQqwvDuj3GGrtQNB3P3nNC3+q99EKf94UGpsG9l4CQ83zBs1NHrk1rtCSYT0+KfK5LsD8A== 201 | 202 | esbuild-freebsd-64@0.15.13: 203 | version "0.15.13" 204 | resolved "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.13.tgz#84ef85535c5cc38b627d1c5115623b088d1de161" 205 | integrity sha512-whItJgDiOXaDG/idy75qqevIpZjnReZkMGCgQaBWZuKHoElDJC1rh7MpoUgupMcdfOd+PgdEwNQW9DAE6i8wyA== 206 | 207 | esbuild-freebsd-arm64@0.15.13: 208 | version "0.15.13" 209 | resolved "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.13.tgz#033f21de434ec8e0c478054b119af8056763c2d8" 210 | integrity sha512-6pCSWt8mLUbPtygv7cufV0sZLeylaMwS5Fznj6Rsx9G2AJJsAjQ9ifA+0rQEIg7DwJmi9it+WjzNTEAzzdoM3Q== 211 | 212 | esbuild-linux-32@0.15.13: 213 | version "0.15.13" 214 | resolved "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.15.13.tgz#54290ea8035cba0faf1791ce9ae6693005512535" 215 | integrity sha512-VbZdWOEdrJiYApm2kkxoTOgsoCO1krBZ3quHdYk3g3ivWaMwNIVPIfEE0f0XQQ0u5pJtBsnk2/7OPiCFIPOe/w== 216 | 217 | esbuild-linux-64@0.15.13: 218 | version "0.15.13" 219 | resolved "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.15.13.tgz#4264249281ea388ead948614b57fb1ddf7779a2c" 220 | integrity sha512-rXmnArVNio6yANSqDQlIO4WiP+Cv7+9EuAHNnag7rByAqFVuRusLbGi2697A5dFPNXoO//IiogVwi3AdcfPC6A== 221 | 222 | esbuild-linux-arm64@0.15.13: 223 | version "0.15.13" 224 | resolved "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.13.tgz#9323c333924f97a02bdd2ae8912b36298acb312d" 225 | integrity sha512-alEMGU4Z+d17U7KQQw2IV8tQycO6T+rOrgW8OS22Ua25x6kHxoG6Ngry6Aq6uranC+pNWNMB6aHFPh7aTQdORQ== 226 | 227 | esbuild-linux-arm@0.15.13: 228 | version "0.15.13" 229 | resolved "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.15.13.tgz#b407f47b3ae721fe4e00e19e9f19289bef87a111" 230 | integrity sha512-Ac6LpfmJO8WhCMQmO253xX2IU2B3wPDbl4IvR0hnqcPrdfCaUa2j/lLMGTjmQ4W5JsJIdHEdW12dG8lFS0MbxQ== 231 | 232 | esbuild-linux-mips64le@0.15.13: 233 | version "0.15.13" 234 | resolved "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.13.tgz#bdf905aae5c0bcaa8f83567fe4c4c1bdc1f14447" 235 | integrity sha512-47PgmyYEu+yN5rD/MbwS6DxP2FSGPo4Uxg5LwIdxTiyGC2XKwHhHyW7YYEDlSuXLQXEdTO7mYe8zQ74czP7W8A== 236 | 237 | esbuild-linux-ppc64le@0.15.13: 238 | version "0.15.13" 239 | resolved "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.13.tgz#2911eae1c90ff58a3bd3259cb557235df25aa3b4" 240 | integrity sha512-z6n28h2+PC1Ayle9DjKoBRcx/4cxHoOa2e689e2aDJSaKug3jXcQw7mM+GLg+9ydYoNzj8QxNL8ihOv/OnezhA== 241 | 242 | esbuild-linux-riscv64@0.15.13: 243 | version "0.15.13" 244 | resolved "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.13.tgz#1837c660be12b1d20d2a29c7189ea703f93e9265" 245 | integrity sha512-+Lu4zuuXuQhgLUGyZloWCqTslcCAjMZH1k3Xc9MSEJEpEFdpsSU0sRDXAnk18FKOfEjhu4YMGaykx9xjtpA6ow== 246 | 247 | esbuild-linux-s390x@0.15.13: 248 | version "0.15.13" 249 | resolved "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.13.tgz#d52880ece229d1bd10b2d936b792914ffb07c7fc" 250 | integrity sha512-BMeXRljruf7J0TMxD5CIXS65y7puiZkAh+s4XFV9qy16SxOuMhxhVIXYLnbdfLrsYGFzx7U9mcdpFWkkvy/Uag== 251 | 252 | esbuild-netbsd-64@0.15.13: 253 | version "0.15.13" 254 | resolved "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.13.tgz#de14da46f1d20352b43e15d97a80a8788275e6ed" 255 | integrity sha512-EHj9QZOTel581JPj7UO3xYbltFTYnHy+SIqJVq6yd3KkCrsHRbapiPb0Lx3EOOtybBEE9EyqbmfW1NlSDsSzvQ== 256 | 257 | esbuild-openbsd-64@0.15.13: 258 | version "0.15.13" 259 | resolved "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.13.tgz#45e8a5fd74d92ad8f732c43582369c7990f5a0ac" 260 | integrity sha512-nkuDlIjF/sfUhfx8SKq0+U+Fgx5K9JcPq1mUodnxI0x4kBdCv46rOGWbuJ6eof2n3wdoCLccOoJAbg9ba/bT2w== 261 | 262 | esbuild-sunos-64@0.15.13: 263 | version "0.15.13" 264 | resolved "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.15.13.tgz#f646ac3da7aac521ee0fdbc192750c87da697806" 265 | integrity sha512-jVeu2GfxZQ++6lRdY43CS0Tm/r4WuQQ0Pdsrxbw+aOrHQPHV0+LNOLnvbN28M7BSUGnJnHkHm2HozGgNGyeIRw== 266 | 267 | esbuild-windows-32@0.15.13: 268 | version "0.15.13" 269 | resolved "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.15.13.tgz#fb4fe77c7591418880b3c9b5900adc4c094f2401" 270 | integrity sha512-XoF2iBf0wnqo16SDq+aDGi/+QbaLFpkiRarPVssMh9KYbFNCqPLlGAWwDvxEVz+ywX6Si37J2AKm+AXq1kC0JA== 271 | 272 | esbuild-windows-64@0.15.13: 273 | version "0.15.13" 274 | resolved "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.15.13.tgz#1fca8c654392c0c31bdaaed168becfea80e20660" 275 | integrity sha512-Et6htEfGycjDrtqb2ng6nT+baesZPYQIW+HUEHK4D1ncggNrDNk3yoboYQ5KtiVrw/JaDMNttz8rrPubV/fvPQ== 276 | 277 | esbuild-windows-arm64@0.15.13: 278 | version "0.15.13" 279 | resolved "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.13.tgz#4ffd01b6b2888603f1584a2fe96b1f6a6f2b3dd8" 280 | integrity sha512-3bv7tqntThQC9SWLRouMDmZnlOukBhOCTlkzNqzGCmrkCJI7io5LLjwJBOVY6kOUlIvdxbooNZwjtBvj+7uuVg== 281 | 282 | esbuild@^0.15.9: 283 | version "0.15.13" 284 | resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.15.13.tgz#7293480038feb2bafa91d3f6a20edab3ba6c108a" 285 | integrity sha512-Cu3SC84oyzzhrK/YyN4iEVy2jZu5t2fz66HEOShHURcjSkOSAVL8C/gfUT+lDJxkVHpg8GZ10DD0rMHRPqMFaQ== 286 | optionalDependencies: 287 | "@esbuild/android-arm" "0.15.13" 288 | "@esbuild/linux-loong64" "0.15.13" 289 | esbuild-android-64 "0.15.13" 290 | esbuild-android-arm64 "0.15.13" 291 | esbuild-darwin-64 "0.15.13" 292 | esbuild-darwin-arm64 "0.15.13" 293 | esbuild-freebsd-64 "0.15.13" 294 | esbuild-freebsd-arm64 "0.15.13" 295 | esbuild-linux-32 "0.15.13" 296 | esbuild-linux-64 "0.15.13" 297 | esbuild-linux-arm "0.15.13" 298 | esbuild-linux-arm64 "0.15.13" 299 | esbuild-linux-mips64le "0.15.13" 300 | esbuild-linux-ppc64le "0.15.13" 301 | esbuild-linux-riscv64 "0.15.13" 302 | esbuild-linux-s390x "0.15.13" 303 | esbuild-netbsd-64 "0.15.13" 304 | esbuild-openbsd-64 "0.15.13" 305 | esbuild-sunos-64 "0.15.13" 306 | esbuild-windows-32 "0.15.13" 307 | esbuild-windows-64 "0.15.13" 308 | esbuild-windows-arm64 "0.15.13" 309 | 310 | estree-walker@^2.0.2: 311 | version "2.0.2" 312 | resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac" 313 | integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w== 314 | 315 | fsevents@~2.3.2: 316 | version "2.3.2" 317 | resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" 318 | integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== 319 | 320 | function-bind@^1.1.1: 321 | version "1.1.1" 322 | resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" 323 | integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== 324 | 325 | has@^1.0.3: 326 | version "1.0.3" 327 | resolved "https://registry.npmjs.org/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" 328 | integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== 329 | dependencies: 330 | function-bind "^1.1.1" 331 | 332 | he@^1.2.0: 333 | version "1.2.0" 334 | resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" 335 | integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== 336 | 337 | is-core-module@^2.9.0: 338 | version "2.11.0" 339 | resolved "https://registry.npmjs.org/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144" 340 | integrity sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw== 341 | dependencies: 342 | has "^1.0.3" 343 | 344 | magic-string@^0.25.7: 345 | version "0.25.9" 346 | resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c" 347 | integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ== 348 | dependencies: 349 | sourcemap-codec "^1.4.8" 350 | 351 | minimatch@^5.1.0: 352 | version "5.1.0" 353 | resolved "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz#1717b464f4971b144f6aabe8f2d0b8e4511e09c7" 354 | integrity sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg== 355 | dependencies: 356 | brace-expansion "^2.0.1" 357 | 358 | muggle-string@^0.1.0: 359 | version "0.1.0" 360 | resolved "https://registry.npmjs.org/muggle-string/-/muggle-string-0.1.0.tgz#1fda8a281c8b27bb8b70466dbc9f27586a8baa6c" 361 | integrity sha512-Tr1knR3d2mKvvWthlk7202rywKbiOm4rVFLsfAaSIhJ6dt9o47W4S+JMtWhd/PW9Wrdew2/S2fSvhz3E2gkfEg== 362 | 363 | nanoid@^3.3.4: 364 | version "3.3.4" 365 | resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab" 366 | integrity sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw== 367 | 368 | path-parse@^1.0.7: 369 | version "1.0.7" 370 | resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" 371 | integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== 372 | 373 | picocolors@^1.0.0: 374 | version "1.0.0" 375 | resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" 376 | integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== 377 | 378 | postcss@^8.1.10, postcss@^8.4.18: 379 | version "8.4.18" 380 | resolved "https://registry.npmjs.org/postcss/-/postcss-8.4.18.tgz#6d50046ea7d3d66a85e0e782074e7203bc7fbca2" 381 | integrity sha512-Wi8mWhncLJm11GATDaQKobXSNEYGUHeQLiQqDFG1qQ5UTDPTEvKw0Xt5NsTpktGTwLps3ByrWsBrG0rB8YQ9oA== 382 | dependencies: 383 | nanoid "^3.3.4" 384 | picocolors "^1.0.0" 385 | source-map-js "^1.0.2" 386 | 387 | resolve@^1.22.1: 388 | version "1.22.1" 389 | resolved "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177" 390 | integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw== 391 | dependencies: 392 | is-core-module "^2.9.0" 393 | path-parse "^1.0.7" 394 | supports-preserve-symlinks-flag "^1.0.0" 395 | 396 | rollup@^2.79.1: 397 | version "2.79.1" 398 | resolved "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz#bedee8faef7c9f93a2647ac0108748f497f081c7" 399 | integrity sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw== 400 | optionalDependencies: 401 | fsevents "~2.3.2" 402 | 403 | source-map-js@^1.0.2: 404 | version "1.0.2" 405 | resolved "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c" 406 | integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw== 407 | 408 | source-map@^0.6.1: 409 | version "0.6.1" 410 | resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" 411 | integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== 412 | 413 | sourcemap-codec@^1.4.8: 414 | version "1.4.8" 415 | resolved "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" 416 | integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== 417 | 418 | supports-preserve-symlinks-flag@^1.0.0: 419 | version "1.0.0" 420 | resolved "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" 421 | integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== 422 | 423 | typescript@^4.6.4: 424 | version "4.8.4" 425 | resolved "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6" 426 | integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ== 427 | 428 | vite@^3.2.0: 429 | version "3.2.2" 430 | resolved "https://registry.npmjs.org/vite/-/vite-3.2.2.tgz#280762bfaf47bcea1d12698427331c0009ac7c1f" 431 | integrity sha512-pLrhatFFOWO9kS19bQ658CnRYzv0WLbsPih6R+iFeEEhDOuYgYCX2rztUViMz/uy/V8cLCJvLFeiOK7RJEzHcw== 432 | dependencies: 433 | esbuild "^0.15.9" 434 | postcss "^8.4.18" 435 | resolve "^1.22.1" 436 | rollup "^2.79.1" 437 | optionalDependencies: 438 | fsevents "~2.3.2" 439 | 440 | vue-template-compiler@^2.7.10: 441 | version "2.7.13" 442 | resolved "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.7.13.tgz#1520a5aa6d1af51dd0622824e79814f6e8cb7058" 443 | integrity sha512-jYM6TClwDS9YqP48gYrtAtaOhRKkbYmbzE+Q51gX5YDr777n7tNI/IZk4QV4l/PjQPNh/FVa/E92sh/RqKMrog== 444 | dependencies: 445 | de-indent "^1.0.2" 446 | he "^1.2.0" 447 | 448 | vue-tsc@^1.0.9: 449 | version "1.0.9" 450 | resolved "https://registry.npmjs.org/vue-tsc/-/vue-tsc-1.0.9.tgz#7d388ec3097bc9c1789d5745a97c608217af4873" 451 | integrity sha512-vRmHD1K6DmBymNhoHjQy/aYKTRQNLGOu2/ESasChG9Vy113K6CdP0NlhR0bzgFJfv2eFB9Ez/9L5kIciUajBxQ== 452 | dependencies: 453 | "@volar/vue-language-core" "1.0.9" 454 | "@volar/vue-typescript" "1.0.9" 455 | 456 | vue@^3.2.41: 457 | version "3.2.41" 458 | resolved "https://registry.npmjs.org/vue/-/vue-3.2.41.tgz#ed452b8a0f7f2b962f055c8955139c28b1c06806" 459 | integrity sha512-uuuvnrDXEeZ9VUPljgHkqB5IaVO8SxhPpqF2eWOukVrBnRBx2THPSGQBnVRt0GrIG1gvCmFXMGbd7FqcT1ixNQ== 460 | dependencies: 461 | "@vue/compiler-dom" "3.2.41" 462 | "@vue/compiler-sfc" "3.2.41" 463 | "@vue/runtime-dom" "3.2.41" 464 | "@vue/server-renderer" "3.2.41" 465 | "@vue/shared" "3.2.41" 466 | -------------------------------------------------------------------------------- /src/core/utils.ts: -------------------------------------------------------------------------------- 1 | import path, { dirname } from 'path' 2 | import fs from 'fs' 3 | import { parse } from '@vue/compiler-sfc' 4 | import * as CompilerDOM from '@vue/compiler-dom' 5 | import { parse as _parse } from '@babel/parser' 6 | import { CodeGenerator } from '@babel/generator' 7 | import { MagicString } from './magic-string' 8 | import { DEFINE_PROPS_NAME } from './constants' 9 | import type { ParserPlugin } from '@babel/parser' 10 | import type { 11 | ElementNode, 12 | NodeTypes as _NodeTypes, 13 | TextModes as _TextModes, 14 | } from '@vue/compiler-core' 15 | import type { CompilerError } from '@vue/compiler-sfc' 16 | import type { 17 | CallExpression, 18 | Declaration, 19 | ExportNamedDeclaration, 20 | Identifier, 21 | ImportDeclaration, 22 | ImportSpecifier, 23 | Node, 24 | Program, 25 | // removeComments, 26 | Statement, 27 | StringLiteral, 28 | TSInterfaceDeclaration, 29 | TSTypeAliasDeclaration, 30 | } from '@babel/types' 31 | import ts from "typescript"; 32 | import { fileURLToPath } from 'node:url' 33 | 34 | const DEFINE_PROPS = 'defineProps' 35 | const WITH_DEFAULTS = 'withDefaults' 36 | const __dirname = dirname(fileURLToPath(import.meta.url)) 37 | 38 | export function isCallOf( 39 | node: Node | null | undefined, 40 | test: string | ((id: string) => boolean) 41 | ): node is CallExpression { 42 | return !!( 43 | node && 44 | node.type === 'CallExpression' && 45 | node.callee.type === 'Identifier' && 46 | (typeof test === 'string' 47 | ? node.callee.name === test 48 | : test(node.callee.name)) 49 | ) 50 | } 51 | 52 | export enum TextModes { 53 | DATA = 0, 54 | RCDATA = 1, 55 | RAWTEXT = 2, 56 | CDATA = 3, 57 | ATTRIBUTE_VALUE = 4, 58 | } 59 | 60 | export enum NodeTypes { 61 | ROOT = 0, 62 | ELEMENT = 1, 63 | TEXT = 2, 64 | COMMENT = 3, 65 | SIMPLE_EXPRESSION = 4, 66 | INTERPOLATION = 5, 67 | ATTRIBUTE = 6, 68 | DIRECTIVE = 7, 69 | COMPOUND_EXPRESSION = 8, 70 | IF = 9, 71 | IF_BRANCH = 10, 72 | FOR = 11, 73 | TEXT_CALL = 12, 74 | VNODE_CALL = 13, 75 | JS_CALL_EXPRESSION = 14, 76 | JS_OBJECT_EXPRESSION = 15, 77 | JS_PROPERTY = 16, 78 | JS_ARRAY_EXPRESSION = 17, 79 | JS_FUNCTION_EXPRESSION = 18, 80 | JS_CONDITIONAL_EXPRESSION = 19, 81 | JS_CACHE_EXPRESSION = 20, 82 | JS_BLOCK_STATEMENT = 21, 83 | JS_TEMPLATE_LITERAL = 22, 84 | JS_IF_STATEMENT = 23, 85 | JS_ASSIGNMENT_EXPRESSION = 24, 86 | JS_SEQUENCE_EXPRESSION = 25, 87 | JS_RETURN_STATEMENT = 26, 88 | } 89 | 90 | export interface ImportDeclarationInfo extends ImportDeclaration { 91 | source: StringLiteral & { curPath?: string; plugins?: ParserPlugin[] } 92 | } 93 | 94 | export function fileExists(path: string) { 95 | return fs.existsSync(path) 96 | } 97 | 98 | export function getFileContent(path: string) { 99 | return fs.readFileSync(path).toString() 100 | } 101 | 102 | export const decide = (n) => n.props.reduce((p, c) => { 103 | if (!p) return false 104 | if (['setup', 'lang'].includes(c.name)) { 105 | if (c.name === 'lang') { 106 | if ( 107 | c.type === 108 | (NodeTypes.ATTRIBUTE as unknown as _NodeTypes.ATTRIBUTE) && 109 | c.value && 110 | c.value.content === 'ts' 111 | ) { 112 | return true 113 | } 114 | return false 115 | } 116 | return true 117 | } 118 | return false 119 | }, true) 120 | 121 | export function parseSfc(code) { 122 | return CompilerDOM.parse(code, { 123 | // there are no components at SFC parsing level 124 | isNativeTag: () => true, 125 | // preserve all whitespaces 126 | isPreTag: () => true, 127 | getTextMode: ({ tag, props }, parent) => { 128 | // all top level elements except