@vue/language-core 3.0.4 → 3.0.5

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.
@@ -25,15 +25,16 @@ declare const raw: {
25
25
  navigation: {
26
26
  navigation: true;
27
27
  };
28
+ navigationWithoutHighlight: {
29
+ navigation: {
30
+ shouldHighlight: () => false;
31
+ };
32
+ };
28
33
  navigationWithoutRename: {
29
34
  navigation: {
30
35
  shouldRename: () => false;
31
36
  };
32
37
  };
33
- navigationAndCompletion: {
34
- navigation: true;
35
- completion: true;
36
- };
37
38
  navigationAndAdditionalCompletion: {
38
39
  navigation: true;
39
40
  completion: {
@@ -62,13 +63,6 @@ declare const raw: {
62
63
  navigation: true;
63
64
  completion: true;
64
65
  };
65
- withoutHighlightAndNavigation: {
66
- semantic: {
67
- shouldHighlight: () => false;
68
- };
69
- verification: true;
70
- completion: true;
71
- };
72
66
  withoutHighlightAndCompletion: {
73
67
  semantic: {
74
68
  shouldHighlight: () => false;
@@ -76,12 +70,6 @@ declare const raw: {
76
70
  verification: true;
77
71
  navigation: true;
78
72
  };
79
- withoutHighlightAndCompletionAndNavigation: {
80
- semantic: {
81
- shouldHighlight: () => false;
82
- };
83
- verification: true;
84
- };
85
73
  withoutSemantic: {
86
74
  verification: true;
87
75
  navigation: true;
@@ -25,13 +25,12 @@ const raw = {
25
25
  navigation: {
26
26
  navigation: true,
27
27
  },
28
+ navigationWithoutHighlight: {
29
+ navigation: { shouldHighlight: () => false },
30
+ },
28
31
  navigationWithoutRename: {
29
32
  navigation: { shouldRename: () => false },
30
33
  },
31
- navigationAndCompletion: {
32
- navigation: true,
33
- completion: true,
34
- },
35
34
  navigationAndAdditionalCompletion: {
36
35
  navigation: true,
37
36
  completion: { isAdditional: true },
@@ -54,20 +53,11 @@ const raw = {
54
53
  navigation: true,
55
54
  completion: true,
56
55
  },
57
- withoutHighlightAndNavigation: {
58
- semantic: { shouldHighlight: () => false },
59
- verification: true,
60
- completion: true,
61
- },
62
56
  withoutHighlightAndCompletion: {
63
57
  semantic: { shouldHighlight: () => false },
64
58
  verification: true,
65
59
  navigation: true,
66
60
  },
67
- withoutHighlightAndCompletionAndNavigation: {
68
- semantic: { shouldHighlight: () => false },
69
- verification: true,
70
- },
71
61
  withoutSemantic: {
72
62
  verification: true,
73
63
  navigation: true,
@@ -1,11 +1,5 @@
1
1
  import type { InlayHintInfo } from '../inlayHints';
2
2
  import type { ScriptCodegenOptions } from './index';
3
- export interface HelperType {
4
- name: string;
5
- used?: boolean;
6
- generated?: boolean;
7
- code: string;
8
- }
9
3
  export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>;
10
4
  export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
11
5
  generatedTemplate: boolean;
@@ -4,6 +4,7 @@ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
4
4
  import type { Code, Sfc, VueCompilerOptions } from '../../types';
5
5
  import type { TemplateCodegenContext } from '../template/context';
6
6
  import { type ScriptCodegenContext } from './context';
7
+ export * from './context';
7
8
  export interface ScriptCodegenOptions {
8
9
  ts: typeof ts;
9
10
  compilerOptions: ts.CompilerOptions;
@@ -19,5 +20,5 @@ export interface ScriptCodegenOptions {
19
20
  destructuredPropNames: Set<string>;
20
21
  templateRefNames: Set<string>;
21
22
  }
22
- export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
23
+ export declare function generateScript(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
23
24
  export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
@@ -1,4 +1,18 @@
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.generateScript = generateScript;
4
18
  exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
@@ -6,12 +20,11 @@ const path = require("path-browserify");
6
20
  const codeFeatures_1 = require("../codeFeatures");
7
21
  const utils_1 = require("../utils");
8
22
  const componentSelf_1 = require("./componentSelf");
9
- const context_1 = require("./context");
10
23
  const scriptSetup_1 = require("./scriptSetup");
11
24
  const src_1 = require("./src");
12
25
  const template_1 = require("./template");
13
- function* generateScript(options) {
14
- const ctx = (0, context_1.createScriptCodegenContext)(options);
26
+ __exportStar(require("./context"), exports);
27
+ function* generateScript(options, ctx) {
15
28
  yield* generateGlobalTypesPath(options);
16
29
  if (options.sfc.script?.src) {
17
30
  yield* (0, src_1.generateSrc)(options.sfc.script.src);
@@ -93,7 +106,6 @@ function* generateScript(options) {
93
106
  if (options.sfc.scriptSetup) {
94
107
  yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures_1.codeFeatures.verification];
95
108
  }
96
- return ctx;
97
109
  }
98
110
  function* generateGlobalTypesPath(options) {
99
111
  const globalTypesPath = options.vueCompilerOptions.globalTypesPath(options.fileName);
@@ -400,7 +400,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
400
400
  yield* generateDefineModelType(scriptSetup, propName, localName, defineModel);
401
401
  yield `,${utils_1.newLine}`;
402
402
  if (defineModel.modifierType) {
403
- const modifierName = `${defineModel.name ? propName : 'model'}Modifiers`;
403
+ const modifierName = `${propName === 'modelValue' ? 'model' : propName}Modifiers`;
404
404
  const modifierType = getRangeText(scriptSetup, defineModel.modifierType);
405
405
  yield `'${modifierName}'?: Partial<Record<${modifierType}, true>>,${utils_1.newLine}`;
406
406
  }
@@ -112,28 +112,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
112
112
  offset: number;
113
113
  };
114
114
  };
115
- codeFeatures: {
116
- all: VueCodeInformation;
117
- verification: VueCodeInformation;
118
- completion: VueCodeInformation;
119
- additionalCompletion: VueCodeInformation;
120
- withoutCompletion: VueCodeInformation;
121
- navigation: VueCodeInformation;
122
- navigationWithoutRename: VueCodeInformation;
123
- navigationAndCompletion: VueCodeInformation;
124
- navigationAndAdditionalCompletion: VueCodeInformation;
125
- navigationAndVerification: VueCodeInformation;
126
- withoutNavigation: VueCodeInformation;
127
- semanticWithoutHighlight: VueCodeInformation;
128
- withoutHighlight: VueCodeInformation;
129
- withoutHighlightAndNavigation: VueCodeInformation;
130
- withoutHighlightAndCompletion: VueCodeInformation;
131
- withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
132
- withoutSemantic: VueCodeInformation;
133
- doNotReportTs2339AndTs2551: VueCodeInformation;
134
- doNotReportTs2353AndTs2561: VueCodeInformation;
135
- doNotReportTs6133: VueCodeInformation;
136
- };
137
115
  resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
138
116
  inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
139
117
  inVFor: boolean;
@@ -154,12 +154,6 @@ function createTemplateCodegenContext(options, templateAst) {
154
154
  get currentInfo() {
155
155
  return stack[stack.length - 1];
156
156
  },
157
- codeFeatures: new Proxy(codeFeatures_1.codeFeatures, {
158
- get(target, key) {
159
- const data = target[key];
160
- return resolveCodeFeatures(data);
161
- },
162
- }),
163
157
  resolveCodeFeatures,
164
158
  inlineTsAsts: templateAst && computedSfc_1.templateInlineTsAsts.get(templateAst),
165
159
  inVFor: false,
@@ -76,12 +76,12 @@ function* generateComponent(options, ctx, node) {
76
76
  componentOriginalVar,
77
77
  'template',
78
78
  tagOffset,
79
- ctx.codeFeatures.withoutHighlightAndCompletion,
79
+ codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
80
80
  ];
81
81
  }
82
82
  else {
83
83
  const shouldCapitalize = matchImportName[0].toUpperCase() === matchImportName[0];
84
- yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
84
+ yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
85
85
  }
86
86
  yield `, `;
87
87
  }
@@ -89,10 +89,10 @@ function* generateComponent(options, ctx, node) {
89
89
  }
90
90
  else if (dynamicTagInfo) {
91
91
  yield `const ${componentOriginalVar} = (`;
92
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0], `(`, `)`);
92
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0], `(`, `)`);
93
93
  if (dynamicTagInfo.offsets[1] !== undefined) {
94
94
  yield `,`;
95
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], `(`, `)`);
95
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], `(`, `)`);
96
96
  }
97
97
  yield `)${utils_1.endOfLine}`;
98
98
  }
@@ -110,12 +110,12 @@ function* generateComponent(options, ctx, node) {
110
110
  .map(name => `'${name}'`)
111
111
  .join(`, `);
112
112
  yield `>).`;
113
- yield* generateCanonicalComponentName(node.tag, tagOffsets[0], ctx.resolveCodeFeatures({
113
+ yield* generateCanonicalComponentName(node.tag, tagOffsets[0], {
114
114
  ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
115
115
  ...options.vueCompilerOptions.checkUnknownComponents
116
116
  ? codeFeatures_1.codeFeatures.verification
117
117
  : codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
118
- }));
118
+ });
119
119
  yield `${utils_1.endOfLine}`;
120
120
  const camelizedTag = (0, shared_1.camelize)(node.tag);
121
121
  if (utils_1.identifierRegex.test(camelizedTag)) {
@@ -145,11 +145,11 @@ function* generateComponent(options, ctx, node) {
145
145
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
146
146
  yield `}))${utils_1.endOfLine}`;
147
147
  yield `const `;
148
- yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.doNotReportTs6133, componentVNodeVar);
148
+ yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, codeFeatures_1.codeFeatures.doNotReportTs6133, componentVNodeVar);
149
149
  yield ` = ${componentFunctionalVar}`;
150
150
  yield* generateComponentGeneric(ctx);
151
151
  yield `(`;
152
- yield* (0, wrapWith_1.wrapWith)(tagOffsets[0], tagOffsets[0] + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
152
+ yield* (0, wrapWith_1.wrapWith)(tagOffsets[0], tagOffsets[0] + node.tag.length, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
153
153
  yield `, ...__VLS_functionalComponentArgsRest(${componentFunctionalVar}))${utils_1.endOfLine}`;
154
154
  yield* generateFailedPropExps(options, ctx, failedPropExps);
155
155
  yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar);
@@ -192,14 +192,18 @@ function* generateElement(options, ctx, node) {
192
192
  ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
193
193
  : undefined;
194
194
  const failedPropExps = [];
195
+ const features = {
196
+ ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
197
+ ...codeFeatures_1.codeFeatures.navigationWithoutHighlight,
198
+ };
195
199
  yield `__VLS_asFunctionalElement(__VLS_elements`;
196
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
200
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, features);
197
201
  if (endTagOffset !== undefined) {
198
202
  yield `, __VLS_elements`;
199
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
203
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, features);
200
204
  }
201
205
  yield `)(`;
202
- yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
206
+ yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
203
207
  yield `)${utils_1.endOfLine}`;
204
208
  yield* generateFailedPropExps(options, ctx, failedPropExps);
205
209
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
@@ -225,7 +229,7 @@ function* generateElement(options, ctx, node) {
225
229
  }
226
230
  function* generateFailedPropExps(options, ctx, failedPropExps) {
227
231
  for (const failedExp of failedPropExps) {
228
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.prefix, failedExp.suffix);
232
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.prefix, failedExp.suffix);
229
233
  yield utils_1.endOfLine;
230
234
  }
231
235
  }
@@ -258,11 +262,11 @@ function* generateCanonicalComponentName(tagText, offset, features) {
258
262
  function* generateComponentGeneric(ctx) {
259
263
  if (ctx.currentInfo.generic) {
260
264
  const { content, offset } = ctx.currentInfo.generic;
261
- yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
265
+ yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, codeFeatures_1.codeFeatures.verification, `<`, [
262
266
  content,
263
267
  'template',
264
268
  offset,
265
- ctx.codeFeatures.all,
269
+ codeFeatures_1.codeFeatures.all,
266
270
  ], `>`);
267
271
  }
268
272
  }
@@ -274,7 +278,7 @@ function* generateElementReference(options, ctx, node) {
274
278
  const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
275
279
  // navigation support for `const foo = ref()`
276
280
  yield `/** @type {typeof __VLS_ctx`;
277
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation);
281
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, codeFeatures_1.codeFeatures.navigation);
278
282
  yield `} */${utils_1.endOfLine}`;
279
283
  if (utils_1.identifierRegex.test(content) && !options.templateRefNames.has(content)) {
280
284
  ctx.accessExternalVariable(content, startOffset);
@@ -30,16 +30,16 @@ function* generateElementDirectives(options, ctx, node) {
30
30
  continue;
31
31
  }
32
32
  ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
33
- yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_asFunctionalDirective(`, ...generateIdentifier(options, ctx, prop), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...generateArg(options, ctx, prop), ...generateModifiers(options, ctx, prop), ...generateValue(options, ctx, prop), ` }, null!, null!)`);
33
+ yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, `__VLS_asFunctionalDirective(`, ...generateIdentifier(options, prop), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...generateArg(options, ctx, prop), ...generateModifiers(options, ctx, prop), ...generateValue(options, ctx, prop), ` }, null!, null!)`);
34
34
  yield utils_1.endOfLine;
35
35
  }
36
36
  }
37
- function* generateIdentifier(options, ctx, prop) {
37
+ function* generateIdentifier(options, prop) {
38
38
  const rawName = 'v-' + prop.name;
39
- yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, ctx.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, ctx.resolveCodeFeatures({
39
+ yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, codeFeatures_1.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, {
40
40
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
41
41
  verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
42
- })));
42
+ }));
43
43
  }
44
44
  function* generateArg(options, ctx, prop) {
45
45
  const { arg } = prop;
@@ -47,13 +47,13 @@ function* generateArg(options, ctx, prop) {
47
47
  return;
48
48
  }
49
49
  const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
50
- yield* (0, wrapWith_1.wrapWith)(startOffset, startOffset + arg.content.length, ctx.codeFeatures.verification, `arg`);
50
+ yield* (0, wrapWith_1.wrapWith)(startOffset, startOffset + arg.content.length, codeFeatures_1.codeFeatures.verification, `arg`);
51
51
  yield `: `;
52
52
  if (arg.isStatic) {
53
- yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, ctx.codeFeatures.all);
53
+ yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, codeFeatures_1.codeFeatures.all);
54
54
  }
55
55
  else {
56
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, arg.content, startOffset, `(`, `)`);
56
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, arg.content, startOffset, `(`, `)`);
57
57
  }
58
58
  yield `, `;
59
59
  }
@@ -64,10 +64,10 @@ function* generateModifiers(options, ctx, prop, propertyName = 'modifiers') {
64
64
  }
65
65
  const startOffset = modifiers[0].loc.start.offset - 1;
66
66
  const endOffset = modifiers.at(-1).loc.end.offset;
67
- yield* (0, wrapWith_1.wrapWith)(startOffset, endOffset, ctx.codeFeatures.verification, propertyName);
67
+ yield* (0, wrapWith_1.wrapWith)(startOffset, endOffset, codeFeatures_1.codeFeatures.verification, propertyName);
68
68
  yield `: { `;
69
69
  for (const mod of modifiers) {
70
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, ctx.codeFeatures.withoutHighlightAndNavigation);
70
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlight);
71
71
  yield `: true, `;
72
72
  }
73
73
  yield `}, `;
@@ -77,7 +77,7 @@ function* generateValue(options, ctx, prop) {
77
77
  if (exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
78
78
  return;
79
79
  }
80
- yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `value`);
80
+ yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `value`);
81
81
  yield `: `;
82
82
  yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
83
83
  }
@@ -4,7 +4,7 @@ import type { Code, VueCodeInformation } 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, componentOriginalVar: string, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
7
- export declare function generateEventArg(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
7
+ export declare function generateEventArg(options: TemplateCodegenOptions, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
8
8
  export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
9
9
  export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
10
10
  export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
@@ -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
  }
@@ -83,7 +96,7 @@ function* generateInheritedAttrs(options, ctx) {
83
96
  loc.source,
84
97
  'template',
85
98
  loc.start.offset,
86
- ctx.codeFeatures.all,
99
+ codeFeatures_1.codeFeatures.all,
87
100
  ];
88
101
  yield `,`;
89
102
  }
@@ -104,7 +117,7 @@ function* generateTemplateRefs(options, ctx) {
104
117
  yield ` | `;
105
118
  }
106
119
  yield `{ `;
107
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigation);
120
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, codeFeatures_1.codeFeatures.navigation);
108
121
  yield `: ${typeExp} }`;
109
122
  }
110
123
  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,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSlotOutlet = generateSlotOutlet;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const codeFeatures_1 = require("../codeFeatures");
5
6
  const inlayHints_1 = require("../inlayHints");
6
7
  const utils_1 = require("../utils");
7
8
  const wrapWith_1 = require("../utils/wrapWith");
@@ -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
  }
@@ -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
  }
@@ -0,0 +1,12 @@
1
+ import type * as ts from 'typescript';
2
+ import type { TextRange } from '../types';
3
+ export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
4
+ range: TextRange;
5
+ moduleName?: string;
6
+ isDefaultImport?: boolean;
7
+ isNamespace?: boolean;
8
+ }[];
9
+ export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
10
+ start: number;
11
+ end: number;
12
+ } | undefined;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseBindingRanges = parseBindingRanges;
4
+ exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
5
+ const collectBindings_1 = require("../utils/collectBindings");
6
+ const shared_1 = require("../utils/shared");
7
+ function parseBindingRanges(ts, ast) {
8
+ const bindings = [];
9
+ ts.forEachChild(ast, node => {
10
+ if (ts.isVariableStatement(node)) {
11
+ for (const decl of node.declarationList.declarations) {
12
+ const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
13
+ bindings.push(...ranges.map(range => ({ range })));
14
+ }
15
+ }
16
+ else if (ts.isFunctionDeclaration(node)) {
17
+ if (node.name && ts.isIdentifier(node.name)) {
18
+ bindings.push({
19
+ range: _getStartEnd(node.name),
20
+ });
21
+ }
22
+ }
23
+ else if (ts.isClassDeclaration(node)) {
24
+ if (node.name) {
25
+ bindings.push({
26
+ range: _getStartEnd(node.name),
27
+ });
28
+ }
29
+ }
30
+ else if (ts.isEnumDeclaration(node)) {
31
+ bindings.push({
32
+ range: _getStartEnd(node.name),
33
+ });
34
+ }
35
+ if (ts.isImportDeclaration(node)) {
36
+ const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
37
+ if (node.importClause && !node.importClause.isTypeOnly) {
38
+ const { name, namedBindings } = node.importClause;
39
+ if (name) {
40
+ bindings.push({
41
+ range: _getStartEnd(name),
42
+ moduleName,
43
+ isDefaultImport: true,
44
+ });
45
+ }
46
+ if (namedBindings) {
47
+ if (ts.isNamedImports(namedBindings)) {
48
+ for (const element of namedBindings.elements) {
49
+ if (element.isTypeOnly) {
50
+ continue;
51
+ }
52
+ bindings.push({
53
+ range: _getStartEnd(element.name),
54
+ moduleName,
55
+ isDefaultImport: element.propertyName?.text === 'default',
56
+ });
57
+ }
58
+ }
59
+ else {
60
+ bindings.push({
61
+ range: _getStartEnd(namedBindings.name),
62
+ moduleName,
63
+ isNamespace: true,
64
+ });
65
+ }
66
+ }
67
+ }
68
+ }
69
+ });
70
+ return bindings;
71
+ function _getStartEnd(node) {
72
+ return (0, shared_1.getStartEnd)(ts, node, ast);
73
+ }
74
+ function _getNodeText(node) {
75
+ return (0, shared_1.getNodeText)(ts, node, ast);
76
+ }
77
+ }
78
+ function getClosestMultiLineCommentRange(ts, node, parents, ast) {
79
+ for (let i = parents.length - 1; i >= 0; i--) {
80
+ if (ts.isStatement(node)) {
81
+ break;
82
+ }
83
+ node = parents[i];
84
+ }
85
+ const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
86
+ ?.reverse()
87
+ .find(range => range.kind === 3);
88
+ if (comment) {
89
+ return {
90
+ start: comment.pos,
91
+ end: comment.end,
92
+ };
93
+ }
94
+ }
95
+ //# sourceMappingURL=utils.js.map
@@ -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 = [
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plugin = () => {
4
4
  return {
5
- version: 2.1,
5
+ version: 2.2,
6
6
  compileSFCStyle(_lang, style) {
7
7
  return {
8
8
  imports: [...parseCssImports(style)],
@@ -149,28 +149,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
149
149
  offset: number;
150
150
  };
151
151
  };
152
- codeFeatures: {
153
- all: import("../types").VueCodeInformation;
154
- verification: import("../types").VueCodeInformation;
155
- completion: import("../types").VueCodeInformation;
156
- additionalCompletion: import("../types").VueCodeInformation;
157
- withoutCompletion: import("../types").VueCodeInformation;
158
- navigation: import("../types").VueCodeInformation;
159
- navigationWithoutRename: import("../types").VueCodeInformation;
160
- navigationAndCompletion: import("../types").VueCodeInformation;
161
- navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
162
- navigationAndVerification: import("../types").VueCodeInformation;
163
- withoutNavigation: import("../types").VueCodeInformation;
164
- semanticWithoutHighlight: import("../types").VueCodeInformation;
165
- withoutHighlight: import("../types").VueCodeInformation;
166
- withoutHighlightAndNavigation: import("../types").VueCodeInformation;
167
- withoutHighlightAndCompletion: import("../types").VueCodeInformation;
168
- withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
169
- withoutSemantic: import("../types").VueCodeInformation;
170
- doNotReportTs2339AndTs2551: import("../types").VueCodeInformation;
171
- doNotReportTs2353AndTs2561: import("../types").VueCodeInformation;
172
- doNotReportTs6133: import("../types").VueCodeInformation;
173
- };
174
152
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
175
153
  inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
176
154
  inVFor: boolean;
@@ -144,8 +144,7 @@ function createTsx(fileName, sfc, ctx) {
144
144
  if (getResolvedOptions().skipTemplateCodegen || !sfc.template) {
145
145
  return;
146
146
  }
147
- const codes = [];
148
- const codegen = (0, template_1.generateTemplate)({
147
+ const options = {
149
148
  ts,
150
149
  compilerOptions: ctx.compilerOptions,
151
150
  vueCompilerOptions: getResolvedOptions(),
@@ -159,21 +158,23 @@ function createTsx(fileName, sfc, ctx) {
159
158
  propsAssignName: getSetupPropsAssignName(),
160
159
  inheritAttrs: getSetupInheritAttrs(),
161
160
  selfComponentName: getComponentSelfName(),
162
- });
163
- let current = codegen.next();
164
- while (!current.done) {
165
- const code = current.value;
161
+ };
162
+ const context = (0, template_1.createTemplateCodegenContext)(options, sfc.template.ast);
163
+ const codegen = (0, template_1.generateTemplate)(options, context);
164
+ const codes = [];
165
+ for (const code of codegen) {
166
+ if (typeof code === 'object') {
167
+ code[3] = context.resolveCodeFeatures(code[3]);
168
+ }
166
169
  codes.push(code);
167
- current = codegen.next();
168
170
  }
169
171
  return {
170
- ...current.value,
172
+ ...context,
171
173
  codes,
172
174
  };
173
175
  });
174
176
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
175
- const codes = [];
176
- const codegen = (0, script_1.generateScript)({
177
+ const options = {
177
178
  ts,
178
179
  compilerOptions: ctx.compilerOptions,
179
180
  vueCompilerOptions: getResolvedOptions(),
@@ -185,16 +186,12 @@ function createTsx(fileName, sfc, ctx) {
185
186
  templateCodegen: getGeneratedTemplate(),
186
187
  destructuredPropNames: getSetupDestructuredPropNames(),
187
188
  templateRefNames: getSetupTemplateRefNames(),
188
- });
189
- let current = codegen.next();
190
- while (!current.done) {
191
- const code = current.value;
192
- codes.push(code);
193
- current = codegen.next();
194
- }
189
+ };
190
+ const context = (0, script_1.createScriptCodegenContext)(options);
191
+ const codegen = (0, script_1.generateScript)(options, context);
195
192
  return {
196
- ...current.value,
197
- codes,
193
+ ...context,
194
+ codes: [...codegen],
198
195
  };
199
196
  });
200
197
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "2.4.20",
16
+ "@volar/language-core": "2.4.22",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
18
  "@vue/compiler-vue2": "^2.7.16",
19
19
  "@vue/shared": "^3.5.0",
@@ -26,7 +26,7 @@
26
26
  "@types/node": "^22.10.4",
27
27
  "@types/path-browserify": "^1.0.1",
28
28
  "@types/picomatch": "^4.0.0",
29
- "@volar/typescript": "2.4.20",
29
+ "@volar/typescript": "2.4.22",
30
30
  "@vue/compiler-sfc": "^3.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "148d386f9779c2de64cdcbd35310e03b36943b05"
40
+ "gitHead": "036b6b1882179d35586e16f2a5cba5150e5d18e6"
41
41
  }