@vue/language-core 3.1.4 → 3.1.6
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/index.d.ts +2 -1
- package/index.js +3 -2
- package/lib/codegen/codeFeatures.d.ts +5 -9
- package/lib/codegen/codeFeatures.js +5 -5
- package/lib/codegen/globalTypes.js +15 -20
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +6 -6
- package/lib/codegen/names.d.ts +30 -0
- package/lib/codegen/names.js +34 -0
- package/lib/codegen/script/component.js +45 -54
- package/lib/codegen/script/context.d.ts +2 -5
- package/lib/codegen/script/context.js +1 -7
- package/lib/codegen/script/index.d.ts +10 -12
- package/lib/codegen/script/index.js +74 -73
- package/lib/codegen/script/scriptSetup.d.ts +3 -2
- package/lib/codegen/script/scriptSetup.js +209 -283
- package/lib/codegen/script/src.js +9 -3
- package/lib/codegen/script/template.js +64 -108
- package/lib/codegen/style/common.d.ts +3 -0
- package/lib/codegen/style/common.js +43 -0
- package/lib/codegen/style/index.d.ts +63 -0
- package/lib/codegen/style/index.js +38 -0
- package/lib/codegen/style/modules.d.ts +3 -2
- package/lib/codegen/style/modules.js +12 -11
- package/lib/codegen/style/scopedClasses.d.ts +2 -3
- package/lib/codegen/style/scopedClasses.js +23 -21
- package/lib/codegen/template/context.d.ts +10 -19
- package/lib/codegen/template/context.js +82 -94
- package/lib/codegen/template/element.js +174 -65
- package/lib/codegen/template/elementDirectives.js +32 -12
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +30 -35
- package/lib/codegen/template/elementProps.d.ts +3 -3
- package/lib/codegen/template/elementProps.js +64 -83
- package/lib/codegen/template/index.d.ts +11 -22
- package/lib/codegen/template/index.js +85 -80
- package/lib/codegen/template/interpolation.d.ts +3 -3
- package/lib/codegen/template/interpolation.js +108 -155
- package/lib/codegen/template/objectProperty.js +8 -4
- package/lib/codegen/template/propertyAccess.d.ts +1 -1
- package/lib/codegen/template/propertyAccess.js +5 -7
- package/lib/codegen/template/slotOutlet.js +26 -14
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
- package/lib/codegen/template/styleScopedClasses.js +23 -149
- package/lib/codegen/template/templateChild.d.ts +0 -1
- package/lib/codegen/template/templateChild.js +11 -68
- package/lib/codegen/template/vFor.js +10 -13
- package/lib/codegen/template/vIf.js +5 -3
- package/lib/codegen/template/vSlot.js +20 -16
- package/lib/codegen/utils/boundary.d.ts +3 -0
- package/lib/codegen/utils/boundary.js +13 -0
- package/lib/codegen/utils/camelized.js +3 -3
- package/lib/codegen/utils/escaped.js +4 -2
- package/lib/codegen/utils/index.d.ts +3 -6
- package/lib/codegen/utils/index.js +41 -26
- package/lib/codegen/utils/merge.d.ts +2 -2
- package/lib/codegen/utils/merge.js +9 -9
- package/lib/codegen/utils/stringLiteralKey.js +6 -3
- package/lib/codegen/utils/transform.d.ts +8 -0
- package/lib/codegen/utils/transform.js +27 -0
- package/lib/codegen/utils/unicode.js +4 -2
- package/lib/compilerOptions.js +4 -4
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +18 -25
- package/lib/plugins/vue-template-html.js +12 -9
- package/lib/plugins/vue-template-inline-css.js +8 -18
- package/lib/plugins/vue-template-inline-ts.js +12 -14
- package/lib/plugins/vue-tsx.d.ts +14 -23
- package/lib/plugins/vue-tsx.js +121 -69
- package/lib/plugins.js +1 -1
- package/lib/types.d.ts +5 -4
- package/lib/utils/parseSfc.js +10 -11
- package/lib/utils/shared.d.ts +1 -0
- package/lib/utils/shared.js +9 -0
- package/lib/utils/signals.d.ts +2 -2
- package/lib/utils/signals.js +8 -6
- package/lib/virtualCode/embeddedCodes.d.ts +12 -0
- package/lib/virtualCode/embeddedCodes.js +249 -0
- package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
- package/lib/virtualCode/index.js +81 -0
- package/lib/virtualCode/ir.d.ts +4 -0
- package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +65 -96
- package/lib/virtualCode/normalize.d.ts +2 -0
- package/lib/virtualCode/normalize.js +170 -0
- package/package.json +4 -4
- package/lib/codegen/style/classProperty.d.ts +0 -2
- package/lib/codegen/style/classProperty.js +0 -18
- package/lib/codegen/style/imports.d.ts +0 -2
- package/lib/codegen/style/imports.js +0 -27
- package/lib/codegen/template/elementChildren.d.ts +0 -5
- package/lib/codegen/template/elementChildren.js +0 -12
- package/lib/codegen/utils/wrapWith.d.ts +0 -3
- package/lib/codegen/utils/wrapWith.js +0 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- package/lib/virtualFile/vueFile.js +0 -49
package/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './lib/utils/collectBindings';
|
|
|
9
9
|
export * from './lib/utils/forEachTemplateNode';
|
|
10
10
|
export * from './lib/utils/parseSfc';
|
|
11
11
|
export * from './lib/utils/shared';
|
|
12
|
-
export * from './lib/
|
|
12
|
+
export * from './lib/virtualCode';
|
|
13
|
+
export * as names from './lib/codegen/names';
|
|
13
14
|
export { tsCodegen } from './lib/plugins/vue-tsx';
|
|
14
15
|
export * from '@volar/language-core';
|
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.tsCodegen = void 0;
|
|
17
|
+
exports.tsCodegen = exports.names = void 0;
|
|
18
18
|
__exportStar(require("./lib/codegen/globalTypes"), exports);
|
|
19
19
|
__exportStar(require("./lib/codegen/template"), exports);
|
|
20
20
|
__exportStar(require("./lib/compilerOptions"), exports);
|
|
@@ -26,7 +26,8 @@ __exportStar(require("./lib/utils/collectBindings"), exports);
|
|
|
26
26
|
__exportStar(require("./lib/utils/forEachTemplateNode"), exports);
|
|
27
27
|
__exportStar(require("./lib/utils/parseSfc"), exports);
|
|
28
28
|
__exportStar(require("./lib/utils/shared"), exports);
|
|
29
|
-
__exportStar(require("./lib/
|
|
29
|
+
__exportStar(require("./lib/virtualCode"), exports);
|
|
30
|
+
exports.names = require("./lib/codegen/names");
|
|
30
31
|
var vue_tsx_1 = require("./lib/plugins/vue-tsx");
|
|
31
32
|
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
|
32
33
|
__exportStar(require("@volar/language-core"), exports);
|
|
@@ -6,17 +6,15 @@ declare const raw: {
|
|
|
6
6
|
semantic: true;
|
|
7
7
|
navigation: true;
|
|
8
8
|
};
|
|
9
|
+
importCompletionOnly: {
|
|
10
|
+
__importCompletion: true;
|
|
11
|
+
};
|
|
9
12
|
verification: {
|
|
10
13
|
verification: true;
|
|
11
14
|
};
|
|
12
15
|
completion: {
|
|
13
16
|
completion: true;
|
|
14
17
|
};
|
|
15
|
-
additionalCompletion: {
|
|
16
|
-
completion: {
|
|
17
|
-
isAdditional: true;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
18
|
withoutCompletion: {
|
|
21
19
|
verification: true;
|
|
22
20
|
semantic: true;
|
|
@@ -30,11 +28,9 @@ declare const raw: {
|
|
|
30
28
|
shouldRename: () => false;
|
|
31
29
|
};
|
|
32
30
|
};
|
|
33
|
-
|
|
31
|
+
navigationAndCompletion: {
|
|
34
32
|
navigation: true;
|
|
35
|
-
completion:
|
|
36
|
-
isAdditional: true;
|
|
37
|
-
};
|
|
33
|
+
completion: true;
|
|
38
34
|
};
|
|
39
35
|
navigationAndVerification: {
|
|
40
36
|
navigation: true;
|
|
@@ -8,15 +8,15 @@ const raw = {
|
|
|
8
8
|
semantic: true,
|
|
9
9
|
navigation: true,
|
|
10
10
|
},
|
|
11
|
+
importCompletionOnly: {
|
|
12
|
+
__importCompletion: true,
|
|
13
|
+
},
|
|
11
14
|
verification: {
|
|
12
15
|
verification: true,
|
|
13
16
|
},
|
|
14
17
|
completion: {
|
|
15
18
|
completion: true,
|
|
16
19
|
},
|
|
17
|
-
additionalCompletion: {
|
|
18
|
-
completion: { isAdditional: true },
|
|
19
|
-
},
|
|
20
20
|
withoutCompletion: {
|
|
21
21
|
verification: true,
|
|
22
22
|
semantic: true,
|
|
@@ -28,9 +28,9 @@ const raw = {
|
|
|
28
28
|
navigationWithoutRename: {
|
|
29
29
|
navigation: { shouldRename: () => false },
|
|
30
30
|
},
|
|
31
|
-
|
|
31
|
+
navigationAndCompletion: {
|
|
32
32
|
navigation: true,
|
|
33
|
-
completion:
|
|
33
|
+
completion: true,
|
|
34
34
|
},
|
|
35
35
|
navigationAndVerification: {
|
|
36
36
|
navigation: true,
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGlobalTypesFileName = getGlobalTypesFileName;
|
|
4
4
|
exports.generateGlobalTypes = generateGlobalTypes;
|
|
5
|
+
const names = require("./names");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
5
7
|
function getGlobalTypesFileName(options) {
|
|
6
8
|
return [
|
|
7
9
|
options.lib,
|
|
@@ -11,21 +13,20 @@ function getGlobalTypesFileName(options) {
|
|
|
11
13
|
}
|
|
12
14
|
function generateGlobalTypes(options) {
|
|
13
15
|
const { lib, target, checkUnknownProps } = options;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
let text = `// @ts-nocheck${utils_1.newLine}`;
|
|
17
|
+
text += `export {}${utils_1.endOfLine}`;
|
|
16
18
|
if (target < 3.5) {
|
|
17
|
-
text += `
|
|
18
|
-
; declare module '${lib}' {
|
|
19
|
+
text += `declare module '${lib}' {
|
|
19
20
|
export interface GlobalComponents { }
|
|
20
21
|
export interface GlobalDirectives { }
|
|
21
|
-
}`;
|
|
22
|
+
}${utils_1.newLine}`;
|
|
22
23
|
}
|
|
23
|
-
text += `
|
|
24
|
-
|
|
24
|
+
text += `declare global {
|
|
25
|
+
${checkUnknownProps ? '' : `var ${names.PROPS_FALLBACK}: Record<string, unknown>;`}
|
|
26
|
+
|
|
25
27
|
const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const __VLS_intrinsics: ${target >= 3.3
|
|
28
|
+
const ${names.placeholder}: any;
|
|
29
|
+
const ${names.intrinsics}: ${target >= 3.3
|
|
29
30
|
? `import('${lib}/jsx-runtime').JSX.IntrinsicElements`
|
|
30
31
|
: `globalThis.JSX.IntrinsicElements`};
|
|
31
32
|
|
|
@@ -54,14 +55,14 @@ function generateGlobalTypes(options) {
|
|
|
54
55
|
? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
|
55
56
|
: T extends (props: infer P, ...args: any) => any ? P
|
|
56
57
|
: {};
|
|
57
|
-
type __VLS_FunctionalComponent<T> = (props: ${
|
|
58
|
+
type __VLS_FunctionalComponent<T> = (props: (T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}, ctx?: any) => ${target >= 3.3
|
|
58
59
|
? `import('${lib}/jsx-runtime').JSX.Element`
|
|
59
60
|
: `globalThis.JSX.Element`} & {
|
|
60
61
|
__ctx?: {
|
|
61
62
|
attrs?: any;
|
|
62
63
|
slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>;
|
|
63
64
|
emit?: T extends { $emit: infer Emit } ? Emit : {};
|
|
64
|
-
props?:
|
|
65
|
+
props?: typeof props;
|
|
65
66
|
expose?: (exposed: T) => void;
|
|
66
67
|
};
|
|
67
68
|
};
|
|
@@ -123,12 +124,7 @@ function generateGlobalTypes(options) {
|
|
|
123
124
|
type __VLS_ResolveDirectives<T> = {
|
|
124
125
|
[K in keyof T & string as \`v\${Capitalize<K>}\`]: T[K];
|
|
125
126
|
};
|
|
126
|
-
type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K]; } & {};
|
|
127
|
-
type __VLS_WithDefaultsGlobal<P, D> = {
|
|
128
|
-
[K in keyof P as K extends keyof D ? K : never]-?: P[K];
|
|
129
|
-
} & {
|
|
130
|
-
[K in keyof P as K extends keyof D ? never : K]: P[K];
|
|
131
|
-
};
|
|
127
|
+
type __VLS_PrettifyGlobal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
|
|
132
128
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
133
129
|
type __VLS_ProxyRefs<T> = import('${lib}').ShallowUnwrapRef<T>;
|
|
134
130
|
|
|
@@ -161,8 +157,7 @@ function generateGlobalTypes(options) {
|
|
|
161
157
|
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownProps ? '' : ' & Record<string, unknown>'}) => void;
|
|
162
158
|
function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
|
|
163
159
|
function __VLS_tryAsConstant<const T>(t: T): T;
|
|
164
|
-
}
|
|
165
|
-
`;
|
|
160
|
+
}${utils_1.newLine}`;
|
|
166
161
|
return text;
|
|
167
162
|
}
|
|
168
163
|
//# sourceMappingURL=globalTypes.js.map
|
|
@@ -2,7 +2,7 @@ import type { VueCompilerOptions } from '../types';
|
|
|
2
2
|
export declare function getLocalTypesGenerator(vueCompilerOptions: VueCompilerOptions): {
|
|
3
3
|
generate: () => Generator<string, void, unknown>;
|
|
4
4
|
readonly PrettifyLocal: string;
|
|
5
|
-
readonly
|
|
5
|
+
readonly WithDefaults: string;
|
|
6
6
|
readonly WithSlots: string;
|
|
7
7
|
readonly PropsChildren: string;
|
|
8
8
|
readonly TypePropsToOption: string;
|
|
@@ -4,14 +4,14 @@ exports.getLocalTypesGenerator = getLocalTypesGenerator;
|
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
function getLocalTypesGenerator(vueCompilerOptions) {
|
|
6
6
|
const used = new Set();
|
|
7
|
-
const
|
|
8
|
-
type
|
|
7
|
+
const WithDefaults = defineHelper(`__VLS_WithDefaults`, () => `
|
|
8
|
+
type __VLS_WithDefaults<P, D> = {
|
|
9
9
|
[K in keyof Pick<P, keyof P>]: K extends keyof D
|
|
10
10
|
? ${PrettifyLocal.name}<P[K] & { default: D[K] }>
|
|
11
11
|
: P[K]
|
|
12
12
|
};
|
|
13
13
|
`.trimStart());
|
|
14
|
-
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T as K]: T[K]; } & {}${utils_1.endOfLine}`);
|
|
14
|
+
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {}${utils_1.endOfLine}`);
|
|
15
15
|
const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
|
|
16
16
|
type __VLS_WithSlots<T, S> = T & {
|
|
17
17
|
new(): {
|
|
@@ -44,7 +44,7 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
44
44
|
const OmitIndexSignature = defineHelper(`__VLS_OmitIndexSignature`, () => `type __VLS_OmitIndexSignature<T> = { [K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K]; }${utils_1.endOfLine}`);
|
|
45
45
|
const helpers = {
|
|
46
46
|
[PrettifyLocal.name]: PrettifyLocal,
|
|
47
|
-
[
|
|
47
|
+
[WithDefaults.name]: WithDefaults,
|
|
48
48
|
[WithSlots.name]: WithSlots,
|
|
49
49
|
[PropsChildren.name]: PropsChildren,
|
|
50
50
|
[TypePropsToOption.name]: TypePropsToOption,
|
|
@@ -56,8 +56,8 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
56
56
|
get PrettifyLocal() {
|
|
57
57
|
return PrettifyLocal.name;
|
|
58
58
|
},
|
|
59
|
-
get
|
|
60
|
-
return
|
|
59
|
+
get WithDefaults() {
|
|
60
|
+
return WithDefaults.name;
|
|
61
61
|
},
|
|
62
62
|
get WithSlots() {
|
|
63
63
|
return WithSlots.name;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const ctx = "__VLS_ctx";
|
|
2
|
+
export declare const self = "__VLS_self";
|
|
3
|
+
export declare const dollars = "__VLS_dollars";
|
|
4
|
+
export declare const slots = "__VLS_slots";
|
|
5
|
+
export declare const props = "__VLS_props";
|
|
6
|
+
export declare const defaults = "__VLS_defaults";
|
|
7
|
+
export declare const defaultModels = "__VLS_defaultModels";
|
|
8
|
+
export declare const modelEmit = "__VLS_modelEmit";
|
|
9
|
+
export declare const emit = "__VLS_emit";
|
|
10
|
+
export declare const exposed = "__VLS_exposed";
|
|
11
|
+
export declare const setup = "__VLS_setup";
|
|
12
|
+
export declare const components = "___VLS_components";
|
|
13
|
+
export declare const directives = "___VLS_directives";
|
|
14
|
+
export declare const intrinsics = "__VLS_intrinsics";
|
|
15
|
+
export declare const placeholder = "__VLS_placeholder";
|
|
16
|
+
export declare const _export = "__VLS_export";
|
|
17
|
+
export declare const ModelProps = "__VLS_ModelProps";
|
|
18
|
+
export declare const Props = "__VLS_Props";
|
|
19
|
+
export declare const Slots = "__VLS_Slots";
|
|
20
|
+
export declare const InheritedAttrs = "__VLS_InheritedAttrs";
|
|
21
|
+
export declare const TemplateRefs = "__VLS_TemplateRefs";
|
|
22
|
+
export declare const RootEl = "__VLS_RootEl";
|
|
23
|
+
export declare const ModelEmit = "__VLS_ModelEmit";
|
|
24
|
+
export declare const EmitProps = "__VLS_EmitProps";
|
|
25
|
+
export declare const InternalProps = "__VLS_InternalProps";
|
|
26
|
+
export declare const Emit = "__VLS_Emit";
|
|
27
|
+
export declare const SetupExposed = "__VLS_SetupExposed";
|
|
28
|
+
export declare const PublicProps = "__VLS_PublicProps";
|
|
29
|
+
export declare const StyleModules = "__VLS_StyleModules";
|
|
30
|
+
export declare const PROPS_FALLBACK = "__VLS_PROPS_FALLBACK";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROPS_FALLBACK = exports.StyleModules = exports.PublicProps = exports.SetupExposed = exports.Emit = exports.InternalProps = exports.EmitProps = exports.ModelEmit = exports.RootEl = exports.TemplateRefs = exports.InheritedAttrs = exports.Slots = exports.Props = exports.ModelProps = exports._export = exports.placeholder = exports.intrinsics = exports.directives = exports.components = exports.setup = exports.exposed = exports.emit = exports.modelEmit = exports.defaultModels = exports.defaults = exports.props = exports.slots = exports.dollars = exports.self = exports.ctx = void 0;
|
|
4
|
+
exports.ctx = '__VLS_ctx';
|
|
5
|
+
exports.self = '__VLS_self';
|
|
6
|
+
exports.dollars = '__VLS_dollars';
|
|
7
|
+
exports.slots = '__VLS_slots';
|
|
8
|
+
exports.props = '__VLS_props';
|
|
9
|
+
exports.defaults = '__VLS_defaults';
|
|
10
|
+
exports.defaultModels = '__VLS_defaultModels';
|
|
11
|
+
exports.modelEmit = '__VLS_modelEmit';
|
|
12
|
+
exports.emit = '__VLS_emit';
|
|
13
|
+
exports.exposed = '__VLS_exposed';
|
|
14
|
+
exports.setup = '__VLS_setup';
|
|
15
|
+
exports.components = '___VLS_components';
|
|
16
|
+
exports.directives = '___VLS_directives';
|
|
17
|
+
exports.intrinsics = '__VLS_intrinsics';
|
|
18
|
+
exports.placeholder = '__VLS_placeholder';
|
|
19
|
+
exports._export = '__VLS_export';
|
|
20
|
+
exports.ModelProps = '__VLS_ModelProps';
|
|
21
|
+
exports.Props = '__VLS_Props';
|
|
22
|
+
exports.Slots = '__VLS_Slots';
|
|
23
|
+
exports.InheritedAttrs = '__VLS_InheritedAttrs';
|
|
24
|
+
exports.TemplateRefs = '__VLS_TemplateRefs';
|
|
25
|
+
exports.RootEl = '__VLS_RootEl';
|
|
26
|
+
exports.ModelEmit = '__VLS_ModelEmit';
|
|
27
|
+
exports.EmitProps = '__VLS_EmitProps';
|
|
28
|
+
exports.InternalProps = '__VLS_InternalProps';
|
|
29
|
+
exports.Emit = '__VLS_Emit';
|
|
30
|
+
exports.SetupExposed = '__VLS_SetupExposed';
|
|
31
|
+
exports.PublicProps = '__VLS_PublicProps';
|
|
32
|
+
exports.StyleModules = '__VLS_StyleModules';
|
|
33
|
+
exports.PROPS_FALLBACK = '__VLS_PROPS_FALLBACK';
|
|
34
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -2,58 +2,45 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateComponent = generateComponent;
|
|
4
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
|
+
const names = require("../names");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const merge_1 = require("../utils/merge");
|
|
7
8
|
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
8
|
-
if (options.
|
|
9
|
+
if (options.script
|
|
9
10
|
&& options.scriptRanges?.componentOptions
|
|
10
11
|
&& options.scriptRanges.componentOptions.expression.start !== options.scriptRanges.componentOptions.args.start) {
|
|
11
12
|
// use defineComponent() from user space code if it exist
|
|
12
|
-
yield (0, utils_1.generateSfcBlockSection)(options.
|
|
13
|
+
yield* (0, utils_1.generateSfcBlockSection)(options.script, options.scriptRanges.componentOptions.expression.start, options.scriptRanges.componentOptions.args.start, codeFeatures_1.codeFeatures.all);
|
|
13
14
|
yield `{${utils_1.newLine}`;
|
|
14
15
|
}
|
|
15
16
|
else {
|
|
16
17
|
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
|
|
17
18
|
}
|
|
18
19
|
const returns = [];
|
|
19
|
-
if (ctx.bypassDefineComponent) {
|
|
20
|
-
// fill $props
|
|
21
|
-
if (scriptSetupRanges.defineProps) {
|
|
22
|
-
const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
|
|
23
|
-
// NOTE: defineProps is inaccurate for $props
|
|
24
|
-
returns.push(name, `{} as { $props: Partial<typeof ${name}> }`);
|
|
25
|
-
}
|
|
26
|
-
// fill $emit
|
|
27
|
-
if (scriptSetupRanges.defineEmits) {
|
|
28
|
-
returns.push(`{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
20
|
if (scriptSetupRanges.defineExpose) {
|
|
32
|
-
returns.push(
|
|
21
|
+
returns.push([names.exposed]);
|
|
33
22
|
}
|
|
34
23
|
if (returns.length) {
|
|
35
24
|
yield `setup: () => (`;
|
|
36
25
|
yield* (0, merge_1.generateSpreadMerge)(returns);
|
|
37
26
|
yield `),${utils_1.newLine}`;
|
|
38
27
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
|
|
43
|
-
}
|
|
28
|
+
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
|
|
29
|
+
yield* emitOptionCodes;
|
|
30
|
+
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
|
|
44
31
|
if (options.vueCompilerOptions.target >= 3.5
|
|
45
32
|
&& options.vueCompilerOptions.inferComponentDollarRefs
|
|
46
|
-
&& options.templateCodegen?.
|
|
47
|
-
yield `__typeRefs: {} as
|
|
33
|
+
&& options.templateCodegen?.generatedTypes.has(names.TemplateRefs)) {
|
|
34
|
+
yield `__typeRefs: {} as ${names.TemplateRefs},${utils_1.newLine}`;
|
|
48
35
|
}
|
|
49
36
|
if (options.vueCompilerOptions.target >= 3.5
|
|
50
37
|
&& options.vueCompilerOptions.inferComponentDollarEl
|
|
51
|
-
&& options.templateCodegen?.
|
|
52
|
-
yield `__typeEl: {} as
|
|
38
|
+
&& options.templateCodegen?.generatedTypes.has(names.RootEl)) {
|
|
39
|
+
yield `__typeEl: {} as ${names.RootEl},${utils_1.newLine}`;
|
|
53
40
|
}
|
|
54
|
-
if (options.
|
|
41
|
+
if (options.script && options.scriptRanges?.componentOptions?.args) {
|
|
55
42
|
const { args } = options.scriptRanges.componentOptions;
|
|
56
|
-
yield (0, utils_1.generateSfcBlockSection)(options.
|
|
43
|
+
yield* (0, utils_1.generateSfcBlockSection)(options.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
|
|
57
44
|
}
|
|
58
45
|
yield `})`;
|
|
59
46
|
}
|
|
@@ -61,14 +48,14 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
61
48
|
const optionCodes = [];
|
|
62
49
|
const typeOptionCodes = [];
|
|
63
50
|
if (scriptSetupRanges.defineModel.length) {
|
|
64
|
-
optionCodes.push(`{} as __VLS_NormalizeEmits<typeof
|
|
65
|
-
typeOptionCodes.push(
|
|
51
|
+
optionCodes.push([`{} as __VLS_NormalizeEmits<typeof ${names.modelEmit}>`]);
|
|
52
|
+
typeOptionCodes.push([names.ModelEmit]);
|
|
66
53
|
}
|
|
67
54
|
if (scriptSetupRanges.defineEmits) {
|
|
68
55
|
const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
|
|
69
|
-
optionCodes.push(`{} as __VLS_NormalizeEmits<typeof ${name ??
|
|
56
|
+
optionCodes.push([`{} as __VLS_NormalizeEmits<typeof ${name ?? names.emit}>`]);
|
|
70
57
|
if (typeArg && !hasUnionTypeArg) {
|
|
71
|
-
typeOptionCodes.push(
|
|
58
|
+
typeOptionCodes.push([names.Emit]);
|
|
72
59
|
}
|
|
73
60
|
else {
|
|
74
61
|
typeOptionCodes.length = 0;
|
|
@@ -86,50 +73,54 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
86
73
|
}
|
|
87
74
|
}
|
|
88
75
|
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
if (options.templateCodegen?.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
getOptionCodes.push(() => {
|
|
76
|
+
const optionGenerates = [];
|
|
77
|
+
const typeOptionGenerates = [];
|
|
78
|
+
if (options.templateCodegen?.generatedTypes.has(names.InheritedAttrs)) {
|
|
79
|
+
const attrsType = hasEmitsOption
|
|
80
|
+
? `Omit<${names.InheritedAttrs}, keyof ${names.EmitProps}>`
|
|
81
|
+
: names.InheritedAttrs;
|
|
82
|
+
optionGenerates.push(function* () {
|
|
97
83
|
const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
|
|
98
84
|
const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
|
|
99
|
-
|
|
85
|
+
yield `{} as ${optionType}`;
|
|
86
|
+
});
|
|
87
|
+
typeOptionGenerates.push(function* () {
|
|
88
|
+
yield `{} as ${attrsType}`;
|
|
100
89
|
});
|
|
101
|
-
typeOptionCodes.push(`{} as ${attrsType}`);
|
|
102
90
|
}
|
|
103
|
-
if (ctx.
|
|
91
|
+
if (ctx.generatedTypes.has(names.PublicProps)) {
|
|
104
92
|
if (options.vueCompilerOptions.target < 3.6) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
optionGenerates.push(function* () {
|
|
94
|
+
let propsType = `${ctx.localTypes.TypePropsToOption}<${names.PublicProps}>`;
|
|
95
|
+
if (scriptSetupRanges.withDefaults?.arg) {
|
|
96
|
+
propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names.defaults}>`;
|
|
97
|
+
}
|
|
98
|
+
yield `{} as ${propsType}`;
|
|
110
99
|
});
|
|
111
100
|
}
|
|
112
|
-
|
|
101
|
+
typeOptionGenerates.push(function* () {
|
|
102
|
+
yield `{} as ${names.PublicProps}`;
|
|
103
|
+
});
|
|
113
104
|
}
|
|
114
105
|
if (scriptSetupRanges.defineProps?.arg) {
|
|
115
106
|
const { arg } = scriptSetupRanges.defineProps;
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
optionGenerates.push(() => (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation));
|
|
108
|
+
typeOptionGenerates.length = 0;
|
|
118
109
|
}
|
|
119
|
-
const useTypeOption = options.vueCompilerOptions.target >= 3.5 &&
|
|
120
|
-
const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) &&
|
|
110
|
+
const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionGenerates.length;
|
|
111
|
+
const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) && optionGenerates.length;
|
|
121
112
|
if (useTypeOption) {
|
|
122
113
|
if (options.vueCompilerOptions.target >= 3.6
|
|
123
114
|
&& scriptSetupRanges.withDefaults?.arg) {
|
|
124
|
-
yield `__defaults:
|
|
115
|
+
yield `__defaults: ${names.defaults},${utils_1.newLine}`;
|
|
125
116
|
}
|
|
126
117
|
yield `__typeProps: `;
|
|
127
|
-
yield* (0, merge_1.generateSpreadMerge)(
|
|
118
|
+
yield* (0, merge_1.generateSpreadMerge)(typeOptionGenerates.map(g => g()));
|
|
128
119
|
yield `,${utils_1.newLine}`;
|
|
129
120
|
}
|
|
130
121
|
if (useOption) {
|
|
131
122
|
yield `props: `;
|
|
132
|
-
yield* (0, merge_1.generateSpreadMerge)(
|
|
123
|
+
yield* (0, merge_1.generateSpreadMerge)(optionGenerates.map(g => g()));
|
|
133
124
|
yield `,${utils_1.newLine}`;
|
|
134
125
|
}
|
|
135
126
|
}
|
|
@@ -2,14 +2,11 @@ import type { InlayHintInfo } from '../inlayHints';
|
|
|
2
2
|
import type { ScriptCodegenOptions } from './index';
|
|
3
3
|
export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>;
|
|
4
4
|
export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
|
|
5
|
-
|
|
6
|
-
generatedPropsType: boolean;
|
|
7
|
-
bypassDefineComponent: boolean;
|
|
8
|
-
bindingNames: Set<string>;
|
|
5
|
+
generatedTypes: Set<string>;
|
|
9
6
|
localTypes: {
|
|
10
7
|
generate: () => Generator<string, void, unknown>;
|
|
11
8
|
readonly PrettifyLocal: string;
|
|
12
|
-
readonly
|
|
9
|
+
readonly WithDefaults: string;
|
|
13
10
|
readonly WithSlots: string;
|
|
14
11
|
readonly PropsChildren: string;
|
|
15
12
|
readonly TypePropsToOption: string;
|
|
@@ -6,13 +6,7 @@ function createScriptCodegenContext(options) {
|
|
|
6
6
|
const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.vueCompilerOptions);
|
|
7
7
|
const inlayHints = [];
|
|
8
8
|
return {
|
|
9
|
-
|
|
10
|
-
generatedPropsType: false,
|
|
11
|
-
bypassDefineComponent: options.lang === 'js' || options.lang === 'jsx',
|
|
12
|
-
bindingNames: new Set([
|
|
13
|
-
...options.scriptRanges?.bindings.map(({ range }) => options.sfc.script.content.slice(range.start, range.end)) ?? [],
|
|
14
|
-
...options.scriptSetupRanges?.bindings.map(({ range }) => options.sfc.scriptSetup.content.slice(range.start, range.end)) ?? [],
|
|
15
|
-
]),
|
|
9
|
+
generatedTypes: new Set(),
|
|
16
10
|
localTypes,
|
|
17
11
|
inlayHints,
|
|
18
12
|
};
|
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
3
3
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
4
|
-
import type { Code, Sfc,
|
|
4
|
+
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
5
5
|
import type { TemplateCodegenContext } from '../template/context';
|
|
6
6
|
export interface ScriptCodegenOptions {
|
|
7
7
|
ts: typeof ts;
|
|
8
|
-
compilerOptions: ts.CompilerOptions;
|
|
9
8
|
vueCompilerOptions: VueCompilerOptions;
|
|
10
|
-
|
|
9
|
+
script: Sfc['script'];
|
|
10
|
+
scriptSetup: Sfc['scriptSetup'];
|
|
11
11
|
fileName: string;
|
|
12
|
-
lang: string;
|
|
13
12
|
scriptRanges: ScriptRanges | undefined;
|
|
14
13
|
scriptSetupRanges: ScriptSetupRanges | undefined;
|
|
14
|
+
templateStartTagOffset: number | undefined;
|
|
15
15
|
templateCodegen: TemplateCodegenContext & {
|
|
16
16
|
codes: Code[];
|
|
17
17
|
} | undefined;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
styleCodegen: TemplateCodegenContext & {
|
|
19
|
+
codes: Code[];
|
|
20
|
+
} | undefined;
|
|
21
|
+
setupExposed: Set<string>;
|
|
20
22
|
}
|
|
21
23
|
export { generate as generateScript };
|
|
22
24
|
declare function generate(options: ScriptCodegenOptions): {
|
|
23
25
|
codes: Code[];
|
|
24
|
-
|
|
25
|
-
generatedPropsType: boolean;
|
|
26
|
-
bypassDefineComponent: boolean;
|
|
27
|
-
bindingNames: Set<string>;
|
|
26
|
+
generatedTypes: Set<string>;
|
|
28
27
|
localTypes: {
|
|
29
28
|
generate: () => Generator<string, void, unknown>;
|
|
30
29
|
readonly PrettifyLocal: string;
|
|
31
|
-
readonly
|
|
30
|
+
readonly WithDefaults: string;
|
|
32
31
|
readonly WithSlots: string;
|
|
33
32
|
readonly PropsChildren: string;
|
|
34
33
|
readonly TypePropsToOption: string;
|
|
@@ -36,4 +35,3 @@ declare function generate(options: ScriptCodegenOptions): {
|
|
|
36
35
|
};
|
|
37
36
|
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
38
37
|
};
|
|
39
|
-
export declare function generateConstExport(options: ScriptCodegenOptions, block: SfcBlock): Generator<Code>;
|