@vue.ts/complex-types 1.0.0-beta.3 → 1.0.0-beta.4

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 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
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/@vue.ts/complex-types?color=a1b858&label=)](https://www.npmjs.com/package/@vue.ts/complex-types)
4
4
 
5
- Use [`@vue/language-core`](https://github.com/vuejs/language-tools/tree/master/packages/language-core) to support complex types for Vue Macros.
5
+ Use [`@vue/language-core`](https://github.com/vuejs/language-tools/tree/master/packages/language-core) to support complex types for Vue's Macros.
6
6
 
7
7
  For example: fixes https://github.com/vuejs/core/issues/8286.
8
8
 
package/dist/astro.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
 
3
3
  //#region src/astro.d.ts
4
4
  declare const _default: (options: Options) => {
package/dist/astro.js CHANGED
@@ -1,4 +1,4 @@
1
- import { unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { unpluginFactory } from "./src-koVD0EYI.js";
2
2
  import { createVitePlugin } from "unplugin";
3
3
 
4
4
  //#region src/astro.ts
package/dist/esbuild.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
  import * as esbuild0 from "esbuild";
4
4
 
package/dist/esbuild.js CHANGED
@@ -1,4 +1,4 @@
1
- import { unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { unpluginFactory } from "./src-koVD0EYI.js";
2
2
  import { createEsbuildPlugin } from "unplugin";
3
3
 
4
4
  //#region src/esbuild.ts
package/dist/farm.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
  import * as _farmfe_core0 from "@farmfe/core";
4
4
 
package/dist/farm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { unpluginFactory } from "./src-koVD0EYI.js";
2
2
  import { createFarmPlugin } from "unplugin";
3
3
 
4
4
  //#region src/farm.ts
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import * as unplugin0 from "unplugin";
3
3
  import { UnpluginFactory } from "unplugin";
4
4
 
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { src_default, unplugin, unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { src_default, unplugin, unpluginFactory } from "./src-koVD0EYI.js";
2
2
 
3
3
  export { src_default as default, unplugin, unpluginFactory };
package/dist/nuxt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
  import * as _nuxt_schema0 from "@nuxt/schema";
4
4
 
package/dist/nuxt.js CHANGED
@@ -1,6 +1,6 @@
1
- import "./src-C2cWUkxC.js";
2
- import { vite_default } from "./vite-kxApzRU8.js";
3
- import { webpack_default } from "./webpack-DB3Ln7vl.js";
1
+ import "./src-koVD0EYI.js";
2
+ import { vite_default } from "./vite-DFtk2L0c.js";
3
+ import { webpack_default } from "./webpack-BWJ3ulvy.js";
4
4
  import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
5
5
 
6
6
  //#region src/nuxt.ts
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
  import * as rolldown0 from "rolldown";
4
4
 
package/dist/rolldown.js CHANGED
@@ -1,4 +1,4 @@
1
- import { unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { unpluginFactory } from "./src-koVD0EYI.js";
2
2
  import { createRolldownPlugin } from "unplugin";
3
3
 
4
4
  //#region src/rolldown.ts
package/dist/rollup.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
  import * as rollup0 from "rollup";
4
4
 
package/dist/rollup.js CHANGED
@@ -1,4 +1,4 @@
1
- import { unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { unpluginFactory } from "./src-koVD0EYI.js";
2
2
  import { createRollupPlugin } from "unplugin";
3
3
 
4
4
  //#region src/rollup.ts
package/dist/rspack.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
 
4
4
  //#region src/rspack.d.ts
package/dist/rspack.js CHANGED
@@ -1,4 +1,4 @@
1
- import { unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { unpluginFactory } from "./src-koVD0EYI.js";
2
2
  import { createRspackPlugin } from "unplugin";
3
3
 
4
4
  //#region src/rspack.ts
@@ -4,15 +4,17 @@ import { createFilter, normalizePath } from "@vue.ts/shared";
4
4
  import MagicString from "magic-string";
5
5
  import ts from "typescript";
6
6
  import { join } from "node:path";
7
+ import { defu } from "defu";
7
8
 
8
9
  //#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
- });
10
+ const defaultOptions = {
11
+ include: ["**/*.vue"],
12
+ exclude: ["node_modules/**"],
13
+ tsconfigPath: join(process.cwd(), "tsconfig.json"),
14
+ defineEmits: true,
15
+ defineProps: true
16
+ };
17
+ const resolveOptions = (rawOptions) => defu(rawOptions, defaultOptions);
16
18
  const quotesReg = /"/g;
17
19
  const escapeQuotes = (s) => s.replace(quotesReg, "\\\"");
18
20
 
@@ -25,11 +27,18 @@ var Printer = class {
25
27
  typeToString(type) {
26
28
  return this.checker.typeToString(type, void 0, ts.TypeFormatFlags.NoTruncation);
27
29
  }
28
- printOuterUnionOrIntersection(type, separator, inner) {
30
+ printUnionOrIntersection(type, separator, inner) {
29
31
  return [...new Set(type.types.map((t) => this.printType(t, inner)).filter(Boolean))].join(separator);
30
32
  }
31
- isUnionUndefined(union) {
32
- return union.types.some((t) => t.flags & ts.TypeFlags.Undefined);
33
+ containsUndefined(type) {
34
+ return type.isUnion() ? type.types.some((t) => t.flags & ts.TypeFlags.Undefined) : !!(type.flags & ts.TypeFlags.Undefined);
35
+ }
36
+ printConditionTypeNode(type) {
37
+ const decl = type.root.node;
38
+ const { trueType, falseType } = decl;
39
+ const trueTypeNode = this.checker.getTypeAtLocation(trueType);
40
+ const falseTypeNode = this.checker.getTypeAtLocation(falseType);
41
+ return `${this.printType(trueTypeNode)} | ${this.printType(falseTypeNode)}`;
33
42
  }
34
43
  printPrimitiveType(type) {
35
44
  if (type.flags & ts.TypeFlags.BooleanLiteral) return "boolean";
@@ -42,9 +51,9 @@ var Printer = class {
42
51
  return "";
43
52
  }
44
53
  printType(type, inner = false) {
45
- if (type.isUnion()) return this.printOuterUnionOrIntersection(type, " | ", inner);
46
- else if (type.isIntersection()) return this.printOuterUnionOrIntersection(type, " & ", inner);
47
- if (this.typeToString(type).endsWith("[]")) return this.typeToString(type);
54
+ if (type.isUnion()) return this.printUnionOrIntersection(type, " | ", inner);
55
+ else if (type.isIntersection()) return this.printUnionOrIntersection(type, " & ", inner);
56
+ if (this.checker.isArrayType(type)) return "Array";
48
57
  else if (type.flags & ts.TypeFlags.Object) {
49
58
  const decl = type.getSymbol()?.declarations?.[0];
50
59
  if (decl && ts.isFunctionTypeNode(decl)) return "Function";
@@ -54,19 +63,19 @@ var Printer = class {
54
63
  for (const prop of properties) {
55
64
  const propType = this.checker.getTypeOfSymbol(prop);
56
65
  props[prop.getName()] = {
57
- value: this.printType(this.checker.getTypeOfSymbol(prop), true),
58
- isOptional: propType.isUnion() ? this.isUnionUndefined(propType) : !!(propType.flags & ts.TypeFlags.Undefined)
66
+ value: this.printType(propType, true),
67
+ isOptional: this.containsUndefined(propType)
59
68
  };
60
69
  }
61
70
  const parts = [];
62
- for (const [propName, propData] of Object.entries(props)) {
63
- const questionMark = propData.isOptional ? "?" : "";
64
- parts.push(`"${propName}"${questionMark}: ${propData.value},`);
71
+ for (const [propName, { isOptional, value }] of Object.entries(props)) {
72
+ const questionMark = isOptional ? "?" : "";
73
+ parts.push(`"${escapeQuotes(propName)}"${questionMark}: ${value},`);
65
74
  }
66
75
  return Object.keys(props).length > 0 ? `{\n${parts.join("\n")}\n}` : "";
67
76
  } else if (type.isLiteral() || type.flags & ts.TypeFlags.BooleanLiteral || type.flags & ts.TypeFlags.String || type.flags & ts.TypeFlags.Number || type.flags & ts.TypeFlags.BigInt || type.flags & ts.TypeFlags.Any || type.flags & ts.TypeFlags.Unknown || type.flags & ts.TypeFlags.Null) return this.printPrimitiveType(type);
68
77
  else if (type.flags & ts.TypeFlags.Undefined) return "";
69
- else if (type.flags & ts.TypeFlags.Conditional) return `${this.printType(type.resolvedTrueType)} | ${this.printType(type.resolvedFalseType)}`;
78
+ else if (type.flags & ts.TypeFlags.Conditional) return this.printConditionTypeNode(type);
70
79
  else if (type.isTypeParameter()) {
71
80
  const symbol = type.getSymbol();
72
81
  const decl = symbol?.declarations?.[0];
@@ -13,8 +13,9 @@ declare class Printer {
13
13
  private checker;
14
14
  constructor(checker: ts.TypeChecker);
15
15
  private typeToString;
16
- private printOuterUnionOrIntersection;
17
- private isUnionUndefined;
16
+ private printUnionOrIntersection;
17
+ private containsUndefined;
18
+ private printConditionTypeNode;
18
19
  private printPrimitiveType;
19
20
  private printType;
20
21
  printPropsTypeArg(node: ts.Node): string;
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Options, ResolvedOptions, TransformOptions, Transformer, Transformers, ValidTransforms } from "./types-afZXKowK.js";
1
+ import { Options, ResolvedOptions, TransformOptions, Transformer, Transformers, ValidTransforms } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
  export { Options, ResolvedOptions, TransformOptions, Transformer, Transformers, ValidTransforms };
@@ -1,4 +1,4 @@
1
- import { unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { unpluginFactory } from "./src-koVD0EYI.js";
2
2
  import { createVitePlugin } from "unplugin";
3
3
 
4
4
  //#region src/vite.ts
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
  import * as vite0 from "vite";
4
4
 
package/dist/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./src-C2cWUkxC.js";
2
- import { vite_default } from "./vite-kxApzRU8.js";
1
+ import "./src-koVD0EYI.js";
2
+ import { vite_default } from "./vite-DFtk2L0c.js";
3
3
 
4
4
  export { vite_default as default };
@@ -1,4 +1,4 @@
1
- import { unpluginFactory } from "./src-C2cWUkxC.js";
1
+ import { unpluginFactory } from "./src-koVD0EYI.js";
2
2
  import { createWebpackPlugin } from "unplugin";
3
3
 
4
4
  //#region src/webpack.ts
package/dist/webpack.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options } from "./types-afZXKowK.js";
1
+ import { Options } from "./types-WYBg4JEW.js";
2
2
  import "./types-u_Hr5uXA.js";
3
3
  import * as webpack0 from "webpack";
4
4
 
package/dist/webpack.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./src-C2cWUkxC.js";
2
- import { webpack_default } from "./webpack-DB3Ln7vl.js";
1
+ import "./src-koVD0EYI.js";
2
+ import { webpack_default } from "./webpack-BWJ3ulvy.js";
3
3
 
4
4
  export { webpack_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue.ts/complex-types",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "author": "Ray <i@mk1.io> (@so1ve)",
5
5
  "type": "module",
6
6
  "description": "Resolve complex types in Vue SFCs.",
@@ -62,31 +62,32 @@
62
62
  "access": "public"
63
63
  },
64
64
  "dependencies": {
65
- "@nuxt/kit": "^3.17.6",
65
+ "@nuxt/kit": "^4.0.2",
66
+ "defu": "^6.1.4",
66
67
  "magic-string": "^0.30.17",
67
68
  "unplugin": "^2.3.5",
68
- "@vue.ts/language": "1.0.0-beta.3",
69
- "@vue.ts/shared": "1.0.0-beta.3"
69
+ "@vue.ts/language": "1.0.0-beta.4",
70
+ "@vue.ts/shared": "1.0.0-beta.4"
70
71
  },
71
72
  "devDependencies": {
72
- "@nuxt/schema": "^3.17.6",
73
+ "@nuxt/schema": "^4.0.2",
73
74
  "@vue-macros/better-define": "^1.11.4",
74
75
  "rolldown": "1.0.0-beta.27",
75
- "rollup": "^4.44.2",
76
+ "rollup": "^4.46.2",
76
77
  "vite": "^7.0.4",
77
- "webpack": "^5.100.1"
78
+ "webpack": "^5.101.0"
78
79
  },
79
80
  "peerDependencies": {
80
- "@farmfe/core": ">=1",
81
- "@nuxt/kit": "^3 || ^4",
82
- "@nuxt/schema": "^3 || ^4",
81
+ "@farmfe/core": ">=1.7.10",
82
+ "@nuxt/kit": "^4.0.2",
83
+ "@nuxt/schema": "^4.0.2",
83
84
  "esbuild": "*",
84
85
  "rolldown": "*",
85
- "rollup": "^3",
86
- "typescript": ">=5.5",
87
- "vite": ">=3",
88
- "vue": ">=3",
89
- "webpack": "^4 || ^5"
86
+ "rollup": "^4.46.2",
87
+ "typescript": ">=5.9.2",
88
+ "vite": ">=7.0.6",
89
+ "vue": ">=3.5.18",
90
+ "webpack": "^5.101.0"
90
91
  },
91
92
  "peerDependenciesMeta": {
92
93
  "@farmfe/core": {