@vue/language-core 2.0.14 → 2.0.15

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 (38) hide show
  1. package/lib/codegen/script/component.d.ts +1 -1
  2. package/lib/codegen/script/component.js +12 -4
  3. package/lib/codegen/script/globalTypes.js +1 -1
  4. package/lib/codegen/script/internalComponent.js +1 -1
  5. package/lib/codegen/script/scriptSetup.js +52 -19
  6. package/lib/codegen/script/template.js +5 -2
  7. package/lib/codegen/template/context.js +0 -1
  8. package/lib/codegen/template/element.d.ts +2 -1
  9. package/lib/codegen/template/element.js +101 -48
  10. package/lib/codegen/template/elementChildren.d.ts +2 -2
  11. package/lib/codegen/template/elementChildren.js +8 -3
  12. package/lib/codegen/template/elementEvents.d.ts +2 -0
  13. package/lib/codegen/template/elementEvents.js +47 -31
  14. package/lib/codegen/template/elementProps.js +33 -8
  15. package/lib/codegen/template/index.d.ts +10 -10
  16. package/lib/codegen/template/index.js +12 -99
  17. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  18. package/lib/codegen/template/slotOutlet.js +2 -2
  19. package/lib/codegen/template/templateChild.d.ts +1 -1
  20. package/lib/codegen/template/templateChild.js +14 -10
  21. package/lib/codegen/template/vFor.d.ts +1 -1
  22. package/lib/codegen/template/vFor.js +2 -2
  23. package/lib/codegen/template/vIf.d.ts +1 -1
  24. package/lib/codegen/template/vIf.js +2 -2
  25. package/lib/languageModule.d.ts +1 -2
  26. package/lib/languageModule.js +30 -12
  27. package/lib/parsers/scriptSetupRanges.d.ts +1 -0
  28. package/lib/parsers/scriptSetupRanges.js +6 -1
  29. package/lib/plugins/file-html.js +63 -66
  30. package/lib/plugins/file-md.js +47 -50
  31. package/lib/plugins/vue-tsx.d.ts +1 -0
  32. package/lib/plugins.d.ts +2 -1
  33. package/lib/plugins.js +18 -9
  34. package/lib/types.d.ts +2 -0
  35. package/lib/utils/ts.js +20 -3
  36. package/lib/virtualFile/computedFiles.d.ts +1 -0
  37. package/lib/virtualFile/computedFiles.js +19 -3
  38. package/package.json +3 -3
@@ -6,4 +6,4 @@ import { ScriptCodegenOptions } from './index';
6
6
  export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
7
7
  export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
8
8
  export declare function generateScriptOptions(script: NonNullable<Sfc['script']>, scriptRanges: ScriptRanges): Generator<Code>;
9
- export declare function generateScriptSetupOptions(ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
9
+ export declare function generateScriptSetupOptions(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
@@ -23,7 +23,7 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
23
23
  yield `}${common_1.endOfLine}`;
24
24
  yield `},${common_1.newLine}`;
25
25
  if (!ctx.bypassDefineComponent) {
26
- yield* generateScriptSetupOptions(ctx, scriptSetup, scriptSetupRanges);
26
+ yield* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRanges);
27
27
  }
28
28
  if (options.sfc.script && options.scriptRanges) {
29
29
  yield* generateScriptOptions(options.sfc.script, options.scriptRanges);
@@ -50,7 +50,7 @@ function* generateScriptOptions(script, scriptRanges) {
50
50
  }
51
51
  }
52
52
  exports.generateScriptOptions = generateScriptOptions;
53
- function* generateScriptSetupOptions(ctx, scriptSetup, scriptSetupRanges) {
53
+ function* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRanges) {
54
54
  const propsCodegens = [];
55
55
  if (ctx.generatedPropsType) {
56
56
  propsCodegens.push(function* () {
@@ -59,8 +59,7 @@ function* generateScriptSetupOptions(ctx, scriptSetup, scriptSetupRanges) {
59
59
  yield `${ctx.helperTypes.WithDefaults.name}<`;
60
60
  }
61
61
  yield `${ctx.helperTypes.TypePropsToOption.name}<`;
62
- yield `typeof __VLS_componentProps`;
63
- yield `>`;
62
+ yield `__VLS_PublicProps>`;
64
63
  if (scriptSetupRanges.props.withDefaults?.arg) {
65
64
  yield `, typeof __VLS_withDefaultsArg>`;
66
65
  }
@@ -96,6 +95,15 @@ function* generateScriptSetupOptions(ctx, scriptSetup, scriptSetupRanges) {
96
95
  }
97
96
  yield `>),${common_1.newLine}`;
98
97
  }
98
+ if (options.vueCompilerOptions.target >= 3.5) {
99
+ // https://github.com/vuejs/core/pull/10801
100
+ if (scriptSetupRanges.props.define?.typeArg) {
101
+ yield `__typeProps: typeof __VLS_typeProps,${common_1.newLine}`;
102
+ }
103
+ if (scriptSetupRanges.emits.define?.typeArg) {
104
+ yield `__typeEmits: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
105
+ }
106
+ }
99
107
  }
100
108
  exports.generateScriptSetupOptions = generateScriptSetupOptions;
101
109
  //# sourceMappingURL=component.js.map
@@ -80,7 +80,7 @@ declare global {
80
80
  : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
81
81
  : T extends (...args: any) => any ? T
82
82
  : (_: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
83
- function __VLS_elementAsFunctionalComponent<T>(t: T): (_: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
83
+ function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
84
84
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
85
85
  function __VLS_pickEvent<E1, E2>(emitEvent: E1, propEvent: E2): __VLS_FillingEventArg<
86
86
  __VLS_PickNotAny<
@@ -40,7 +40,7 @@ function* generateInternalComponent(options, ctx, templateCodegenCtx) {
40
40
  yield `}${common_1.endOfLine}`; // return {
41
41
  yield `},${common_1.newLine}`; // setup() {
42
42
  if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
43
- yield* (0, component_1.generateScriptSetupOptions)(ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
43
+ yield* (0, component_1.generateScriptSetupOptions)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
44
44
  }
45
45
  if (options.sfc.script && options.scriptRanges) {
46
46
  yield* (0, component_1.generateScriptOptions)(options.sfc.script, options.scriptRanges);
@@ -37,7 +37,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
37
37
  + ` __VLS_setup = (async () => {${common_1.newLine}`;
38
38
  yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined, definePropMirrors);
39
39
  yield ` return {} as {${common_1.newLine}`
40
- + ` props: ${ctx.helperTypes.Prettify.name}<typeof __VLS_functionalComponentProps & typeof __VLS_componentProps> & typeof __VLS_publicProps,${common_1.newLine}`
40
+ + ` props: ${ctx.helperTypes.Prettify.name}<typeof __VLS_functionalComponentProps & __VLS_PublicProps> & __VLS_BuiltInPublicProps,${common_1.newLine}`
41
41
  + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${common_1.newLine}`
42
42
  + ` attrs: any,${common_1.newLine}`
43
43
  + ` slots: ReturnType<typeof __VLS_template>,${common_1.newLine}`
@@ -101,24 +101,57 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
101
101
  }
102
102
  ctx.scriptSetupGeneratedOffset = options.getGeneratedLength() - scriptSetupRanges.importSectionEndOffset;
103
103
  let setupCodeModifies = [];
104
- if (scriptSetupRanges.props.define && !scriptSetupRanges.props.name) {
105
- const range = scriptSetupRanges.props.withDefaults ?? scriptSetupRanges.props.define;
104
+ const propsRange = scriptSetupRanges.props.withDefaults ?? scriptSetupRanges.props.define;
105
+ if (propsRange && scriptSetupRanges.props.define) {
106
106
  const statement = scriptSetupRanges.props.define.statement;
107
- if (statement.start === range.start && statement.end === range.end) {
108
- setupCodeModifies.push([[`const __VLS_props = `], range.start, range.start]);
109
- }
110
- else {
107
+ if (scriptSetupRanges.props.define.typeArg) {
111
108
  setupCodeModifies.push([[
112
- `const __VLS_props = `,
113
- (0, common_1.generateSfcBlockSection)(scriptSetup, range.start, range.end, index_1.codeFeatures.all),
114
- `${common_1.endOfLine}`,
115
- (0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, range.start, index_1.codeFeatures.all),
116
- `__VLS_props`,
117
- ], statement.start, range.end]);
109
+ `let __VLS_typeProps!: `,
110
+ (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end, index_1.codeFeatures.all),
111
+ common_1.endOfLine,
112
+ ], statement.start, statement.start]);
113
+ setupCodeModifies.push([[`typeof __VLS_typeProps`], scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end]);
114
+ }
115
+ if (!scriptSetupRanges.props.name) {
116
+ if (statement.start === propsRange.start && statement.end === propsRange.end) {
117
+ setupCodeModifies.push([[`const __VLS_props = `], propsRange.start, propsRange.start]);
118
+ }
119
+ else {
120
+ if (scriptSetupRanges.props.define.typeArg) {
121
+ setupCodeModifies.push([[
122
+ `const __VLS_props = `,
123
+ (0, common_1.generateSfcBlockSection)(scriptSetup, propsRange.start, scriptSetupRanges.props.define.typeArg.start, index_1.codeFeatures.all),
124
+ ], statement.start, scriptSetupRanges.props.define.typeArg.start]);
125
+ setupCodeModifies.push([[
126
+ (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.typeArg.end, propsRange.end, index_1.codeFeatures.all),
127
+ `${common_1.endOfLine}`,
128
+ (0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, propsRange.start, index_1.codeFeatures.all),
129
+ `__VLS_props`,
130
+ ], scriptSetupRanges.props.define.typeArg.end, propsRange.end]);
131
+ }
132
+ else {
133
+ setupCodeModifies.push([[
134
+ `const __VLS_props = `,
135
+ (0, common_1.generateSfcBlockSection)(scriptSetup, propsRange.start, propsRange.end, index_1.codeFeatures.all),
136
+ `${common_1.endOfLine}`,
137
+ (0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, propsRange.start, index_1.codeFeatures.all),
138
+ `__VLS_props`,
139
+ ], statement.start, propsRange.end]);
140
+ }
141
+ }
118
142
  }
119
143
  }
120
- if (scriptSetupRanges.slots.define && !scriptSetupRanges.slots.name) {
121
- setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
144
+ if (scriptSetupRanges.slots.define) {
145
+ if (!scriptSetupRanges.slots.name) {
146
+ setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
147
+ }
148
+ else if (scriptSetupRanges.slots.isObjectBindingPattern) {
149
+ setupCodeModifies.push([
150
+ [`__VLS_slots;\nconst __VLS_slots = `],
151
+ scriptSetupRanges.slots.define.start,
152
+ scriptSetupRanges.slots.define.start,
153
+ ]);
154
+ }
122
155
  }
123
156
  if (scriptSetupRanges.emits.define && !scriptSetupRanges.emits.name) {
124
157
  setupCodeModifies.push([[`const __VLS_emit = `], scriptSetupRanges.emits.define.start, scriptSetupRanges.emits.define.start]);
@@ -214,13 +247,13 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
214
247
  }
215
248
  yield `})${common_1.endOfLine}`;
216
249
  yield `let __VLS_functionalComponentProps!: `;
217
- yield `${ctx.helperTypes.OmitKeepDiscriminatedUnion.name}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof typeof __VLS_publicProps>`;
250
+ yield `${ctx.helperTypes.OmitKeepDiscriminatedUnion.name}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
218
251
  yield common_1.endOfLine;
219
252
  }
220
253
  else {
221
254
  yield `let __VLS_functionalComponentProps!: {}${common_1.endOfLine}`;
222
255
  }
223
- yield `let __VLS_publicProps!:${common_1.newLine}`
256
+ yield `type __VLS_BuiltInPublicProps =${common_1.newLine}`
224
257
  + ` import('${options.vueCompilerOptions.lib}').VNodeProps${common_1.newLine}`
225
258
  + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps${common_1.newLine}`
226
259
  + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps${common_1.endOfLine}`;
@@ -241,7 +274,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
241
274
  }
242
275
  yield `}${common_1.endOfLine}`;
243
276
  }
244
- yield `let __VLS_componentProps!: `;
277
+ yield `type __VLS_PublicProps = `;
245
278
  if (scriptSetupRanges.slots.define && options.vueCompilerOptions.jsxSlots) {
246
279
  if (ctx.generatedPropsType) {
247
280
  yield ` & `;
@@ -302,7 +335,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
302
335
  yield ` & `;
303
336
  }
304
337
  ctx.generatedPropsType = true;
305
- yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end, index_1.codeFeatures.all);
338
+ yield `typeof __VLS_typeProps`;
306
339
  }
307
340
  if (!ctx.generatedPropsType) {
308
341
  yield `{}`;
@@ -97,9 +97,7 @@ function* generateTemplateContext(options, ctx, templateCodegenCtx) {
97
97
  }
98
98
  yield common_1.endOfLine;
99
99
  yield `let __VLS_styleScopedClasses!: __VLS_StyleScopedClasses | keyof __VLS_StyleScopedClasses | (keyof __VLS_StyleScopedClasses)[]${common_1.endOfLine}`;
100
- yield `/* CSS variable injection */${common_1.newLine}`;
101
100
  yield* generateCssVars(options, templateCodegenCtx);
102
- yield `/* CSS variable injection end */${common_1.newLine}`;
103
101
  if (options.templateCodegen) {
104
102
  for (const code of options.templateCodegen.tsCodes) {
105
103
  yield code;
@@ -147,6 +145,10 @@ function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propert
147
145
  yield ` }`;
148
146
  }
149
147
  function* generateCssVars(options, ctx) {
148
+ if (!options.sfc.styles.length) {
149
+ return;
150
+ }
151
+ yield `// CSS variable injection ${common_1.newLine}`;
150
152
  for (const style of options.sfc.styles) {
151
153
  for (const cssBind of style.cssVars) {
152
154
  for (const [segment, offset, onlyError] of (0, interpolation_1.forEachInterpolationSegment)(options.ts, options.vueCompilerOptions, ctx, cssBind.text, cssBind.offset, options.ts.createSourceFile('/a.txt', cssBind.text, 99))) {
@@ -167,6 +169,7 @@ function* generateCssVars(options, ctx) {
167
169
  yield common_1.endOfLine;
168
170
  }
169
171
  }
172
+ yield `// CSS variable injection end ${common_1.newLine}`;
170
173
  }
171
174
  function getTemplateUsageVars(options, ctx) {
172
175
  const usageVars = new Set();
@@ -146,7 +146,6 @@ function createTemplateCodegenContext() {
146
146
  generateAutoImportCompletion: function* () {
147
147
  const all = [...accessGlobalVariables.entries()];
148
148
  if (!all.some(([_, offsets]) => offsets.size)) {
149
- yield `// no auto imports${common_1.endOfLine}`;
150
149
  return;
151
150
  }
152
151
  yield `// @ts-ignore${common_1.newLine}`; // #2304
@@ -2,6 +2,7 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentElement: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
5
+ export declare function generateComponent(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): Generator<Code>;
6
7
  export declare function getCanonicalComponentName(tagText: string): string;
7
8
  export declare function getPossibleOriginalComponentNames(tagText: string, deduplicate: boolean): string[];
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPossibleOriginalComponentNames = exports.getCanonicalComponentName = exports.generateElement = void 0;
3
+ exports.getPossibleOriginalComponentNames = exports.getCanonicalComponentName = exports.generateElement = exports.generateComponent = void 0;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
5
  const shared_1 = require("@vue/shared");
6
+ const shared_2 = require("../../utils/shared");
6
7
  const common_1 = require("../common");
7
8
  const camelized_1 = require("./camelized");
8
9
  const elementChildren_1 = require("./elementChildren");
@@ -11,18 +12,15 @@ const elementEvents_1 = require("./elementEvents");
11
12
  const elementProps_1 = require("./elementProps");
12
13
  const interpolation_1 = require("./interpolation");
13
14
  const propertyAccess_1 = require("./propertyAccess");
14
- const stringLiteralKey_1 = require("./stringLiteralKey");
15
15
  const templateChild_1 = require("./templateChild");
16
16
  const colonReg = /:/g;
17
- function* generateElement(options, ctx, node, currentElement, componentCtxVar) {
17
+ function* generateComponent(options, ctx, node, currentComponent, componentCtxVar) {
18
18
  const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
19
19
  const propsFailedExps = [];
20
20
  const var_originalComponent = ctx.getInternalVariable();
21
21
  const var_functionalComponent = ctx.getInternalVariable();
22
22
  const var_componentInstance = ctx.getInternalVariable();
23
23
  const var_componentEvents = ctx.getInternalVariable();
24
- const isIntrinsicElement = node.tagType === CompilerDOM.ElementTypes.ELEMENT
25
- || node.tagType === CompilerDOM.ElementTypes.TEMPLATE;
26
24
  const isComponentTag = node.tag.toLowerCase() === 'component';
27
25
  let endTagOffset = !node.isSelfClosing && options.template.lang === 'html' ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag) : undefined;
28
26
  let tag = node.tag;
@@ -54,12 +52,7 @@ function* generateElement(options, ctx, node, currentElement, componentCtxVar) {
54
52
  offset: startTagOffset,
55
53
  };
56
54
  }
57
- if (isIntrinsicElement) {
58
- yield `const ${var_originalComponent} = __VLS_intrinsicElements[`;
59
- yield* (0, stringLiteralKey_1.generateStringLiteralKey)(tag, startTagOffset, ctx.codeFeatures.verification);
60
- yield `]${common_1.endOfLine}`;
61
- }
62
- else if (dynamicTagInfo) {
55
+ if (dynamicTagInfo) {
63
56
  yield `const ${var_originalComponent} = `;
64
57
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.exp, dynamicTagInfo.astHolder, dynamicTagInfo.offset, ctx.codeFeatures.all, '(', ')');
65
58
  yield common_1.endOfLine;
@@ -78,22 +71,48 @@ function* generateElement(options, ctx, node, currentElement, componentCtxVar) {
78
71
  else {
79
72
  yield `const ${var_originalComponent} = {} as any${common_1.endOfLine}`;
80
73
  }
81
- if (isIntrinsicElement) {
82
- yield `const ${var_functionalComponent} = __VLS_elementAsFunctionalComponent(${var_originalComponent})${common_1.endOfLine}`;
83
- }
84
- else {
85
- yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
86
- yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
87
- yield `}))${common_1.endOfLine}`;
88
- }
74
+ yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
75
+ yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
76
+ yield `}))${common_1.endOfLine}`;
89
77
  if (!dynamicTagInfo
90
- && !isIntrinsicElement
91
78
  && !isComponentTag) {
79
+ // hover support
92
80
  for (const offset of tagOffsets) {
93
81
  yield `({} as { ${getCanonicalComponentName(tag)}: typeof ${var_originalComponent} }).`;
94
82
  yield* generateCanonicalComponentName(tag, offset, ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation);
95
83
  yield common_1.endOfLine;
96
84
  }
85
+ const camelizedTag = (0, shared_1.camelize)(node.tag);
86
+ if (common_1.variableNameRegex.test(camelizedTag)) {
87
+ // renaming / find references support
88
+ for (const tagOffset of tagOffsets) {
89
+ for (const shouldCapitalize of (node.tag[0] === node.tag[0].toUpperCase() ? [false] : [true, false])) {
90
+ const expectName = shouldCapitalize ? (0, shared_1.capitalize)(camelizedTag) : camelizedTag;
91
+ yield `__VLS_components.`;
92
+ yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, tagOffset, {
93
+ navigation: {
94
+ resolveRenameNewName: node.tag !== expectName ? camelizeComponentName : undefined,
95
+ resolveRenameEditText: getTagRenameApply(node.tag),
96
+ },
97
+ });
98
+ yield `;`;
99
+ }
100
+ }
101
+ yield `${common_1.newLine}`;
102
+ // auto import support
103
+ yield `// @ts-ignore${common_1.newLine}`; // #2304
104
+ yield `[`;
105
+ for (const tagOffset of tagOffsets) {
106
+ yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), tagOffset, {
107
+ completion: {
108
+ isAdditional: true,
109
+ onlyImport: true,
110
+ },
111
+ });
112
+ yield `,`;
113
+ }
114
+ yield `]${common_1.endOfLine}`;
115
+ }
97
116
  }
98
117
  if (options.vueCompilerOptions.strictTemplates) {
99
118
  // with strictTemplates, generate once for props type-checking + instance type
@@ -111,16 +130,63 @@ function* generateElement(options, ctx, node, currentElement, componentCtxVar) {
111
130
  yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, true, propsFailedExps), `}`);
112
131
  yield `)${common_1.endOfLine}`;
113
132
  }
114
- if (node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
115
- defineComponentCtxVar = ctx.getInternalVariable();
116
- componentCtxVar = defineComponentCtxVar;
117
- currentElement = node;
133
+ defineComponentCtxVar = ctx.getInternalVariable();
134
+ componentCtxVar = defineComponentCtxVar;
135
+ currentComponent = node;
136
+ for (const failedExp of propsFailedExps) {
137
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
138
+ yield common_1.endOfLine;
139
+ }
140
+ yield* generateVScope(options, ctx, node, props);
141
+ if (componentCtxVar) {
142
+ ctx.usedComponentCtxVars.add(componentCtxVar);
143
+ yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEvents, () => usedComponentEventsVar = true);
144
+ }
145
+ const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
146
+ if (slotDir && componentCtxVar) {
147
+ yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
148
+ }
149
+ else {
150
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
151
+ }
152
+ if (defineComponentCtxVar && ctx.usedComponentCtxVars.has(defineComponentCtxVar)) {
153
+ yield `const ${componentCtxVar} = __VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance})!${common_1.endOfLine}`;
118
154
  }
119
- //#region fix #1775
155
+ if (usedComponentEventsVar) {
156
+ yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${componentCtxVar}.emit>${common_1.endOfLine}`;
157
+ }
158
+ }
159
+ exports.generateComponent = generateComponent;
160
+ function* generateElement(options, ctx, node, currentComponent, componentCtxVar) {
161
+ const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
162
+ const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
163
+ ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
164
+ : undefined;
165
+ const propsFailedExps = [];
166
+ yield `__VLS_elementAsFunction(__VLS_intrinsicElements`;
167
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
168
+ if (endTagOffset !== undefined) {
169
+ yield `, __VLS_intrinsicElements`;
170
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
171
+ }
172
+ yield `)(`;
173
+ yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, true, propsFailedExps), `}`);
174
+ yield `)${common_1.endOfLine}`;
120
175
  for (const failedExp of propsFailedExps) {
121
176
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
122
177
  yield common_1.endOfLine;
123
178
  }
179
+ yield* generateVScope(options, ctx, node, node.props);
180
+ const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
181
+ if (slotDir && componentCtxVar) {
182
+ yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
183
+ }
184
+ else {
185
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
186
+ }
187
+ }
188
+ exports.generateElement = generateElement;
189
+ function* generateVScope(options, ctx, node, props) {
124
190
  const vScope = props.find(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && (prop.name === 'scope' || prop.name === 'data'));
125
191
  let inScope = false;
126
192
  let originalConditionsNum = ctx.blockConditions.length;
@@ -144,30 +210,11 @@ function* generateElement(options, ctx, node, currentElement, componentCtxVar) {
144
210
  if (options.shouldGenerateScopedClasses) {
145
211
  yield* generateReferencesForScopedCssClasses(ctx, node);
146
212
  }
147
- if (componentCtxVar) {
148
- ctx.usedComponentCtxVars.add(componentCtxVar);
149
- yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEvents, () => usedComponentEventsVar = true);
150
- }
151
213
  if (inScope) {
152
214
  yield `}${common_1.newLine}`;
153
215
  ctx.blockConditions.length = originalConditionsNum;
154
216
  }
155
- //#endregion
156
- const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
157
- if (slotDir && componentCtxVar) {
158
- yield* generateComponentSlot(options, ctx, node, slotDir, currentElement, componentCtxVar);
159
- }
160
- else {
161
- yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentElement, componentCtxVar);
162
- }
163
- if (defineComponentCtxVar && ctx.usedComponentCtxVars.has(defineComponentCtxVar)) {
164
- yield `const ${componentCtxVar} = __VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance})!${common_1.endOfLine}`;
165
- }
166
- if (usedComponentEventsVar) {
167
- yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${componentCtxVar}.emit>${common_1.endOfLine}`;
168
- }
169
217
  }
170
- exports.generateElement = generateElement;
171
218
  function getCanonicalComponentName(tagText) {
172
219
  return common_1.variableNameRegex.test(tagText)
173
220
  ? tagText
@@ -196,11 +243,11 @@ function* generateCanonicalComponentName(tagText, offset, features) {
196
243
  yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), offset, features);
197
244
  }
198
245
  }
199
- function* generateComponentSlot(options, ctx, node, slotDir, currentElement, componentCtxVar) {
246
+ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar) {
200
247
  yield `{${common_1.newLine}`;
201
248
  ctx.usedComponentCtxVars.add(componentCtxVar);
202
- if (currentElement) {
203
- ctx.hasSlotElements.add(currentElement);
249
+ if (currentComponent) {
250
+ ctx.hasSlotElements.add(currentComponent);
204
251
  }
205
252
  const slotBlockVars = [];
206
253
  let hasProps = false;
@@ -249,7 +296,7 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentElement, com
249
296
  yield* ctx.resetDirectiveComments('end of slot children start');
250
297
  let prev;
251
298
  for (const childNode of node.children) {
252
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentElement, prev, componentCtxVar);
299
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
253
300
  prev = childNode;
254
301
  }
255
302
  for (const varName of slotBlockVars) {
@@ -322,4 +369,10 @@ function* generateReferencesForScopedCssClasses(ctx, node) {
322
369
  }
323
370
  }
324
371
  }
372
+ function camelizeComponentName(newName) {
373
+ return (0, shared_1.camelize)('-' + newName);
374
+ }
375
+ function getTagRenameApply(oldName) {
376
+ return oldName === (0, shared_2.hyphenateTag)(oldName) ? shared_2.hyphenateTag : undefined;
377
+ }
325
378
  //# sourceMappingURL=element.js.map
@@ -1,5 +1,5 @@
1
- import type * as CompilerDOM from '@vue/compiler-dom';
1
+ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentElement: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
5
+ export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
@@ -1,17 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateElementChildren = void 0;
4
+ const CompilerDOM = require("@vue/compiler-dom");
4
5
  const common_1 = require("../common");
5
6
  const templateChild_1 = require("./templateChild");
6
- function* generateElementChildren(options, ctx, node, currentElement, componentCtxVar) {
7
+ function* generateElementChildren(options, ctx, node, currentComponent, componentCtxVar) {
7
8
  yield* ctx.resetDirectiveComments('end of element children start');
8
9
  let prev;
9
10
  for (const childNode of node.children) {
10
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentElement, prev, componentCtxVar);
11
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
11
12
  prev = childNode;
12
13
  }
14
+ yield* ctx.generateAutoImportCompletion();
13
15
  // fix https://github.com/vuejs/language-tools/issues/932
14
- if (!ctx.hasSlotElements.has(node) && node.children.length) {
16
+ if (!ctx.hasSlotElements.has(node)
17
+ && node.children.length
18
+ && node.tagType !== CompilerDOM.ElementTypes.ELEMENT
19
+ && node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
15
20
  yield `(${componentCtxVar}.slots!).`;
16
21
  yield* (0, common_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
17
22
  yield common_1.endOfLine;
@@ -4,4 +4,6 @@ import type { Code } from '../../types';
4
4
  import type { TemplateCodegenContext } from './context';
5
5
  import type { TemplateCodegenOptions } from './index';
6
6
  export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentVar: string, componentInstanceVar: string, eventsVar: string, used: () => void): Generator<Code>;
7
+ export declare function generateEventArg(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, arg: CompilerDOM.SimpleExpressionNode, access: boolean): Generator<Code>;
8
+ export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
7
9
  export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCompoundExpression = exports.generateElementEvents = void 0;
3
+ exports.isCompoundExpression = exports.generateEventExpression = exports.generateEventArg = exports.generateElementEvents = void 0;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
5
  const shared_1 = require("@vue/shared");
6
6
  const shared_2 = require("../../utils/shared");
@@ -18,33 +18,7 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
18
18
  yield `let ${eventVar} = { '${prop.arg.loc.source}': __VLS_pickEvent(`;
19
19
  yield `${eventsVar}['${prop.arg.loc.source}'], `;
20
20
  yield `({} as __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>)`;
21
- const startMappingFeatures = {
22
- navigation: {
23
- // @click-outside -> onClickOutside
24
- resolveRenameNewName(newName) {
25
- return (0, shared_1.camelize)('on-' + newName);
26
- },
27
- // onClickOutside -> @click-outside
28
- resolveRenameEditText(newName) {
29
- const hName = (0, shared_2.hyphenateAttr)(newName);
30
- if ((0, shared_2.hyphenateAttr)(newName).startsWith('on-')) {
31
- return (0, shared_1.camelize)(hName.slice('on-'.length));
32
- }
33
- return newName;
34
- },
35
- },
36
- };
37
- if (common_1.variableNameRegex.test((0, shared_1.camelize)(prop.arg.loc.source))) {
38
- yield `.`;
39
- yield ['', 'template', prop.arg.loc.start.offset, startMappingFeatures];
40
- yield `on`;
41
- yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(prop.arg.loc.source), prop.arg.loc.start.offset, common_1.combineLastMapping);
42
- }
43
- else {
44
- yield `[`;
45
- yield* (0, common_1.wrapWith)(prop.arg.loc.start.offset, prop.arg.loc.end.offset, startMappingFeatures, `'`, ['', 'template', prop.arg.loc.start.offset, common_1.combineLastMapping], 'on', ...(0, camelized_1.generateCamelized)((0, shared_1.capitalize)(prop.arg.loc.source), prop.arg.loc.start.offset, common_1.combineLastMapping), `'`);
46
- yield `]`;
47
- }
21
+ yield* generateEventArg(options, ctx, prop.arg, true);
48
22
  yield `) }${common_1.endOfLine}`;
49
23
  yield `${eventVar} = { `;
50
24
  if (prop.arg.loc.source.startsWith('[') && prop.arg.loc.source.endsWith(']')) {
@@ -56,7 +30,7 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
56
30
  yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, prop.arg.loc.source, prop.arg.loc.start.offset, ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation, prop.arg.loc);
57
31
  }
58
32
  yield `: `;
59
- yield* appendExpressionNode(options, ctx, prop);
33
+ yield* generateEventExpression(options, ctx, prop);
60
34
  yield ` }${common_1.endOfLine}`;
61
35
  }
62
36
  else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -70,7 +44,48 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
70
44
  }
71
45
  }
72
46
  exports.generateElementEvents = generateElementEvents;
73
- function* appendExpressionNode(options, ctx, prop) {
47
+ const eventArgFeatures = {
48
+ navigation: {
49
+ // @click-outside -> onClickOutside
50
+ resolveRenameNewName(newName) {
51
+ return (0, shared_1.camelize)('on-' + newName);
52
+ },
53
+ // onClickOutside -> @click-outside
54
+ resolveRenameEditText(newName) {
55
+ const hName = (0, shared_2.hyphenateAttr)(newName);
56
+ if ((0, shared_2.hyphenateAttr)(newName).startsWith('on-')) {
57
+ return (0, shared_1.camelize)(hName.slice('on-'.length));
58
+ }
59
+ return newName;
60
+ },
61
+ },
62
+ };
63
+ function* generateEventArg(options, ctx, arg, access) {
64
+ if (arg.loc.source.startsWith('[') && arg.loc.source.endsWith(']')) {
65
+ yield `[`;
66
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, arg.loc.source.slice(1, -1), arg.loc, arg.loc.start.offset + 1, ctx.codeFeatures.all, '', '');
67
+ yield `]`;
68
+ }
69
+ else if (common_1.variableNameRegex.test((0, shared_1.camelize)(arg.loc.source))) {
70
+ if (access) {
71
+ yield `.`;
72
+ }
73
+ yield ['', 'template', arg.loc.start.offset, eventArgFeatures];
74
+ yield `on`;
75
+ yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping);
76
+ }
77
+ else {
78
+ if (access) {
79
+ yield `[`;
80
+ }
81
+ yield* (0, common_1.wrapWith)(arg.loc.start.offset, arg.loc.end.offset, eventArgFeatures, `'`, ['', 'template', arg.loc.start.offset, common_1.combineLastMapping], 'on', ...(0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping), `'`);
82
+ if (access) {
83
+ yield `]`;
84
+ }
85
+ }
86
+ }
87
+ exports.generateEventArg = generateEventArg;
88
+ function* generateEventExpression(options, ctx, prop) {
74
89
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
75
90
  let prefix = '(';
76
91
  let suffix = ')';
@@ -109,13 +124,14 @@ function* appendExpressionNode(options, ctx, prop) {
109
124
  ctx.removeLocalVariable('$event');
110
125
  yield common_1.endOfLine;
111
126
  yield* ctx.generateAutoImportCompletion();
112
- yield `}${common_1.newLine}`;
127
+ yield `}`;
113
128
  }
114
129
  }
115
130
  else {
116
131
  yield `() => {}`;
117
132
  }
118
133
  }
134
+ exports.generateEventExpression = generateEventExpression;
119
135
  function isCompoundExpression(ts, ast) {
120
136
  let result = true;
121
137
  if (ast.statements.length === 1) {