@vue/language-core 3.0.4 → 3.0.6

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 (61) hide show
  1. package/lib/codegen/codeFeatures.d.ts +0 -17
  2. package/lib/codegen/codeFeatures.js +0 -13
  3. package/lib/codegen/script/component.d.ts +1 -1
  4. package/lib/codegen/script/component.js +10 -14
  5. package/lib/codegen/script/componentSelf.js +19 -23
  6. package/lib/codegen/script/context.d.ts +0 -6
  7. package/lib/codegen/script/index.d.ts +2 -1
  8. package/lib/codegen/script/index.js +16 -4
  9. package/lib/codegen/script/scriptSetup.js +2 -2
  10. package/lib/codegen/script/template.d.ts +0 -1
  11. package/lib/codegen/script/template.js +6 -43
  12. package/lib/codegen/template/context.d.ts +0 -22
  13. package/lib/codegen/template/context.js +0 -6
  14. package/lib/codegen/template/element.js +17 -27
  15. package/lib/codegen/template/elementDirectives.js +10 -10
  16. package/lib/codegen/template/elementEvents.d.ts +1 -1
  17. package/lib/codegen/template/elementEvents.js +17 -19
  18. package/lib/codegen/template/elementProps.js +14 -14
  19. package/lib/codegen/template/index.d.ts +3 -2
  20. package/lib/codegen/template/index.js +25 -13
  21. package/lib/codegen/template/interpolation.js +2 -1
  22. package/lib/codegen/template/slotOutlet.js +8 -7
  23. package/lib/codegen/template/styleScopedClasses.js +9 -12
  24. package/lib/codegen/template/templateChild.js +2 -1
  25. package/lib/codegen/template/vFor.js +4 -3
  26. package/lib/codegen/template/vIf.js +2 -1
  27. package/lib/codegen/template/vSlot.js +9 -8
  28. package/lib/plugins/file-html.js +1 -1
  29. package/lib/plugins/file-md.js +1 -1
  30. package/lib/plugins/file-vue.js +17 -2
  31. package/lib/plugins/vue-root-tags.js +1 -1
  32. package/lib/plugins/vue-script-js.js +1 -1
  33. package/lib/plugins/vue-sfc-customblocks.js +1 -1
  34. package/lib/plugins/vue-sfc-scripts.js +1 -1
  35. package/lib/plugins/vue-sfc-styles.js +5 -5
  36. package/lib/plugins/vue-sfc-template.js +1 -1
  37. package/lib/plugins/vue-style-css.js +1 -1
  38. package/lib/plugins/vue-template-html.js +1 -1
  39. package/lib/plugins/vue-template-inline-css.js +1 -1
  40. package/lib/plugins/vue-template-inline-ts.js +1 -1
  41. package/lib/plugins/vue-tsx.d.ts +0 -22
  42. package/lib/plugins/vue-tsx.js +17 -20
  43. package/lib/plugins.js +2 -0
  44. package/lib/types.d.ts +3 -2
  45. package/lib/types.js +1 -1
  46. package/lib/utils/shared.d.ts +3 -1
  47. package/lib/utils/shared.js +13 -0
  48. package/lib/utils/ts.d.ts +7 -6
  49. package/lib/utils/ts.js +43 -66
  50. package/lib/virtualFile/computedSfc.js +13 -8
  51. package/package.json +4 -4
  52. package/lib/codegen/tenp.d.ts +0 -1
  53. package/lib/codegen/tenp.js +0 -3
  54. package/lib/plugins/file-css.d.ts +0 -3
  55. package/lib/plugins/file-css.js +0 -57
  56. package/lib/utils/parseCssClassNames.d.ts +0 -4
  57. package/lib/utils/parseCssClassNames.js +0 -17
  58. package/lib/utils/parseCssImports.d.ts +0 -4
  59. package/lib/utils/parseCssImports.js +0 -19
  60. package/lib/utils/parseCssVars.d.ts +0 -6
  61. package/lib/utils/parseCssVars.js +0 -26
@@ -49,12 +49,12 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
49
49
  yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
50
50
  if (prop.name === 'on') {
51
51
  yield `{ `;
52
- yield* generateEventArg(options, ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
52
+ yield* generateEventArg(options, source, start, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
53
53
  yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
54
54
  }
55
55
  yield `{ `;
56
56
  if (prop.name === 'on') {
57
- yield* generateEventArg(options, ctx, source, start, propPrefix.slice(0, -1));
57
+ yield* generateEventArg(options, source, start, propPrefix.slice(0, -1));
58
58
  yield `: `;
59
59
  yield* generateEventExpression(options, ctx, prop);
60
60
  }
@@ -66,14 +66,14 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
66
66
  }
67
67
  }
68
68
  }
69
- function* generateEventArg(options, ctx, name, start, directive = 'on', features) {
70
- features ??= ctx.resolveCodeFeatures({
69
+ function* generateEventArg(options, name, start, directive = 'on', features) {
70
+ features ??= {
71
71
  ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
72
72
  ...codeFeatures_1.codeFeatures.navigationWithoutRename,
73
73
  ...options.vueCompilerOptions.checkUnknownEvents
74
74
  ? codeFeatures_1.codeFeatures.verification
75
75
  : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
76
- });
76
+ };
77
77
  if (directive.length) {
78
78
  name = (0, shared_1.capitalize)(name);
79
79
  }
@@ -88,19 +88,10 @@ function* generateEventArg(options, ctx, name, start, directive = 'on', features
88
88
  }
89
89
  function* generateEventExpression(options, ctx, prop) {
90
90
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
91
- let prefix = `(`;
92
- let suffix = `)`;
93
91
  let isFirstMapping = true;
94
92
  const ast = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, prop.exp.content);
95
93
  const isCompound = isCompoundExpression(options.ts, ast);
96
- if (isCompound) {
97
- ctx.addLocalVariable('$event');
98
- yield `(...[$event]) => {${utils_1.newLine}`;
99
- yield* ctx.generateConditionGuards();
100
- prefix = ``;
101
- suffix = ``;
102
- }
103
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
94
+ const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
104
95
  if (isCompound && isFirstMapping) {
105
96
  isFirstMapping = false;
106
97
  ctx.inlayHints.push({
@@ -116,14 +107,21 @@ function* generateEventExpression(options, ctx, prop) {
116
107
  ].join('\n\n'),
117
108
  });
118
109
  }
119
- return ctx.codeFeatures.all;
120
- }, prop.exp.content, prop.exp.loc.start.offset, prefix, suffix);
110
+ return codeFeatures_1.codeFeatures.all;
111
+ }, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
121
112
  if (isCompound) {
122
- ctx.removeLocalVariable('$event');
113
+ yield `(...[$event]) => {${utils_1.newLine}`;
114
+ ctx.addLocalVariable('$event');
115
+ yield* ctx.generateConditionGuards();
116
+ yield* interpolation;
123
117
  yield utils_1.endOfLine;
118
+ ctx.removeLocalVariable('$event');
124
119
  yield* ctx.generateAutoImportCompletion();
125
120
  yield `}`;
126
121
  }
122
+ else {
123
+ yield* interpolation;
124
+ }
127
125
  }
128
126
  else {
129
127
  yield `() => {}`;
@@ -133,7 +131,7 @@ function* generateModelEventExpression(options, ctx, prop) {
133
131
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
134
132
  yield `(...[$event]) => {${utils_1.newLine}`;
135
133
  yield* ctx.generateConditionGuards();
136
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
134
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
137
135
  yield ` = $event${utils_1.endOfLine}`;
138
136
  yield `}`;
139
137
  }
@@ -27,7 +27,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
27
27
  && !prop.arg.loc.source.endsWith(']')) {
28
28
  if (!isComponent) {
29
29
  yield `...{ `;
30
- yield* (0, elementEvents_1.generateEventArg)(options, ctx, prop.arg.loc.source, prop.arg.loc.start.offset);
30
+ yield* (0, elementEvents_1.generateEventArg)(options, prop.arg.loc.source, prop.arg.loc.start.offset);
31
31
  yield `: `;
32
32
  yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
33
33
  yield `},`;
@@ -77,13 +77,13 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
77
77
  }
78
78
  const shouldSpread = propName === 'style' || propName === 'class';
79
79
  const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
80
- const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
80
+ const features = getPropsCodeFeatures(strictPropsCheck);
81
81
  if (shouldSpread) {
82
82
  yield `...{ `;
83
83
  }
84
- const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
85
- ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, shouldCamelize)
86
- : (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)(prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, ctx.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures)))];
84
+ const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...(prop.arg
85
+ ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize)
86
+ : (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)(prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures)))];
87
87
  if (enableCodeFeatures) {
88
88
  yield* codes;
89
89
  }
@@ -120,12 +120,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
120
120
  }
121
121
  const shouldSpread = prop.name === 'style' || prop.name === 'class';
122
122
  const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
123
- const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
123
+ const features = getPropsCodeFeatures(strictPropsCheck);
124
124
  if (shouldSpread) {
125
125
  yield `...{ `;
126
126
  }
127
- const codes = [...(0, wrapWith_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, shouldCamelize), `: `, ...(prop.value
128
- ? generateAttrValue(prop.value, ctx.codeFeatures.withoutNavigation)
127
+ const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, features, shouldCamelize), `: `, ...(prop.value
128
+ ? generateAttrValue(prop.value, codeFeatures_1.codeFeatures.withoutNavigation)
129
129
  : [`true`]))];
130
130
  if (enableCodeFeatures) {
131
131
  yield* codes;
@@ -148,7 +148,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
148
148
  }
149
149
  }
150
150
  else {
151
- const codes = [...(0, wrapWith_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures))];
151
+ const codes = [...(0, wrapWith_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures))];
152
152
  if (enableCodeFeatures) {
153
153
  yield* codes;
154
154
  }
@@ -163,8 +163,8 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
163
163
  function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
164
164
  const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
165
165
  const features = isShorthand
166
- ? ctx.codeFeatures.withoutHighlightAndCompletion
167
- : ctx.codeFeatures.all;
166
+ ? codeFeatures_1.codeFeatures.withoutHighlightAndCompletion
167
+ : codeFeatures_1.codeFeatures.all;
168
168
  if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
169
169
  if (!isShorthand) { // vue 3.4+
170
170
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, `(`, `)`);
@@ -220,13 +220,13 @@ function getShouldCamelize(options, prop, propName) {
220
220
  && (0, shared_2.hyphenateAttr)(propName) === propName
221
221
  && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
222
222
  }
223
- function getPropsCodeInfo(ctx, strictPropsCheck) {
224
- return ctx.resolveCodeFeatures({
223
+ function getPropsCodeFeatures(strictPropsCheck) {
224
+ return {
225
225
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
226
226
  ...strictPropsCheck
227
227
  ? codeFeatures_1.codeFeatures.verification
228
228
  : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
229
- });
229
+ };
230
230
  }
231
231
  function getModelPropName(node, vueCompilerOptions) {
232
232
  for (const modelName in vueCompilerOptions.experimentalModelPropName) {
@@ -1,7 +1,8 @@
1
1
  import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type * as ts from 'typescript';
3
3
  import type { Code, Sfc, VueCompilerOptions } from '../../types';
4
- import { type TemplateCodegenContext } from './context';
4
+ import type { TemplateCodegenContext } from './context';
5
+ export * from './context';
5
6
  export interface TemplateCodegenOptions {
6
7
  ts: typeof ts;
7
8
  compilerOptions: ts.CompilerOptions;
@@ -17,5 +18,5 @@ export interface TemplateCodegenOptions {
17
18
  inheritAttrs: boolean;
18
19
  selfComponentName?: string;
19
20
  }
20
- export declare function generateTemplate(options: TemplateCodegenOptions): Generator<Code, TemplateCodegenContext>;
21
+ export declare function generateTemplate(options: TemplateCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
21
22
  export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
@@ -1,17 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.generateTemplate = generateTemplate;
4
18
  exports.forEachElementNode = forEachElementNode;
5
19
  const CompilerDOM = require("@vue/compiler-dom");
6
20
  const shared_1 = require("../../utils/shared");
21
+ const codeFeatures_1 = require("../codeFeatures");
7
22
  const utils_1 = require("../utils");
8
23
  const wrapWith_1 = require("../utils/wrapWith");
9
- const context_1 = require("./context");
10
24
  const objectProperty_1 = require("./objectProperty");
11
25
  const styleScopedClasses_1 = require("./styleScopedClasses");
12
26
  const templateChild_1 = require("./templateChild");
13
- function* generateTemplate(options) {
14
- const ctx = (0, context_1.createTemplateCodegenContext)(options, options.template.ast);
27
+ __exportStar(require("./context"), exports);
28
+ function* generateTemplate(options, ctx) {
15
29
  if (options.slotsAssignName) {
16
30
  ctx.addLocalVariable(options.slotsAssignName);
17
31
  }
@@ -47,7 +61,6 @@ function* generateTemplate(options) {
47
61
  yield `${name}: ${type}${utils_1.endOfLine}`;
48
62
  }
49
63
  yield `} & { [K in keyof import('${options.vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
50
- return ctx;
51
64
  }
52
65
  function* generateSlots(options, ctx) {
53
66
  if (!options.hasDefineSlots) {
@@ -58,10 +71,10 @@ function* generateSlots(options, ctx) {
58
71
  for (const slot of ctx.slots) {
59
72
  yield `${utils_1.newLine}& { `;
60
73
  if (slot.name && slot.offset !== undefined) {
61
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.navigation);
74
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
62
75
  }
63
76
  else {
64
- yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.navigation, `default`);
77
+ yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], codeFeatures_1.codeFeatures.navigation, `default`);
65
78
  }
66
79
  yield `?: (props: typeof ${slot.propsVar}) => any }`;
67
80
  }
@@ -70,10 +83,9 @@ function* generateSlots(options, ctx) {
70
83
  return `__VLS_Slots`;
71
84
  }
72
85
  function* generateInheritedAttrs(options, ctx) {
73
- yield `type __VLS_InheritedAttrs = {}`;
74
- for (const varName of ctx.inheritedAttrVars) {
75
- yield ` & typeof ${varName}`;
76
- }
86
+ yield `type __VLS_InheritedAttrs = ${ctx.inheritedAttrVars.size
87
+ ? `Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`
88
+ : `{}`}`;
77
89
  yield utils_1.endOfLine;
78
90
  if (ctx.bindingAttrLocs.length) {
79
91
  yield `[`;
@@ -83,13 +95,13 @@ function* generateInheritedAttrs(options, ctx) {
83
95
  loc.source,
84
96
  'template',
85
97
  loc.start.offset,
86
- ctx.codeFeatures.all,
98
+ codeFeatures_1.codeFeatures.all,
87
99
  ];
88
100
  yield `,`;
89
101
  }
90
102
  yield `]${utils_1.endOfLine}`;
91
103
  }
92
- return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
104
+ return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & __VLS_InheritedAttrs`;
93
105
  }
94
106
  function* generateTemplateRefs(options, ctx) {
95
107
  yield `type __VLS_TemplateRefs = {}`;
@@ -104,7 +116,7 @@ function* generateTemplateRefs(options, ctx) {
104
116
  yield ` | `;
105
117
  }
106
118
  yield `{ `;
107
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigation);
119
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, codeFeatures_1.codeFeatures.navigation);
108
120
  yield `: ${typeExp} }`;
109
121
  }
110
122
  if (refs.length >= 2) {
@@ -4,6 +4,7 @@ exports.generateInterpolation = generateInterpolation;
4
4
  const shared_1 = require("@vue/shared");
5
5
  const collectBindings_1 = require("../../utils/collectBindings");
6
6
  const shared_2 = require("../../utils/shared");
7
+ const codeFeatures_1 = require("../codeFeatures");
7
8
  const utils_1 = require("../utils");
8
9
  // https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
9
10
  const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
@@ -35,7 +36,7 @@ function* generateInterpolation(options, ctx, source, data, code, start, prefix
35
36
  source,
36
37
  start + offset,
37
38
  type === 'errorMappingOnly'
38
- ? ctx.codeFeatures.verification
39
+ ? codeFeatures_1.codeFeatures.verification
39
40
  : typeof data === 'function'
40
41
  ? data(start + offset)
41
42
  : data,
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSlotOutlet = generateSlotOutlet;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const shared_1 = require("../../utils/shared");
6
+ const codeFeatures_1 = require("../codeFeatures");
5
7
  const inlayHints_1 = require("../inlayHints");
6
8
  const utils_1 = require("../utils");
7
9
  const wrapWith_1 = require("../utils/wrapWith");
@@ -10,8 +12,7 @@ const elementProps_1 = require("./elementProps");
10
12
  const interpolation_1 = require("./interpolation");
11
13
  const propertyAccess_1 = require("./propertyAccess");
12
14
  function* generateSlotOutlet(options, ctx, node) {
13
- const startTagOffset = node.loc.start.offset
14
- + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
15
+ const [startTagOffset] = (0, shared_1.getElementTagOffsets)(node, options.template);
15
16
  const startTagEndOffset = startTagOffset + node.tag.length;
16
17
  const propsVar = ctx.getInternalVariable();
17
18
  const nameProp = node.props.find(prop => {
@@ -34,7 +35,7 @@ function* generateSlotOutlet(options, ctx, node) {
34
35
  source = source.slice(1, -1);
35
36
  offset++;
36
37
  }
37
- codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, source, offset, ctx.codeFeatures.navigationAndVerification);
38
+ codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, source, offset, codeFeatures_1.codeFeatures.navigationAndVerification);
38
39
  }
39
40
  else if (nameProp.type === CompilerDOM.NodeTypes.DIRECTIVE
40
41
  && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
@@ -47,13 +48,13 @@ function* generateSlotOutlet(options, ctx, node) {
47
48
  else {
48
49
  codes = [`['default']`];
49
50
  }
50
- yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
51
+ yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
51
52
  }
52
53
  else {
53
- yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `'default'`), `]`);
54
+ yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `'default'`), `]`);
54
55
  }
55
56
  yield `)(`;
56
- yield* (0, wrapWith_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), `}`);
57
+ yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
57
58
  yield `)${utils_1.endOfLine}`;
58
59
  }
59
60
  else {
@@ -78,7 +79,7 @@ function* generateSlotOutlet(options, ctx, node) {
78
79
  }
79
80
  const expVar = ctx.getInternalVariable();
80
81
  yield `var ${expVar} = __VLS_tryAsConstant(`;
81
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset);
82
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset);
82
83
  yield `)${utils_1.endOfLine}`;
83
84
  ctx.dynamicSlots.push({
84
85
  expVar: ctx.getHoistVariable(expVar),
@@ -4,6 +4,7 @@ exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
4
4
  exports.collectStyleScopedClassReferences = collectStyleScopedClassReferences;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const shared_1 = require("../../utils/shared");
7
+ const codeFeatures_1 = require("../codeFeatures");
7
8
  const utils_1 = require("../utils");
8
9
  const escaped_1 = require("../utils/escaped");
9
10
  const wrapWith_1 = require("../utils/wrapWith");
@@ -15,13 +16,13 @@ function* generateStyleScopedClassReferences(ctx, withDot = false) {
15
16
  '',
16
17
  'template',
17
18
  offset,
18
- ctx.codeFeatures.additionalCompletion,
19
+ codeFeatures_1.codeFeatures.additionalCompletion,
19
20
  ];
20
21
  yield `']} */${utils_1.endOfLine}`;
21
22
  }
22
23
  for (const { source, className, offset } of ctx.scopedClasses) {
23
24
  yield `/** @type {__VLS_StyleScopedClasses[`;
24
- yield* (0, wrapWith_1.wrapWith)(offset - (withDot ? 1 : 0), offset + className.length, source, ctx.codeFeatures.navigation, `'`, ...(0, escaped_1.generateEscaped)(className, source, offset, ctx.codeFeatures.navigationAndAdditionalCompletion, classNameEscapeRegex), `'`);
25
+ yield* (0, wrapWith_1.wrapWith)(offset - (withDot ? 1 : 0), offset + className.length, source, codeFeatures_1.codeFeatures.navigation, `'`, ...(0, escaped_1.generateEscaped)(className, source, offset, codeFeatures_1.codeFeatures.navigationAndAdditionalCompletion, classNameEscapeRegex), `'`);
25
26
  yield `]} */${utils_1.endOfLine}`;
26
27
  }
27
28
  }
@@ -61,24 +62,24 @@ function collectStyleScopedClassReferences(options, ctx, node) {
61
62
  && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
62
63
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
63
64
  && prop.arg.content === 'class') {
64
- const content = '`${' + prop.exp.content + '}`';
65
- const startOffset = prop.exp.loc.start.offset - 3;
65
+ const content = '(' + prop.exp.content + ')';
66
+ const startOffset = prop.exp.loc.start.offset - 1;
66
67
  const { ts } = options;
67
68
  const ast = ts.createSourceFile('', content, 99);
68
69
  const literals = [];
69
70
  ts.forEachChild(ast, node => {
70
71
  if (!ts.isExpressionStatement(node)
71
- || !isTemplateExpression(node.expression)) {
72
+ || !ts.isParenthesizedExpression(node.expression)) {
72
73
  return;
73
74
  }
74
- const expression = node.expression.templateSpans[0].expression;
75
+ const { expression } = node.expression;
75
76
  if (ts.isStringLiteralLike(expression)) {
76
77
  literals.push(expression);
77
78
  }
78
- if (ts.isArrayLiteralExpression(expression)) {
79
+ else if (ts.isArrayLiteralExpression(expression)) {
79
80
  walkArrayLiteral(expression);
80
81
  }
81
- if (ts.isObjectLiteralExpression(expression)) {
82
+ else if (ts.isObjectLiteralExpression(expression)) {
82
83
  walkObjectLiteral(expression);
83
84
  }
84
85
  });
@@ -159,8 +160,4 @@ function collectClasses(content, startOffset = 0) {
159
160
  }
160
161
  return classes;
161
162
  }
162
- // isTemplateExpression is missing in tsc
163
- function isTemplateExpression(node) {
164
- return node.kind === 228;
165
- }
166
163
  //# sourceMappingURL=styleScopedClasses.js.map
@@ -5,6 +5,7 @@ exports.getVForNode = getVForNode;
5
5
  exports.parseInterpolationNode = parseInterpolationNode;
6
6
  const CompilerDOM = require("@vue/compiler-dom");
7
7
  const shared_1 = require("../../utils/shared");
8
+ const codeFeatures_1 = require("../codeFeatures");
8
9
  const utils_1 = require("../utils");
9
10
  const element_1 = require("./element");
10
11
  const elementChildren_1 = require("./elementChildren");
@@ -83,7 +84,7 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
83
84
  else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
84
85
  // {{ ... }}
85
86
  const [content, start] = parseInterpolationNode(node, options.template.content);
86
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, `(`, `)${utils_1.endOfLine}`);
87
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, content, start, `(`, `)${utils_1.endOfLine}`);
87
88
  }
88
89
  else if (node.type === CompilerDOM.NodeTypes.IF) {
89
90
  // v-if / v-else-if / v-else
@@ -4,6 +4,7 @@ exports.generateVFor = generateVFor;
4
4
  exports.parseVForNode = parseVForNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const collectBindings_1 = require("../../utils/collectBindings");
7
+ const codeFeatures_1 = require("../codeFeatures");
7
8
  const utils_1 = require("../utils");
8
9
  const elementChildren_1 = require("./elementChildren");
9
10
  const interpolation_1 = require("./interpolation");
@@ -19,13 +20,13 @@ function* generateVFor(options, ctx, node) {
19
20
  leftExpressionText,
20
21
  'template',
21
22
  leftExpressionRange.start,
22
- ctx.codeFeatures.all,
23
+ codeFeatures_1.codeFeatures.all,
23
24
  ];
24
25
  }
25
26
  yield `] of `;
26
27
  if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
27
28
  yield `__VLS_getVForSourceType(`;
28
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
29
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
29
30
  yield `!)`; // #3102
30
31
  }
31
32
  else {
@@ -47,7 +48,7 @@ function* generateVFor(options, ctx, node) {
47
48
  for (const prop of argument.returns.props.properties) {
48
49
  if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
49
50
  && !prop.value.isStatic) {
50
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
51
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
51
52
  yield utils_1.endOfLine;
52
53
  }
53
54
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVIf = generateVIf;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
5
  const muggle_string_1 = require("muggle-string");
6
+ const codeFeatures_1 = require("../codeFeatures");
6
7
  const utils_1 = require("../utils");
7
8
  const elementChildren_1 = require("./elementChildren");
8
9
  const interpolation_1 = require("./interpolation");
@@ -21,7 +22,7 @@ function* generateVIf(options, ctx, node) {
21
22
  }
22
23
  let addedBlockCondition = false;
23
24
  if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
24
- const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
25
+ const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
25
26
  yield* codes;
26
27
  ctx.blockConditions.push((0, muggle_string_1.toString)(codes));
27
28
  addedBlockCondition = true;
@@ -4,6 +4,7 @@ exports.generateVSlot = generateVSlot;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
5
  const collectBindings_1 = require("../../utils/collectBindings");
6
6
  const shared_1 = require("../../utils/shared");
7
+ const codeFeatures_1 = require("../codeFeatures");
7
8
  const utils_1 = require("../utils");
8
9
  const wrapWith_1 = require("../utils/wrapWith");
9
10
  const elementChildren_1 = require("./elementChildren");
@@ -22,22 +23,22 @@ function* generateVSlot(options, ctx, node, slotDir) {
22
23
  yield `const { `;
23
24
  if (slotDir) {
24
25
  if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
25
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, false, true);
26
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? codeFeatures_1.codeFeatures.withoutHighlight : codeFeatures_1.codeFeatures.all, false, true);
26
27
  }
27
28
  else {
28
- yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
29
+ yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), codeFeatures_1.codeFeatures.withoutHighlightAndCompletion, `default`);
29
30
  }
30
31
  }
31
32
  else {
32
33
  // #932: reference for implicit default slot
33
- yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.navigation, `default`);
34
+ yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, codeFeatures_1.codeFeatures.navigation, `default`);
34
35
  }
35
36
  yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
36
37
  }
37
38
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
38
39
  const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
39
40
  slotBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
40
- yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
41
+ yield* generateSlotParameters(options, slotAst, slotDir.exp, slotVar);
41
42
  }
42
43
  for (const varName of slotBlockVars) {
43
44
  ctx.addLocalVariable(varName);
@@ -61,14 +62,14 @@ function* generateVSlot(options, ctx, node, slotDir) {
61
62
  : slotDir.loc.source.startsWith('v-slot:')
62
63
  ? 'v-slot:'.length
63
64
  : 0),
64
- ctx.codeFeatures.completion,
65
+ codeFeatures_1.codeFeatures.completion,
65
66
  ];
66
67
  yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
67
68
  }
68
69
  yield `}${utils_1.newLine}`;
69
70
  }
70
71
  }
71
- function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
72
+ function* generateSlotParameters(options, ast, exp, slotVar) {
72
73
  const { ts } = options;
73
74
  const statement = ast.statements[0];
74
75
  if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
@@ -102,7 +103,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
102
103
  yield `] = __VLS_getSlotParameters(${slotVar}!`;
103
104
  if (types.some(t => t)) {
104
105
  yield `, `;
105
- yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
106
+ yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
106
107
  }
107
108
  yield `)${utils_1.endOfLine}`;
108
109
  function chunk(start, end) {
@@ -110,7 +111,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
110
111
  ast.text.slice(start, end),
111
112
  'template',
112
113
  startOffset + start,
113
- ctx.codeFeatures.all,
114
+ codeFeatures_1.codeFeatures.all,
114
115
  ];
115
116
  }
116
117
  }
@@ -4,7 +4,7 @@ const sfcBlockReg = /<(script|style)\b([\s\S]*?)>([\s\S]*?)<\/\1>/g;
4
4
  const langReg = /\blang\s*=\s*(['"]?)(\S*)\b\1/;
5
5
  const plugin = ({ vueCompilerOptions }) => {
6
6
  return {
7
- version: 2.1,
7
+ version: 2.2,
8
8
  getLanguageId(fileName) {
9
9
  if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
10
10
  return 'html';
@@ -15,7 +15,7 @@ const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
15
15
  const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
16
16
  const plugin = ({ vueCompilerOptions }) => {
17
17
  return {
18
- version: 2.1,
18
+ version: 2.2,
19
19
  getLanguageId(fileName) {
20
20
  if (vueCompilerOptions.vitePressExtensions.some(ext => fileName.endsWith(ext))) {
21
21
  return 'markdown';
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const parseSfc_1 = require("../utils/parseSfc");
4
4
  const plugin = ({ vueCompilerOptions }) => {
5
5
  return {
6
- version: 2.1,
6
+ version: 2.2,
7
7
  getLanguageId(fileName) {
8
8
  if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
9
9
  return 'vue';
@@ -16,7 +16,22 @@ const plugin = ({ vueCompilerOptions }) => {
16
16
  if (languageId !== 'vue') {
17
17
  return;
18
18
  }
19
- return (0, parseSfc_1.parse)(content);
19
+ const sfc = (0, parseSfc_1.parse)(content);
20
+ for (const error of sfc.errors) {
21
+ // Handle 'Element is missing end tag.' error, see #4893
22
+ if ('code' in error && error.code === 24 && sfc.descriptor.template
23
+ && error.loc?.start.line === sfc.descriptor.template.loc.start.line) {
24
+ const template = sfc.descriptor.template;
25
+ const templateText = template.content;
26
+ const endTagOffset = templateText.lastIndexOf('<');
27
+ const endTagText = templateText.slice(endTagOffset).trimEnd();
28
+ if ('</template>'.startsWith(endTagText)) {
29
+ sfc.descriptor.template.loc.end.offset = template.loc.start.offset + endTagOffset;
30
+ template.content = templateText.slice(0, endTagOffset);
31
+ }
32
+ }
33
+ }
34
+ return sfc;
20
35
  },
21
36
  updateSFC(sfc, change) {
22
37
  const blocks = [
@@ -4,7 +4,7 @@ const muggle_string_1 = require("muggle-string");
4
4
  const shared_1 = require("./shared");
5
5
  const plugin = () => {
6
6
  return {
7
- version: 2.1,
7
+ version: 2.2,
8
8
  getEmbeddedCodes() {
9
9
  return [{
10
10
  id: 'root_tags',
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plugin = ({ modules }) => {
4
4
  return {
5
- version: 2.1,
5
+ version: 2.2,
6
6
  compileSFCScript(lang, script) {
7
7
  if (lang === 'js' || lang === 'ts' || lang === 'jsx' || lang === 'tsx') {
8
8
  const ts = modules.typescript;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
- version: 2.1,
6
+ version: 2.2,
7
7
  getEmbeddedCodes(_fileName, sfc) {
8
8
  return sfc.customBlocks.map((customBlock, i) => ({
9
9
  id: 'custom_block_' + i,