@vue.ts/complex-types 0.6.0 → 1.0.0-beta.1
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 -21
- package/README.md +19 -0
- package/dist/astro.d.ts +8 -10
- package/dist/astro.js +14 -0
- package/dist/esbuild.d.ts +7 -8
- package/dist/esbuild.js +8 -0
- package/dist/farm.d.ts +8 -0
- package/dist/farm.js +8 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +3 -0
- package/dist/nuxt.d.ts +7 -8
- package/dist/nuxt.js +20 -0
- package/dist/rolldown.d.ts +8 -0
- package/dist/rolldown.js +8 -0
- package/dist/rollup.d.ts +7 -8
- package/dist/rollup.js +8 -0
- package/dist/rspack.d.ts +5 -6
- package/dist/rspack.js +8 -0
- package/dist/src-CI8-WIu4.js +354 -0
- package/dist/types-CFmCIAvs.d.ts +51 -0
- package/dist/types-u_Hr5uXA.d.ts +1 -0
- package/dist/types.d.ts +3 -30
- package/dist/types.js +0 -0
- package/dist/vite-Dyi1m2wg.js +8 -0
- package/dist/vite.d.ts +7 -8
- package/dist/vite.js +4 -0
- package/dist/webpack-CFfuQfGw.js +8 -0
- package/dist/webpack.d.ts +7 -8
- package/dist/webpack.js +4 -0
- package/package.json +67 -53
- package/dist/astro.cjs +0 -22
- package/dist/astro.d.cts +0 -13
- package/dist/astro.d.mts +0 -13
- package/dist/astro.mjs +0 -20
- package/dist/esbuild.cjs +0 -13
- package/dist/esbuild.d.cts +0 -9
- package/dist/esbuild.d.mts +0 -9
- package/dist/esbuild.mjs +0 -11
- package/dist/index.cjs +0 -238
- package/dist/index.d.cts +0 -9
- package/dist/index.d.mts +0 -9
- package/dist/index.mjs +0 -231
- package/dist/nuxt.cjs +0 -35
- package/dist/nuxt.d.cts +0 -9
- package/dist/nuxt.d.mts +0 -9
- package/dist/nuxt.mjs +0 -33
- package/dist/rollup.cjs +0 -13
- package/dist/rollup.d.cts +0 -9
- package/dist/rollup.d.mts +0 -9
- package/dist/rollup.mjs +0 -11
- package/dist/rspack.cjs +0 -13
- package/dist/rspack.d.cts +0 -8
- package/dist/rspack.d.mts +0 -8
- package/dist/rspack.mjs +0 -11
- package/dist/types.cjs +0 -2
- package/dist/types.d.cts +0 -30
- package/dist/types.d.mts +0 -30
- package/dist/types.mjs +0 -1
- package/dist/vite.cjs +0 -13
- package/dist/vite.d.cts +0 -9
- package/dist/vite.d.mts +0 -9
- package/dist/vite.mjs +0 -11
- package/dist/webpack.cjs +0 -13
- package/dist/webpack.d.cts +0 -9
- package/dist/webpack.d.mts +0 -9
- package/dist/webpack.mjs +0 -11
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import MagicString from "magic-string";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { FilterPattern } from "@rollup/pluginutils";
|
|
4
|
+
|
|
5
|
+
//#region ../common/src/types.d.ts
|
|
6
|
+
interface BaseOptions {
|
|
7
|
+
include?: FilterPattern;
|
|
8
|
+
exclude?: FilterPattern;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/core/printer.d.ts
|
|
12
|
+
declare class Printer {
|
|
13
|
+
private checker;
|
|
14
|
+
constructor(checker: ts.TypeChecker);
|
|
15
|
+
private getBaseType;
|
|
16
|
+
private typeToString;
|
|
17
|
+
private printIntersectionTypeNode;
|
|
18
|
+
private printUnionTypeNode;
|
|
19
|
+
private printTypeLiteralNode;
|
|
20
|
+
private printTypeByType;
|
|
21
|
+
private printIdentifier;
|
|
22
|
+
private printInterfaceDeclaration;
|
|
23
|
+
private printEnumDeclaration;
|
|
24
|
+
private printClassDeclaration;
|
|
25
|
+
private printFunctionTypeNode;
|
|
26
|
+
private printConstructorTypeNode;
|
|
27
|
+
private printTypeQueryNode;
|
|
28
|
+
private printArrayTypeNode;
|
|
29
|
+
private printTupleTypeNode;
|
|
30
|
+
private printConditionalTypeNode;
|
|
31
|
+
private printIndexedAccessTypeNode;
|
|
32
|
+
private printHeritageClause;
|
|
33
|
+
private printImportSpecifier;
|
|
34
|
+
private isKeywordTypeNode;
|
|
35
|
+
print(node: ts.Node): string;
|
|
36
|
+
private printEventsByCallSignatures;
|
|
37
|
+
private printEventsByMembers;
|
|
38
|
+
printEventsRuntimeArg(node: ts.Node): string;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/core/types.d.ts
|
|
42
|
+
type ValidTransforms = "defineEmits" | "defineProps";
|
|
43
|
+
type Options = {
|
|
44
|
+
tsconfigPath?: string;
|
|
45
|
+
} & Partial<Record<ValidTransforms, boolean>> & BaseOptions;
|
|
46
|
+
type ResolvedOptions = Required<Options>;
|
|
47
|
+
type TransformOptions = Pick<ResolvedOptions, ValidTransforms>;
|
|
48
|
+
type Transformer = (printer: Printer, s: MagicString, id: string) => void;
|
|
49
|
+
type Transformers = [ValidTransforms, Transformer][];
|
|
50
|
+
//#endregion
|
|
51
|
+
export { Options, ResolvedOptions, TransformOptions, Transformer, Transformers, ValidTransforms };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare class Printer {
|
|
6
|
-
private checker;
|
|
7
|
-
constructor(checker: ts.TypeChecker);
|
|
8
|
-
private getBaseType;
|
|
9
|
-
private printIntersectionTypeNode;
|
|
10
|
-
private printUnionTypeNode;
|
|
11
|
-
private printTypeLiteralNode;
|
|
12
|
-
private printByType;
|
|
13
|
-
printTypeArg(node: ts.Node): string;
|
|
14
|
-
private printEventsByCallSignatures;
|
|
15
|
-
private printEventsByMembers;
|
|
16
|
-
printEventsRuntimeArg(node: ts.Node): string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type ValidTransforms = "defineEmits" | "defineProps";
|
|
20
|
-
type Options = {
|
|
21
|
-
tsconfigPath?: string;
|
|
22
|
-
} & {
|
|
23
|
-
[Transform in ValidTransforms]?: boolean;
|
|
24
|
-
} & BaseOptions;
|
|
25
|
-
type ResolvedOptions = Required<Options>;
|
|
26
|
-
type TransformOptions = Pick<ResolvedOptions, ValidTransforms>;
|
|
27
|
-
type Transformer = (printer: Printer, s: MagicString, id: string) => void;
|
|
28
|
-
type Transformers = [ValidTransforms, Transformer][];
|
|
29
|
-
|
|
30
|
-
export type { Options, ResolvedOptions, TransformOptions, Transformer, Transformers, ValidTransforms };
|
|
1
|
+
import { Options, ResolvedOptions, TransformOptions, Transformer, Transformers, ValidTransforms } from "./types-CFmCIAvs.js";
|
|
2
|
+
import "./types-u_Hr5uXA.js";
|
|
3
|
+
export { Options, ResolvedOptions, TransformOptions, Transformer, Transformers, ValidTransforms };
|
package/dist/types.js
ADDED
|
File without changes
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import 'magic-string';
|
|
5
|
-
import 'typescript';
|
|
1
|
+
import { Options } from "./types-CFmCIAvs.js";
|
|
2
|
+
import "./types-u_Hr5uXA.js";
|
|
3
|
+
import * as vite0 from "vite";
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
//#region src/vite.d.ts
|
|
6
|
+
declare const _default: (options?: Options | undefined) => vite0.Plugin<any> | vite0.Plugin<any>[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { _default as default };
|
package/dist/vite.js
ADDED
package/dist/webpack.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import 'magic-string';
|
|
5
|
-
import 'typescript';
|
|
1
|
+
import { Options } from "./types-CFmCIAvs.js";
|
|
2
|
+
import "./types-u_Hr5uXA.js";
|
|
3
|
+
import * as webpack0 from "webpack";
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
//#region src/webpack.d.ts
|
|
6
|
+
declare const _default: (options?: Options | undefined) => webpack0.WebpackPluginInstance;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { _default as default };
|
package/dist/webpack.js
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue.ts/complex-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"author": "Ray <i@mk1.io> (@so1ve)",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"description": "Resolve complex types in Vue SFCs.",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"astro",
|
|
9
|
+
"farm",
|
|
8
10
|
"nuxt",
|
|
11
|
+
"rolldown",
|
|
9
12
|
"rollup",
|
|
10
13
|
"rspack",
|
|
11
14
|
"transform",
|
|
@@ -13,6 +16,7 @@
|
|
|
13
16
|
"unplugin",
|
|
14
17
|
"vite",
|
|
15
18
|
"vue",
|
|
19
|
+
"vue.ts",
|
|
16
20
|
"webpack"
|
|
17
21
|
],
|
|
18
22
|
"homepage": "https://github.com/so1ve/vue.ts/tree/main/packages/language#readme",
|
|
@@ -27,46 +31,22 @@
|
|
|
27
31
|
"license": "MIT",
|
|
28
32
|
"sideEffects": false,
|
|
29
33
|
"exports": {
|
|
30
|
-
".":
|
|
31
|
-
"require": "./dist/index.cjs",
|
|
32
|
-
"import": "./dist/index.mjs"
|
|
33
|
-
},
|
|
34
|
+
".": "./dist/index.js",
|
|
34
35
|
"./*": "./*",
|
|
35
|
-
"./astro":
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"./
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"./
|
|
44
|
-
|
|
45
|
-
"import": "./dist/nuxt.mjs"
|
|
46
|
-
},
|
|
47
|
-
"./rollup": {
|
|
48
|
-
"require": "./dist/rollup.cjs",
|
|
49
|
-
"import": "./dist/rollup.mjs"
|
|
50
|
-
},
|
|
51
|
-
"./rspack": {
|
|
52
|
-
"require": "./dist/rspack.cjs",
|
|
53
|
-
"import": "./dist/rspack.mjs"
|
|
54
|
-
},
|
|
55
|
-
"./types": {
|
|
56
|
-
"require": "./dist/types.cjs",
|
|
57
|
-
"import": "./dist/types.mjs"
|
|
58
|
-
},
|
|
59
|
-
"./vite": {
|
|
60
|
-
"require": "./dist/vite.cjs",
|
|
61
|
-
"import": "./dist/vite.mjs"
|
|
62
|
-
},
|
|
63
|
-
"./webpack": {
|
|
64
|
-
"require": "./dist/webpack.cjs",
|
|
65
|
-
"import": "./dist/webpack.mjs"
|
|
66
|
-
}
|
|
36
|
+
"./astro": "./dist/astro.js",
|
|
37
|
+
"./esbuild": "./dist/esbuild.js",
|
|
38
|
+
"./farm": "./dist/farm.js",
|
|
39
|
+
"./nuxt": "./dist/nuxt.js",
|
|
40
|
+
"./rolldown": "./dist/rolldown.js",
|
|
41
|
+
"./rollup": "./dist/rollup.js",
|
|
42
|
+
"./rspack": "./dist/rspack.js",
|
|
43
|
+
"./types": "./dist/types.js",
|
|
44
|
+
"./vite": "./dist/vite.js",
|
|
45
|
+
"./webpack": "./dist/webpack.js"
|
|
67
46
|
},
|
|
68
|
-
"main": "./dist/index.
|
|
69
|
-
"module": "./dist/index.
|
|
47
|
+
"main": "./dist/index.js",
|
|
48
|
+
"module": "./dist/index.js",
|
|
49
|
+
"types": "dist/index.d.ts",
|
|
70
50
|
"typesVersions": {
|
|
71
51
|
"*": {
|
|
72
52
|
"*": [
|
|
@@ -82,26 +62,60 @@
|
|
|
82
62
|
"access": "public"
|
|
83
63
|
},
|
|
84
64
|
"dependencies": {
|
|
85
|
-
"@nuxt/kit": "^3.
|
|
86
|
-
"magic-string": "^0.30.
|
|
87
|
-
"unplugin": "^
|
|
88
|
-
"@vue.ts/
|
|
89
|
-
"@vue.ts/
|
|
65
|
+
"@nuxt/kit": "^3.17.6",
|
|
66
|
+
"magic-string": "^0.30.17",
|
|
67
|
+
"unplugin": "^2.3.5",
|
|
68
|
+
"@vue.ts/language": "1.0.0-beta.1",
|
|
69
|
+
"@vue.ts/common": "1.0.0-beta.1"
|
|
90
70
|
},
|
|
91
71
|
"devDependencies": {
|
|
92
|
-
"@nuxt/schema": "^3.
|
|
93
|
-
"@vue-macros/better-define": "^1.
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"vite": "^
|
|
97
|
-
"webpack": "^5.
|
|
72
|
+
"@nuxt/schema": "^3.17.6",
|
|
73
|
+
"@vue-macros/better-define": "^1.11.4",
|
|
74
|
+
"rolldown": "1.0.0-beta.27",
|
|
75
|
+
"rollup": "^4.44.2",
|
|
76
|
+
"vite": "^7.0.4",
|
|
77
|
+
"webpack": "^5.100.1"
|
|
98
78
|
},
|
|
99
79
|
"peerDependencies": {
|
|
80
|
+
"@farmfe/core": ">=1",
|
|
81
|
+
"@nuxt/kit": "^3 || ^4",
|
|
82
|
+
"@nuxt/schema": "^3 || ^4",
|
|
83
|
+
"esbuild": "*",
|
|
84
|
+
"rolldown": "*",
|
|
85
|
+
"rollup": "^3",
|
|
100
86
|
"typescript": "^5.2.2",
|
|
101
|
-
"
|
|
87
|
+
"vite": ">=3",
|
|
88
|
+
"vue": "^3.3.7",
|
|
89
|
+
"webpack": "^4 || ^5"
|
|
90
|
+
},
|
|
91
|
+
"peerDependenciesMeta": {
|
|
92
|
+
"@farmfe/core": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@nuxt/kit": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@nuxt/schema": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"esbuild": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"rolldown": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"rollup": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"vite": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"webpack": {
|
|
114
|
+
"optional": true
|
|
115
|
+
}
|
|
102
116
|
},
|
|
103
117
|
"scripts": {
|
|
104
|
-
"build": "
|
|
105
|
-
"
|
|
118
|
+
"build": "tsdown",
|
|
119
|
+
"watch": "tsdown --watch"
|
|
106
120
|
}
|
|
107
121
|
}
|
package/dist/astro.cjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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: "@vue.ts/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
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Options } from './types.cjs';
|
|
2
|
-
import '@vue.ts/common';
|
|
3
|
-
import 'magic-string';
|
|
4
|
-
import 'typescript';
|
|
5
|
-
|
|
6
|
-
declare const _default: (options: Options) => {
|
|
7
|
-
name: string;
|
|
8
|
-
hooks: {
|
|
9
|
-
"astro:config:setup": (astro: any) => Promise<void>;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export { _default as default };
|
package/dist/astro.d.mts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Options } from './types.mjs';
|
|
2
|
-
import '@vue.ts/common';
|
|
3
|
-
import 'magic-string';
|
|
4
|
-
import 'typescript';
|
|
5
|
-
|
|
6
|
-
declare const _default: (options: Options) => {
|
|
7
|
-
name: string;
|
|
8
|
-
hooks: {
|
|
9
|
-
"astro:config:setup": (astro: any) => Promise<void>;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export { _default as default };
|
package/dist/astro.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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: "@vue.ts/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
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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.d.cts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as unplugin from 'unplugin';
|
|
2
|
-
import { Options } from './types.cjs';
|
|
3
|
-
import '@vue.ts/common';
|
|
4
|
-
import 'magic-string';
|
|
5
|
-
import 'typescript';
|
|
6
|
-
|
|
7
|
-
declare const _default: (options?: Options | undefined) => unplugin.EsbuildPlugin;
|
|
8
|
-
|
|
9
|
-
export { _default as default };
|
package/dist/esbuild.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as unplugin from 'unplugin';
|
|
2
|
-
import { Options } from './types.mjs';
|
|
3
|
-
import '@vue.ts/common';
|
|
4
|
-
import 'magic-string';
|
|
5
|
-
import 'typescript';
|
|
6
|
-
|
|
7
|
-
declare const _default: (options?: Options | undefined) => unplugin.EsbuildPlugin;
|
|
8
|
-
|
|
9
|
-
export { _default as default };
|
package/dist/esbuild.mjs
DELETED
package/dist/index.cjs
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
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"],
|
|
17
|
-
exclude: rawOptions.exclude ?? ["node_modules/**"],
|
|
18
|
-
tsconfigPath: rawOptions.tsconfigPath ?? node_path.join(process.cwd(), "tsconfig.json"),
|
|
19
|
-
defineEmits: rawOptions.defineEmits ?? true,
|
|
20
|
-
defineProps: rawOptions.defineProps ?? true
|
|
21
|
-
});
|
|
22
|
-
const quotesReg = /"/g;
|
|
23
|
-
const escapeQuotes = (s) => s.replace(quotesReg, '\\"');
|
|
24
|
-
|
|
25
|
-
class Printer {
|
|
26
|
-
constructor(checker) {
|
|
27
|
-
this.checker = checker;
|
|
28
|
-
}
|
|
29
|
-
getBaseType(nodeOrType) {
|
|
30
|
-
if ("kind" in nodeOrType) {
|
|
31
|
-
nodeOrType = this.checker.getTypeAtLocation(nodeOrType);
|
|
32
|
-
}
|
|
33
|
-
return this.checker.getBaseConstraintOfType(nodeOrType) ?? this.checker.getBaseTypeOfLiteralType(nodeOrType);
|
|
34
|
-
}
|
|
35
|
-
printIntersectionTypeNode(node) {
|
|
36
|
-
return node.types.map((t) => this.printTypeArg(t)).join(" & ");
|
|
37
|
-
}
|
|
38
|
-
printUnionTypeNode(node) {
|
|
39
|
-
return node.types.map((t) => this.printTypeArg(t)).join(" | ");
|
|
40
|
-
}
|
|
41
|
-
printTypeLiteralNode(node) {
|
|
42
|
-
const parts = ["{"];
|
|
43
|
-
for (const member of node.members) {
|
|
44
|
-
if (ts__default.isPropertySignature(member)) {
|
|
45
|
-
const stringBaseType = member.type ? this.checker.typeToString(
|
|
46
|
-
this.getBaseType(member.type),
|
|
47
|
-
void 0,
|
|
48
|
-
ts__default.TypeFormatFlags.NoTruncation
|
|
49
|
-
) : "any";
|
|
50
|
-
parts.push(
|
|
51
|
-
[
|
|
52
|
-
member.name.getText(),
|
|
53
|
-
member.questionToken?.getText(),
|
|
54
|
-
": ",
|
|
55
|
-
stringBaseType
|
|
56
|
-
].filter(Boolean).join("")
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
parts.push("}");
|
|
61
|
-
return parts.join("\n");
|
|
62
|
-
}
|
|
63
|
-
printByType(node) {
|
|
64
|
-
const type = this.checker.getTypeAtLocation(node);
|
|
65
|
-
const properties = type.getProperties();
|
|
66
|
-
const parts = ["{"];
|
|
67
|
-
let questionToken = "";
|
|
68
|
-
if (ts__default.isMappedTypeNode(node)) {
|
|
69
|
-
questionToken = node.questionToken?.getText() ?? "";
|
|
70
|
-
}
|
|
71
|
-
for (const property of properties) {
|
|
72
|
-
const valueType = this.checker.getTypeOfSymbol(property);
|
|
73
|
-
const stringValueType = this.checker.typeToString(
|
|
74
|
-
this.getBaseType(valueType),
|
|
75
|
-
void 0,
|
|
76
|
-
ts__default.TypeFormatFlags.NoTruncation
|
|
77
|
-
);
|
|
78
|
-
parts.push(
|
|
79
|
-
`${this.checker.symbolToString(
|
|
80
|
-
property
|
|
81
|
-
)}${questionToken}: ${stringValueType}`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
parts.push("}");
|
|
85
|
-
return parts.join("\n");
|
|
86
|
-
}
|
|
87
|
-
printTypeArg(node) {
|
|
88
|
-
if (ts__default.isIntersectionTypeNode(node)) {
|
|
89
|
-
return this.printIntersectionTypeNode(node);
|
|
90
|
-
} else if (ts__default.isUnionTypeNode(node)) {
|
|
91
|
-
return this.printUnionTypeNode(node);
|
|
92
|
-
} else if (ts__default.isTypeLiteralNode(node)) {
|
|
93
|
-
return this.printTypeLiteralNode(node);
|
|
94
|
-
} else if (ts__default.isMappedTypeNode(node) || ts__default.isTypeReferenceNode(node)) {
|
|
95
|
-
return this.printByType(node);
|
|
96
|
-
} else {
|
|
97
|
-
console.error(
|
|
98
|
-
`[@vue.ts/complex-types] \`${ts__default.SyntaxKind[node.kind]}\` is not supported.`
|
|
99
|
-
);
|
|
100
|
-
return node.getText();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
printEventsByCallSignatures(callSignatures) {
|
|
104
|
-
return callSignatures.map((c) => {
|
|
105
|
-
const parameters = c.getParameters();
|
|
106
|
-
const event = parameters[0];
|
|
107
|
-
return this.checker.typeToString(
|
|
108
|
-
this.checker.getTypeOfSymbol(event),
|
|
109
|
-
void 0,
|
|
110
|
-
ts__default.TypeFormatFlags.NoTruncation
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
printEventsByMembers(members) {
|
|
115
|
-
return members.map((m) => `"${escapeQuotes(m.getName())}"`);
|
|
116
|
-
}
|
|
117
|
-
printEventsRuntimeArg(node) {
|
|
118
|
-
const parts = [];
|
|
119
|
-
const type = this.checker.getTypeAtLocation(node);
|
|
120
|
-
const callSignatures = type.getCallSignatures();
|
|
121
|
-
const members = type.getProperties();
|
|
122
|
-
if (callSignatures.length > 0 && members.length > 0) {
|
|
123
|
-
throw new Error(
|
|
124
|
-
"[@vue.ts/complex-types] You may not use old style `defineEmits` and `defineEmits` shorthand together."
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
if (members.length > 0) {
|
|
128
|
-
parts.push(...this.printEventsByMembers(members));
|
|
129
|
-
} else {
|
|
130
|
-
parts.push(...this.printEventsByCallSignatures(callSignatures));
|
|
131
|
-
}
|
|
132
|
-
return `[${parts.join(", ")}]`;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const transformDefineEmits = (printer, s, id) => {
|
|
137
|
-
const language$1 = language.getLanguage();
|
|
138
|
-
const defineEmits = language$1.findNodeByRange(
|
|
139
|
-
id,
|
|
140
|
-
(scriptSetupRanges) => scriptSetupRanges.emits.define
|
|
141
|
-
);
|
|
142
|
-
if (!defineEmits) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const scriptSetupAst = language$1.getScriptSetupAst(id);
|
|
146
|
-
const {
|
|
147
|
-
scriptNode: defineEmitsNode,
|
|
148
|
-
virtualFileNode: virtualFileDefineEmitsNode,
|
|
149
|
-
offset
|
|
150
|
-
} = defineEmits;
|
|
151
|
-
const defineEmitsTypeArg = ts__default.isCallExpression(virtualFileDefineEmitsNode) && virtualFileDefineEmitsNode.typeArguments?.[0];
|
|
152
|
-
const defineEmitsRuntimeArg = ts__default.isCallExpression(virtualFileDefineEmitsNode) && virtualFileDefineEmitsNode.arguments[0];
|
|
153
|
-
if (!defineEmitsTypeArg) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (defineEmitsRuntimeArg) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
"[@vue.ts/complex-types] `defineEmits` cannot accept both runtime argument and type argument."
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
const tokens = defineEmitsNode.getChildren(scriptSetupAst);
|
|
162
|
-
const lessThanToken = tokens.find(
|
|
163
|
-
(t) => t.kind === ts__default.SyntaxKind.LessThanToken
|
|
164
|
-
);
|
|
165
|
-
const greaterThanToken = tokens.find(
|
|
166
|
-
(t) => t.kind === ts__default.SyntaxKind.GreaterThanToken
|
|
167
|
-
);
|
|
168
|
-
const openParenToken = tokens.find(
|
|
169
|
-
(t) => t.kind === ts__default.SyntaxKind.OpenParenToken
|
|
170
|
-
);
|
|
171
|
-
if (!lessThanToken || !greaterThanToken || !openParenToken) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const defineEmitsTypeArgRange = [
|
|
175
|
-
offset + lessThanToken.pos,
|
|
176
|
-
offset + greaterThanToken.end
|
|
177
|
-
];
|
|
178
|
-
const runtimeArgPos = offset + openParenToken.end;
|
|
179
|
-
const printedRuntimeArg = printer.printEventsRuntimeArg(defineEmitsTypeArg);
|
|
180
|
-
s.remove(...defineEmitsTypeArgRange);
|
|
181
|
-
s.appendRight(runtimeArgPos, printedRuntimeArg);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
const transformDefineProps = (printer, s, id) => {
|
|
185
|
-
const language$1 = language.getLanguage();
|
|
186
|
-
const definePropsTypeArg = language$1.findNodeByRange(
|
|
187
|
-
id,
|
|
188
|
-
(scriptSetupRanges) => scriptSetupRanges.props.define?.typeArg
|
|
189
|
-
);
|
|
190
|
-
if (!definePropsTypeArg) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const { virtualFileNode: typeArgNode, setupRange: typeArgRange } = definePropsTypeArg;
|
|
194
|
-
const printedType = printer.printTypeArg(typeArgNode);
|
|
195
|
-
s.overwrite(typeArgRange.start, typeArgRange.end, printedType);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const transformers = [
|
|
199
|
-
["defineEmits", transformDefineEmits],
|
|
200
|
-
["defineProps", transformDefineProps]
|
|
201
|
-
];
|
|
202
|
-
const getTransformers = (options) => transformers.filter(([key]) => !!options[key]);
|
|
203
|
-
|
|
204
|
-
function transform(code, id, options) {
|
|
205
|
-
const s = new MagicString__default(code);
|
|
206
|
-
const language$1 = language.getLanguage();
|
|
207
|
-
const typeChecker = language$1.__internal__.typeChecker;
|
|
208
|
-
const printer = new Printer(typeChecker);
|
|
209
|
-
const transformers = getTransformers(options);
|
|
210
|
-
for (const [, transform2] of transformers) {
|
|
211
|
-
transform2(printer, s, id);
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
code: s.toString(),
|
|
215
|
-
map: s.generateMap({ hires: true })
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const unplugin = unplugin$1.createUnplugin((options = {}) => ({
|
|
220
|
-
name: "@vue.ts/complex-types",
|
|
221
|
-
buildStart() {
|
|
222
|
-
const resolvedOptions = resolveOptions(options);
|
|
223
|
-
language.ensureLanguage(resolvedOptions.tsconfigPath);
|
|
224
|
-
},
|
|
225
|
-
transform(code, id) {
|
|
226
|
-
const resolvedOptions = resolveOptions(options);
|
|
227
|
-
const filter = common.createFilter(
|
|
228
|
-
resolvedOptions.include,
|
|
229
|
-
resolvedOptions.exclude
|
|
230
|
-
);
|
|
231
|
-
if (!filter(id)) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
return transform(code, id, resolvedOptions);
|
|
235
|
-
}
|
|
236
|
-
}));
|
|
237
|
-
|
|
238
|
-
module.exports = unplugin;
|