@vue/language-core 2.1.6 → 2.1.10
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/common.d.ts +2 -2
- package/lib/codegen/common.js +8 -10
- package/lib/codegen/globalTypes.js +10 -7
- package/lib/codegen/{types.d.ts → inlayHints.d.ts} +2 -0
- package/lib/codegen/inlayHints.js +17 -0
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +8 -5
- package/lib/codegen/script/componentSelf.js +3 -2
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/index.d.ts +2 -1
- package/lib/codegen/script/index.js +28 -10
- package/lib/codegen/script/scriptSetup.js +107 -112
- package/lib/codegen/script/styleModulesType.js +4 -6
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +13 -14
- package/lib/codegen/template/context.d.ts +3 -2
- package/lib/codegen/template/context.js +1 -0
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +31 -11
- package/lib/codegen/template/elementDirectives.js +63 -31
- package/lib/codegen/template/elementProps.js +7 -17
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +63 -53
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +34 -28
- package/lib/codegen/template/slotOutlet.js +5 -0
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +6 -2
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/parsers/scriptSetupRanges.d.ts +17 -5
- package/lib/parsers/scriptSetupRanges.js +43 -27
- package/lib/plugins/vue-tsx.d.ts +30 -17
- package/lib/plugins/vue-tsx.js +44 -33
- package/lib/types.d.ts +3 -1
- package/lib/utils/parseCssClassNames.d.ts +1 -1
- package/lib/utils/parseCssClassNames.js +5 -4
- package/lib/utils/parseCssVars.d.ts +3 -2
- package/lib/utils/parseCssVars.js +12 -11
- package/lib/utils/ts.d.ts +1 -1
- package/lib/utils/ts.js +3 -5
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +2 -1
- package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
- package/lib/virtualFile/computedSfc.d.ts +2 -1
- package/lib/virtualFile/computedSfc.js +77 -76
- package/lib/virtualFile/computedVueSfc.d.ts +2 -1
- package/lib/virtualFile/computedVueSfc.js +8 -8
- package/lib/virtualFile/vueFile.d.ts +6 -7
- package/lib/virtualFile/vueFile.js +13 -12
- package/package.json +9 -8
- package/lib/codegen/types.js +0 -3
package/lib/codegen/common.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const combineLastMapping: VueCodeInformation;
|
|
|
6
6
|
export declare const variableNameRegex: RegExp;
|
|
7
7
|
export declare function conditionWrapWith(condition: boolean, startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
|
8
8
|
export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
|
9
|
-
export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]
|
|
10
|
-
export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: ts.Identifier[],
|
|
9
|
+
export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
|
|
10
|
+
export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: [id: ts.Identifier, isRest: boolean][], isRest?: boolean): [id: ts.Identifier, isRest: boolean][];
|
|
11
11
|
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
|
12
12
|
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
package/lib/codegen/common.js
CHANGED
|
@@ -33,33 +33,31 @@ function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
|
|
|
33
33
|
}
|
|
34
34
|
yield ['', 'template', endOffset, { __combineOffsetMapping: offset }];
|
|
35
35
|
}
|
|
36
|
-
function collectVars(ts, node, ast, results = []
|
|
37
|
-
const identifiers = collectIdentifiers(ts, node, []
|
|
38
|
-
for (const id of identifiers) {
|
|
36
|
+
function collectVars(ts, node, ast, results = []) {
|
|
37
|
+
const identifiers = collectIdentifiers(ts, node, []);
|
|
38
|
+
for (const [id] of identifiers) {
|
|
39
39
|
results.push((0, scriptSetupRanges_1.getNodeText)(ts, id, ast));
|
|
40
40
|
}
|
|
41
41
|
return results;
|
|
42
42
|
}
|
|
43
|
-
function collectIdentifiers(ts, node, results = [],
|
|
43
|
+
function collectIdentifiers(ts, node, results = [], isRest = false) {
|
|
44
44
|
if (ts.isIdentifier(node)) {
|
|
45
|
-
results.push(node);
|
|
45
|
+
results.push([node, isRest]);
|
|
46
46
|
}
|
|
47
47
|
else if (ts.isObjectBindingPattern(node)) {
|
|
48
48
|
for (const el of node.elements) {
|
|
49
|
-
|
|
50
|
-
collectIdentifiers(ts, el.name, results, includesRest);
|
|
51
|
-
}
|
|
49
|
+
collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
52
|
else if (ts.isArrayBindingPattern(node)) {
|
|
55
53
|
for (const el of node.elements) {
|
|
56
54
|
if (ts.isBindingElement(el)) {
|
|
57
|
-
collectIdentifiers(ts, el.name, results,
|
|
55
|
+
collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
else {
|
|
62
|
-
ts.forEachChild(node, node => collectIdentifiers(ts, node, results,
|
|
60
|
+
ts.forEachChild(node, node => collectIdentifiers(ts, node, results, false));
|
|
63
61
|
}
|
|
64
62
|
return results;
|
|
65
63
|
}
|
|
@@ -79,6 +79,11 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
79
79
|
>
|
|
80
80
|
>;
|
|
81
81
|
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
82
|
+
type __VLS_PickFunctionalComponentCtx<T, K> = NonNullable<__VLS_PickNotAny<
|
|
83
|
+
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
84
|
+
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
85
|
+
>>;
|
|
86
|
+
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
82
87
|
|
|
83
88
|
function __VLS_getVForSourceType(source: number): [number, number, number][];
|
|
84
89
|
function __VLS_getVForSourceType(source: string): [string, number, number][];
|
|
@@ -107,9 +112,11 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
107
112
|
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
|
|
108
113
|
// @ts-ignore
|
|
109
114
|
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
|
|
110
|
-
function
|
|
111
|
-
? T |
|
|
112
|
-
:
|
|
115
|
+
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
|
|
116
|
+
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
|
|
117
|
+
: T extends (...args: any) => any
|
|
118
|
+
? T
|
|
119
|
+
: __VLS_unknownDirective;
|
|
113
120
|
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
|
114
121
|
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
115
122
|
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
|
|
@@ -125,10 +132,6 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
125
132
|
: (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
|
|
126
133
|
function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
|
|
127
134
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
128
|
-
function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
|
|
129
|
-
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
130
|
-
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
131
|
-
>>;
|
|
132
135
|
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
|
|
133
136
|
function __VLS_tryAsConstant<const T>(t: T): T;
|
|
134
137
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as CompilerDOM from '@vue/compiler-dom';
|
|
1
2
|
export interface InlayHintInfo {
|
|
2
3
|
blockName: string;
|
|
3
4
|
offset: number;
|
|
@@ -7,3 +8,4 @@ export interface InlayHintInfo {
|
|
|
7
8
|
paddingRight?: boolean;
|
|
8
9
|
paddingLeft?: boolean;
|
|
9
10
|
}
|
|
11
|
+
export declare function createVBindShorthandInlayHintInfo(loc: CompilerDOM.SourceLocation, variableName: string): InlayHintInfo;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createVBindShorthandInlayHintInfo = createVBindShorthandInlayHintInfo;
|
|
4
|
+
function createVBindShorthandInlayHintInfo(loc, variableName) {
|
|
5
|
+
return {
|
|
6
|
+
blockName: 'template',
|
|
7
|
+
offset: loc.end.offset,
|
|
8
|
+
setting: 'vue.inlayHints.vBindShorthand',
|
|
9
|
+
label: `="${variableName}"`,
|
|
10
|
+
tooltip: [
|
|
11
|
+
`This is a shorthand for \`${loc.source}="${variableName}"\`.`,
|
|
12
|
+
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
|
|
13
|
+
'[More info](https://github.com/vuejs/core/pull/9451)',
|
|
14
|
+
].join('\n\n'),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=inlayHints.js.map
|
|
@@ -4,5 +4,5 @@ import type { ScriptCodegenContext } from './context';
|
|
|
4
4
|
import { ScriptCodegenOptions } from './index';
|
|
5
5
|
export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
6
6
|
export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
7
|
-
export declare function generateEmitsOption(options: ScriptCodegenOptions,
|
|
7
|
+
export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
8
8
|
export declare function generatePropsOption(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, hasEmitsOption: boolean, inheritAttrs: boolean): Generator<Code>;
|
|
@@ -26,7 +26,7 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
26
26
|
yield `}${common_1.endOfLine}`;
|
|
27
27
|
yield `},${common_1.newLine}`;
|
|
28
28
|
if (!ctx.bypassDefineComponent) {
|
|
29
|
-
const emitOptionCodes = [...generateEmitsOption(options,
|
|
29
|
+
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
|
|
30
30
|
for (const code of emitOptionCodes) {
|
|
31
31
|
yield code;
|
|
32
32
|
}
|
|
@@ -39,6 +39,9 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
39
39
|
if (options.vueCompilerOptions.target >= 3.5 && scriptSetupRanges.templateRefs.length) {
|
|
40
40
|
yield `__typeRefs: {} as __VLS_TemplateResult['refs'],${common_1.newLine}`;
|
|
41
41
|
}
|
|
42
|
+
if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) {
|
|
43
|
+
yield `__typeEl: {} as __VLS_TemplateResult['rootEl'],${common_1.newLine}`;
|
|
44
|
+
}
|
|
42
45
|
yield `})`;
|
|
43
46
|
}
|
|
44
47
|
function* generateComponentSetupReturns(scriptSetupRanges) {
|
|
@@ -53,12 +56,12 @@ function* generateComponentSetupReturns(scriptSetupRanges) {
|
|
|
53
56
|
yield `$emit: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
|
-
function* generateEmitsOption(options,
|
|
59
|
+
function* generateEmitsOption(options, scriptSetupRanges) {
|
|
57
60
|
const codes = [];
|
|
58
61
|
if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
|
|
59
62
|
codes.push({
|
|
60
|
-
optionExp: `{} as __VLS_NormalizeEmits<
|
|
61
|
-
typeOptionType: `
|
|
63
|
+
optionExp: `{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`,
|
|
64
|
+
typeOptionType: `__VLS_ModelEmit`,
|
|
62
65
|
});
|
|
63
66
|
}
|
|
64
67
|
if (scriptSetupRanges.emits.define) {
|
|
@@ -66,7 +69,7 @@ function* generateEmitsOption(options, scriptSetup, scriptSetupRanges) {
|
|
|
66
69
|
codes.push({
|
|
67
70
|
optionExp: `{} as __VLS_NormalizeEmits<typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}>`,
|
|
68
71
|
typeOptionType: typeArg && !hasUnionTypeArg
|
|
69
|
-
?
|
|
72
|
+
? `__VLS_Emit`
|
|
70
73
|
: undefined,
|
|
71
74
|
});
|
|
72
75
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateComponentSelf = generateComponentSelf;
|
|
4
|
+
const path = require("path-browserify");
|
|
4
5
|
const common_1 = require("../common");
|
|
5
6
|
const component_1 = require("./component");
|
|
6
7
|
const index_1 = require("./index");
|
|
@@ -41,7 +42,7 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
41
42
|
yield `}${common_1.endOfLine}`; // return {
|
|
42
43
|
yield `},${common_1.newLine}`; // setup() {
|
|
43
44
|
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
|
|
44
|
-
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.
|
|
45
|
+
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
|
|
45
46
|
for (const code of emitOptionCodes) {
|
|
46
47
|
yield code;
|
|
47
48
|
}
|
|
@@ -54,7 +55,7 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
54
55
|
yield `})${common_1.endOfLine}`; // defineComponent {
|
|
55
56
|
}
|
|
56
57
|
else if (options.sfc.script) {
|
|
57
|
-
yield `let __VLS_self!: typeof import('./${options.
|
|
58
|
+
yield `let __VLS_self!: typeof import('./${path.basename(options.fileName)}').default${common_1.endOfLine}`;
|
|
58
59
|
}
|
|
59
60
|
else {
|
|
60
61
|
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
|
|
@@ -13,7 +13,7 @@ export declare const codeFeatures: {
|
|
|
13
13
|
navigationWithoutRename: VueCodeInformation;
|
|
14
14
|
};
|
|
15
15
|
export interface ScriptCodegenOptions {
|
|
16
|
-
|
|
16
|
+
fileName: string;
|
|
17
17
|
ts: typeof ts;
|
|
18
18
|
compilerOptions: ts.CompilerOptions;
|
|
19
19
|
vueCompilerOptions: VueCompilerOptions;
|
|
@@ -30,3 +30,4 @@ export interface ScriptCodegenOptions {
|
|
|
30
30
|
linkedCodeMappings: Mapping[];
|
|
31
31
|
}
|
|
32
32
|
export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
|
|
33
|
+
export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code>;
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.codeFeatures = void 0;
|
|
4
4
|
exports.generateScript = generateScript;
|
|
5
|
+
exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
|
|
6
|
+
const path = require("path-browserify");
|
|
5
7
|
const common_1 = require("../common");
|
|
6
8
|
const globalTypes_1 = require("../globalTypes");
|
|
7
|
-
const context_1 = require("./context");
|
|
8
9
|
const componentSelf_1 = require("./componentSelf");
|
|
10
|
+
const context_1 = require("./context");
|
|
9
11
|
const scriptSetup_1 = require("./scriptSetup");
|
|
10
12
|
const src_1 = require("./src");
|
|
11
13
|
const styleModulesType_1 = require("./styleModulesType");
|
|
@@ -35,7 +37,17 @@ exports.codeFeatures = {
|
|
|
35
37
|
function* generateScript(options) {
|
|
36
38
|
const ctx = (0, context_1.createScriptCodegenContext)(options);
|
|
37
39
|
if (options.vueCompilerOptions.__setupedGlobalTypes) {
|
|
38
|
-
|
|
40
|
+
const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
|
|
41
|
+
if (typeof globalTypes === 'object') {
|
|
42
|
+
let relativePath = path.relative(path.dirname(options.fileName), globalTypes.absolutePath);
|
|
43
|
+
if (relativePath !== globalTypes.absolutePath && !relativePath.startsWith('./') && !relativePath.startsWith('../')) {
|
|
44
|
+
relativePath = './' + relativePath;
|
|
45
|
+
}
|
|
46
|
+
yield `/// <reference types="${relativePath}" />${common_1.newLine}`;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${common_1.newLine}`;
|
|
50
|
+
}
|
|
39
51
|
}
|
|
40
52
|
else {
|
|
41
53
|
yield `/* placeholder */`;
|
|
@@ -57,6 +69,7 @@ function* generateScript(options) {
|
|
|
57
69
|
}
|
|
58
70
|
else {
|
|
59
71
|
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
72
|
+
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
|
|
60
73
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
61
74
|
}
|
|
62
75
|
}
|
|
@@ -92,10 +105,10 @@ function* generateScript(options) {
|
|
|
92
105
|
}
|
|
93
106
|
else {
|
|
94
107
|
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
|
|
95
|
-
yield `__VLS_template = () => {`;
|
|
96
|
-
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx
|
|
108
|
+
yield `__VLS_template = () => {${common_1.newLine}`;
|
|
109
|
+
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
97
110
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
98
|
-
yield `}
|
|
111
|
+
yield `}${common_1.endOfLine}`;
|
|
99
112
|
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
100
113
|
}
|
|
101
114
|
}
|
|
@@ -108,15 +121,15 @@ function* generateScript(options) {
|
|
|
108
121
|
yield* generateDefineProp(options, options.sfc.scriptSetup);
|
|
109
122
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
110
123
|
}
|
|
111
|
-
|
|
124
|
+
if (options.sfc.script) {
|
|
125
|
+
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
|
|
126
|
+
}
|
|
112
127
|
if (options.sfc.scriptSetup) {
|
|
113
|
-
|
|
114
|
-
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, exports.codeFeatures.verification];
|
|
128
|
+
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
|
|
115
129
|
}
|
|
116
|
-
yield common_1.newLine;
|
|
117
130
|
if (!ctx.generatedTemplate) {
|
|
118
131
|
yield `function __VLS_template() {${common_1.newLine}`;
|
|
119
|
-
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx
|
|
132
|
+
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
120
133
|
yield `}${common_1.endOfLine}`;
|
|
121
134
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
122
135
|
}
|
|
@@ -134,6 +147,11 @@ function* generateScript(options) {
|
|
|
134
147
|
}
|
|
135
148
|
return ctx;
|
|
136
149
|
}
|
|
150
|
+
function* generateScriptSectionPartiallyEnding(source, end, mark) {
|
|
151
|
+
yield `;`;
|
|
152
|
+
yield ['', source, end, exports.codeFeatures.verification];
|
|
153
|
+
yield `/* PartiallyEnd: ${mark} */${common_1.newLine}`;
|
|
154
|
+
}
|
|
137
155
|
function* generateDefineProp(options, scriptSetup) {
|
|
138
156
|
const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
139
157
|
const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
|
@@ -4,8 +4,8 @@ exports.generateScriptSetupImports = generateScriptSetupImports;
|
|
|
4
4
|
exports.generateScriptSetup = generateScriptSetup;
|
|
5
5
|
const common_1 = require("../common");
|
|
6
6
|
const component_1 = require("./component");
|
|
7
|
-
const index_1 = require("./index");
|
|
8
7
|
const componentSelf_1 = require("./componentSelf");
|
|
8
|
+
const index_1 = require("./index");
|
|
9
9
|
const template_1 = require("./template");
|
|
10
10
|
function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
|
11
11
|
yield [
|
|
@@ -52,10 +52,10 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
52
52
|
emitTypes.push(`typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}`);
|
|
53
53
|
}
|
|
54
54
|
if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
|
|
55
|
-
emitTypes.push(`
|
|
55
|
+
emitTypes.push(`typeof __VLS_modelEmit`);
|
|
56
56
|
}
|
|
57
57
|
yield ` return {} as {${common_1.newLine}`
|
|
58
|
-
+ ` props: ${ctx.localTypes.PrettifyLocal}<typeof __VLS_functionalComponentProps & __VLS_PublicProps> & __VLS_BuiltInPublicProps,${common_1.newLine}`
|
|
58
|
+
+ ` props: ${ctx.localTypes.PrettifyLocal}<typeof __VLS_functionalComponentProps & __VLS_TemplateResult['attrs'] & __VLS_PublicProps> & __VLS_BuiltInPublicProps,${common_1.newLine}`
|
|
59
59
|
+ ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${common_1.newLine}`
|
|
60
60
|
+ ` attrs: any,${common_1.newLine}`
|
|
61
61
|
+ ` slots: __VLS_TemplateResult['slots'],${common_1.newLine}`
|
|
@@ -106,45 +106,8 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
106
106
|
}
|
|
107
107
|
ctx.scriptSetupGeneratedOffset = options.getGeneratedLength() - scriptSetupRanges.importSectionEndOffset;
|
|
108
108
|
let setupCodeModifies = [];
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const statement = scriptSetupRanges.props.define.statement;
|
|
112
|
-
if (scriptSetupRanges.props.define.typeArg) {
|
|
113
|
-
setupCodeModifies.push([[
|
|
114
|
-
`let __VLS_typeProps!: `,
|
|
115
|
-
(0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end, index_1.codeFeatures.all),
|
|
116
|
-
common_1.endOfLine,
|
|
117
|
-
], statement.start, statement.start]);
|
|
118
|
-
setupCodeModifies.push([[`typeof __VLS_typeProps`], scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end]);
|
|
119
|
-
}
|
|
120
|
-
if (!scriptSetupRanges.props.name) {
|
|
121
|
-
if (statement.start === propsRange.start && statement.end === propsRange.end) {
|
|
122
|
-
setupCodeModifies.push([[`const __VLS_props = `], propsRange.start, propsRange.start]);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
if (scriptSetupRanges.props.define.typeArg) {
|
|
126
|
-
setupCodeModifies.push([[
|
|
127
|
-
`const __VLS_props = `,
|
|
128
|
-
(0, common_1.generateSfcBlockSection)(scriptSetup, propsRange.start, scriptSetupRanges.props.define.typeArg.start, index_1.codeFeatures.all),
|
|
129
|
-
], statement.start, scriptSetupRanges.props.define.typeArg.start]);
|
|
130
|
-
setupCodeModifies.push([[
|
|
131
|
-
(0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.typeArg.end, propsRange.end, index_1.codeFeatures.all),
|
|
132
|
-
`${common_1.endOfLine}`,
|
|
133
|
-
(0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, propsRange.start, index_1.codeFeatures.all),
|
|
134
|
-
`__VLS_props`,
|
|
135
|
-
], scriptSetupRanges.props.define.typeArg.end, propsRange.end]);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
setupCodeModifies.push([[
|
|
139
|
-
`const __VLS_props = `,
|
|
140
|
-
(0, common_1.generateSfcBlockSection)(scriptSetup, propsRange.start, propsRange.end, index_1.codeFeatures.all),
|
|
141
|
-
`${common_1.endOfLine}`,
|
|
142
|
-
(0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, propsRange.start, index_1.codeFeatures.all),
|
|
143
|
-
`__VLS_props`,
|
|
144
|
-
], statement.start, propsRange.end]);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
109
|
+
if (scriptSetupRanges.props.define) {
|
|
110
|
+
setupCodeModifies.push(...generateDefineWithType(scriptSetup, scriptSetupRanges.props.name, scriptSetupRanges.props.define, scriptSetupRanges.props.withDefaults ?? scriptSetupRanges.props.define, '__VLS_props', '__VLS_Props'));
|
|
148
111
|
}
|
|
149
112
|
if (scriptSetupRanges.slots.define) {
|
|
150
113
|
if (scriptSetupRanges.slots.isObjectBindingPattern) {
|
|
@@ -158,8 +121,8 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
158
121
|
setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
|
|
159
122
|
}
|
|
160
123
|
}
|
|
161
|
-
if (scriptSetupRanges.emits.define
|
|
162
|
-
setupCodeModifies.push(
|
|
124
|
+
if (scriptSetupRanges.emits.define) {
|
|
125
|
+
setupCodeModifies.push(...generateDefineWithType(scriptSetup, scriptSetupRanges.emits.name, scriptSetupRanges.emits.define, scriptSetupRanges.emits.define, '__VLS_emit', '__VLS_Emit'));
|
|
163
126
|
}
|
|
164
127
|
if (scriptSetupRanges.expose.define) {
|
|
165
128
|
if (scriptSetupRanges.expose.define?.typeArg) {
|
|
@@ -193,66 +156,71 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
193
156
|
}
|
|
194
157
|
}
|
|
195
158
|
if (scriptSetupRanges.cssModules.length) {
|
|
196
|
-
for (const {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
]
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
[
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
],
|
|
217
|
-
exp.end,
|
|
218
|
-
exp.end
|
|
219
|
-
]);
|
|
220
|
-
}
|
|
159
|
+
for (const { define } of scriptSetupRanges.cssModules) {
|
|
160
|
+
setupCodeModifies.push([
|
|
161
|
+
[`(`],
|
|
162
|
+
define.start,
|
|
163
|
+
define.start
|
|
164
|
+
], [
|
|
165
|
+
define.arg ? [
|
|
166
|
+
` as Omit<__VLS_StyleModules, '$style'>[`,
|
|
167
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.all),
|
|
168
|
+
`])`
|
|
169
|
+
] : [
|
|
170
|
+
` as __VLS_StyleModules[`,
|
|
171
|
+
['', scriptSetup.name, define.exp.start, index_1.codeFeatures.verification],
|
|
172
|
+
`'$style'`,
|
|
173
|
+
['', scriptSetup.name, define.exp.end, index_1.codeFeatures.verification],
|
|
174
|
+
`])`
|
|
175
|
+
],
|
|
176
|
+
define.end,
|
|
177
|
+
define.end
|
|
178
|
+
]);
|
|
221
179
|
}
|
|
222
180
|
}
|
|
181
|
+
const isTs = options.lang !== 'js' && options.lang !== 'jsx';
|
|
223
182
|
for (const { define } of scriptSetupRanges.templateRefs) {
|
|
224
|
-
if (define
|
|
183
|
+
if (!define.arg) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (isTs) {
|
|
225
187
|
setupCodeModifies.push([
|
|
226
188
|
[
|
|
227
189
|
`<__VLS_TemplateResult['refs'][`,
|
|
228
190
|
(0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
|
|
229
191
|
`], keyof __VLS_TemplateResult['refs']>`
|
|
230
192
|
],
|
|
231
|
-
define.
|
|
232
|
-
define.
|
|
193
|
+
define.exp.end,
|
|
194
|
+
define.exp.end
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
setupCodeModifies.push([
|
|
199
|
+
[`(`],
|
|
200
|
+
define.start,
|
|
201
|
+
define.start
|
|
202
|
+
], [
|
|
203
|
+
[
|
|
204
|
+
` as __VLS_UseTemplateRef<__VLS_TemplateResult['refs'][`,
|
|
205
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
|
|
206
|
+
`]>)`
|
|
207
|
+
],
|
|
208
|
+
define.end,
|
|
209
|
+
define.end
|
|
233
210
|
]);
|
|
234
211
|
}
|
|
235
212
|
}
|
|
236
213
|
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
yield code;
|
|
243
|
-
}
|
|
244
|
-
if (setupCodeModifies.length) {
|
|
245
|
-
const nextStart = setupCodeModifies[0][1];
|
|
246
|
-
yield (0, common_1.generateSfcBlockSection)(scriptSetup, end, nextStart, index_1.codeFeatures.all);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
yield (0, common_1.generateSfcBlockSection)(scriptSetup, end, scriptSetup.content.length, index_1.codeFeatures.all);
|
|
250
|
-
}
|
|
214
|
+
let nextStart = scriptSetupRanges.importSectionEndOffset;
|
|
215
|
+
for (const [codes, start, end] of setupCodeModifies) {
|
|
216
|
+
yield (0, common_1.generateSfcBlockSection)(scriptSetup, nextStart, start, index_1.codeFeatures.all);
|
|
217
|
+
for (const code of codes) {
|
|
218
|
+
yield code;
|
|
251
219
|
}
|
|
220
|
+
nextStart = end;
|
|
252
221
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
222
|
+
yield (0, common_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, index_1.codeFeatures.all);
|
|
223
|
+
yield* (0, index_1.generateScriptSectionPartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
|
|
256
224
|
if (scriptSetupRanges.props.define?.typeArg && scriptSetupRanges.props.withDefaults?.arg) {
|
|
257
225
|
// fix https://github.com/vuejs/language-tools/issues/1187
|
|
258
226
|
yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
|
|
@@ -260,9 +228,9 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
260
228
|
yield `)${common_1.endOfLine}`;
|
|
261
229
|
}
|
|
262
230
|
yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
|
|
263
|
-
yield*
|
|
231
|
+
yield* generateModelEmit(scriptSetup, scriptSetupRanges);
|
|
264
232
|
yield `function __VLS_template() {${common_1.newLine}`;
|
|
265
|
-
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx
|
|
233
|
+
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
266
234
|
yield `}${common_1.endOfLine}`;
|
|
267
235
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
268
236
|
yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${common_1.endOfLine}`;
|
|
@@ -281,6 +249,43 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
281
249
|
}
|
|
282
250
|
}
|
|
283
251
|
}
|
|
252
|
+
function* generateDefineWithType(scriptSetup, name, define, expression, defaultName, typeName) {
|
|
253
|
+
const { statement, typeArg } = define;
|
|
254
|
+
if (typeArg) {
|
|
255
|
+
yield [[
|
|
256
|
+
`type ${typeName} = `,
|
|
257
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, index_1.codeFeatures.all),
|
|
258
|
+
common_1.endOfLine,
|
|
259
|
+
], statement.start, statement.start];
|
|
260
|
+
yield [[typeName], typeArg.start, typeArg.end];
|
|
261
|
+
}
|
|
262
|
+
if (!name) {
|
|
263
|
+
if (statement.start === expression.start && statement.end === expression.end) {
|
|
264
|
+
yield [[`const ${defaultName} = `], expression.start, expression.start];
|
|
265
|
+
}
|
|
266
|
+
else if (typeArg) {
|
|
267
|
+
yield [[
|
|
268
|
+
`const ${defaultName} = `,
|
|
269
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, expression.start, typeArg.start, index_1.codeFeatures.all)
|
|
270
|
+
], statement.start, typeArg.start];
|
|
271
|
+
yield [[
|
|
272
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, typeArg.end, expression.end, index_1.codeFeatures.all),
|
|
273
|
+
common_1.endOfLine,
|
|
274
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, expression.start, index_1.codeFeatures.all),
|
|
275
|
+
defaultName
|
|
276
|
+
], typeArg.end, expression.end];
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
yield [[
|
|
280
|
+
`const ${defaultName} = `,
|
|
281
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, expression.start, expression.end, index_1.codeFeatures.all),
|
|
282
|
+
common_1.endOfLine,
|
|
283
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, expression.start, index_1.codeFeatures.all),
|
|
284
|
+
defaultName
|
|
285
|
+
], statement.start, expression.end];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
284
289
|
function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors) {
|
|
285
290
|
yield `const __VLS_fnComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
|
|
286
291
|
if (scriptSetupRanges.props.define?.arg) {
|
|
@@ -288,7 +293,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
288
293
|
yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, index_1.codeFeatures.navigation);
|
|
289
294
|
yield `,${common_1.newLine}`;
|
|
290
295
|
}
|
|
291
|
-
yield* (0, component_1.generateEmitsOption)(options,
|
|
296
|
+
yield* (0, component_1.generateEmitsOption)(options, scriptSetupRanges);
|
|
292
297
|
yield `})${common_1.endOfLine}`;
|
|
293
298
|
yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
|
|
294
299
|
? `import('${options.vueCompilerOptions.lib}').PublicProps;`
|
|
@@ -374,35 +379,25 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
374
379
|
yield ` & `;
|
|
375
380
|
}
|
|
376
381
|
ctx.generatedPropsType = true;
|
|
377
|
-
yield `
|
|
382
|
+
yield `__VLS_Props`;
|
|
378
383
|
}
|
|
379
384
|
if (!ctx.generatedPropsType) {
|
|
380
385
|
yield `{}`;
|
|
381
386
|
}
|
|
382
387
|
yield common_1.endOfLine;
|
|
383
388
|
}
|
|
384
|
-
function*
|
|
389
|
+
function* generateModelEmit(scriptSetup, scriptSetupRanges) {
|
|
385
390
|
const defineModels = scriptSetupRanges.defineProp.filter(p => p.isModel);
|
|
386
391
|
if (defineModels.length) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
if (options.vueCompilerOptions.target >= 3.5) {
|
|
396
|
-
yield `type __VLS_ModelEmitsType = {${common_1.newLine}`;
|
|
397
|
-
yield* generateDefineModels();
|
|
398
|
-
yield `}${common_1.endOfLine}`;
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
yield `const __VLS_modelEmitsType = (await import('${options.vueCompilerOptions.lib}')).defineEmits<{${common_1.newLine}`;
|
|
402
|
-
yield* generateDefineModels();
|
|
403
|
-
yield `}>()${common_1.endOfLine}`;
|
|
404
|
-
yield `type __VLS_ModelEmitsType = typeof __VLS_modelEmitsType${common_1.endOfLine}`;
|
|
392
|
+
yield `type __VLS_ModelEmit = {${common_1.newLine}`;
|
|
393
|
+
for (const defineModel of defineModels) {
|
|
394
|
+
const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
|
|
395
|
+
yield `'update:${propName}': [value:`;
|
|
396
|
+
yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
|
|
397
|
+
yield `]${common_1.endOfLine}`;
|
|
405
398
|
}
|
|
399
|
+
yield `}${common_1.endOfLine}`;
|
|
400
|
+
yield `const __VLS_modelEmit = defineEmits<__VLS_ModelEmit>()${common_1.endOfLine}`;
|
|
406
401
|
}
|
|
407
402
|
}
|
|
408
403
|
function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
|
|
@@ -5,13 +5,12 @@ const index_1 = require("./index");
|
|
|
5
5
|
const template_1 = require("./template");
|
|
6
6
|
const common_1 = require("../common");
|
|
7
7
|
function* generateStyleModulesType(options, ctx) {
|
|
8
|
-
const styles = options.sfc.styles.filter(style => style.module);
|
|
9
|
-
if (!styles.length) {
|
|
8
|
+
const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
|
|
9
|
+
if (!styles.length && !options.scriptSetupRanges?.cssModules.length) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
yield `type __VLS_StyleModules = {${common_1.newLine}`;
|
|
13
|
-
for (
|
|
14
|
-
const style = styles[i];
|
|
13
|
+
for (const [style, i] of styles) {
|
|
15
14
|
const { name, offset } = style.module;
|
|
16
15
|
if (offset) {
|
|
17
16
|
yield [
|
|
@@ -30,7 +29,6 @@ function* generateStyleModulesType(options, ctx) {
|
|
|
30
29
|
}
|
|
31
30
|
yield `>${common_1.endOfLine}`;
|
|
32
31
|
}
|
|
33
|
-
yield `}`;
|
|
34
|
-
yield common_1.endOfLine;
|
|
32
|
+
yield `}${common_1.endOfLine}`;
|
|
35
33
|
}
|
|
36
34
|
//# sourceMappingURL=styleModulesType.js.map
|