@vue/language-core 2.1.6-patch.1 → 2.1.8

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.
Files changed (43) hide show
  1. package/lib/codegen/globalTypes.js +9 -4
  2. package/lib/codegen/inlayHints.d.ts +11 -0
  3. package/lib/codegen/inlayHints.js +17 -0
  4. package/lib/codegen/script/component.d.ts +1 -1
  5. package/lib/codegen/script/component.js +5 -5
  6. package/lib/codegen/script/componentSelf.js +1 -1
  7. package/lib/codegen/script/context.d.ts +1 -1
  8. package/lib/codegen/script/index.d.ts +1 -0
  9. package/lib/codegen/script/index.js +23 -10
  10. package/lib/codegen/script/scriptSetup.js +103 -112
  11. package/lib/codegen/script/styleModulesType.js +3 -5
  12. package/lib/codegen/script/template.d.ts +1 -1
  13. package/lib/codegen/script/template.js +4 -9
  14. package/lib/codegen/template/context.d.ts +1 -1
  15. package/lib/codegen/template/element.d.ts +1 -1
  16. package/lib/codegen/template/element.js +19 -8
  17. package/lib/codegen/template/elementDirectives.js +63 -31
  18. package/lib/codegen/template/elementProps.js +6 -16
  19. package/lib/codegen/template/interpolation.js +0 -6
  20. package/lib/codegen/template/slotOutlet.js +5 -0
  21. package/lib/codegen/template/templateChild.d.ts +1 -1
  22. package/lib/codegen/template/templateChild.js +2 -2
  23. package/lib/codegen/template/vFor.js +1 -1
  24. package/lib/parsers/scriptSetupRanges.d.ts +12 -3
  25. package/lib/parsers/scriptSetupRanges.js +28 -25
  26. package/lib/plugins/vue-tsx.d.ts +23 -14
  27. package/lib/plugins/vue-tsx.js +35 -35
  28. package/lib/types.d.ts +3 -1
  29. package/lib/utils/parseCssClassNames.d.ts +1 -1
  30. package/lib/utils/parseCssClassNames.js +5 -4
  31. package/lib/utils/parseCssVars.d.ts +3 -2
  32. package/lib/utils/parseCssVars.js +12 -11
  33. package/lib/utils/ts.d.ts +1 -1
  34. package/lib/utils/ts.js +3 -5
  35. package/lib/virtualFile/computedEmbeddedCodes.d.ts +2 -1
  36. package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
  37. package/lib/virtualFile/computedSfc.d.ts +2 -1
  38. package/lib/virtualFile/computedSfc.js +77 -76
  39. package/lib/virtualFile/computedVueSfc.d.ts +2 -1
  40. package/lib/virtualFile/computedVueSfc.js +8 -8
  41. package/lib/virtualFile/vueFile.d.ts +6 -7
  42. package/lib/virtualFile/vueFile.js +13 -12
  43. package/package.json +10 -8
@@ -83,11 +83,14 @@ function generateGlobalTypes(lib, target, strictTemplates) {
83
83
  '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
84
84
  , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
85
85
  >>;
86
+ type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
86
87
 
87
88
  function __VLS_getVForSourceType(source: number): [number, number, number][];
88
89
  function __VLS_getVForSourceType(source: string): [string, number, number][];
89
90
  function __VLS_getVForSourceType<T extends any[]>(source: T): [
90
- item: T[number],
91
+ item: ${(target >= 3 ? `import('${lib}').Reactive<T[number]>` :
92
+ target >= 2.7 ? `import('${lib}').UnwrapNestedRefs<T[number]>` :
93
+ `T[number]`)},
91
94
  key: number,
92
95
  index: number,
93
96
  ][];
@@ -111,9 +114,11 @@ function generateGlobalTypes(lib, target, strictTemplates) {
111
114
  function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
112
115
  // @ts-ignore
113
116
  function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
114
- function __VLS_directiveAsFunction<T extends import('${lib}').Directive>(dir: T): T extends (...args: any) => any
115
- ? T | __VLS_unknownDirective
116
- : NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
117
+ function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
118
+ ? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
119
+ : T extends (...args: any) => any
120
+ ? T
121
+ : __VLS_unknownDirective;
117
122
  function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
118
123
  function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
119
124
  function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
@@ -0,0 +1,11 @@
1
+ import type * as CompilerDOM from '@vue/compiler-dom';
2
+ export interface InlayHintInfo {
3
+ blockName: string;
4
+ offset: number;
5
+ setting: string;
6
+ label: string;
7
+ tooltip?: string;
8
+ paddingRight?: boolean;
9
+ paddingLeft?: boolean;
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, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
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, scriptSetup, scriptSetupRanges)];
29
+ const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
30
30
  for (const code of emitOptionCodes) {
31
31
  yield code;
32
32
  }
@@ -56,12 +56,12 @@ function* generateComponentSetupReturns(scriptSetupRanges) {
56
56
  yield `$emit: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
57
57
  }
58
58
  }
59
- function* generateEmitsOption(options, scriptSetup, scriptSetupRanges) {
59
+ function* generateEmitsOption(options, scriptSetupRanges) {
60
60
  const codes = [];
61
61
  if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
62
62
  codes.push({
63
- optionExp: `{} as __VLS_NormalizeEmits<__VLS_ModelEmitsType>`,
64
- typeOptionType: `__VLS_ModelEmitsType`,
63
+ optionExp: `{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`,
64
+ typeOptionType: `__VLS_ModelEmit`,
65
65
  });
66
66
  }
67
67
  if (scriptSetupRanges.emits.define) {
@@ -69,7 +69,7 @@ function* generateEmitsOption(options, scriptSetup, scriptSetupRanges) {
69
69
  codes.push({
70
70
  optionExp: `{} as __VLS_NormalizeEmits<typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}>`,
71
71
  typeOptionType: typeArg && !hasUnionTypeArg
72
- ? scriptSetup.content.slice(typeArg.start, typeArg.end)
72
+ ? `__VLS_Emit`
73
73
  : undefined,
74
74
  });
75
75
  }
@@ -41,7 +41,7 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
41
41
  yield `}${common_1.endOfLine}`; // return {
42
42
  yield `},${common_1.newLine}`; // setup() {
43
43
  if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
44
- const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.sfc.scriptSetup, options.scriptSetupRanges)];
44
+ const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
45
45
  for (const code of emitOptionCodes) {
46
46
  yield code;
47
47
  }
@@ -1,4 +1,4 @@
1
- import { InlayHintInfo } from '../types';
1
+ import { InlayHintInfo } from '../inlayHints';
2
2
  import type { ScriptCodegenOptions } from './index';
3
3
  export interface HelperType {
4
4
  name: string;
@@ -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,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.codeFeatures = void 0;
4
4
  exports.generateScript = generateScript;
5
+ exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
5
6
  const common_1 = require("../common");
6
7
  const globalTypes_1 = require("../globalTypes");
7
- const context_1 = require("./context");
8
8
  const componentSelf_1 = require("./componentSelf");
9
+ const context_1 = require("./context");
9
10
  const scriptSetup_1 = require("./scriptSetup");
10
11
  const src_1 = require("./src");
11
12
  const styleModulesType_1 = require("./styleModulesType");
@@ -35,7 +36,13 @@ exports.codeFeatures = {
35
36
  function* generateScript(options) {
36
37
  const ctx = (0, context_1.createScriptCodegenContext)(options);
37
38
  if (options.vueCompilerOptions.__setupedGlobalTypes) {
38
- yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${common_1.newLine}`;
39
+ const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
40
+ if (typeof globalTypes === 'object') {
41
+ yield `/// <reference types="${globalTypes.absolutePath}" />${common_1.newLine}`;
42
+ }
43
+ else {
44
+ yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${common_1.newLine}`;
45
+ }
39
46
  }
40
47
  else {
41
48
  yield `/* placeholder */`;
@@ -57,6 +64,7 @@ function* generateScript(options) {
57
64
  }
58
65
  else {
59
66
  yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
67
+ yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
60
68
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
61
69
  }
62
70
  }
@@ -92,10 +100,10 @@ function* generateScript(options) {
92
100
  }
93
101
  else {
94
102
  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, true);
103
+ yield `__VLS_template = () => {${common_1.newLine}`;
104
+ const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
97
105
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
98
- yield `},${common_1.newLine}`;
106
+ yield `}${common_1.endOfLine}`;
99
107
  yield (0, common_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
100
108
  }
101
109
  }
@@ -108,15 +116,15 @@ function* generateScript(options) {
108
116
  yield* generateDefineProp(options, options.sfc.scriptSetup);
109
117
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
110
118
  }
111
- yield `;`;
119
+ if (options.sfc.script) {
120
+ yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
121
+ }
112
122
  if (options.sfc.scriptSetup) {
113
- // #4569
114
- yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, exports.codeFeatures.verification];
123
+ yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
115
124
  }
116
- yield common_1.newLine;
117
125
  if (!ctx.generatedTemplate) {
118
126
  yield `function __VLS_template() {${common_1.newLine}`;
119
- const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx, false);
127
+ const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
120
128
  yield `}${common_1.endOfLine}`;
121
129
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
122
130
  }
@@ -134,6 +142,11 @@ function* generateScript(options) {
134
142
  }
135
143
  return ctx;
136
144
  }
145
+ function* generateScriptSectionPartiallyEnding(source, end, mark) {
146
+ yield `;`;
147
+ yield ['', source, end, exports.codeFeatures.verification];
148
+ yield `/* PartiallyEnd: ${mark} */${common_1.newLine}`;
149
+ }
137
150
  function* generateDefineProp(options, scriptSetup) {
138
151
  const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
139
152
  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(`__VLS_ModelEmitsType`);
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
- const propsRange = scriptSetupRanges.props.withDefaults ?? scriptSetupRanges.props.define;
110
- if (propsRange && scriptSetupRanges.props.define) {
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 && !scriptSetupRanges.emits.name) {
162
- setupCodeModifies.push([[`const __VLS_emit = `], scriptSetupRanges.emits.define.start, scriptSetupRanges.emits.define.start]);
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,67 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
193
156
  }
194
157
  }
195
158
  if (scriptSetupRanges.cssModules.length) {
196
- for (const { exp, arg } of scriptSetupRanges.cssModules) {
197
- if (arg) {
198
- setupCodeModifies.push([
199
- [
200
- ` as Omit<__VLS_StyleModules, '$style'>[`,
201
- (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.all),
202
- `]`
203
- ],
204
- exp.end,
205
- exp.end
206
- ]);
207
- }
208
- else {
209
- setupCodeModifies.push([
210
- [
211
- ` as __VLS_StyleModules[`,
212
- ['', scriptSetup.name, exp.start, index_1.codeFeatures.verification],
213
- `'$style'`,
214
- ['', scriptSetup.name, exp.end, index_1.codeFeatures.verification],
215
- `]`
216
- ],
217
- exp.end,
218
- exp.end
219
- ]);
220
- }
159
+ for (const { define: { arg, exp } } of scriptSetupRanges.cssModules) {
160
+ setupCodeModifies.push([
161
+ arg ? [
162
+ ` as Omit<__VLS_StyleModules, '$style'>[`,
163
+ (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.all),
164
+ `]`
165
+ ] : [
166
+ ` as __VLS_StyleModules[`,
167
+ ['', scriptSetup.name, exp.start, index_1.codeFeatures.verification],
168
+ `'$style'`,
169
+ ['', scriptSetup.name, exp.end, index_1.codeFeatures.verification],
170
+ `]`
171
+ ],
172
+ exp.end,
173
+ exp.end
174
+ ]);
221
175
  }
222
176
  }
177
+ const isTs = options.lang !== 'js' && options.lang !== 'jsx';
223
178
  for (const { define } of scriptSetupRanges.templateRefs) {
224
- if (define?.arg) {
179
+ if (!define?.arg) {
180
+ continue;
181
+ }
182
+ if (isTs) {
225
183
  setupCodeModifies.push([
226
184
  [
227
185
  `<__VLS_TemplateResult['refs'][`,
228
186
  (0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
229
187
  `], keyof __VLS_TemplateResult['refs']>`
230
188
  ],
231
- define.arg.start - 1,
232
- define.arg.start - 1
189
+ define.exp.end,
190
+ define.exp.end
191
+ ]);
192
+ }
193
+ else {
194
+ setupCodeModifies.push([
195
+ [`(`],
196
+ define.start,
197
+ define.start
198
+ ], [
199
+ [
200
+ ` as __VLS_UseTemplateRef<__VLS_TemplateResult['refs'][`,
201
+ (0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
202
+ `]>)`
203
+ ],
204
+ define.end,
205
+ define.end
233
206
  ]);
234
207
  }
235
208
  }
236
209
  setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
237
- if (setupCodeModifies.length) {
238
- yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.importSectionEndOffset, setupCodeModifies[0][1], index_1.codeFeatures.all);
239
- while (setupCodeModifies.length) {
240
- const [codes, _start, end] = setupCodeModifies.shift();
241
- for (const code of codes) {
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
- }
210
+ let nextStart = scriptSetupRanges.importSectionEndOffset;
211
+ for (const [codes, start, end] of setupCodeModifies) {
212
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, nextStart, start, index_1.codeFeatures.all);
213
+ for (const code of codes) {
214
+ yield code;
251
215
  }
216
+ nextStart = end;
252
217
  }
253
- else {
254
- yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.importSectionEndOffset, scriptSetup.content.length, index_1.codeFeatures.all);
255
- }
218
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, index_1.codeFeatures.all);
219
+ yield* (0, index_1.generateScriptSectionPartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
256
220
  if (scriptSetupRanges.props.define?.typeArg && scriptSetupRanges.props.withDefaults?.arg) {
257
221
  // fix https://github.com/vuejs/language-tools/issues/1187
258
222
  yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
@@ -260,9 +224,9 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
260
224
  yield `)${common_1.endOfLine}`;
261
225
  }
262
226
  yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
263
- yield* generateModelEmits(options, scriptSetup, scriptSetupRanges);
227
+ yield* generateModelEmit(scriptSetup, scriptSetupRanges);
264
228
  yield `function __VLS_template() {${common_1.newLine}`;
265
- const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx, false);
229
+ const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
266
230
  yield `}${common_1.endOfLine}`;
267
231
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
268
232
  yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${common_1.endOfLine}`;
@@ -281,6 +245,43 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
281
245
  }
282
246
  }
283
247
  }
248
+ function* generateDefineWithType(scriptSetup, name, define, expression, defaultName, typeName) {
249
+ const { statement, typeArg } = define;
250
+ if (typeArg) {
251
+ yield [[
252
+ `type ${typeName} = `,
253
+ (0, common_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, index_1.codeFeatures.all),
254
+ common_1.endOfLine,
255
+ ], statement.start, statement.start];
256
+ yield [[typeName], typeArg.start, typeArg.end];
257
+ }
258
+ if (!name) {
259
+ if (statement.start === expression.start && statement.end === expression.end) {
260
+ yield [[`const ${defaultName} = `], expression.start, expression.start];
261
+ }
262
+ else if (typeArg) {
263
+ yield [[
264
+ `const ${defaultName} = `,
265
+ (0, common_1.generateSfcBlockSection)(scriptSetup, expression.start, typeArg.start, index_1.codeFeatures.all)
266
+ ], statement.start, typeArg.start];
267
+ yield [[
268
+ (0, common_1.generateSfcBlockSection)(scriptSetup, typeArg.end, expression.end, index_1.codeFeatures.all),
269
+ common_1.endOfLine,
270
+ (0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, expression.start, index_1.codeFeatures.all),
271
+ defaultName
272
+ ], typeArg.end, expression.end];
273
+ }
274
+ else {
275
+ yield [[
276
+ `const ${defaultName} = `,
277
+ (0, common_1.generateSfcBlockSection)(scriptSetup, expression.start, expression.end, index_1.codeFeatures.all),
278
+ common_1.endOfLine,
279
+ (0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, expression.start, index_1.codeFeatures.all),
280
+ defaultName
281
+ ], statement.start, expression.end];
282
+ }
283
+ }
284
+ }
284
285
  function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors) {
285
286
  yield `const __VLS_fnComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
286
287
  if (scriptSetupRanges.props.define?.arg) {
@@ -288,7 +289,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
288
289
  yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, index_1.codeFeatures.navigation);
289
290
  yield `,${common_1.newLine}`;
290
291
  }
291
- yield* (0, component_1.generateEmitsOption)(options, scriptSetup, scriptSetupRanges);
292
+ yield* (0, component_1.generateEmitsOption)(options, scriptSetupRanges);
292
293
  yield `})${common_1.endOfLine}`;
293
294
  yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
294
295
  ? `import('${options.vueCompilerOptions.lib}').PublicProps;`
@@ -374,35 +375,25 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
374
375
  yield ` & `;
375
376
  }
376
377
  ctx.generatedPropsType = true;
377
- yield `typeof __VLS_typeProps`;
378
+ yield `__VLS_Props`;
378
379
  }
379
380
  if (!ctx.generatedPropsType) {
380
381
  yield `{}`;
381
382
  }
382
383
  yield common_1.endOfLine;
383
384
  }
384
- function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
385
+ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
385
386
  const defineModels = scriptSetupRanges.defineProp.filter(p => p.isModel);
386
387
  if (defineModels.length) {
387
- const generateDefineModels = function* () {
388
- for (const defineModel of defineModels) {
389
- const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
390
- yield `'update:${propName}': [${propName}:`;
391
- yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
392
- yield `]${common_1.endOfLine}`;
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}`;
388
+ yield `type __VLS_ModelEmit = {${common_1.newLine}`;
389
+ for (const defineModel of defineModels) {
390
+ const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
391
+ yield `'update:${propName}': [value:`;
392
+ yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
393
+ yield `]${common_1.endOfLine}`;
405
394
  }
395
+ yield `}${common_1.endOfLine}`;
396
+ yield `const __VLS_modelEmit = defineEmits<__VLS_ModelEmit>()${common_1.endOfLine}`;
406
397
  }
407
398
  }
408
399
  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);
8
+ const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
9
9
  if (!styles.length) {
10
10
  return;
11
11
  }
12
12
  yield `type __VLS_StyleModules = {${common_1.newLine}`;
13
- for (let i = 0; i < styles.length; i++) {
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
@@ -3,6 +3,6 @@ import { TemplateCodegenContext } from '../template/context';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import { type ScriptCodegenOptions } from './index';
5
5
  export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
6
- export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, isClassComponent: boolean): Generator<Code, TemplateCodegenContext>;
6
+ export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code, TemplateCodegenContext>;
7
7
  export declare function generateCssClassProperty(styleIndex: number, classNameWithDot: string, offset: number, propertyType: string, optional: boolean): Generator<Code>;
8
8
  export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
@@ -10,14 +10,9 @@ const context_1 = require("../template/context");
10
10
  const interpolation_1 = require("../template/interpolation");
11
11
  const styleScopedClasses_1 = require("../template/styleScopedClasses");
12
12
  const index_1 = require("./index");
13
- function* generateTemplateCtx(options, isClassComponent) {
13
+ function* generateTemplateCtx(options) {
14
14
  const exps = [];
15
- if (isClassComponent) {
16
- exps.push(`this`);
17
- }
18
- else {
19
- exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);
20
- }
15
+ exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);
21
16
  if (options.vueCompilerOptions.petiteVueExtensions.some(ext => options.fileBaseName.endsWith(ext))) {
22
17
  exps.push(`globalThis`);
23
18
  }
@@ -99,13 +94,13 @@ function* generateTemplateDirectives(options) {
99
94
  yield `}${common_1.endOfLine}`;
100
95
  yield `let __VLS_directives!: typeof __VLS_localDirectives & __VLS_GlobalDirectives${common_1.endOfLine}`;
101
96
  }
102
- function* generateTemplate(options, ctx, isClassComponent) {
97
+ function* generateTemplate(options, ctx) {
103
98
  ctx.generatedTemplate = true;
104
99
  const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
105
100
  scriptSetupBindingNames: new Set(),
106
101
  edited: options.edited,
107
102
  });
108
- yield* generateTemplateCtx(options, isClassComponent);
103
+ yield* generateTemplateCtx(options);
109
104
  yield* generateTemplateComponents(options);
110
105
  yield* generateTemplateDirectives(options);
111
106
  yield* generateTemplateBody(options, templateCodegenCtx);
@@ -1,7 +1,7 @@
1
1
  import type * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code, VueCodeInformation } from '../../types';
3
3
  import type { TemplateCodegenOptions } from './index';
4
- import { InlayHintInfo } from '../types';
4
+ import { InlayHintInfo } from '../inlayHints';
5
5
  export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
6
6
  export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames' | 'edited'>): {
7
7
  slots: {
@@ -3,6 +3,6 @@ import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
5
  export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined): Generator<Code>;
6
- export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
6
+ export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined, isVForChild: boolean): Generator<Code>;
7
7
  export declare function getCanonicalComponentName(tagText: string): string;
8
8
  export declare function getPossibleOriginalComponentNames(tagText: string, deduplicate: boolean): string[];