@vue/language-core 2.2.2 → 2.2.4

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 (72) hide show
  1. package/lib/codegen/globalTypes.js +20 -28
  2. package/lib/codegen/script/component.js +10 -6
  3. package/lib/codegen/script/index.js +4 -6
  4. package/lib/codegen/script/scriptSetup.js +45 -34
  5. package/lib/codegen/script/src.d.ts +2 -2
  6. package/lib/codegen/script/src.js +36 -37
  7. package/lib/codegen/script/template.d.ts +1 -2
  8. package/lib/codegen/script/template.js +4 -50
  9. package/lib/codegen/style/classProperty.d.ts +2 -0
  10. package/lib/codegen/style/classProperty.js +31 -0
  11. package/lib/codegen/style/modules.d.ts +3 -0
  12. package/lib/codegen/{script/styleModulesType.js → style/modules.js} +14 -14
  13. package/lib/codegen/style/scopedClasses.d.ts +4 -0
  14. package/lib/codegen/style/scopedClasses.js +32 -0
  15. package/lib/codegen/template/context.d.ts +106 -5
  16. package/lib/codegen/template/context.js +129 -5
  17. package/lib/codegen/template/element.d.ts +1 -1
  18. package/lib/codegen/template/element.js +61 -85
  19. package/lib/codegen/template/elementChildren.d.ts +1 -1
  20. package/lib/codegen/template/elementChildren.js +1 -13
  21. package/lib/codegen/template/elementDirectives.js +2 -1
  22. package/lib/codegen/template/elementEvents.d.ts +1 -1
  23. package/lib/codegen/template/elementEvents.js +15 -11
  24. package/lib/codegen/template/elementProps.d.ts +1 -1
  25. package/lib/codegen/template/elementProps.js +11 -9
  26. package/lib/codegen/template/index.js +27 -13
  27. package/lib/codegen/template/interpolation.js +5 -5
  28. package/lib/codegen/template/slotOutlet.js +11 -10
  29. package/lib/codegen/template/styleScopedClasses.js +5 -9
  30. package/lib/codegen/template/templateChild.js +60 -28
  31. package/lib/codegen/template/vFor.js +2 -2
  32. package/lib/codegen/template/vIf.js +3 -3
  33. package/lib/codegen/template/vSlot.d.ts +1 -0
  34. package/lib/codegen/template/vSlot.js +12 -0
  35. package/lib/codegen/utils/index.d.ts +2 -1
  36. package/lib/codegen/utils/index.js +18 -2
  37. package/lib/parsers/scriptSetupRanges.js +20 -28
  38. package/lib/plugins/file-md.js +3 -0
  39. package/lib/plugins/vue-template-inline-ts.js +3 -3
  40. package/lib/plugins/vue-tsx.d.ts +9 -5
  41. package/lib/plugins/vue-tsx.js +20 -20
  42. package/lib/types.d.ts +23 -14
  43. package/lib/utils/parseSfc.js +40 -16
  44. package/lib/utils/ts.js +17 -0
  45. package/lib/virtualFile/computedEmbeddedCodes.js +3 -13
  46. package/lib/virtualFile/computedSfc.js +21 -28
  47. package/lib/virtualFile/vueFile.d.ts +7 -10
  48. package/lib/virtualFile/vueFile.js +10 -4
  49. package/package.json +2 -2
  50. package/lib/codeFeatures.d.ts +0 -1
  51. package/lib/codeFeatures.js +0 -3
  52. package/lib/codegen/common.d.ts +0 -12
  53. package/lib/codegen/common.js +0 -79
  54. package/lib/codegen/script/binding.d.ts +0 -4
  55. package/lib/codegen/script/binding.js +0 -41
  56. package/lib/codegen/script/styleModulesType.d.ts +0 -4
  57. package/lib/codegen/template/camelized.d.ts +0 -2
  58. package/lib/codegen/template/camelized.js +0 -31
  59. package/lib/codegen/utils/src.d.ts +0 -2
  60. package/lib/codegen/utils/src.js +0 -19
  61. package/lib/plugins/vue-style-class-names.d.ts +0 -5
  62. package/lib/plugins/vue-style-class-names.js +0 -32
  63. package/lib/plugins/vue-style-reference-link.d.ts +0 -1
  64. package/lib/plugins/vue-style-reference-link.js +0 -3
  65. package/lib/plugins/vue-style-reference-links.d.ts +0 -3
  66. package/lib/plugins/vue-style-reference-links.js +0 -26
  67. package/lib/plugins/vue-vine.d.ts +0 -3
  68. package/lib/plugins/vue-vine.js +0 -35
  69. package/lib/utils/findDestructuredProps.d.ts +0 -1
  70. package/lib/utils/findDestructuredProps.js +0 -3
  71. package/lib/utils/parseCssImports.d.ts +0 -4
  72. package/lib/utils/parseCssImports.js +0 -19
@@ -9,6 +9,7 @@ const codeFeatures_1 = require("../codeFeatures");
9
9
  const utils_1 = require("../utils");
10
10
  const camelized_1 = require("../utils/camelized");
11
11
  const stringLiteralKey_1 = require("../utils/stringLiteralKey");
12
+ const elementProps_1 = require("./elementProps");
12
13
  const interpolation_1 = require("./interpolation");
13
14
  const objectProperty_1 = require("./objectProperty");
14
15
  const builtInDirectives = new Set([
@@ -86,7 +87,7 @@ function* generateValue(options, ctx, prop) {
86
87
  }
87
88
  yield* (0, utils_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `value`);
88
89
  yield `: `;
89
- yield* (0, utils_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, ...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, exp.content, exp.loc.start.offset, exp.loc, `(`, `)`));
90
+ yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp, ctx.codeFeatures.all);
90
91
  }
91
92
  function getPropRenameApply(oldName) {
92
93
  return oldName === (0, shared_2.hyphenateAttr)(oldName) ? shared_2.hyphenateAttr : undefined;
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
3
3
  import type { Code } from '../../types';
4
4
  import type { TemplateCodegenContext } from './context';
5
5
  import type { TemplateCodegenOptions } from './index';
6
- export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentVar: string, componentInstanceVar: string, eventsVar: string): Generator<Code, boolean>;
6
+ export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
7
7
  export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string): Generator<Code>;
8
8
  export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
9
9
  export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
@@ -9,8 +9,9 @@ const shared_1 = require("@vue/shared");
9
9
  const utils_1 = require("../utils");
10
10
  const camelized_1 = require("../utils/camelized");
11
11
  const interpolation_1 = require("./interpolation");
12
- function* generateElementEvents(options, ctx, node, componentVar, componentInstanceVar, eventsVar) {
13
- let usedComponentEventsVar = false;
12
+ function* generateElementEvents(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
13
+ let emitVar;
14
+ let eventsVar;
14
15
  let propsVar;
15
16
  for (const prop of node.props) {
16
17
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -18,10 +19,14 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
18
19
  && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
19
20
  && !prop.arg.loc.source.startsWith('[')
20
21
  && !prop.arg.loc.source.endsWith(']')) {
21
- usedComponentEventsVar = true;
22
- if (!propsVar) {
22
+ ctx.currentComponent.used = true;
23
+ if (!emitVar) {
24
+ emitVar = ctx.getInternalVariable();
25
+ eventsVar = ctx.getInternalVariable();
23
26
  propsVar = ctx.getInternalVariable();
24
- yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>${utils_1.endOfLine}`;
27
+ yield `let ${emitVar}!: typeof ${componentCtxVar}.emit${utils_1.endOfLine}`;
28
+ yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
29
+ yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
25
30
  }
26
31
  let source = prop.arg.loc.source;
27
32
  let start = prop.arg.loc.start.offset;
@@ -40,7 +45,6 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
40
45
  yield `}${utils_1.endOfLine}`;
41
46
  }
42
47
  }
43
- return usedComponentEventsVar;
44
48
  }
45
49
  function* generateEventArg(ctx, name, start, directive = 'on') {
46
50
  const features = {
@@ -58,18 +62,18 @@ function* generateEventArg(ctx, name, start, directive = 'on') {
58
62
  }
59
63
  function* generateEventExpression(options, ctx, prop) {
60
64
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
61
- let prefix = '(';
62
- let suffix = ')';
65
+ let prefix = `(`;
66
+ let suffix = `)`;
63
67
  let isFirstMapping = true;
64
68
  const ast = (0, utils_1.createTsAst)(options.ts, prop.exp, prop.exp.content);
65
69
  const _isCompoundExpression = isCompoundExpression(options.ts, ast);
66
70
  if (_isCompoundExpression) {
67
71
  yield `(...[$event]) => {${utils_1.newLine}`;
68
72
  ctx.addLocalVariable('$event');
69
- prefix = '';
70
- suffix = '';
73
+ prefix = ``;
74
+ suffix = ``;
71
75
  for (const blockCondition of ctx.blockConditions) {
72
- prefix += `if (!(${blockCondition})) return${utils_1.endOfLine}`;
76
+ prefix += `if (!${blockCondition}) return${utils_1.endOfLine}`;
73
77
  }
74
78
  }
75
79
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
@@ -8,4 +8,4 @@ export interface FailedPropExpression {
8
8
  suffix: string;
9
9
  }
10
10
  export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, enableCodeFeatures: boolean, failedPropExps?: FailedPropExpression[]): Generator<Code>;
11
- export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined, features: VueCodeInformation, enableCodeFeatures: boolean): Generator<Code>;
11
+ export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined, features: VueCodeInformation, enableCodeFeatures?: boolean): Generator<Code>;
@@ -40,12 +40,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
40
40
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
41
41
  && prop.arg.loc.source.startsWith('[')
42
42
  && prop.arg.loc.source.endsWith(']')) {
43
- failedPropExps?.push({ node: prop.arg, prefix: '(', suffix: ')' });
44
- failedPropExps?.push({ node: prop.exp, prefix: '() => {', suffix: '}' });
43
+ failedPropExps?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
44
+ failedPropExps?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
45
45
  }
46
46
  else if (!prop.arg
47
47
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
48
- failedPropExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
48
+ failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
49
49
  }
50
50
  }
51
51
  }
@@ -66,7 +66,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
66
66
  if (propName === undefined
67
67
  || options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
68
68
  if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
69
- failedPropExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
69
+ failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
70
70
  }
71
71
  continue;
72
72
  }
@@ -82,7 +82,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
82
82
  }
83
83
  const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
84
84
  ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
85
- : (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: (`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures), `)`);
85
+ : (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: `, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures));
86
86
  if (enableCodeFeatures) {
87
87
  yield* codes;
88
88
  }
@@ -123,9 +123,9 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
123
123
  if (shouldSpread) {
124
124
  yield `...{ `;
125
125
  }
126
- const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, prop.loc.name_1 ??= {}, shouldCamelize), `: (`, ...(prop.value
126
+ const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, prop.loc.name_1 ??= {}, shouldCamelize), `: `, ...(prop.value
127
127
  ? generateAttrValue(prop.value, ctx.codeFeatures.withoutNavigation)
128
- : [`true`]), `)`);
128
+ : [`true`]));
129
129
  if (enableCodeFeatures) {
130
130
  yield* codes;
131
131
  }
@@ -159,7 +159,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
159
159
  }
160
160
  }
161
161
  }
162
- function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures) {
162
+ function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures = true) {
163
163
  const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
164
164
  if (isShorthand && features.completion) {
165
165
  features = {
@@ -169,7 +169,7 @@ function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures)
169
169
  }
170
170
  if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
171
171
  if (!isShorthand) { // vue 3.4+
172
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, '(', ')');
172
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, `(`, `)`);
173
173
  }
174
174
  else {
175
175
  const propVariableName = (0, shared_1.camelize)(exp.loc.source);
@@ -231,6 +231,8 @@ function getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize) {
231
231
  },
232
232
  verification: strictPropsCheck || {
233
233
  shouldReport(_source, code) {
234
+ // https://typescript.tv/errors/#ts2353
235
+ // https://typescript.tv/errors/#ts2561
234
236
  if (String(code) === '2353' || String(code) === '2561') {
235
237
  return false;
236
238
  }
@@ -18,26 +18,35 @@ function* generateTemplate(options) {
18
18
  ctx.addLocalVariable(options.propsAssignName);
19
19
  }
20
20
  const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
21
- ctx.specialVars.add(slotsPropertyName);
22
- ctx.specialVars.add('$attrs');
23
- ctx.specialVars.add('$refs');
24
- ctx.specialVars.add('$el');
21
+ if (options.vueCompilerOptions.inferTemplateDollarSlots) {
22
+ ctx.dollarVars.add(slotsPropertyName);
23
+ }
24
+ if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
25
+ ctx.dollarVars.add('$attrs');
26
+ }
27
+ if (options.vueCompilerOptions.inferTemplateDollarRefs) {
28
+ ctx.dollarVars.add('$refs');
29
+ }
30
+ if (options.vueCompilerOptions.inferTemplateDollarEl) {
31
+ ctx.dollarVars.add('$el');
32
+ }
25
33
  if (options.template.ast) {
26
34
  yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined);
27
35
  }
28
36
  yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
37
+ yield* ctx.generateAutoImportCompletion();
38
+ yield* ctx.generateHoistVariables();
29
39
  const speicalTypes = [
30
40
  [slotsPropertyName, yield* generateSlots(options, ctx)],
31
41
  ['$attrs', yield* generateInheritedAttrs(options, ctx)],
32
42
  ['$refs', yield* generateTemplateRefs(options, ctx)],
33
43
  ['$el', yield* generateRootEl(ctx)]
34
44
  ];
35
- yield `var __VLS_special!: {${utils_1.newLine}`;
45
+ yield `var __VLS_dollars!: {${utils_1.newLine}`;
36
46
  for (const [name, type] of speicalTypes) {
37
47
  yield `${name}: ${type}${utils_1.endOfLine}`;
38
48
  }
39
- yield `} & { [K in keyof typeof __VLS_ctx]: unknown }${utils_1.endOfLine}`;
40
- yield* ctx.generateAutoImportCompletion();
49
+ yield `} & { [K in keyof import('${options.vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
41
50
  return ctx;
42
51
  }
43
52
  function* generateSlots(options, ctx) {
@@ -45,12 +54,10 @@ function* generateSlots(options, ctx) {
45
54
  const name = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
46
55
  yield `type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${name}>`;
47
56
  for (const { expVar, propsVar } of ctx.dynamicSlots) {
48
- ctx.hasSlot = true;
49
57
  yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
50
58
  }
51
59
  for (const slot of ctx.slots) {
52
60
  yield `${utils_1.newLine}& { `;
53
- ctx.hasSlot = true;
54
61
  if (slot.name && slot.offset !== undefined) {
55
62
  yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
56
63
  }
@@ -72,7 +79,7 @@ function* generateInheritedAttrs(options, ctx) {
72
79
  if (ctx.bindingAttrLocs.length) {
73
80
  yield `[`;
74
81
  for (const loc of ctx.bindingAttrLocs) {
75
- yield `__VLS_special.`;
82
+ yield `__VLS_dollars.`;
76
83
  yield [
77
84
  loc.source,
78
85
  'template',
@@ -87,16 +94,23 @@ function* generateInheritedAttrs(options, ctx) {
87
94
  }
88
95
  function* generateTemplateRefs(options, ctx) {
89
96
  yield `type __VLS_TemplateRefs = {${utils_1.newLine}`;
90
- for (const [name, [varName, offset]] of ctx.templateRefs) {
97
+ for (const [name, { typeExp, offset }] of ctx.templateRefs) {
91
98
  yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigationAndCompletion);
92
- yield `: typeof ${varName},${utils_1.newLine}`;
99
+ yield `: ${typeExp},${utils_1.newLine}`;
93
100
  }
94
101
  yield `}${utils_1.endOfLine}`;
95
102
  return `__VLS_TemplateRefs`;
96
103
  }
97
104
  function* generateRootEl(ctx) {
98
105
  yield `type __VLS_RootEl = `;
99
- yield ctx.singleRootElType ?? `any`;
106
+ if (ctx.singleRootElTypes.length && !ctx.singleRootNodes.has(null)) {
107
+ for (const type of ctx.singleRootElTypes) {
108
+ yield `${utils_1.newLine}| ${type}`;
109
+ }
110
+ }
111
+ else {
112
+ yield `any`;
113
+ }
100
114
  yield utils_1.endOfLine;
101
115
  return `__VLS_RootEl`;
102
116
  }
@@ -87,7 +87,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
87
87
  for (let i = 0; i < ctxVars.length - 1; i++) {
88
88
  const curVar = ctxVars[i];
89
89
  const nextVar = ctxVars[i + 1];
90
- yield* generateVar(code, ctx.specialVars, destructuredPropNames, templateRefNames, curVar);
90
+ yield* generateVar(code, ctx.dollarVars, destructuredPropNames, templateRefNames, curVar);
91
91
  if (nextVar.isShorthand) {
92
92
  yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
93
93
  yield [': ', undefined];
@@ -97,7 +97,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
97
97
  }
98
98
  }
99
99
  const lastVar = ctxVars.at(-1);
100
- yield* generateVar(code, ctx.specialVars, destructuredPropNames, templateRefNames, lastVar);
100
+ yield* generateVar(code, ctx.dollarVars, destructuredPropNames, templateRefNames, lastVar);
101
101
  if (lastVar.offset + lastVar.text.length < code.length) {
102
102
  yield [code.slice(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
103
103
  }
@@ -106,7 +106,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
106
106
  yield [code, 0];
107
107
  }
108
108
  }
109
- function* generateVar(code, specialVars, destructuredPropNames, templateRefNames, curVar) {
109
+ function* generateVar(code, dollarVars, destructuredPropNames, templateRefNames, curVar) {
110
110
  // fix https://github.com/vuejs/language-tools/issues/1205
111
111
  // fix https://github.com/vuejs/language-tools/issues/1264
112
112
  yield ['', curVar.offset, 'errorMappingOnly'];
@@ -118,8 +118,8 @@ function* generateVar(code, specialVars, destructuredPropNames, templateRefNames
118
118
  yield [`)`, undefined];
119
119
  }
120
120
  else {
121
- if (specialVars.has(curVar.text)) {
122
- yield [`__VLS_special.`, undefined];
121
+ if (dollarVars.has(curVar.text)) {
122
+ yield [`__VLS_dollars.`, undefined];
123
123
  }
124
124
  else if (!isDestructuredProp) {
125
125
  yield [`__VLS_ctx.`, undefined];
@@ -10,6 +10,7 @@ const interpolation_1 = require("./interpolation");
10
10
  const propertyAccess_1 = require("./propertyAccess");
11
11
  function* generateSlotOutlet(options, ctx, node) {
12
12
  const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
13
+ const startTagEndOffset = startTagOffset + node.tag.length;
13
14
  const propsVar = ctx.getInternalVariable();
14
15
  const nameProp = node.props.find(prop => {
15
16
  if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
@@ -22,7 +23,7 @@ function* generateSlotOutlet(options, ctx, node) {
22
23
  }
23
24
  });
24
25
  if (options.hasDefineSlots) {
25
- yield `__VLS_normalizeSlot(`;
26
+ yield `__VLS_asFunctionalSlot(`;
26
27
  if (nameProp) {
27
28
  let codes;
28
29
  if (nameProp.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value) {
@@ -37,7 +38,7 @@ function* generateSlotOutlet(options, ctx, node) {
37
38
  && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
38
39
  codes = [
39
40
  `[`,
40
- ...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp, ctx.codeFeatures.all, true),
41
+ ...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp, ctx.codeFeatures.all),
41
42
  `]`
42
43
  ];
43
44
  }
@@ -47,10 +48,10 @@ function* generateSlotOutlet(options, ctx, node) {
47
48
  yield* (0, utils_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
48
49
  }
49
50
  else {
50
- yield* (0, utils_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}['default']`);
51
+ yield* (0, utils_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, utils_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `'default'`), `]`);
51
52
  }
52
- yield `)?.(`;
53
- yield* (0, utils_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
53
+ yield `)(`;
54
+ yield* (0, utils_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
54
55
  yield `)${utils_1.endOfLine}`;
55
56
  }
56
57
  else {
@@ -64,7 +65,7 @@ function* generateSlotOutlet(options, ctx, node) {
64
65
  offset: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
65
66
  tagRange: [startTagOffset, startTagOffset + node.tag.length],
66
67
  nodeLoc: node.loc,
67
- propsVar,
68
+ propsVar: ctx.getHoistVariable(propsVar),
68
69
  });
69
70
  }
70
71
  else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -78,16 +79,16 @@ function* generateSlotOutlet(options, ctx, node) {
78
79
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset, nameProp.exp);
79
80
  yield `)${utils_1.endOfLine}`;
80
81
  ctx.dynamicSlots.push({
81
- expVar,
82
- propsVar,
82
+ expVar: ctx.getHoistVariable(expVar),
83
+ propsVar: ctx.getHoistVariable(propsVar),
83
84
  });
84
85
  }
85
86
  else {
86
87
  ctx.slots.push({
87
88
  name: 'default',
88
- tagRange: [startTagOffset, startTagOffset + node.tag.length],
89
+ tagRange: [startTagOffset, startTagEndOffset],
89
90
  nodeLoc: node.loc,
90
- propsVar,
91
+ propsVar: ctx.getHoistVariable(propsVar),
91
92
  });
92
93
  }
93
94
  }
@@ -6,21 +6,18 @@ const CompilerDOM = require("@vue/compiler-dom");
6
6
  const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
7
7
  const utils_1 = require("../utils");
8
8
  function* generateStyleScopedClassReferences(ctx, withDot = false) {
9
- if (!ctx.emptyClassOffsets.length && !ctx.scopedClasses.length) {
10
- return;
11
- }
12
- yield `[`;
13
9
  for (const offset of ctx.emptyClassOffsets) {
14
- yield `'`;
10
+ yield `/** @type {__VLS_StyleScopedClasses['`;
15
11
  yield [
16
12
  '',
17
13
  'template',
18
14
  offset,
19
15
  ctx.codeFeatures.additionalCompletion,
20
16
  ];
21
- yield `', `;
17
+ yield `']} */${utils_1.endOfLine}`;
22
18
  }
23
19
  for (const { source, className, offset } of ctx.scopedClasses) {
20
+ yield `/** @type {__VLS_StyleScopedClasses[`;
24
21
  yield [
25
22
  '',
26
23
  source,
@@ -35,11 +32,10 @@ function* generateStyleScopedClassReferences(ctx, withDot = false) {
35
32
  '',
36
33
  source,
37
34
  offset + className.length,
38
- ctx.codeFeatures.navigationWithoutRename,
35
+ ctx.codeFeatures.navigation,
39
36
  ];
40
- yield `, `;
37
+ yield `]} */${utils_1.endOfLine}`;
41
38
  }
42
- yield `] as (keyof __VLS_StyleScopedClasses)[]${utils_1.endOfLine}`;
43
39
  function* escapeString(source, className, offset, escapeTargets) {
44
40
  let count = 0;
45
41
  const currentEscapeTargets = [...escapeTargets];
@@ -4,6 +4,7 @@ exports.generateTemplateChild = generateTemplateChild;
4
4
  exports.getVForNode = getVForNode;
5
5
  exports.parseInterpolationNode = parseInterpolationNode;
6
6
  const CompilerDOM = require("@vue/compiler-dom");
7
+ const shared_1 = require("../../utils/shared");
7
8
  const utils_1 = require("../utils");
8
9
  const element_1 = require("./element");
9
10
  const interpolation_1 = require("./interpolation");
@@ -11,6 +12,7 @@ const slotOutlet_1 = require("./slotOutlet");
11
12
  const vFor_1 = require("./vFor");
12
13
  const vIf_1 = require("./vIf");
13
14
  const vSlot_1 = require("./vSlot");
15
+ const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
14
16
  // @ts-ignore
15
17
  const transformContext = {
16
18
  onError: () => { },
@@ -28,38 +30,44 @@ const transformContext = {
28
30
  };
29
31
  function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = false) {
30
32
  if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
31
- const commentText = prevNode.content.trim().split(' ')[0];
32
- if (/^@vue-skip\b[\s\S]*/.test(commentText)) {
33
- yield `// @vue-skip${utils_1.newLine}`;
34
- return;
35
- }
36
- else if (/^@vue-ignore\b[\s\S]*/.test(commentText)) {
37
- yield* ctx.ignoreError();
38
- }
39
- else if (/^@vue-expect-error\b[\s\S]*/.test(commentText)) {
40
- yield* ctx.expectError(prevNode);
41
- }
42
- else {
43
- const match = prevNode.loc.source.match(/^<!--\s*@vue-generic\b\s*\{(?<content>[^}]*)\}/);
44
- if (match) {
45
- const { content } = match.groups ?? {};
46
- ctx.lastGenericComment = {
47
- content,
48
- offset: prevNode.loc.start.offset + match[0].indexOf(content)
49
- };
33
+ const match = prevNode.loc.source.match(commentDirectiveRegex);
34
+ if (match) {
35
+ const { name, content } = match.groups;
36
+ switch (name) {
37
+ case 'skip': {
38
+ yield `// @vue-skip${utils_1.newLine}`;
39
+ return;
40
+ }
41
+ case 'ignore': {
42
+ yield* ctx.ignoreError();
43
+ break;
44
+ }
45
+ case 'expect-error': {
46
+ yield* ctx.expectError(prevNode);
47
+ break;
48
+ }
49
+ case 'generic': {
50
+ const text = content.trim();
51
+ if (text.startsWith('{') && text.endsWith('}')) {
52
+ ctx.lastGenericComment = {
53
+ content: text.slice(1, -1),
54
+ offset: prevNode.loc.start.offset + prevNode.loc.source.indexOf('{') + 1,
55
+ };
56
+ }
57
+ break;
58
+ }
50
59
  }
51
60
  }
52
61
  }
53
- const shouldInheritRootNodeAttrs = options.inheritAttrs;
54
62
  const cur = node;
55
63
  if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
56
64
  cur.codegenNode = cur.codegenNode.value;
57
65
  }
58
66
  if (node.type === CompilerDOM.NodeTypes.ROOT) {
59
- let prev;
60
- if (shouldInheritRootNodeAttrs && node.children.length === 1 && node.children[0].type === CompilerDOM.NodeTypes.ELEMENT) {
61
- ctx.singleRootNode = node.children[0];
67
+ for (const item of collectSingleRootNodes(options, node.children)) {
68
+ ctx.singleRootNodes.add(item);
62
69
  }
70
+ let prev;
63
71
  for (const childNode of node.children) {
64
72
  yield* generateTemplateChild(options, ctx, childNode, prev);
65
73
  prev = childNode;
@@ -91,7 +99,7 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
91
99
  }
92
100
  else {
93
101
  const { currentComponent } = ctx;
94
- yield* (0, element_1.generateComponent)(options, ctx, node);
102
+ yield* (0, element_1.generateComponent)(options, ctx, node, isVForChild);
95
103
  ctx.currentComponent = currentComponent;
96
104
  }
97
105
  }
@@ -126,6 +134,30 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
126
134
  // not needed progress
127
135
  }
128
136
  }
137
+ function* collectSingleRootNodes(options, children) {
138
+ if (children.length !== 1) {
139
+ // "null" is used to determine whether the component is not always has a single root
140
+ if (children.length > 1) {
141
+ yield null;
142
+ }
143
+ return;
144
+ }
145
+ const child = children[0];
146
+ if (child.type === CompilerDOM.NodeTypes.IF) {
147
+ for (const branch of child.branches) {
148
+ yield* collectSingleRootNodes(options, branch.children);
149
+ }
150
+ return;
151
+ }
152
+ else if (child.type !== CompilerDOM.NodeTypes.ELEMENT) {
153
+ return;
154
+ }
155
+ yield child;
156
+ const tag = (0, shared_1.hyphenateTag)(child.tag);
157
+ if (options.vueCompilerOptions.fallthroughComponentNames.includes(tag)) {
158
+ yield* collectSingleRootNodes(options, child.children);
159
+ }
160
+ }
129
161
  // TODO: track https://github.com/vuejs/vue-next/issues/3498
130
162
  function getVForNode(node) {
131
163
  const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -146,11 +178,11 @@ function getVForNode(node) {
146
178
  }
147
179
  }
148
180
  function getVIfNode(node) {
149
- const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
181
+ const ifDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
150
182
  && prop.name === 'if');
151
- if (forDirective) {
183
+ if (ifDirective) {
152
184
  let ifNode;
153
- CompilerDOM.processIf(node, forDirective, transformContext, _ifNode => {
185
+ CompilerDOM.processIf(node, ifDirective, transformContext, _ifNode => {
154
186
  ifNode = { ..._ifNode };
155
187
  return undefined;
156
188
  });
@@ -158,7 +190,7 @@ function getVIfNode(node) {
158
190
  for (const branch of ifNode.branches) {
159
191
  branch.children = [{
160
192
  ...node,
161
- props: node.props.filter(prop => prop !== forDirective),
193
+ props: node.props.filter(prop => prop !== ifDirective),
162
194
  }];
163
195
  }
164
196
  return ifNode;
@@ -24,7 +24,7 @@ function* generateVFor(options, ctx, node) {
24
24
  yield `] of `;
25
25
  if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
26
26
  yield `__VLS_getVForSourceType(`;
27
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, source.loc, '(', ')');
27
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, source.loc, `(`, `)`);
28
28
  yield `!)`; // #3102
29
29
  }
30
30
  else {
@@ -46,7 +46,7 @@ function* generateVFor(options, ctx, node) {
46
46
  for (const prop of argument.returns.props.properties) {
47
47
  if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
48
48
  && !prop.value.isStatic) {
49
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, prop.value.loc, '(', ')');
49
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, prop.value.loc, `(`, `)`);
50
50
  yield utils_1.endOfLine;
51
51
  }
52
52
  }
@@ -7,7 +7,7 @@ const utils_1 = require("../utils");
7
7
  const interpolation_1 = require("./interpolation");
8
8
  const templateChild_1 = require("./templateChild");
9
9
  function* generateVIf(options, ctx, node) {
10
- let originalBlockConditionsLength = ctx.blockConditions.length;
10
+ const originalBlockConditionsLength = ctx.blockConditions.length;
11
11
  for (let i = 0; i < node.branches.length; i++) {
12
12
  const branch = node.branches[i];
13
13
  if (i === 0) {
@@ -22,7 +22,7 @@ function* generateVIf(options, ctx, node) {
22
22
  let addedBlockCondition = false;
23
23
  if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
24
24
  const codes = [
25
- ...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, branch.condition.loc, '(', ')'),
25
+ ...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, branch.condition.loc, `(`, `)`),
26
26
  ];
27
27
  for (const code of codes) {
28
28
  yield code;
@@ -43,7 +43,7 @@ function* generateVIf(options, ctx, node) {
43
43
  yield* ctx.generateAutoImportCompletion();
44
44
  yield `}${utils_1.newLine}`;
45
45
  if (addedBlockCondition) {
46
- ctx.blockConditions[ctx.blockConditions.length - 1] = `!(${ctx.blockConditions[ctx.blockConditions.length - 1]})`;
46
+ ctx.blockConditions[ctx.blockConditions.length - 1] = `!${ctx.blockConditions[ctx.blockConditions.length - 1]}`;
47
47
  }
48
48
  }
49
49
  ctx.blockConditions.length = originalBlockConditionsLength;
@@ -3,3 +3,4 @@ import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
5
  export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode): Generator<Code>;
6
+ export declare function generateImplicitDefaultSlot(ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code, void, any>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVSlot = generateVSlot;
4
+ exports.generateImplicitDefaultSlot = generateImplicitDefaultSlot;
4
5
  const CompilerDOM = require("@vue/compiler-dom");
5
6
  const utils_1 = require("../utils");
6
7
  const objectProperty_1 = require("./objectProperty");
@@ -77,4 +78,15 @@ function* generateVSlot(options, ctx, node, slotDir) {
77
78
  yield* ctx.generateAutoImportCompletion();
78
79
  yield `}${utils_1.newLine}`;
79
80
  }
81
+ function* generateImplicitDefaultSlot(ctx, node) {
82
+ if (!ctx.currentComponent) {
83
+ return;
84
+ }
85
+ if (node.children.length) {
86
+ ctx.currentComponent.used = true;
87
+ yield `${ctx.currentComponent.ctxVar}.slots!.`;
88
+ yield* (0, utils_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
89
+ yield utils_1.endOfLine;
90
+ }
91
+ }
80
92
  //# sourceMappingURL=vSlot.js.map