@vue/language-core 2.1.10 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codegen/globalTypes.js +11 -2
- package/lib/codegen/localTypes.js +3 -3
- package/lib/codegen/script/component.js +42 -42
- package/lib/codegen/script/componentSelf.js +13 -13
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +5 -3
- package/lib/codegen/script/index.js +19 -37
- package/lib/codegen/script/scriptSetup.js +240 -197
- package/lib/codegen/script/src.js +6 -6
- package/lib/codegen/script/styleModulesType.js +5 -5
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +86 -98
- package/lib/codegen/template/context.d.ts +13 -3
- package/lib/codegen/template/context.js +21 -12
- package/lib/codegen/template/element.d.ts +2 -4
- package/lib/codegen/template/element.js +132 -105
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +8 -8
- package/lib/codegen/template/elementDirectives.d.ts +1 -0
- package/lib/codegen/template/elementDirectives.js +28 -22
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +32 -65
- package/lib/codegen/template/elementProps.d.ts +3 -2
- package/lib/codegen/template/elementProps.js +119 -122
- package/lib/codegen/template/index.js +52 -60
- package/lib/codegen/template/interpolation.d.ts +5 -3
- package/lib/codegen/template/interpolation.js +18 -19
- package/lib/codegen/template/objectProperty.js +8 -8
- package/lib/codegen/template/propertyAccess.js +4 -4
- package/lib/codegen/template/slotOutlet.d.ts +1 -1
- package/lib/codegen/template/slotOutlet.js +13 -13
- package/lib/codegen/template/styleScopedClasses.d.ts +1 -1
- package/lib/codegen/template/styleScopedClasses.js +11 -8
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +31 -19
- package/lib/codegen/template/vFor.d.ts +1 -1
- package/lib/codegen/template/vFor.js +11 -11
- package/lib/codegen/template/vIf.d.ts +1 -1
- package/lib/codegen/template/vIf.js +6 -6
- package/lib/codegen/{template → utils}/camelized.js +2 -2
- package/lib/codegen/{common.d.ts → utils/index.d.ts} +1 -2
- package/lib/codegen/{common.js → utils/index.js} +4 -15
- package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +2 -0
- package/lib/codegen/utils/unicode.js +25 -0
- package/lib/languagePlugin.js +1 -1
- package/lib/parsers/scriptRanges.d.ts +7 -2
- package/lib/parsers/scriptSetupRanges.d.ts +67 -83
- package/lib/parsers/scriptSetupRanges.js +193 -167
- package/lib/parsers/vueCompilerOptions.d.ts +2 -0
- package/lib/parsers/vueCompilerOptions.js +23 -0
- package/lib/plugins/file-html.js +4 -3
- package/lib/plugins/file-md.js +1 -1
- package/lib/plugins/file-vue.js +4 -4
- package/lib/plugins/vue-root-tags.js +2 -2
- package/lib/plugins/vue-template-html.js +6 -2
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +13 -5
- package/lib/plugins/vue-tsx.d.ts +101 -74
- package/lib/plugins/vue-tsx.js +65 -68
- package/lib/types.d.ts +19 -10
- package/lib/utils/buildMappings.d.ts +1 -1
- package/lib/utils/parseSfc.d.ts +5 -0
- package/lib/utils/parseSfc.js +7 -2
- package/lib/utils/ts.d.ts +1 -1
- package/lib/utils/ts.js +38 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +23 -12
- package/lib/virtualFile/computedVueSfc.d.ts +1 -1
- package/lib/virtualFile/vueFile.d.ts +3 -3
- package/package.json +5 -5
- package/lib/utils/findDestructuredProps.d.ts +0 -1
- package/lib/utils/findDestructuredProps.js +0 -3
- /package/lib/codegen/{template → utils}/camelized.d.ts +0 -0
- /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
|
@@ -17,6 +17,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
17
17
|
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
|
|
18
18
|
const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
|
|
19
19
|
const __VLS_unref: typeof import('${lib}').unref;
|
|
20
|
+
const __VLS_placeholder: any;
|
|
20
21
|
|
|
21
22
|
const __VLS_nativeElements = {
|
|
22
23
|
...{} as SVGElementTagNameMap,
|
|
@@ -43,7 +44,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
43
44
|
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
|
|
44
45
|
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
|
|
45
46
|
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
46
|
-
${strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
|
|
47
|
+
${strictTemplates ? '{}' : '{ [K in N0]: unknown }'};
|
|
47
48
|
type __VLS_FunctionalComponentProps<T, K> =
|
|
48
49
|
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
|
49
50
|
: T extends (props: infer P, ...args: any) => any ? P :
|
|
@@ -55,6 +56,15 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
55
56
|
: true
|
|
56
57
|
: false
|
|
57
58
|
: false;
|
|
59
|
+
type __VLS_NormalizeComponentEvent<Props, Events, onEvent extends keyof Props, Event extends keyof Events, CamelizedEvent extends keyof Events> = (
|
|
60
|
+
__VLS_IsFunction<Props, onEvent> extends true
|
|
61
|
+
? Props
|
|
62
|
+
: __VLS_IsFunction<Events, Event> extends true
|
|
63
|
+
? { [K in onEvent]?: Events[Event] }
|
|
64
|
+
: __VLS_IsFunction<Events, CamelizedEvent> extends true
|
|
65
|
+
? { [K in onEvent]?: Events[CamelizedEvent] }
|
|
66
|
+
: Props
|
|
67
|
+
)${strictTemplates ? '' : ' & Record<string, unknown>'};
|
|
58
68
|
// fix https://github.com/vuejs/language-tools/issues/926
|
|
59
69
|
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
|
|
60
70
|
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
|
|
@@ -119,7 +129,6 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
119
129
|
: __VLS_unknownDirective;
|
|
120
130
|
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
|
121
131
|
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
122
|
-
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
|
|
123
132
|
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
124
133
|
T extends new (...args: any) => any
|
|
125
134
|
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLocalTypesGenerator = getLocalTypesGenerator;
|
|
4
4
|
const shared_1 = require("../utils/shared");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
6
|
function getLocalTypesGenerator(compilerOptions, vueCompilerOptions) {
|
|
7
7
|
const used = new Set();
|
|
8
8
|
const OmitKeepDiscriminatedUnion = defineHelper(`__VLS_OmitKeepDiscriminatedUnion`, () => `
|
|
@@ -17,7 +17,7 @@ type __VLS_WithDefaults<P, D> = {
|
|
|
17
17
|
: P[K]
|
|
18
18
|
};
|
|
19
19
|
`.trimStart());
|
|
20
|
-
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${
|
|
20
|
+
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${utils_1.endOfLine}`);
|
|
21
21
|
const WithTemplateSlots = defineHelper(`__VLS_WithTemplateSlots`, () => `
|
|
22
22
|
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
23
23
|
new(): {
|
|
@@ -57,7 +57,7 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
57
57
|
: { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
58
58
|
};
|
|
59
59
|
`.trimStart());
|
|
60
|
-
const OmitIndexSignature = defineHelper(`__VLS_OmitIndexSignature`, () => `type __VLS_OmitIndexSignature<T> = { [K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K]; }${
|
|
60
|
+
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}`);
|
|
61
61
|
const helpers = {
|
|
62
62
|
[PrettifyLocal.name]: PrettifyLocal,
|
|
63
63
|
[OmitKeepDiscriminatedUnion.name]: OmitKeepDiscriminatedUnion,
|
|
@@ -4,27 +4,27 @@ exports.generateComponent = generateComponent;
|
|
|
4
4
|
exports.generateComponentSetupReturns = generateComponentSetupReturns;
|
|
5
5
|
exports.generateEmitsOption = generateEmitsOption;
|
|
6
6
|
exports.generatePropsOption = generatePropsOption;
|
|
7
|
-
const
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
8
|
const index_1 = require("./index");
|
|
9
9
|
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
10
10
|
if (options.sfc.script && options.scriptRanges?.exportDefault && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
|
|
11
11
|
// use defineComponent() from user space code if it exist
|
|
12
|
-
yield (0,
|
|
13
|
-
yield `{${
|
|
12
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, index_1.codeFeatures.all);
|
|
13
|
+
yield `{${utils_1.newLine}`;
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${
|
|
16
|
+
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
|
|
17
17
|
}
|
|
18
|
-
yield `setup() {${
|
|
19
|
-
yield `return {${
|
|
18
|
+
yield `setup() {${utils_1.newLine}`;
|
|
19
|
+
yield `return {${utils_1.newLine}`;
|
|
20
20
|
if (ctx.bypassDefineComponent) {
|
|
21
21
|
yield* generateComponentSetupReturns(scriptSetupRanges);
|
|
22
22
|
}
|
|
23
|
-
if (scriptSetupRanges.
|
|
24
|
-
yield `...__VLS_exposed,${
|
|
23
|
+
if (scriptSetupRanges.defineExpose) {
|
|
24
|
+
yield `...__VLS_exposed,${utils_1.newLine}`;
|
|
25
25
|
}
|
|
26
|
-
yield `}${
|
|
27
|
-
yield `},${
|
|
26
|
+
yield `}${utils_1.endOfLine}`;
|
|
27
|
+
yield `},${utils_1.newLine}`;
|
|
28
28
|
if (!ctx.bypassDefineComponent) {
|
|
29
29
|
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
|
|
30
30
|
for (const code of emitOptionCodes) {
|
|
@@ -34,26 +34,26 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
34
34
|
}
|
|
35
35
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
|
36
36
|
const { args } = options.scriptRanges.exportDefault;
|
|
37
|
-
yield (0,
|
|
37
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
|
|
38
38
|
}
|
|
39
|
-
if (options.vueCompilerOptions.target >= 3.5 &&
|
|
40
|
-
yield `__typeRefs: {} as __VLS_TemplateResult['refs'],${
|
|
39
|
+
if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.templateRefs.size) {
|
|
40
|
+
yield `__typeRefs: {} as __VLS_TemplateResult['refs'],${utils_1.newLine}`;
|
|
41
41
|
}
|
|
42
42
|
if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) {
|
|
43
|
-
yield `__typeEl: {} as __VLS_TemplateResult['rootEl'],${
|
|
43
|
+
yield `__typeEl: {} as __VLS_TemplateResult['rootEl'],${utils_1.newLine}`;
|
|
44
44
|
}
|
|
45
45
|
yield `})`;
|
|
46
46
|
}
|
|
47
47
|
function* generateComponentSetupReturns(scriptSetupRanges) {
|
|
48
48
|
// fill $props
|
|
49
|
-
if (scriptSetupRanges.
|
|
49
|
+
if (scriptSetupRanges.defineProps) {
|
|
50
50
|
// NOTE: defineProps is inaccurate for $props
|
|
51
|
-
yield `$props: __VLS_makeOptional(${scriptSetupRanges.
|
|
52
|
-
yield `...${scriptSetupRanges.
|
|
51
|
+
yield `$props: __VLS_makeOptional(${scriptSetupRanges.defineProps.name ?? `__VLS_props`}),${utils_1.newLine}`;
|
|
52
|
+
yield `...${scriptSetupRanges.defineProps.name ?? `__VLS_props`},${utils_1.newLine}`;
|
|
53
53
|
}
|
|
54
54
|
// fill $emit
|
|
55
|
-
if (scriptSetupRanges.
|
|
56
|
-
yield `$emit: ${scriptSetupRanges.
|
|
55
|
+
if (scriptSetupRanges.defineEmits) {
|
|
56
|
+
yield `$emit: ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'},${utils_1.newLine}`;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function* generateEmitsOption(options, scriptSetupRanges) {
|
|
@@ -64,10 +64,10 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
64
64
|
typeOptionType: `__VLS_ModelEmit`,
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
if (scriptSetupRanges.
|
|
68
|
-
const { typeArg, hasUnionTypeArg } = scriptSetupRanges.
|
|
67
|
+
if (scriptSetupRanges.defineEmits) {
|
|
68
|
+
const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
|
|
69
69
|
codes.push({
|
|
70
|
-
optionExp: `{} as __VLS_NormalizeEmits<typeof ${
|
|
70
|
+
optionExp: `{} as __VLS_NormalizeEmits<typeof ${name ?? '__VLS_emit'}>`,
|
|
71
71
|
typeOptionType: typeArg && !hasUnionTypeArg
|
|
72
72
|
? `__VLS_Emit`
|
|
73
73
|
: undefined,
|
|
@@ -77,7 +77,7 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
77
77
|
if (codes.length === 1) {
|
|
78
78
|
yield `__typeEmits: {} as `;
|
|
79
79
|
yield codes[0].typeOptionType;
|
|
80
|
-
yield `,${
|
|
80
|
+
yield `,${utils_1.newLine}`;
|
|
81
81
|
}
|
|
82
82
|
else if (codes.length >= 2) {
|
|
83
83
|
yield `__typeEmits: {} as `;
|
|
@@ -86,23 +86,23 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
86
86
|
yield ` & `;
|
|
87
87
|
yield codes[i].typeOptionType;
|
|
88
88
|
}
|
|
89
|
-
yield `,${
|
|
89
|
+
yield `,${utils_1.newLine}`;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
else if (codes.every(code => code.optionExp)) {
|
|
93
93
|
if (codes.length === 1) {
|
|
94
94
|
yield `emits: `;
|
|
95
95
|
yield codes[0].optionExp;
|
|
96
|
-
yield `,${
|
|
96
|
+
yield `,${utils_1.newLine}`;
|
|
97
97
|
}
|
|
98
98
|
else if (codes.length >= 2) {
|
|
99
|
-
yield `emits: {${
|
|
99
|
+
yield `emits: {${utils_1.newLine}`;
|
|
100
100
|
for (const code of codes) {
|
|
101
101
|
yield `...`;
|
|
102
102
|
yield code.optionExp;
|
|
103
|
-
yield `,${
|
|
103
|
+
yield `,${utils_1.newLine}`;
|
|
104
104
|
}
|
|
105
|
-
yield `},${
|
|
105
|
+
yield `},${utils_1.newLine}`;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
}
|
|
@@ -112,17 +112,17 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
112
112
|
codes.push({
|
|
113
113
|
optionExp: [
|
|
114
114
|
`{} as `,
|
|
115
|
-
scriptSetupRanges.
|
|
115
|
+
scriptSetupRanges.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
|
|
116
116
|
`${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
|
|
117
|
-
scriptSetupRanges.
|
|
117
|
+
scriptSetupRanges.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
|
|
118
118
|
].join(''),
|
|
119
119
|
typeOptionExp: `{} as __VLS_PublicProps`,
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
if (scriptSetupRanges.
|
|
123
|
-
const { arg } = scriptSetupRanges.
|
|
122
|
+
if (scriptSetupRanges.defineProps?.arg) {
|
|
123
|
+
const { arg } = scriptSetupRanges.defineProps;
|
|
124
124
|
codes.push({
|
|
125
|
-
optionExp: (0,
|
|
125
|
+
optionExp: (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation),
|
|
126
126
|
typeOptionExp: undefined,
|
|
127
127
|
});
|
|
128
128
|
}
|
|
@@ -142,37 +142,37 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
const useTypeOption = options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionExp);
|
|
145
|
-
const useOption = !useTypeOption || scriptSetupRanges.
|
|
145
|
+
const useOption = !useTypeOption || scriptSetupRanges.withDefaults;
|
|
146
146
|
if (useTypeOption) {
|
|
147
147
|
if (codes.length === 1) {
|
|
148
148
|
yield `__typeProps: `;
|
|
149
149
|
yield codes[0].typeOptionExp;
|
|
150
|
-
yield `,${
|
|
150
|
+
yield `,${utils_1.newLine}`;
|
|
151
151
|
}
|
|
152
152
|
else if (codes.length >= 2) {
|
|
153
|
-
yield `__typeProps: {${
|
|
153
|
+
yield `__typeProps: {${utils_1.newLine}`;
|
|
154
154
|
for (const { typeOptionExp } of codes) {
|
|
155
155
|
yield `...`;
|
|
156
156
|
yield typeOptionExp;
|
|
157
|
-
yield `,${
|
|
157
|
+
yield `,${utils_1.newLine}`;
|
|
158
158
|
}
|
|
159
|
-
yield `},${
|
|
159
|
+
yield `},${utils_1.newLine}`;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
if (useOption) {
|
|
163
163
|
if (codes.length === 1) {
|
|
164
164
|
yield `props: `;
|
|
165
165
|
yield codes[0].optionExp;
|
|
166
|
-
yield `,${
|
|
166
|
+
yield `,${utils_1.newLine}`;
|
|
167
167
|
}
|
|
168
168
|
else if (codes.length >= 2) {
|
|
169
|
-
yield `props: {${
|
|
169
|
+
yield `props: {${utils_1.newLine}`;
|
|
170
170
|
for (const { optionExp } of codes) {
|
|
171
171
|
yield `...`;
|
|
172
172
|
yield optionExp;
|
|
173
|
-
yield `,${
|
|
173
|
+
yield `,${utils_1.newLine}`;
|
|
174
174
|
}
|
|
175
|
-
yield `},${
|
|
175
|
+
yield `},${utils_1.newLine}`;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateComponentSelf = generateComponentSelf;
|
|
4
4
|
const path = require("path-browserify");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
6
|
const component_1 = require("./component");
|
|
7
7
|
const index_1 = require("./index");
|
|
8
8
|
const template_1 = require("./template");
|
|
9
9
|
function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
10
10
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
11
|
-
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${
|
|
12
|
-
yield `setup() {${
|
|
13
|
-
yield `return {${
|
|
11
|
+
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
|
|
12
|
+
yield `setup() {${utils_1.newLine}`;
|
|
13
|
+
yield `return {${utils_1.newLine}`;
|
|
14
14
|
if (ctx.bypassDefineComponent) {
|
|
15
15
|
yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
|
|
16
16
|
}
|
|
@@ -22,15 +22,15 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
22
22
|
? [options.sfc.script.content, options.scriptRanges.bindings]
|
|
23
23
|
: ['', []],
|
|
24
24
|
]) {
|
|
25
|
-
for (const
|
|
26
|
-
const varName = content.
|
|
25
|
+
for (const { range } of bindings) {
|
|
26
|
+
const varName = content.slice(range.start, range.end);
|
|
27
27
|
if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
30
30
|
const templateOffset = options.getGeneratedLength();
|
|
31
31
|
yield `${varName}: ${varName} as typeof `;
|
|
32
32
|
const scriptOffset = options.getGeneratedLength();
|
|
33
|
-
yield `${varName},${
|
|
33
|
+
yield `${varName},${utils_1.newLine}`;
|
|
34
34
|
options.linkedCodeMappings.push({
|
|
35
35
|
sourceOffsets: [scriptOffset],
|
|
36
36
|
generatedOffsets: [templateOffset],
|
|
@@ -39,8 +39,8 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
yield `}${
|
|
43
|
-
yield `},${
|
|
42
|
+
yield `}${utils_1.endOfLine}`; // return {
|
|
43
|
+
yield `},${utils_1.newLine}`; // setup() {
|
|
44
44
|
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
|
|
45
45
|
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
|
|
46
46
|
for (const code of emitOptionCodes) {
|
|
@@ -50,15 +50,15 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
50
50
|
}
|
|
51
51
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
|
52
52
|
const { args } = options.scriptRanges.exportDefault;
|
|
53
|
-
yield (0,
|
|
53
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
|
|
54
54
|
}
|
|
55
|
-
yield `})${
|
|
55
|
+
yield `})${utils_1.endOfLine}`; // defineComponent {
|
|
56
56
|
}
|
|
57
57
|
else if (options.sfc.script) {
|
|
58
|
-
yield `let __VLS_self!: typeof import('./${path.basename(options.fileName)}').default${
|
|
58
|
+
yield `let __VLS_self!: typeof import('./${path.basename(options.fileName)}').default${utils_1.endOfLine}`;
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${
|
|
61
|
+
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
//# sourceMappingURL=componentSelf.js.map
|
|
@@ -11,8 +11,8 @@ function createScriptCodegenContext(options) {
|
|
|
11
11
|
scriptSetupGeneratedOffset: undefined,
|
|
12
12
|
bypassDefineComponent: options.lang === 'js' || options.lang === 'jsx',
|
|
13
13
|
bindingNames: new Set([
|
|
14
|
-
...options.scriptRanges?.bindings.map(range => options.sfc.script.content.
|
|
15
|
-
...options.scriptSetupRanges?.bindings.map(range => options.sfc.scriptSetup.content.
|
|
14
|
+
...options.scriptRanges?.bindings.map(({ range }) => options.sfc.script.content.slice(range.start, range.end)) ?? [],
|
|
15
|
+
...options.scriptSetupRanges?.bindings.map(({ range }) => options.sfc.scriptSetup.content.slice(range.start, range.end)) ?? [],
|
|
16
16
|
]),
|
|
17
17
|
localTypes,
|
|
18
18
|
inlayHints,
|
|
@@ -13,21 +13,23 @@ export declare const codeFeatures: {
|
|
|
13
13
|
navigationWithoutRename: VueCodeInformation;
|
|
14
14
|
};
|
|
15
15
|
export interface ScriptCodegenOptions {
|
|
16
|
-
fileName: string;
|
|
17
16
|
ts: typeof ts;
|
|
18
17
|
compilerOptions: ts.CompilerOptions;
|
|
19
18
|
vueCompilerOptions: VueCompilerOptions;
|
|
20
19
|
sfc: Sfc;
|
|
20
|
+
edited: boolean;
|
|
21
|
+
fileName: string;
|
|
21
22
|
lang: string;
|
|
22
23
|
scriptRanges: ScriptRanges | undefined;
|
|
23
24
|
scriptSetupRanges: ScriptSetupRanges | undefined;
|
|
24
25
|
templateCodegen: TemplateCodegenContext & {
|
|
25
26
|
codes: Code[];
|
|
26
27
|
} | undefined;
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
destructuredPropNames: Set<string>;
|
|
29
|
+
templateRefNames: Set<string>;
|
|
29
30
|
getGeneratedLength: () => number;
|
|
30
31
|
linkedCodeMappings: Mapping[];
|
|
32
|
+
appendGlobalTypes: boolean;
|
|
31
33
|
}
|
|
32
34
|
export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
|
|
33
35
|
export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code>;
|
|
@@ -4,8 +4,8 @@ exports.codeFeatures = void 0;
|
|
|
4
4
|
exports.generateScript = generateScript;
|
|
5
5
|
exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
|
|
6
6
|
const path = require("path-browserify");
|
|
7
|
-
const common_1 = require("../common");
|
|
8
7
|
const globalTypes_1 = require("../globalTypes");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
9
|
const componentSelf_1 = require("./componentSelf");
|
|
10
10
|
const context_1 = require("./context");
|
|
11
11
|
const scriptSetup_1 = require("./scriptSetup");
|
|
@@ -43,10 +43,10 @@ function* generateScript(options) {
|
|
|
43
43
|
if (relativePath !== globalTypes.absolutePath && !relativePath.startsWith('./') && !relativePath.startsWith('../')) {
|
|
44
44
|
relativePath = './' + relativePath;
|
|
45
45
|
}
|
|
46
|
-
yield `/// <reference types="${relativePath}" />${
|
|
46
|
+
yield `/// <reference types="${relativePath}" />${utils_1.newLine}`;
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${
|
|
49
|
+
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${utils_1.newLine}`;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
@@ -61,14 +61,13 @@ function* generateScript(options) {
|
|
|
61
61
|
&& options.sfc.script.content[exportDefault.expression.start] === '{';
|
|
62
62
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
63
63
|
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
64
|
-
yield* generateDefineProp(options, options.sfc.scriptSetup);
|
|
65
64
|
if (exportDefault) {
|
|
66
|
-
yield (0,
|
|
65
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
|
|
67
66
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
68
|
-
yield (0,
|
|
67
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
69
68
|
}
|
|
70
69
|
else {
|
|
71
|
-
yield (0,
|
|
70
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
72
71
|
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
|
|
73
72
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
74
73
|
}
|
|
@@ -93,32 +92,31 @@ function* generateScript(options) {
|
|
|
93
92
|
? options.vueCompilerOptions.optionsWrapper[1]
|
|
94
93
|
: '[Missing optionsWrapper[1]]',
|
|
95
94
|
});
|
|
96
|
-
yield (0,
|
|
95
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
|
|
97
96
|
yield options.vueCompilerOptions.optionsWrapper[0];
|
|
98
|
-
yield (0,
|
|
97
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, exports.codeFeatures.all);
|
|
99
98
|
yield options.vueCompilerOptions.optionsWrapper[1];
|
|
100
|
-
yield (0,
|
|
99
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
101
100
|
}
|
|
102
101
|
else if (classBlockEnd !== undefined) {
|
|
103
102
|
if (options.vueCompilerOptions.skipTemplateCodegen) {
|
|
104
|
-
yield (0,
|
|
103
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
105
104
|
}
|
|
106
105
|
else {
|
|
107
|
-
yield (0,
|
|
108
|
-
yield `__VLS_template = () => {${
|
|
106
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
|
|
107
|
+
yield `__VLS_template = () => {${utils_1.newLine}`;
|
|
109
108
|
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
110
109
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
111
|
-
yield `}${
|
|
112
|
-
yield (0,
|
|
110
|
+
yield `}${utils_1.endOfLine}`;
|
|
111
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
else {
|
|
116
|
-
yield (0,
|
|
115
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
118
|
else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
120
119
|
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
121
|
-
yield* generateDefineProp(options, options.sfc.scriptSetup);
|
|
122
120
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
123
121
|
}
|
|
124
122
|
if (options.sfc.script) {
|
|
@@ -128,15 +126,15 @@ function* generateScript(options) {
|
|
|
128
126
|
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
|
|
129
127
|
}
|
|
130
128
|
if (!ctx.generatedTemplate) {
|
|
131
|
-
yield `function __VLS_template() {${
|
|
129
|
+
yield `function __VLS_template() {${utils_1.newLine}`;
|
|
132
130
|
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
133
|
-
yield `}${
|
|
131
|
+
yield `}${utils_1.endOfLine}`;
|
|
134
132
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
135
133
|
}
|
|
136
134
|
// #4788
|
|
137
135
|
yield* (0, styleModulesType_1.generateStyleModulesType)(options, ctx);
|
|
138
136
|
if (options.edited) {
|
|
139
|
-
yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${
|
|
137
|
+
yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${utils_1.endOfLine}`;
|
|
140
138
|
}
|
|
141
139
|
yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
|
|
142
140
|
if (options.appendGlobalTypes) {
|
|
@@ -150,22 +148,6 @@ function* generateScript(options) {
|
|
|
150
148
|
function* generateScriptSectionPartiallyEnding(source, end, mark) {
|
|
151
149
|
yield `;`;
|
|
152
150
|
yield ['', source, end, exports.codeFeatures.verification];
|
|
153
|
-
yield `/* PartiallyEnd: ${mark} */${
|
|
154
|
-
}
|
|
155
|
-
function* generateDefineProp(options, scriptSetup) {
|
|
156
|
-
const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
157
|
-
const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
|
158
|
-
if (definePropProposalA || definePropProposalB) {
|
|
159
|
-
yield `type __VLS_PropOptions<T> = Exclude<import('${options.vueCompilerOptions.lib}').Prop<T>, import('${options.vueCompilerOptions.lib}').PropType<T>>${common_1.endOfLine}`;
|
|
160
|
-
if (definePropProposalA) {
|
|
161
|
-
yield `declare function defineProp<T>(name: string, options: ({ required: true } | { default: T }) & __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
|
|
162
|
-
yield `declare function defineProp<T>(name?: string, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${common_1.endOfLine}`;
|
|
163
|
-
}
|
|
164
|
-
if (definePropProposalB) {
|
|
165
|
-
yield `declare function defineProp<T>(value: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
|
|
166
|
-
yield `declare function defineProp<T>(value: T | (() => T) | undefined, required: true, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
|
|
167
|
-
yield `declare function defineProp<T>(value?: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${common_1.endOfLine}`;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
151
|
+
yield `/* PartiallyEnd: ${mark} */${utils_1.newLine}`;
|
|
170
152
|
}
|
|
171
153
|
//# sourceMappingURL=index.js.map
|