@vue.ts/tsx-auto-props 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +206 -0
- package/dist/astro.cjs +22 -0
- package/dist/astro.d.cts +11 -0
- package/dist/astro.d.mts +11 -0
- package/dist/astro.d.ts +11 -0
- package/dist/astro.mjs +20 -0
- package/dist/esbuild.cjs +13 -0
- package/dist/esbuild.d.cts +7 -0
- package/dist/esbuild.d.mts +7 -0
- package/dist/esbuild.d.ts +7 -0
- package/dist/esbuild.mjs +11 -0
- package/dist/index.cjs +119 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +112 -0
- package/dist/nuxt.cjs +35 -0
- package/dist/nuxt.d.cts +7 -0
- package/dist/nuxt.d.mts +7 -0
- package/dist/nuxt.d.ts +7 -0
- package/dist/nuxt.mjs +33 -0
- package/dist/rollup.cjs +13 -0
- package/dist/rollup.d.cts +7 -0
- package/dist/rollup.d.mts +7 -0
- package/dist/rollup.d.ts +7 -0
- package/dist/rollup.mjs +11 -0
- package/dist/rspack.cjs +13 -0
- package/dist/rspack.d.cts +6 -0
- package/dist/rspack.d.mts +6 -0
- package/dist/rspack.d.ts +6 -0
- package/dist/rspack.mjs +11 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +8 -0
- package/dist/types.d.mts +8 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.mjs +1 -0
- package/dist/vite.cjs +13 -0
- package/dist/vite.d.cts +7 -0
- package/dist/vite.d.mts +7 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.mjs +11 -0
- package/dist/webpack.cjs +13 -0
- package/dist/webpack.d.cts +7 -0
- package/dist/webpack.d.mts +7 -0
- package/dist/webpack.d.ts +7 -0
- package/dist/webpack.mjs +11 -0
- package/package.json +107 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Ray <https://github.com/so1ve>
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# unplugin-vue-tsx-auto-props
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/unplugin-vue-tsx-auto-props)
|
|
4
|
+
|
|
5
|
+
## Why?
|
|
6
|
+
|
|
7
|
+
Vue does not provide a way to automatically specify props for functional components written in TSX. This plugin solves this problem.
|
|
8
|
+
|
|
9
|
+
Before:
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { defineComponent } from "vue";
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
foo: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const Foo = defineComponent((props: Props) => () => <div>{props.foo}</div>);
|
|
19
|
+
Foo.props = ["foo"]; // 👈 You need to manually specify the props :(
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
After:
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { defineComponent } from "vue";
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
foo: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const Foo = defineComponent((props: Props) => () => <div>{props.foo}</div>);
|
|
32
|
+
Object.defineProperty(Foo, "props", {
|
|
33
|
+
value: ["foo"],
|
|
34
|
+
}); // 👈 This plugin will do it for you!
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 📦 Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
$ npm install -D unplugin-vue-tsx-auto-props
|
|
41
|
+
$ yarn add -D unplugin-vue-tsx-auto-props
|
|
42
|
+
$ pnpm add -D unplugin-vue-tsx-auto-props
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 🚀 Usage
|
|
46
|
+
|
|
47
|
+
<details>
|
|
48
|
+
<summary>Vite</summary><br>
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// vite.config.ts
|
|
52
|
+
import VueTsxAutoProps from "unplugin-vue-tsx-auto-props/vite";
|
|
53
|
+
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
plugins: [
|
|
56
|
+
VueTsxAutoProps({
|
|
57
|
+
/* options */
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
<br></details>
|
|
64
|
+
|
|
65
|
+
<details>
|
|
66
|
+
<summary>Rollup</summary><br>
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
// rollup.config.js
|
|
70
|
+
import VueTsxAutoProps from "unplugin-vue-tsx-auto-props/rollup";
|
|
71
|
+
|
|
72
|
+
export default {
|
|
73
|
+
plugins: [
|
|
74
|
+
VueTsxAutoProps({
|
|
75
|
+
/* options */
|
|
76
|
+
}),
|
|
77
|
+
// other plugins
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
<br></details>
|
|
83
|
+
|
|
84
|
+
<details>
|
|
85
|
+
<summary>Webpack</summary><br>
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
// webpack.config.js
|
|
89
|
+
module.exports = {
|
|
90
|
+
/* ... */
|
|
91
|
+
plugins: [
|
|
92
|
+
require("unplugin-vue-tsx-auto-props/webpack")({
|
|
93
|
+
/* options */
|
|
94
|
+
}),
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
<br></details>
|
|
100
|
+
|
|
101
|
+
<details>
|
|
102
|
+
<summary>Nuxt</summary><br>
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
// nuxt.config.ts
|
|
106
|
+
export default defineNuxtConfig({
|
|
107
|
+
modules: ["unplugin-vue-tsx-auto-props/nuxt"],
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
<br></details>
|
|
112
|
+
|
|
113
|
+
<details>
|
|
114
|
+
<summary>Vue CLI</summary><br>
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
// vue.config.js
|
|
118
|
+
module.exports = {
|
|
119
|
+
configureWebpack: {
|
|
120
|
+
plugins: [
|
|
121
|
+
require("unplugin-vue-tsx-auto-props/webpack")({
|
|
122
|
+
/* options */
|
|
123
|
+
}),
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
<br></details>
|
|
130
|
+
|
|
131
|
+
<details>
|
|
132
|
+
<summary>Quasar</summary><br>
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
// quasar.conf.js [Vite]
|
|
136
|
+
module.exports = {
|
|
137
|
+
vitePlugins: [
|
|
138
|
+
[
|
|
139
|
+
"unplugin-vue-tsx-auto-props/vite",
|
|
140
|
+
{
|
|
141
|
+
/* options */
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
],
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
// quasar.conf.js [Webpack]
|
|
150
|
+
const VueTsxAutoPropsPlugin = require("unplugin-vue-tsx-auto-props/webpack");
|
|
151
|
+
|
|
152
|
+
module.exports = {
|
|
153
|
+
build: {
|
|
154
|
+
chainWebpack(chain) {
|
|
155
|
+
chain.plugin("unplugin-vue-tsx-auto-props").use(
|
|
156
|
+
VueTsxAutoPropsPlugin({
|
|
157
|
+
/* options */
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
<br></details>
|
|
166
|
+
|
|
167
|
+
<details>
|
|
168
|
+
<summary>esbuild</summary><br>
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
// esbuild.config.js
|
|
172
|
+
import { build } from "esbuild";
|
|
173
|
+
|
|
174
|
+
build({
|
|
175
|
+
/* ... */
|
|
176
|
+
plugins: [
|
|
177
|
+
require("unplugin-vue-tsx-auto-props/esbuild")({
|
|
178
|
+
/* options */
|
|
179
|
+
}),
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
<br></details>
|
|
185
|
+
|
|
186
|
+
<details>
|
|
187
|
+
<summary>Astro</summary><br>
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
// astro.config.mjs
|
|
191
|
+
import VueTsxAutoProps from "unplugin-vue-tsx-auto-props/astro";
|
|
192
|
+
|
|
193
|
+
export default defineConfig({
|
|
194
|
+
integrations: [
|
|
195
|
+
VueTsxAutoProps({
|
|
196
|
+
/* options */
|
|
197
|
+
}),
|
|
198
|
+
],
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
<br></details>
|
|
203
|
+
|
|
204
|
+
## 📝 License
|
|
205
|
+
|
|
206
|
+
[MIT](./LICENSE). Made with ❤️ by [Ray](https://github.com/so1ve)
|
package/dist/astro.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
require('@vue.ts/common');
|
|
5
|
+
require('@vue.ts/language');
|
|
6
|
+
require('unplugin');
|
|
7
|
+
require('magic-string');
|
|
8
|
+
require('typescript');
|
|
9
|
+
require('node:path');
|
|
10
|
+
|
|
11
|
+
const astro = (options) => ({
|
|
12
|
+
name: "unplugin-vue-complex-types",
|
|
13
|
+
hooks: {
|
|
14
|
+
"astro:config:setup": async (astro) => {
|
|
15
|
+
var _a;
|
|
16
|
+
(_a = astro.config.vite).plugins || (_a.plugins = []);
|
|
17
|
+
astro.config.vite.plugins.push(index.vite(options));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
module.exports = astro;
|
package/dist/astro.d.cts
ADDED
package/dist/astro.d.mts
ADDED
package/dist/astro.d.ts
ADDED
package/dist/astro.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import unplugin from './index.mjs';
|
|
2
|
+
import '@vue.ts/common';
|
|
3
|
+
import '@vue.ts/language';
|
|
4
|
+
import 'unplugin';
|
|
5
|
+
import 'magic-string';
|
|
6
|
+
import 'typescript';
|
|
7
|
+
import 'node:path';
|
|
8
|
+
|
|
9
|
+
const astro = (options) => ({
|
|
10
|
+
name: "unplugin-vue-complex-types",
|
|
11
|
+
hooks: {
|
|
12
|
+
"astro:config:setup": async (astro) => {
|
|
13
|
+
var _a;
|
|
14
|
+
(_a = astro.config.vite).plugins || (_a.plugins = []);
|
|
15
|
+
astro.config.vite.plugins.push(unplugin.vite(options));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export { astro as default };
|
package/dist/esbuild.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
require('@vue.ts/common');
|
|
5
|
+
require('@vue.ts/language');
|
|
6
|
+
require('unplugin');
|
|
7
|
+
require('magic-string');
|
|
8
|
+
require('typescript');
|
|
9
|
+
require('node:path');
|
|
10
|
+
|
|
11
|
+
const esbuild = index.esbuild;
|
|
12
|
+
|
|
13
|
+
module.exports = esbuild;
|
package/dist/esbuild.mjs
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const common = require('@vue.ts/common');
|
|
4
|
+
const language = require('@vue.ts/language');
|
|
5
|
+
const unplugin$1 = require('unplugin');
|
|
6
|
+
const MagicString = require('magic-string');
|
|
7
|
+
const ts = require('typescript');
|
|
8
|
+
const node_path = require('node:path');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
11
|
+
|
|
12
|
+
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
13
|
+
const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
|
|
14
|
+
|
|
15
|
+
const resolveOptions = (rawOptions) => ({
|
|
16
|
+
include: rawOptions.include ?? ["**/*.vue", "**/*.tsx"],
|
|
17
|
+
exclude: rawOptions.exclude ?? ["node_modules/**"],
|
|
18
|
+
tsconfigPath: rawOptions.tsconfigPath ?? node_path.join(process.cwd(), "tsconfig.json")
|
|
19
|
+
});
|
|
20
|
+
function getNodeAssignNode(node) {
|
|
21
|
+
let parent = null;
|
|
22
|
+
let variableList = null;
|
|
23
|
+
let variable = null;
|
|
24
|
+
while (node) {
|
|
25
|
+
if (parent) {
|
|
26
|
+
if (ts__default.isVariableDeclarationList(parent)) {
|
|
27
|
+
variableList = parent;
|
|
28
|
+
}
|
|
29
|
+
if (ts__default.isVariableDeclaration(parent)) {
|
|
30
|
+
variable = parent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
parent = node;
|
|
34
|
+
node = node.parent;
|
|
35
|
+
}
|
|
36
|
+
return { variableList, variable };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const generateDefineProps = (name, props) => `
|
|
40
|
+
;Object.defineProperty(${name}, "props", {
|
|
41
|
+
value: ${JSON.stringify(props)},
|
|
42
|
+
});`;
|
|
43
|
+
const DEFINE_COMPONENT = "defineComponent";
|
|
44
|
+
function transform(code, id) {
|
|
45
|
+
const s = new MagicString__default(code);
|
|
46
|
+
const language$1 = language.getLanguage();
|
|
47
|
+
const typeChecker = language$1.__internal__.typeChecker;
|
|
48
|
+
language$1.traverseAst(
|
|
49
|
+
id,
|
|
50
|
+
(node, { virtualFileOrTsAst: ast, isVirtualOrTsFile }) => {
|
|
51
|
+
if (isVirtualOrTsFile && ts__default.isCallExpression(node)) {
|
|
52
|
+
const identifier = node.expression;
|
|
53
|
+
const symbol = typeChecker.getSymbolAtLocation(identifier);
|
|
54
|
+
if (symbol?.declarations?.some(
|
|
55
|
+
(d) => ts__default.isImportSpecifier(d) && (d.propertyName ?? d.name)?.escapedText === DEFINE_COMPONENT
|
|
56
|
+
)) {
|
|
57
|
+
const arg = node.arguments[0];
|
|
58
|
+
let setupFn;
|
|
59
|
+
if (ts__default.isObjectLiteralExpression(arg)) {
|
|
60
|
+
const props2 = arg.properties.find(
|
|
61
|
+
(p) => ts__default.isPropertyAssignment(p) && ts__default.isIdentifier(p.name) && p.name.escapedText === "props"
|
|
62
|
+
);
|
|
63
|
+
const setup = arg.properties.find(
|
|
64
|
+
(p) => ts__default.isPropertyAssignment(p) && ts__default.isIdentifier(p.name) && p.name.escapedText === "setup"
|
|
65
|
+
);
|
|
66
|
+
if (!props2 && setup && ts__default.isPropertyAssignment(setup)) {
|
|
67
|
+
const value = setup.initializer;
|
|
68
|
+
if (ts__default.isFunctionLike(value)) {
|
|
69
|
+
setupFn = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else if (ts__default.isFunctionLike(arg)) {
|
|
73
|
+
setupFn = arg;
|
|
74
|
+
} else {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"[@vue.ts/tsx-auto-props] Invalid defineComponent argument"
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const props = setupFn?.parameters[0];
|
|
80
|
+
if (props) {
|
|
81
|
+
const propsList = typeChecker.getTypeAtLocation(props).getProperties().map((p) => p.name);
|
|
82
|
+
const { variableList, variable } = getNodeAssignNode(node);
|
|
83
|
+
if (propsList.length > 0 && variableList && variable) {
|
|
84
|
+
s.appendRight(
|
|
85
|
+
variableList.getEnd() + 1,
|
|
86
|
+
generateDefineProps(variable.name.getText(ast), propsList)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
return {
|
|
95
|
+
code: s.toString(),
|
|
96
|
+
map: s.generateMap({ hires: true })
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const unplugin = unplugin$1.createUnplugin((options = {}) => ({
|
|
101
|
+
name: "unplugin-vue-complex-types",
|
|
102
|
+
buildStart() {
|
|
103
|
+
const resolvedOptions = resolveOptions(options);
|
|
104
|
+
language.ensureLanguage(resolvedOptions.tsconfigPath);
|
|
105
|
+
},
|
|
106
|
+
transform(code, id) {
|
|
107
|
+
const resolvedOptions = resolveOptions(options);
|
|
108
|
+
const filter = common.createFilter(
|
|
109
|
+
resolvedOptions.include,
|
|
110
|
+
resolvedOptions.exclude
|
|
111
|
+
);
|
|
112
|
+
if (!filter(id)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
return transform(code, id);
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
module.exports = unplugin;
|
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createFilter } from '@vue.ts/common';
|
|
2
|
+
import { getLanguage, ensureLanguage } from '@vue.ts/language';
|
|
3
|
+
import { createUnplugin } from 'unplugin';
|
|
4
|
+
import MagicString from 'magic-string';
|
|
5
|
+
import ts from 'typescript';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
const resolveOptions = (rawOptions) => ({
|
|
9
|
+
include: rawOptions.include ?? ["**/*.vue", "**/*.tsx"],
|
|
10
|
+
exclude: rawOptions.exclude ?? ["node_modules/**"],
|
|
11
|
+
tsconfigPath: rawOptions.tsconfigPath ?? join(process.cwd(), "tsconfig.json")
|
|
12
|
+
});
|
|
13
|
+
function getNodeAssignNode(node) {
|
|
14
|
+
let parent = null;
|
|
15
|
+
let variableList = null;
|
|
16
|
+
let variable = null;
|
|
17
|
+
while (node) {
|
|
18
|
+
if (parent) {
|
|
19
|
+
if (ts.isVariableDeclarationList(parent)) {
|
|
20
|
+
variableList = parent;
|
|
21
|
+
}
|
|
22
|
+
if (ts.isVariableDeclaration(parent)) {
|
|
23
|
+
variable = parent;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
parent = node;
|
|
27
|
+
node = node.parent;
|
|
28
|
+
}
|
|
29
|
+
return { variableList, variable };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const generateDefineProps = (name, props) => `
|
|
33
|
+
;Object.defineProperty(${name}, "props", {
|
|
34
|
+
value: ${JSON.stringify(props)},
|
|
35
|
+
});`;
|
|
36
|
+
const DEFINE_COMPONENT = "defineComponent";
|
|
37
|
+
function transform(code, id) {
|
|
38
|
+
const s = new MagicString(code);
|
|
39
|
+
const language = getLanguage();
|
|
40
|
+
const typeChecker = language.__internal__.typeChecker;
|
|
41
|
+
language.traverseAst(
|
|
42
|
+
id,
|
|
43
|
+
(node, { virtualFileOrTsAst: ast, isVirtualOrTsFile }) => {
|
|
44
|
+
if (isVirtualOrTsFile && ts.isCallExpression(node)) {
|
|
45
|
+
const identifier = node.expression;
|
|
46
|
+
const symbol = typeChecker.getSymbolAtLocation(identifier);
|
|
47
|
+
if (symbol?.declarations?.some(
|
|
48
|
+
(d) => ts.isImportSpecifier(d) && (d.propertyName ?? d.name)?.escapedText === DEFINE_COMPONENT
|
|
49
|
+
)) {
|
|
50
|
+
const arg = node.arguments[0];
|
|
51
|
+
let setupFn;
|
|
52
|
+
if (ts.isObjectLiteralExpression(arg)) {
|
|
53
|
+
const props2 = arg.properties.find(
|
|
54
|
+
(p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.escapedText === "props"
|
|
55
|
+
);
|
|
56
|
+
const setup = arg.properties.find(
|
|
57
|
+
(p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.escapedText === "setup"
|
|
58
|
+
);
|
|
59
|
+
if (!props2 && setup && ts.isPropertyAssignment(setup)) {
|
|
60
|
+
const value = setup.initializer;
|
|
61
|
+
if (ts.isFunctionLike(value)) {
|
|
62
|
+
setupFn = value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else if (ts.isFunctionLike(arg)) {
|
|
66
|
+
setupFn = arg;
|
|
67
|
+
} else {
|
|
68
|
+
throw new Error(
|
|
69
|
+
"[@vue.ts/tsx-auto-props] Invalid defineComponent argument"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const props = setupFn?.parameters[0];
|
|
73
|
+
if (props) {
|
|
74
|
+
const propsList = typeChecker.getTypeAtLocation(props).getProperties().map((p) => p.name);
|
|
75
|
+
const { variableList, variable } = getNodeAssignNode(node);
|
|
76
|
+
if (propsList.length > 0 && variableList && variable) {
|
|
77
|
+
s.appendRight(
|
|
78
|
+
variableList.getEnd() + 1,
|
|
79
|
+
generateDefineProps(variable.name.getText(ast), propsList)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
return {
|
|
88
|
+
code: s.toString(),
|
|
89
|
+
map: s.generateMap({ hires: true })
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const unplugin = createUnplugin((options = {}) => ({
|
|
94
|
+
name: "unplugin-vue-complex-types",
|
|
95
|
+
buildStart() {
|
|
96
|
+
const resolvedOptions = resolveOptions(options);
|
|
97
|
+
ensureLanguage(resolvedOptions.tsconfigPath);
|
|
98
|
+
},
|
|
99
|
+
transform(code, id) {
|
|
100
|
+
const resolvedOptions = resolveOptions(options);
|
|
101
|
+
const filter = createFilter(
|
|
102
|
+
resolvedOptions.include,
|
|
103
|
+
resolvedOptions.exclude
|
|
104
|
+
);
|
|
105
|
+
if (!filter(id)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
return transform(code, id);
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
export { unplugin as default };
|
package/dist/nuxt.cjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const kit = require('@nuxt/kit');
|
|
4
|
+
const vite = require('./vite.cjs');
|
|
5
|
+
const webpack = require('./webpack.cjs');
|
|
6
|
+
require('./index.cjs');
|
|
7
|
+
require('@vue.ts/common');
|
|
8
|
+
require('@vue.ts/language');
|
|
9
|
+
require('unplugin');
|
|
10
|
+
require('magic-string');
|
|
11
|
+
require('typescript');
|
|
12
|
+
require('node:path');
|
|
13
|
+
|
|
14
|
+
const name = "@vue.ts/tsx-auto-props";
|
|
15
|
+
const version = "0.5.0";
|
|
16
|
+
|
|
17
|
+
const nuxt = kit.defineNuxtModule({
|
|
18
|
+
meta: {
|
|
19
|
+
name,
|
|
20
|
+
version,
|
|
21
|
+
configKey: "complexTypes",
|
|
22
|
+
compatibility: {
|
|
23
|
+
bridge: true
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
defaults: {
|
|
27
|
+
tsconfigPath: "tsconfig.json"
|
|
28
|
+
},
|
|
29
|
+
setup(options) {
|
|
30
|
+
kit.addVitePlugin(vite(options));
|
|
31
|
+
kit.addWebpackPlugin(webpack(options));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
module.exports = nuxt;
|
package/dist/nuxt.d.cts
ADDED
package/dist/nuxt.d.mts
ADDED
package/dist/nuxt.d.ts
ADDED
package/dist/nuxt.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineNuxtModule, addVitePlugin, addWebpackPlugin } from '@nuxt/kit';
|
|
2
|
+
import VitePlugin from './vite.mjs';
|
|
3
|
+
import WebpackPlugin from './webpack.mjs';
|
|
4
|
+
import './index.mjs';
|
|
5
|
+
import '@vue.ts/common';
|
|
6
|
+
import '@vue.ts/language';
|
|
7
|
+
import 'unplugin';
|
|
8
|
+
import 'magic-string';
|
|
9
|
+
import 'typescript';
|
|
10
|
+
import 'node:path';
|
|
11
|
+
|
|
12
|
+
const name = "@vue.ts/tsx-auto-props";
|
|
13
|
+
const version = "0.5.0";
|
|
14
|
+
|
|
15
|
+
const nuxt = defineNuxtModule({
|
|
16
|
+
meta: {
|
|
17
|
+
name,
|
|
18
|
+
version,
|
|
19
|
+
configKey: "complexTypes",
|
|
20
|
+
compatibility: {
|
|
21
|
+
bridge: true
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
defaults: {
|
|
25
|
+
tsconfigPath: "tsconfig.json"
|
|
26
|
+
},
|
|
27
|
+
setup(options) {
|
|
28
|
+
addVitePlugin(VitePlugin(options));
|
|
29
|
+
addWebpackPlugin(WebpackPlugin(options));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export { nuxt as default };
|
package/dist/rollup.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
require('@vue.ts/common');
|
|
5
|
+
require('@vue.ts/language');
|
|
6
|
+
require('unplugin');
|
|
7
|
+
require('magic-string');
|
|
8
|
+
require('typescript');
|
|
9
|
+
require('node:path');
|
|
10
|
+
|
|
11
|
+
const rollup = index.rollup;
|
|
12
|
+
|
|
13
|
+
module.exports = rollup;
|
package/dist/rollup.d.ts
ADDED
package/dist/rollup.mjs
ADDED
package/dist/rspack.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
require('@vue.ts/common');
|
|
5
|
+
require('@vue.ts/language');
|
|
6
|
+
require('unplugin');
|
|
7
|
+
require('magic-string');
|
|
8
|
+
require('typescript');
|
|
9
|
+
require('node:path');
|
|
10
|
+
|
|
11
|
+
const rspack = index.rspack;
|
|
12
|
+
|
|
13
|
+
module.exports = rspack;
|
package/dist/rspack.d.ts
ADDED
package/dist/rspack.mjs
ADDED
package/dist/types.cjs
ADDED
package/dist/types.d.cts
ADDED
package/dist/types.d.mts
ADDED
package/dist/types.d.ts
ADDED
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
require('@vue.ts/common');
|
|
5
|
+
require('@vue.ts/language');
|
|
6
|
+
require('unplugin');
|
|
7
|
+
require('magic-string');
|
|
8
|
+
require('typescript');
|
|
9
|
+
require('node:path');
|
|
10
|
+
|
|
11
|
+
const VitePlugin = index.vite;
|
|
12
|
+
|
|
13
|
+
module.exports = VitePlugin;
|
package/dist/vite.d.cts
ADDED
package/dist/vite.d.mts
ADDED
package/dist/vite.d.ts
ADDED
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import unplugin from './index.mjs';
|
|
2
|
+
import '@vue.ts/common';
|
|
3
|
+
import '@vue.ts/language';
|
|
4
|
+
import 'unplugin';
|
|
5
|
+
import 'magic-string';
|
|
6
|
+
import 'typescript';
|
|
7
|
+
import 'node:path';
|
|
8
|
+
|
|
9
|
+
const VitePlugin = unplugin.vite;
|
|
10
|
+
|
|
11
|
+
export { VitePlugin as default };
|
package/dist/webpack.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
require('@vue.ts/common');
|
|
5
|
+
require('@vue.ts/language');
|
|
6
|
+
require('unplugin');
|
|
7
|
+
require('magic-string');
|
|
8
|
+
require('typescript');
|
|
9
|
+
require('node:path');
|
|
10
|
+
|
|
11
|
+
const WebpackPlugin = index.webpack;
|
|
12
|
+
|
|
13
|
+
module.exports = WebpackPlugin;
|
package/dist/webpack.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import unplugin from './index.mjs';
|
|
2
|
+
import '@vue.ts/common';
|
|
3
|
+
import '@vue.ts/language';
|
|
4
|
+
import 'unplugin';
|
|
5
|
+
import 'magic-string';
|
|
6
|
+
import 'typescript';
|
|
7
|
+
import 'node:path';
|
|
8
|
+
|
|
9
|
+
const WebpackPlugin = unplugin.webpack;
|
|
10
|
+
|
|
11
|
+
export { WebpackPlugin as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vue.ts/tsx-auto-props",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"author": "Ray <i@mk1.io> (@so1ve)",
|
|
5
|
+
"description": "Automatically add props definition for Vue 3 TSX.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"astro",
|
|
8
|
+
"nuxt",
|
|
9
|
+
"rollup",
|
|
10
|
+
"rspack",
|
|
11
|
+
"transform",
|
|
12
|
+
"tsx",
|
|
13
|
+
"typescript",
|
|
14
|
+
"unplugin",
|
|
15
|
+
"vite",
|
|
16
|
+
"vue",
|
|
17
|
+
"webpack"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://github.com/so1ve/vue.ts/tree/main/packages/tsx-auto-props#readme",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/so1ve/vue.ts.git",
|
|
23
|
+
"directory": "/"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/so1ve/vue.ts/issues"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"require": "./dist/index.cjs",
|
|
33
|
+
"import": "./dist/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./*": "./*",
|
|
36
|
+
"./astro": {
|
|
37
|
+
"require": "./dist/astro.cjs",
|
|
38
|
+
"import": "./dist/astro.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./esbuild": {
|
|
41
|
+
"require": "./dist/esbuild.cjs",
|
|
42
|
+
"import": "./dist/esbuild.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./nuxt": {
|
|
45
|
+
"require": "./dist/nuxt.cjs",
|
|
46
|
+
"import": "./dist/nuxt.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./rollup": {
|
|
49
|
+
"require": "./dist/rollup.cjs",
|
|
50
|
+
"import": "./dist/rollup.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./rspack": {
|
|
53
|
+
"require": "./dist/rspack.cjs",
|
|
54
|
+
"import": "./dist/rspack.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./types": {
|
|
57
|
+
"require": "./dist/types.cjs",
|
|
58
|
+
"import": "./dist/types.mjs"
|
|
59
|
+
},
|
|
60
|
+
"./vite": {
|
|
61
|
+
"require": "./dist/vite.cjs",
|
|
62
|
+
"import": "./dist/vite.mjs"
|
|
63
|
+
},
|
|
64
|
+
"./webpack": {
|
|
65
|
+
"require": "./dist/webpack.cjs",
|
|
66
|
+
"import": "./dist/webpack.mjs"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"main": "./dist/index.cjs",
|
|
70
|
+
"module": "./dist/index.mjs",
|
|
71
|
+
"typesVersions": {
|
|
72
|
+
"*": {
|
|
73
|
+
"*": [
|
|
74
|
+
"./dist/*",
|
|
75
|
+
"./dist/index.d.ts"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"files": [
|
|
80
|
+
"dist"
|
|
81
|
+
],
|
|
82
|
+
"publishConfig": {
|
|
83
|
+
"access": "public"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"@nuxt/kit": "^3.8.1",
|
|
87
|
+
"magic-string": "^0.30.5",
|
|
88
|
+
"unplugin": "^1.5.0",
|
|
89
|
+
"@vue.ts/common": "0.5.0",
|
|
90
|
+
"@vue.ts/language": "0.5.0"
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@nuxt/schema": "^3.8.1",
|
|
94
|
+
"rollup": "^4.3.0",
|
|
95
|
+
"unbuild": "^2.0.0",
|
|
96
|
+
"vite": "^5.0.2",
|
|
97
|
+
"webpack": "^5.89.0"
|
|
98
|
+
},
|
|
99
|
+
"peerDependencies": {
|
|
100
|
+
"typescript": "^5.2.2",
|
|
101
|
+
"vue": "^3.3.7"
|
|
102
|
+
},
|
|
103
|
+
"scripts": {
|
|
104
|
+
"build": "unbuild",
|
|
105
|
+
"stub": "unbuild --stub"
|
|
106
|
+
}
|
|
107
|
+
}
|