@vue.ts/complex-types 0.6.0 → 1.0.0-beta.2

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.
Files changed (66) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +19 -0
  3. package/dist/astro.d.ts +8 -10
  4. package/dist/astro.js +14 -0
  5. package/dist/esbuild.d.ts +7 -8
  6. package/dist/esbuild.js +8 -0
  7. package/dist/farm.d.ts +8 -0
  8. package/dist/farm.js +8 -0
  9. package/dist/index.d.ts +8 -8
  10. package/dist/index.js +3 -0
  11. package/dist/nuxt.d.ts +7 -8
  12. package/dist/nuxt.js +20 -0
  13. package/dist/rolldown.d.ts +8 -0
  14. package/dist/rolldown.js +8 -0
  15. package/dist/rollup.d.ts +7 -8
  16. package/dist/rollup.js +8 -0
  17. package/dist/rspack.d.ts +5 -6
  18. package/dist/rspack.js +8 -0
  19. package/dist/src-k-9RVLWt.js +360 -0
  20. package/dist/types-CFmCIAvs.d.ts +51 -0
  21. package/dist/types-u_Hr5uXA.d.ts +1 -0
  22. package/dist/types.d.ts +3 -30
  23. package/dist/types.js +0 -0
  24. package/dist/vite-D_E5rjeG.js +8 -0
  25. package/dist/vite.d.ts +7 -8
  26. package/dist/vite.js +4 -0
  27. package/dist/webpack-BQtMUXaQ.js +8 -0
  28. package/dist/webpack.d.ts +7 -8
  29. package/dist/webpack.js +4 -0
  30. package/package.json +67 -53
  31. package/dist/astro.cjs +0 -22
  32. package/dist/astro.d.cts +0 -13
  33. package/dist/astro.d.mts +0 -13
  34. package/dist/astro.mjs +0 -20
  35. package/dist/esbuild.cjs +0 -13
  36. package/dist/esbuild.d.cts +0 -9
  37. package/dist/esbuild.d.mts +0 -9
  38. package/dist/esbuild.mjs +0 -11
  39. package/dist/index.cjs +0 -238
  40. package/dist/index.d.cts +0 -9
  41. package/dist/index.d.mts +0 -9
  42. package/dist/index.mjs +0 -231
  43. package/dist/nuxt.cjs +0 -35
  44. package/dist/nuxt.d.cts +0 -9
  45. package/dist/nuxt.d.mts +0 -9
  46. package/dist/nuxt.mjs +0 -33
  47. package/dist/rollup.cjs +0 -13
  48. package/dist/rollup.d.cts +0 -9
  49. package/dist/rollup.d.mts +0 -9
  50. package/dist/rollup.mjs +0 -11
  51. package/dist/rspack.cjs +0 -13
  52. package/dist/rspack.d.cts +0 -8
  53. package/dist/rspack.d.mts +0 -8
  54. package/dist/rspack.mjs +0 -11
  55. package/dist/types.cjs +0 -2
  56. package/dist/types.d.cts +0 -30
  57. package/dist/types.d.mts +0 -30
  58. package/dist/types.mjs +0 -1
  59. package/dist/vite.cjs +0 -13
  60. package/dist/vite.d.cts +0 -9
  61. package/dist/vite.d.mts +0 -9
  62. package/dist/vite.mjs +0 -11
  63. package/dist/webpack.cjs +0 -13
  64. package/dist/webpack.d.cts +0 -9
  65. package/dist/webpack.d.mts +0 -9
  66. package/dist/webpack.mjs +0 -11
package/LICENSE CHANGED
@@ -1,21 +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.
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 CHANGED
@@ -38,6 +38,25 @@ export default defineConfig({
38
38
 
39
39
  <br></details>
40
40
 
41
+ <details>
42
+ <summary>Rolldown</summary><br>
43
+
44
+ ```ts
45
+ // rolldown.config.js
46
+ import VueComplexTypes from "@vue.ts/complex-types/rolldown";
47
+
48
+ export default {
49
+ plugins: [
50
+ VueComplexTypes({
51
+ /* options */
52
+ }),
53
+ // other plugins
54
+ ],
55
+ };
56
+ ```
57
+
58
+ <br></details>
59
+
41
60
  <details>
42
61
  <summary>Rollup</summary><br>
43
62
 
package/dist/astro.d.ts CHANGED
@@ -1,13 +1,11 @@
1
- import { Options } from './types.js';
2
- import '@vue.ts/common';
3
- import 'magic-string';
4
- import 'typescript';
1
+ import { Options } from "./types-CFmCIAvs.js";
5
2
 
3
+ //#region src/astro.d.ts
6
4
  declare const _default: (options: Options) => {
7
- name: string;
8
- hooks: {
9
- "astro:config:setup": (astro: any) => Promise<void>;
10
- };
5
+ name: string;
6
+ hooks: {
7
+ "astro:config:setup": (astro: any) => Promise<void>;
8
+ };
11
9
  };
12
-
13
- export { _default as default };
10
+ //#endregion
11
+ export { _default as default };
package/dist/astro.js ADDED
@@ -0,0 +1,14 @@
1
+ import { unpluginFactory } from "./src-k-9RVLWt.js";
2
+ import { createVitePlugin } from "unplugin";
3
+
4
+ //#region src/astro.ts
5
+ var astro_default = (options) => ({
6
+ name: "@vue.ts/complex-types",
7
+ hooks: { "astro:config:setup": async (astro) => {
8
+ astro.config.vite.plugins ??= [];
9
+ astro.config.vite.plugins.push(createVitePlugin(unpluginFactory)(options));
10
+ } }
11
+ });
12
+
13
+ //#endregion
14
+ export { astro_default as default };
package/dist/esbuild.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import * as unplugin from 'unplugin';
2
- import { Options } from './types.js';
3
- import '@vue.ts/common';
4
- import 'magic-string';
5
- import 'typescript';
1
+ import { Options } from "./types-CFmCIAvs.js";
2
+ import "./types-u_Hr5uXA.js";
3
+ import * as esbuild0 from "esbuild";
6
4
 
7
- declare const _default: (options?: Options | undefined) => unplugin.EsbuildPlugin;
8
-
9
- export { _default as default };
5
+ //#region src/esbuild.d.ts
6
+ declare const _default: (options?: Options | undefined) => esbuild0.Plugin;
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-k-9RVLWt.js";
2
+ import { createEsbuildPlugin } from "unplugin";
3
+
4
+ //#region src/esbuild.ts
5
+ var esbuild_default = createEsbuildPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { esbuild_default as default };
package/dist/farm.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-CFmCIAvs.js";
2
+ import "./types-u_Hr5uXA.js";
3
+ import * as _farmfe_core0 from "@farmfe/core";
4
+
5
+ //#region src/farm.d.ts
6
+ declare const _default: (options?: Options | undefined) => _farmfe_core0.JsPlugin;
7
+ //#endregion
8
+ export { _default as default };
package/dist/farm.js ADDED
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-k-9RVLWt.js";
2
+ import { createFarmPlugin } from "unplugin";
3
+
4
+ //#region src/farm.ts
5
+ var farm_default = createFarmPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { farm_default as default };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import * as unplugin from 'unplugin';
2
- import { Options } from './types.js';
3
- import '@vue.ts/common';
4
- import 'magic-string';
5
- import 'typescript';
1
+ import { Options } from "./types-CFmCIAvs.js";
2
+ import * as unplugin0 from "unplugin";
3
+ import { UnpluginFactory } from "unplugin";
6
4
 
7
- declare const _default: unplugin.UnpluginInstance<Options | undefined, boolean>;
8
-
9
- export { _default as default };
5
+ //#region src/index.d.ts
6
+ declare const unpluginFactory: UnpluginFactory<Options | undefined>;
7
+ declare const unplugin: unplugin0.UnpluginInstance<Options | undefined, boolean>;
8
+ //#endregion
9
+ export { unplugin as default, unplugin, unpluginFactory };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { src_default, unplugin, unpluginFactory } from "./src-k-9RVLWt.js";
2
+
3
+ export { src_default as default, unplugin, unpluginFactory };
package/dist/nuxt.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { ModuleDefinition } from '@nuxt/schema';
2
- import { Options } from './types.js';
3
- import '@vue.ts/common';
4
- import 'magic-string';
5
- import 'typescript';
1
+ import { Options } from "./types-CFmCIAvs.js";
2
+ import "./types-u_Hr5uXA.js";
3
+ import * as _nuxt_schema0 from "@nuxt/schema";
6
4
 
7
- declare const _default: ModuleDefinition<Options>;
8
-
9
- export { _default as default };
5
+ //#region src/nuxt.d.ts
6
+ declare const _default: _nuxt_schema0.NuxtModule<Options, Options, false>;
7
+ //#endregion
8
+ export { _default as default };
package/dist/nuxt.js ADDED
@@ -0,0 +1,20 @@
1
+ import "./src-k-9RVLWt.js";
2
+ import { vite_default } from "./vite-D_E5rjeG.js";
3
+ import { webpack_default } from "./webpack-BQtMUXaQ.js";
4
+ import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
5
+
6
+ //#region src/nuxt.ts
7
+ var nuxt_default = defineNuxtModule({
8
+ meta: {
9
+ name: "@vue.ts/complex-types",
10
+ configKey: "complexTypes"
11
+ },
12
+ defaults: {},
13
+ setup(options, _nuxt) {
14
+ addVitePlugin(() => vite_default(options));
15
+ addWebpackPlugin(() => webpack_default(options));
16
+ }
17
+ });
18
+
19
+ //#endregion
20
+ export { nuxt_default as default };
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-CFmCIAvs.js";
2
+ import "./types-u_Hr5uXA.js";
3
+ import * as rolldown0 from "rolldown";
4
+
5
+ //#region src/rolldown.d.ts
6
+ declare const _default: (options?: Options | undefined) => rolldown0.Plugin<any> | rolldown0.Plugin<any>[];
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-k-9RVLWt.js";
2
+ import { createRolldownPlugin } from "unplugin";
3
+
4
+ //#region src/rolldown.ts
5
+ var rolldown_default = createRolldownPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { rolldown_default as default };
package/dist/rollup.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import * as rollup from 'rollup';
2
- import { Options } from './types.js';
3
- import '@vue.ts/common';
4
- import 'magic-string';
5
- import 'typescript';
1
+ import { Options } from "./types-CFmCIAvs.js";
2
+ import "./types-u_Hr5uXA.js";
3
+ import * as rollup0 from "rollup";
6
4
 
7
- declare const _default: (options?: Options | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[];
8
-
9
- export { _default as default };
5
+ //#region src/rollup.d.ts
6
+ declare const _default: (options?: Options | undefined) => rollup0.Plugin<any> | rollup0.Plugin<any>[];
7
+ //#endregion
8
+ export { _default as default };
package/dist/rollup.js ADDED
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-k-9RVLWt.js";
2
+ import { createRollupPlugin } from "unplugin";
3
+
4
+ //#region src/rollup.ts
5
+ var rollup_default = createRollupPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { rollup_default as default };
package/dist/rspack.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { Options } from './types.js';
2
- import '@vue.ts/common';
3
- import 'magic-string';
4
- import 'typescript';
1
+ import { Options } from "./types-CFmCIAvs.js";
2
+ import "./types-u_Hr5uXA.js";
5
3
 
4
+ //#region src/rspack.d.ts
6
5
  declare const _default: (options?: Options | undefined) => RspackPluginInstance;
7
-
8
- export { _default as default };
6
+ //#endregion
7
+ export { _default as default };
package/dist/rspack.js ADDED
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-k-9RVLWt.js";
2
+ import { createRspackPlugin } from "unplugin";
3
+
4
+ //#region src/rspack.ts
5
+ var rspack_default = createRspackPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { rspack_default as default };
@@ -0,0 +1,360 @@
1
+ import { createUnplugin } from "unplugin";
2
+ import { createFilter, normalizePath } from "@vue.ts/common";
3
+ import { ensureLanguage, getLanguage } from "@vue.ts/language";
4
+ import MagicString from "magic-string";
5
+ import ts from "typescript";
6
+ import { join } from "node:path";
7
+
8
+ //#region src/core/utils.ts
9
+ const resolveOptions = (rawOptions) => ({
10
+ include: rawOptions.include ?? ["**/*.vue"],
11
+ exclude: rawOptions.exclude ?? ["node_modules/**"],
12
+ tsconfigPath: rawOptions.tsconfigPath ?? join(process.cwd(), "tsconfig.json"),
13
+ defineEmits: rawOptions.defineEmits ?? true,
14
+ defineProps: rawOptions.defineProps ?? true
15
+ });
16
+ const quotesReg = /"/g;
17
+ const escapeQuotes = (s) => s.replace(quotesReg, "\\\"");
18
+
19
+ //#endregion
20
+ //#region src/core/printer.ts
21
+ var Printer = class {
22
+ constructor(checker) {
23
+ this.checker = checker;
24
+ }
25
+ getBaseType(nodeOrType) {
26
+ if ("kind" in nodeOrType) nodeOrType = this.checker.getTypeAtLocation(nodeOrType);
27
+ return this.checker.getBaseConstraintOfType(nodeOrType) ?? this.checker.getBaseTypeOfLiteralType(nodeOrType);
28
+ }
29
+ typeToString(type) {
30
+ return this.checker.typeToString(type, void 0, ts.TypeFormatFlags.NoTruncation);
31
+ }
32
+ printIntersectionTypeNode(node) {
33
+ return node.types.map((t) => this.print(t)).join(" & ");
34
+ }
35
+ printUnionTypeNode(node) {
36
+ return node.types.map((t) => this.print(t)).join(" | ");
37
+ }
38
+ printTypeLiteralNode(node) {
39
+ const parts = ["{"];
40
+ for (const member of node.members) if (ts.isPropertySignature(member)) {
41
+ const stringBaseType = member.type ? this.typeToString(this.getBaseType(member.type)) : "any";
42
+ parts.push([
43
+ member.name.getText(),
44
+ member.questionToken?.getText(),
45
+ ": ",
46
+ stringBaseType
47
+ ].filter(Boolean).join(""));
48
+ }
49
+ parts.push("}");
50
+ return parts.join("\n");
51
+ }
52
+ printTypeByType(node) {
53
+ const type = this.checker.getTypeAtLocation(node);
54
+ const properties = type.getProperties();
55
+ const parts = ["{"];
56
+ const isMapped = ts.isMappedTypeNode(node);
57
+ for (const property of properties) {
58
+ const isOptional = property.flags & ts.SymbolFlags.Optional;
59
+ const questionToken = isMapped ? node.questionToken?.getText() ?? "" : isOptional ? "?" : "";
60
+ const valueType = this.checker.getTypeOfSymbol(property);
61
+ const stringValueType = this.typeToString(this.getBaseType(valueType));
62
+ parts.push(`${this.checker.symbolToString(property)}${questionToken}: ${stringValueType}`);
63
+ }
64
+ parts.push("}");
65
+ return parts.join("\n");
66
+ }
67
+ printIdentifier(node) {
68
+ const symbol = this.checker.getSymbolAtLocation(node);
69
+ if (!symbol) return node.getText();
70
+ const declarations = symbol.getDeclarations();
71
+ if (!declarations || declarations.length === 0) return node.getText();
72
+ return this.print(declarations[0]);
73
+ }
74
+ printInterfaceDeclaration(node) {
75
+ const parts = ["{"];
76
+ for (const member of node.members) if (ts.isPropertySignature(member)) {
77
+ const stringBaseType = member.type ? this.print(member.type) : "any";
78
+ parts.push([
79
+ member.name?.getText(),
80
+ member.questionToken?.getText(),
81
+ ": ",
82
+ stringBaseType
83
+ ].filter(Boolean).join(""));
84
+ } else if (ts.isMethodSignature(member)) {
85
+ const signature = this.checker.getSignatureFromDeclaration(member);
86
+ const returnType = signature ? this.typeToString(signature.getReturnType()) : "any";
87
+ const parameters = member.parameters.map((param) => {
88
+ const paramType = param.type ? this.typeToString(this.getBaseType(param.type)) : "any";
89
+ return `${param.name.getText()}: ${paramType}`;
90
+ }).join(", ");
91
+ parts.push(`${member.name?.getText()}(${parameters}): ${returnType}`);
92
+ }
93
+ parts.push("}");
94
+ let result = parts.join("\n");
95
+ if (node.heritageClauses && node.heritageClauses.length > 0) result = node.heritageClauses.map((clause) => this.print(clause)).join(" & ");
96
+ return result;
97
+ }
98
+ printEnumDeclaration(node) {
99
+ const parts = ["{"];
100
+ for (const member of node.members) {
101
+ const name = member.name.getText();
102
+ if (member.initializer) {
103
+ const value = member.initializer.getText();
104
+ parts.push(`${name}: ${value}`);
105
+ } else parts.push(`${name}: number`);
106
+ }
107
+ parts.push("}");
108
+ return parts.join("\n");
109
+ }
110
+ printClassDeclaration(node) {
111
+ const parts = ["{"];
112
+ for (const member of node.members) if (ts.isPropertyDeclaration(member)) {
113
+ const name = member.name?.getText();
114
+ const typeAnnotation = member.type ? this.typeToString(this.getBaseType(member.type)) : "any";
115
+ const optional = member.questionToken ? "?" : "";
116
+ parts.push(`${name}${optional}: ${typeAnnotation}`);
117
+ } else if (ts.isMethodDeclaration(member)) {
118
+ const name = member.name?.getText();
119
+ const signature = this.checker.getSignatureFromDeclaration(member);
120
+ const returnType = signature ? this.typeToString(signature.getReturnType()) : "any";
121
+ const parameters = member.parameters.map((param) => {
122
+ const paramType = param.type ? this.typeToString(this.getBaseType(param.type)) : "any";
123
+ return `${param.name.getText()}: ${paramType}`;
124
+ }).join(", ");
125
+ parts.push(`${name}(${parameters}): ${returnType}`);
126
+ } else if (ts.isConstructorDeclaration(member)) {
127
+ const parameters = member.parameters.map((param) => {
128
+ const paramType = param.type ? this.typeToString(this.getBaseType(param.type)) : "any";
129
+ return `${param.name.getText()}: ${paramType}`;
130
+ }).join(", ");
131
+ parts.push(`constructor(${parameters}): void`);
132
+ }
133
+ parts.push("}");
134
+ return parts.join("\n");
135
+ }
136
+ printFunctionTypeNode(node) {
137
+ const parameters = node.parameters.map((param) => {
138
+ const paramType = param.type ? this.print(param.type) : "any";
139
+ const optional = param.questionToken ? "?" : "";
140
+ const rest = param.dotDotDotToken ? "..." : "";
141
+ return `${rest}${param.name.getText()}${optional}: ${paramType}`;
142
+ }).join(", ");
143
+ const returnType = node.type ? this.print(node.type) : "any";
144
+ return `(${parameters}) => ${returnType}`;
145
+ }
146
+ printConstructorTypeNode(node) {
147
+ const parameters = node.parameters.map((param) => {
148
+ const paramType = param.type ? this.print(param.type) : "any";
149
+ const optional = param.questionToken ? "?" : "";
150
+ const rest = param.dotDotDotToken ? "..." : "";
151
+ return `${rest}${param.name.getText()}${optional}: ${paramType}`;
152
+ }).join(", ");
153
+ const returnType = node.type ? this.print(node.type) : "any";
154
+ return `new (${parameters}) => ${returnType}`;
155
+ }
156
+ printTypeQueryNode(node) {
157
+ const exprName = node.exprName.getText();
158
+ return `typeof ${exprName}`;
159
+ }
160
+ printArrayTypeNode(node) {
161
+ return `${this.print(node.elementType)}[]`;
162
+ }
163
+ printTupleTypeNode(node) {
164
+ const elements = node.elements.map((element) => {
165
+ if (ts.isRestTypeNode(element)) return `...${this.print(element.type)}`;
166
+ if (ts.isOptionalTypeNode(element)) return `${this.print(element.type)}?`;
167
+ if (ts.isNamedTupleMember(element)) {
168
+ const type = this.print(element.type);
169
+ const optional = element.questionToken ? "?" : "";
170
+ const rest = element.dotDotDotToken ? "..." : "";
171
+ return `${rest}${element.name.getText()}${optional}: ${type}`;
172
+ }
173
+ return this.print(element);
174
+ });
175
+ return `[${elements.join(", ")}]`;
176
+ }
177
+ printConditionalTypeNode(node) {
178
+ const conditionalType = this.checker.getTypeAtLocation(node);
179
+ if (conditionalType && !(conditionalType.flags & ts.TypeFlags.Conditional)) {
180
+ const resolvedTypeString = this.typeToString(conditionalType);
181
+ if (resolvedTypeString !== node.getText()) return resolvedTypeString;
182
+ }
183
+ const checkType = this.print(node.checkType);
184
+ const extendsType = this.print(node.extendsType);
185
+ const trueType = this.print(node.trueType);
186
+ const falseType = this.print(node.falseType);
187
+ return `${checkType} extends ${extendsType} ? ${trueType} : ${falseType}`;
188
+ }
189
+ printIndexedAccessTypeNode(node) {
190
+ const objectType = this.print(node.objectType);
191
+ const indexType = this.print(node.indexType);
192
+ return `${objectType}[${indexType}]`;
193
+ }
194
+ printHeritageClause(node) {
195
+ if (node.token === ts.SyntaxKind.ExtendsKeyword) {
196
+ const parts = [];
197
+ for (const type of node.types) if (ts.isExpressionWithTypeArguments(type)) if (type.expression && type.typeArguments) parts.push(this.print(type));
198
+ else parts.push(this.print(type.expression));
199
+ return parts.join(" & ");
200
+ }
201
+ return "";
202
+ }
203
+ printImportSpecifier(node) {
204
+ const name = node.propertyName ? node.propertyName.getText() : node.name.getText();
205
+ const symbol = this.checker.getSymbolAtLocation(node.name);
206
+ if (!symbol) return name;
207
+ const aliasedSymbol = this.checker.getAliasedSymbol(symbol);
208
+ const targetSymbol = aliasedSymbol || symbol;
209
+ const declarations = targetSymbol.getDeclarations();
210
+ if (!declarations || declarations.length === 0) return name;
211
+ const declaration = declarations.find((decl) => ts.isTypeAliasDeclaration(decl) || ts.isInterfaceDeclaration(decl) || ts.isClassDeclaration(decl) || ts.isEnumDeclaration(decl) || ts.isVariableDeclaration(decl));
212
+ if (declaration) return this.print(declaration);
213
+ return name;
214
+ }
215
+ isKeywordTypeNode(node) {
216
+ return node.kind === ts.SyntaxKind.StringKeyword || node.kind === ts.SyntaxKind.NumberKeyword || node.kind === ts.SyntaxKind.BooleanKeyword || node.kind === ts.SyntaxKind.ObjectKeyword || node.kind === ts.SyntaxKind.UndefinedKeyword || node.kind === ts.SyntaxKind.NullKeyword || node.kind === ts.SyntaxKind.VoidKeyword || node.kind === ts.SyntaxKind.AnyKeyword || node.kind === ts.SyntaxKind.UnknownKeyword || node.kind === ts.SyntaxKind.NeverKeyword || node.kind === ts.SyntaxKind.SymbolKeyword || node.kind === ts.SyntaxKind.BigIntKeyword;
217
+ }
218
+ print(node) {
219
+ if (ts.isIdentifier(node)) return this.printIdentifier(node);
220
+ else if (ts.isIntersectionTypeNode(node)) return this.printIntersectionTypeNode(node);
221
+ else if (ts.isUnionTypeNode(node)) return this.printUnionTypeNode(node);
222
+ else if (ts.isTypeLiteralNode(node)) return this.printTypeLiteralNode(node);
223
+ else if (ts.isTypeReferenceNode(node)) return this.print(node.typeName);
224
+ else if (ts.isInterfaceDeclaration(node)) return this.printInterfaceDeclaration(node);
225
+ else if (ts.isTypeAliasDeclaration(node)) return node.type ? this.print(node.type) : "any";
226
+ else if (ts.isEnumDeclaration(node)) return this.printEnumDeclaration(node);
227
+ else if (ts.isClassDeclaration(node)) return this.printClassDeclaration(node);
228
+ else if (ts.isFunctionTypeNode(node)) return this.printFunctionTypeNode(node);
229
+ else if (ts.isConstructorTypeNode(node)) return this.printConstructorTypeNode(node);
230
+ else if (ts.isTypeQueryNode(node)) return this.printTypeQueryNode(node);
231
+ else if (ts.isArrayTypeNode(node)) return this.printArrayTypeNode(node);
232
+ else if (ts.isTupleTypeNode(node)) return this.printTupleTypeNode(node);
233
+ else if (ts.isConditionalTypeNode(node)) return this.printConditionalTypeNode(node);
234
+ else if (ts.isIndexedAccessTypeNode(node)) return this.printIndexedAccessTypeNode(node);
235
+ else if (ts.isParenthesizedTypeNode(node)) return this.print(node.type);
236
+ else if (ts.isHeritageClause(node)) return this.printHeritageClause(node);
237
+ else if (ts.isTypeAliasDeclaration(node) && node.type) return this.print(node.type);
238
+ else if (ts.isInterfaceDeclaration(node)) return this.printInterfaceDeclaration(node);
239
+ else if (ts.isVariableDeclaration(node) && node.type) return this.print(node.type);
240
+ else if (ts.isImportSpecifier(node)) return this.printImportSpecifier(node);
241
+ else if (ts.isTypeParameterDeclaration(node)) {
242
+ if (node.constraint) return this.print(node.constraint);
243
+ else if (node.default) return this.print(node.default);
244
+ return "{}";
245
+ } else if (ts.isParameter(node) && node.type) return this.print(node.type);
246
+ else if (ts.isLiteralTypeNode(node) || ts.isThisTypeNode(node) || ts.isPropertyAccessExpression(node) || this.isKeywordTypeNode(node)) return node.getText();
247
+ else if (ts.isMappedTypeNode(node) || ts.isExpressionWithTypeArguments(node)) return this.printTypeByType(node);
248
+ else {
249
+ console.error(`[@vue.ts/complex-types] \`${ts.SyntaxKind[node.kind]}\` is not supported.`);
250
+ return node.getText();
251
+ }
252
+ }
253
+ printEventsByCallSignatures(callSignatures) {
254
+ return callSignatures.map((c) => {
255
+ const parameters = c.getParameters();
256
+ const event = parameters[0];
257
+ return this.typeToString(this.checker.getTypeOfSymbol(event));
258
+ });
259
+ }
260
+ printEventsByMembers(members) {
261
+ return members.map((m) => `"${escapeQuotes(m.getName())}"`);
262
+ }
263
+ printEventsRuntimeArg(node) {
264
+ const parts = [];
265
+ const type = this.checker.getTypeAtLocation(node);
266
+ const callSignatures = type.getCallSignatures();
267
+ const members = type.getProperties();
268
+ if (callSignatures.length > 0 && members.length > 0) throw new Error("[@vue.ts/complex-types] You may not use old style `defineEmits` and `defineEmits` shorthand together.");
269
+ if (members.length > 0) parts.push(...this.printEventsByMembers(members));
270
+ else parts.push(...this.printEventsByCallSignatures(callSignatures));
271
+ return `[${parts.join(", ")}]`;
272
+ }
273
+ };
274
+
275
+ //#endregion
276
+ //#region src/core/transformers/defineEmits.ts
277
+ const transformDefineEmits = (printer, s, id) => {
278
+ const normalizedFilepath = normalizePath(id);
279
+ const language = getLanguage();
280
+ const scriptSetupBlock = language.getScriptSetupBlock(normalizedFilepath);
281
+ const scriptSetupAst = language.getScriptSetupAst(normalizedFilepath);
282
+ const virtualFileAst = language.getVirtualFileOrTsAst(normalizedFilepath);
283
+ if (!scriptSetupBlock || !scriptSetupAst || !virtualFileAst) return;
284
+ const scriptSetupDefineEmitsNode = language.findNodeByRange(scriptSetupAst, (scriptSetupRanges) => scriptSetupRanges.defineEmits?.callExp);
285
+ const virtualFileDefineEmitsTypeNode = language.findNodeByName(virtualFileAst, "__VLS_Emit");
286
+ if (!scriptSetupDefineEmitsNode || !virtualFileDefineEmitsTypeNode) return;
287
+ const offset = scriptSetupBlock.startTagEnd;
288
+ const defineEmitsRuntimeArg = ts.isCallExpression(scriptSetupDefineEmitsNode) && scriptSetupDefineEmitsNode.arguments[0];
289
+ if (defineEmitsRuntimeArg) throw new Error("[@vue.ts/complex-types] `defineEmits` cannot accept both runtime argument and type argument.");
290
+ const tokens = scriptSetupDefineEmitsNode.getChildren(scriptSetupAst);
291
+ const lessThanToken = tokens.find((t) => t.kind === ts.SyntaxKind.LessThanToken);
292
+ const greaterThanToken = tokens.find((t) => t.kind === ts.SyntaxKind.GreaterThanToken);
293
+ const openParenToken = tokens.find((t) => t.kind === ts.SyntaxKind.OpenParenToken);
294
+ if (!lessThanToken || !greaterThanToken || !openParenToken) return;
295
+ const defineEmitsTypeArgRange = [offset + lessThanToken.pos, offset + greaterThanToken.end];
296
+ const runtimeArgPos = offset + openParenToken.end;
297
+ const printedRuntimeArg = printer.printEventsRuntimeArg(virtualFileDefineEmitsTypeNode);
298
+ s.remove(...defineEmitsTypeArgRange);
299
+ s.appendRight(runtimeArgPos, printedRuntimeArg);
300
+ };
301
+
302
+ //#endregion
303
+ //#region src/core/transformers/defineProps.ts
304
+ const transformDefineProps = (printer, s, id) => {
305
+ const normalizedFilepath = normalizePath(id);
306
+ const language = getLanguage();
307
+ const scriptSetupBlock = language.getScriptSetupBlock(normalizedFilepath);
308
+ const scriptSetupAst = language.getScriptSetupAst(normalizedFilepath);
309
+ const virtualFileAst = language.getVirtualFileOrTsAst(normalizedFilepath);
310
+ if (!scriptSetupBlock || !scriptSetupAst || !virtualFileAst) return;
311
+ const scriptSetupDefinePropsTypeRange = language.parseScriptSetupRanges(scriptSetupAst).defineProps?.typeArg;
312
+ const virtualFileDefinePropsTypeNode = language.findNodeByName(virtualFileAst, "__VLS_Props");
313
+ if (!scriptSetupDefinePropsTypeRange || !virtualFileDefinePropsTypeNode) return;
314
+ const printedType = printer.print(virtualFileDefinePropsTypeNode);
315
+ const offset = scriptSetupBlock.startTagEnd;
316
+ s.overwrite(offset + scriptSetupDefinePropsTypeRange.start, offset + scriptSetupDefinePropsTypeRange.end, printedType);
317
+ };
318
+
319
+ //#endregion
320
+ //#region src/core/transformers/index.ts
321
+ const transformers = [["defineEmits", transformDefineEmits], ["defineProps", transformDefineProps]];
322
+ const getTransformers = (options) => transformers.filter(([key]) => !!options[key]);
323
+
324
+ //#endregion
325
+ //#region src/core/transform.ts
326
+ function transform(code, id, options) {
327
+ const s = new MagicString(code);
328
+ const language = getLanguage();
329
+ const typeChecker = language.__internal__.typeChecker;
330
+ const printer = new Printer(typeChecker);
331
+ const transformers$1 = getTransformers(options);
332
+ for (const [, transform$1] of transformers$1) transform$1(printer, s, id);
333
+ return {
334
+ code: s.toString(),
335
+ map: s.generateMap({ hires: true })
336
+ };
337
+ }
338
+
339
+ //#endregion
340
+ //#region src/index.ts
341
+ const unpluginFactory = (options = {}) => {
342
+ const resolvedOptions = resolveOptions(options);
343
+ const filter = createFilter(resolvedOptions.include, resolvedOptions.exclude);
344
+ return {
345
+ name: "@vue.ts/complex-types",
346
+ buildStart() {
347
+ const resolvedOptions$1 = resolveOptions(options);
348
+ ensureLanguage(resolvedOptions$1.tsconfigPath);
349
+ },
350
+ transform(code, id) {
351
+ if (!filter(id)) return;
352
+ return transform(code, id, resolvedOptions);
353
+ }
354
+ };
355
+ };
356
+ const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
357
+ var src_default = unplugin;
358
+
359
+ //#endregion
360
+ export { src_default, unplugin, unpluginFactory };