@vue/language-core 3.1.3 → 3.1.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.
Files changed (47) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/lib/codegen/globalTypes.js +4 -3
  4. package/lib/codegen/script/component.js +1 -1
  5. package/lib/codegen/script/index.js +17 -10
  6. package/lib/codegen/script/scriptSetup.js +2 -2
  7. package/lib/codegen/script/src.js +1 -1
  8. package/lib/codegen/style/classProperty.js +1 -1
  9. package/lib/codegen/style/imports.js +1 -1
  10. package/lib/codegen/template/context.d.ts +3 -3
  11. package/lib/codegen/template/context.js +8 -4
  12. package/lib/codegen/template/element.js +30 -17
  13. package/lib/codegen/template/elementDirectives.js +5 -5
  14. package/lib/codegen/template/elementEvents.d.ts +1 -1
  15. package/lib/codegen/template/elementEvents.js +4 -8
  16. package/lib/codegen/template/elementProps.d.ts +2 -2
  17. package/lib/codegen/template/elementProps.js +38 -83
  18. package/lib/codegen/template/index.d.ts +7 -9
  19. package/lib/codegen/template/index.js +2 -37
  20. package/lib/codegen/template/interpolation.js +38 -39
  21. package/lib/codegen/template/objectProperty.js +1 -1
  22. package/lib/codegen/template/slotOutlet.js +5 -10
  23. package/lib/codegen/template/styleScopedClasses.js +8 -8
  24. package/lib/codegen/template/templateChild.js +5 -12
  25. package/lib/codegen/template/vIf.js +5 -7
  26. package/lib/codegen/template/vSlot.js +3 -4
  27. package/lib/codegen/utils/index.d.ts +0 -2
  28. package/lib/codegen/utils/index.js +0 -11
  29. package/lib/codegen/utils/stringLiteralKey.js +1 -1
  30. package/lib/codegen/utils/unicode.js +1 -1
  31. package/lib/codegen/utils/wrapWith.d.ts +1 -2
  32. package/lib/codegen/utils/wrapWith.js +1 -10
  33. package/lib/compilerOptions.d.ts +2 -5
  34. package/lib/compilerOptions.js +43 -66
  35. package/lib/languagePlugin.js +16 -23
  36. package/lib/plugins/vue-template-html.js +12 -9
  37. package/lib/plugins/vue-template-inline-css.js +10 -16
  38. package/lib/plugins/vue-tsx.d.ts +3 -3
  39. package/lib/plugins/vue-tsx.js +0 -1
  40. package/lib/utils/forEachTemplateNode.d.ts +3 -0
  41. package/lib/utils/forEachTemplateNode.js +68 -0
  42. package/lib/utils/parseSfc.js +5 -10
  43. package/lib/utils/shared.d.ts +1 -0
  44. package/lib/utils/shared.js +8 -0
  45. package/lib/virtualFile/computedSfc.d.ts +1 -1
  46. package/lib/virtualFile/computedSfc.js +6 -2
  47. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './lib/parsers/scriptSetupRanges';
6
6
  export * from './lib/plugins';
7
7
  export * from './lib/types';
8
8
  export * from './lib/utils/collectBindings';
9
+ export * from './lib/utils/forEachTemplateNode';
9
10
  export * from './lib/utils/parseSfc';
10
11
  export * from './lib/utils/shared';
11
12
  export * from './lib/virtualFile/vueFile';
package/index.js CHANGED
@@ -23,6 +23,7 @@ __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
23
23
  __exportStar(require("./lib/plugins"), exports);
24
24
  __exportStar(require("./lib/types"), exports);
25
25
  __exportStar(require("./lib/utils/collectBindings"), exports);
26
+ __exportStar(require("./lib/utils/forEachTemplateNode"), exports);
26
27
  __exportStar(require("./lib/utils/parseSfc"), exports);
27
28
  __exportStar(require("./lib/utils/shared"), exports);
28
29
  __exportStar(require("./lib/virtualFile/vueFile"), exports);
@@ -11,7 +11,6 @@ function getGlobalTypesFileName(options) {
11
11
  }
12
12
  function generateGlobalTypes(options) {
13
13
  const { lib, target, checkUnknownProps } = options;
14
- const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
15
14
  let text = `// @ts-nocheck\nexport {};\n`;
16
15
  if (target < 3.5) {
17
16
  text += `
@@ -22,6 +21,8 @@ function generateGlobalTypes(options) {
22
21
  }
23
22
  text += `
24
23
  ; declare global {
24
+ ${checkUnknownProps ? '' : 'var __VLS_PROPS_FALLBACK: Record<string, unknown>;'}
25
+
25
26
  const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
26
27
  const __VLS_unref: typeof import('${lib}').unref;
27
28
  const __VLS_placeholder: any;
@@ -54,14 +55,14 @@ function generateGlobalTypes(options) {
54
55
  ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
55
56
  : T extends (props: infer P, ...args: any) => any ? P
56
57
  : {};
57
- type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => ${target >= 3.3
58
+ type __VLS_FunctionalComponent<T> = (props: (T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}, ctx?: any) => ${target >= 3.3
58
59
  ? `import('${lib}/jsx-runtime').JSX.Element`
59
60
  : `globalThis.JSX.Element`} & {
60
61
  __ctx?: {
61
62
  attrs?: any;
62
63
  slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>;
63
64
  emit?: T extends { $emit: infer Emit } ? Emit : {};
64
- props?: ${fnPropsType};
65
+ props?: typeof props;
65
66
  expose?: (exposed: T) => void;
66
67
  };
67
68
  };
@@ -48,7 +48,7 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
48
48
  }
49
49
  if (options.vueCompilerOptions.target >= 3.5
50
50
  && options.vueCompilerOptions.inferComponentDollarEl
51
- && options.templateCodegen?.singleRootElTypes.length) {
51
+ && options.templateCodegen?.singleRootElTypes.size) {
52
52
  yield `__typeEl: {} as __VLS_RootEl,${utils_1.newLine}`;
53
53
  }
54
54
  if (options.sfc.script && options.scriptRanges?.componentOptions?.args) {
@@ -107,7 +107,7 @@ function* generateConstExport(options, block) {
107
107
  yield* (0, utils_1.generatePartiallyEnding)(options.sfc.script.name, options.scriptRanges?.exportDefault?.start ?? options.sfc.script.content.length, '#3632/script.vue');
108
108
  }
109
109
  yield `const `;
110
- yield* (0, wrapWith_1.wrapWith)(0, block.content.length, block.name, codeFeatures_1.codeFeatures.doNotReportTs6133, `__VLS_export`);
110
+ yield* (0, wrapWith_1.wrapWith)(block.name, 0, block.content.length, codeFeatures_1.codeFeatures.doNotReportTs6133, `__VLS_export`);
111
111
  yield ` = `;
112
112
  }
113
113
  function* generateExportDefault(options) {
@@ -115,19 +115,26 @@ function* generateExportDefault(options) {
115
115
  yield* (0, src_1.generateSrc)(options.sfc.script.src);
116
116
  return;
117
117
  }
118
- let prefix;
119
- let suffix;
118
+ const expression = `{} as typeof __VLS_export`;
120
119
  if (options.sfc.script && options.scriptRanges?.exportDefault) {
121
120
  const { exportDefault, componentOptions } = options.scriptRanges;
122
- prefix = (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.start, (componentOptions ?? exportDefault).expression.start, codeFeatures_1.codeFeatures.all);
123
- suffix = (0, utils_1.generateSfcBlockSection)(options.sfc.script, (componentOptions ?? exportDefault).expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
121
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.start, (componentOptions ?? exportDefault).expression.start, codeFeatures_1.codeFeatures.all);
122
+ yield expression;
123
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, (componentOptions ?? exportDefault).expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
124
124
  }
125
125
  else {
126
- prefix = `export default `;
127
- suffix = utils_1.endOfLine;
126
+ yield `export `;
127
+ if (options.sfc.template) {
128
+ for (let i = 0; i < 'template'.length + 1; i++) {
129
+ yield [
130
+ ``,
131
+ 'main',
132
+ options.sfc.template.start + 1 + i,
133
+ i ? { __combineOffset: i } : codeFeatures_1.codeFeatures.navigationWithoutRename,
134
+ ];
135
+ }
136
+ }
137
+ yield `default ${expression}${utils_1.endOfLine}`;
128
138
  }
129
- yield prefix;
130
- yield `{} as typeof __VLS_export`;
131
- yield suffix;
132
139
  }
133
140
  //# sourceMappingURL=index.js.map
@@ -71,7 +71,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
71
71
  ? `import('${options.vueCompilerOptions.lib}').VNodeProps`
72
72
  + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
73
73
  + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
74
- : `globalThis.JSX.IntrinsicAttributes`}${utils_1.endOfLine}`
74
+ : `globalThis.JSX.IntrinsicAttributes`} & (typeof globalThis extends { __VLS_PROPS_FALLBACK: infer P } ? P : {})${utils_1.endOfLine}`
75
75
  + ` expose: (exposed: ${scriptSetupRanges.defineExpose
76
76
  ? `import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<typeof __VLS_exposed>`
77
77
  : `{}`}) => void${utils_1.endOfLine}`
@@ -174,7 +174,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
174
174
  ]
175
175
  : [
176
176
  ` as __VLS_StyleModules[`,
177
- ...(0, wrapWith_1.wrapWith)(exp.start, exp.end, scriptSetup.name, codeFeatures_1.codeFeatures.verification, `'$style'`),
177
+ ...(0, wrapWith_1.wrapWith)(scriptSetup.name, exp.start, exp.end, codeFeatures_1.codeFeatures.verification, `'$style'`),
178
178
  `])`,
179
179
  ],
180
180
  callExp.end,
@@ -22,7 +22,7 @@ function* generateSrc(src) {
22
22
  text = text + '.js';
23
23
  }
24
24
  yield `export * from `;
25
- yield* (0, wrapWith_1.wrapWith)(src.offset, src.offset + src.text.length, 'main', {
25
+ yield* (0, wrapWith_1.wrapWith)('main', src.offset, src.offset + src.text.length, {
26
26
  ...codeFeatures_1.codeFeatures.all,
27
27
  ...text !== src.text ? codeFeatures_1.codeFeatures.navigationWithoutRename : {},
28
28
  }, `'`, [text.slice(0, src.text.length), 'main', src.offset, utils_1.combineLastMapping], text.slice(src.text.length), `'`);
@@ -6,7 +6,7 @@ const utils_1 = require("../utils");
6
6
  const wrapWith_1 = require("../utils/wrapWith");
7
7
  function* generateClassProperty(styleIndex, classNameWithDot, offset, propertyType) {
8
8
  yield `${utils_1.newLine} & { `;
9
- yield* (0, wrapWith_1.wrapWith)(offset, offset + classNameWithDot.length, 'style_' + styleIndex, codeFeatures_1.codeFeatures.navigation, `'`, [
9
+ yield* (0, wrapWith_1.wrapWith)('style_' + styleIndex, offset, offset + classNameWithDot.length, codeFeatures_1.codeFeatures.navigation, `'`, [
10
10
  classNameWithDot.slice(1),
11
11
  'style_' + styleIndex,
12
12
  offset + 1,
@@ -10,7 +10,7 @@ function* generateStyleImports(style) {
10
10
  };
11
11
  if (typeof style.src === 'object') {
12
12
  yield `${utils_1.newLine} & typeof import(`;
13
- yield* (0, wrapWith_1.wrapWith)(style.src.offset, style.src.offset + style.src.text.length, 'main', features, `'`, [style.src.text, 'main', style.src.offset, utils_1.combineLastMapping], `'`);
13
+ yield* (0, wrapWith_1.wrapWith)('main', style.src.offset, style.src.offset + style.src.text.length, features, `'`, [style.src.text, 'main', style.src.offset, utils_1.combineLastMapping], `'`);
14
14
  yield `).default`;
15
15
  }
16
16
  for (const { text, offset } of style.imports) {
@@ -143,10 +143,10 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
143
143
  offset: number;
144
144
  }[]>;
145
145
  currentComponent: {
146
- ctxVar: string;
147
- used: boolean;
146
+ get ctxVar(): string;
147
+ get propsVar(): string;
148
148
  } | undefined;
149
- singleRootElTypes: string[];
149
+ singleRootElTypes: Set<string>;
150
150
  singleRootNodes: Set<CompilerDOM.ElementNode | null>;
151
151
  addTemplateRef(name: string, typeExp: string, offset: number): void;
152
152
  accessExternalVariable(name: string, offset?: number): void;
@@ -125,8 +125,12 @@ function createTemplateCodegenContext(options, templateAst) {
125
125
  return {
126
126
  ...features,
127
127
  verification: {
128
- shouldReport: () => {
129
- data.expectError.token++;
128
+ shouldReport: (source, code) => {
129
+ if (typeof features.verification !== 'object'
130
+ || !features.verification.shouldReport
131
+ || features.verification.shouldReport(source, code) === true) {
132
+ data.expectError.token++;
133
+ }
130
134
  return false;
131
135
  },
132
136
  },
@@ -169,7 +173,7 @@ function createTemplateCodegenContext(options, templateAst) {
169
173
  inheritedAttrVars,
170
174
  templateRefs,
171
175
  currentComponent: undefined,
172
- singleRootElTypes: [],
176
+ singleRootElTypes: new Set(),
173
177
  singleRootNodes: new Set(),
174
178
  addTemplateRef(name, typeExp, offset) {
175
179
  let refs = templateRefs.get(name);
@@ -304,7 +308,7 @@ function createTemplateCodegenContext(options, templateAst) {
304
308
  const data = stack.pop();
305
309
  commentBuffer.length = 0;
306
310
  if (data.expectError !== undefined) {
307
- yield* (0, wrapWith_1.wrapWith)(data.expectError.node.loc.start.offset, data.expectError.node.loc.end.offset, {
311
+ yield* (0, wrapWith_1.wrapWith)('template', data.expectError.node.loc.start.offset, data.expectError.node.loc.end.offset, {
308
312
  verification: {
309
313
  // If no errors/warnings/diagnostics were reported within the region of code covered
310
314
  // by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
@@ -4,6 +4,7 @@ exports.generateComponent = generateComponent;
4
4
  exports.generateElement = generateElement;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const shared_1 = require("@vue/shared");
7
+ const muggle_string_1 = require("muggle-string");
7
8
  const shared_2 = require("../../utils/shared");
8
9
  const codeFeatures_1 = require("../codeFeatures");
9
10
  const inlayHints_1 = require("../inlayHints");
@@ -28,10 +29,19 @@ function* generateComponent(options, ctx, node) {
28
29
  const componentFunctionalVar = ctx.getInternalVariable();
29
30
  const componentVNodeVar = ctx.getInternalVariable();
30
31
  const componentCtxVar = ctx.getInternalVariable();
32
+ const componentPropsVar = ctx.getInternalVariable();
31
33
  const isComponentTag = node.tag.toLowerCase() === 'component';
34
+ let isCtxVarUsed = false;
35
+ let isPropsVarUsed = false;
32
36
  ctx.currentComponent = {
33
- ctxVar: componentCtxVar,
34
- used: false,
37
+ get ctxVar() {
38
+ isCtxVarUsed = true;
39
+ return componentCtxVar;
40
+ },
41
+ get propsVar() {
42
+ isPropsVarUsed = true;
43
+ return componentPropsVar;
44
+ },
35
45
  };
36
46
  let props = node.props;
37
47
  let dynamicTagInfo;
@@ -132,19 +142,20 @@ function* generateComponent(options, ctx, node) {
132
142
  yield utils_1.endOfLine;
133
143
  }
134
144
  }
145
+ const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failedPropExps)];
135
146
  yield `// @ts-ignore${utils_1.newLine}`;
136
147
  yield `const ${componentFunctionalVar} = __VLS_asFunctionalComponent(${componentOriginalVar}, new ${componentOriginalVar}({${utils_1.newLine}`;
137
- yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
148
+ yield* (0, muggle_string_1.toString)(propCodes);
138
149
  yield `}))${utils_1.endOfLine}`;
139
150
  yield `const `;
140
- yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, codeFeatures_1.codeFeatures.doNotReportTs6133, componentVNodeVar);
151
+ yield* (0, wrapWith_1.wrapWith)('template', node.loc.start.offset, node.loc.end.offset, codeFeatures_1.codeFeatures.doNotReportTs6133, componentVNodeVar);
141
152
  yield ` = ${componentFunctionalVar}`;
142
153
  yield* generateComponentGeneric(ctx);
143
154
  yield `(`;
144
- 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), `}`);
155
+ yield* (0, wrapWith_1.wrapWith)('template', tagOffsets[0], tagOffsets[0] + node.tag.length, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...propCodes, `}`);
145
156
  yield `, ...__VLS_functionalComponentArgsRest(${componentFunctionalVar}))${utils_1.endOfLine}`;
146
157
  yield* generateFailedPropExps(options, ctx, failedPropExps);
147
- yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar);
158
+ yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar);
148
159
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
149
160
  const reference = yield* generateElementReference(options, ctx, node);
150
161
  const tag = (0, shared_2.hyphenateTag)(node.tag);
@@ -152,7 +163,7 @@ function* generateComponent(options, ctx, node) {
152
163
  && !options.vueCompilerOptions.fallthroughComponentNames.includes(tag);
153
164
  if (reference || isRootNode) {
154
165
  const componentInstanceVar = ctx.getInternalVariable();
155
- ctx.currentComponent.used = true;
166
+ isCtxVarUsed = true;
156
167
  yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${componentCtxVar}['expose']>>[0] | null)`;
157
168
  if (ctx.inVFor) {
158
169
  yield `[]`;
@@ -163,21 +174,22 @@ function* generateComponent(options, ctx, node) {
163
174
  ctx.addTemplateRef(reference.name, typeExp, reference.offset);
164
175
  }
165
176
  if (isRootNode) {
166
- ctx.singleRootElTypes.push(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
177
+ ctx.singleRootElTypes.add(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
167
178
  }
168
179
  }
169
180
  if (hasVBindAttrs(options, ctx, node)) {
170
- const attrsVar = ctx.getInternalVariable();
171
- ctx.currentComponent.used = true;
172
- yield `var ${attrsVar}!: NonNullable<typeof ${componentCtxVar}['props']>${utils_1.endOfLine}`;
173
- ctx.inheritedAttrVars.add(attrsVar);
181
+ ctx.inheritedAttrVars.add(componentPropsVar);
182
+ isPropsVarUsed = true;
174
183
  }
175
184
  (0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
176
185
  const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
177
186
  yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
178
- if (ctx.currentComponent.used) {
187
+ if (isCtxVarUsed) {
179
188
  yield `var ${componentCtxVar}!: __VLS_FunctionalComponentCtx<typeof ${componentOriginalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
180
189
  }
190
+ if (isPropsVarUsed) {
191
+ yield `var ${componentPropsVar}!: __VLS_FunctionalComponentProps<typeof ${componentOriginalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
192
+ }
181
193
  }
182
194
  function* generateElement(options, ctx, node) {
183
195
  const [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
@@ -189,7 +201,7 @@ function* generateElement(options, ctx, node) {
189
201
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
190
202
  }
191
203
  yield `)(`;
192
- 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), `}`);
204
+ yield* (0, wrapWith_1.wrapWith)('template', startTagOffset, startTagOffset + node.tag.length, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, failedPropExps), `}`);
193
205
  yield `)${utils_1.endOfLine}`;
194
206
  yield* generateFailedPropExps(options, ctx, failedPropExps);
195
207
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
@@ -202,7 +214,7 @@ function* generateElement(options, ctx, node) {
202
214
  ctx.addTemplateRef(reference.name, typeExp, reference.offset);
203
215
  }
204
216
  if (ctx.singleRootNodes.has(node)) {
205
- ctx.singleRootElTypes.push(`__VLS_Elements['${node.tag}']`);
217
+ ctx.singleRootElTypes.add(`__VLS_Elements['${node.tag}']`);
206
218
  }
207
219
  if (hasVBindAttrs(options, ctx, node)) {
208
220
  ctx.inheritedAttrVars.add(`__VLS_intrinsics.${node.tag}`);
@@ -248,7 +260,7 @@ function* generateCanonicalComponentName(tagText, offset, features) {
248
260
  function* generateComponentGeneric(ctx) {
249
261
  if (ctx.currentInfo.generic) {
250
262
  const { content, offset } = ctx.currentInfo.generic;
251
- yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, codeFeatures_1.codeFeatures.verification, `<`, [
263
+ yield* (0, wrapWith_1.wrapWith)('template', offset, offset + content.length, codeFeatures_1.codeFeatures.verification, `<`, [
252
264
  content,
253
265
  'template',
254
266
  offset,
@@ -261,7 +273,8 @@ function* generateElementReference(options, ctx, node) {
261
273
  if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
262
274
  && prop.name === 'ref'
263
275
  && prop.value) {
264
- const [name, offset] = (0, utils_1.normalizeAttributeValue)(prop.value);
276
+ const name = prop.value.content;
277
+ const offset = (0, shared_2.getAttributeValueOffset)(prop.value);
265
278
  // navigation support for `const foo = ref()`
266
279
  yield `/** @type {typeof __VLS_ctx`;
267
280
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, name, offset, codeFeatures_1.codeFeatures.navigation);
@@ -32,13 +32,13 @@ function* generateElementDirectives(options, ctx, node) {
32
32
  if (!builtInDirectives.has(prop.name)) {
33
33
  ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
34
34
  }
35
- 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!)`);
35
+ yield* (0, wrapWith_1.wrapWith)('template', 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!)`);
36
36
  yield utils_1.endOfLine;
37
37
  }
38
38
  }
39
39
  function* generateIdentifier(options, prop) {
40
40
  const rawName = 'v-' + prop.name;
41
- 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, {
41
+ yield* (0, wrapWith_1.wrapWith)('template', 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, {
42
42
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
43
43
  verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
44
44
  }));
@@ -49,7 +49,7 @@ function* generateArg(options, ctx, prop) {
49
49
  return;
50
50
  }
51
51
  const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
52
- yield* (0, wrapWith_1.wrapWith)(startOffset, startOffset + arg.content.length, codeFeatures_1.codeFeatures.verification, `arg`);
52
+ yield* (0, wrapWith_1.wrapWith)('template', startOffset, startOffset + arg.content.length, codeFeatures_1.codeFeatures.verification, `arg`);
53
53
  yield `: `;
54
54
  if (arg.isStatic) {
55
55
  yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, codeFeatures_1.codeFeatures.all);
@@ -66,7 +66,7 @@ function* generateModifiers(options, ctx, prop, propertyName = 'modifiers') {
66
66
  }
67
67
  const startOffset = modifiers[0].loc.start.offset - 1;
68
68
  const endOffset = modifiers.at(-1).loc.end.offset;
69
- yield* (0, wrapWith_1.wrapWith)(startOffset, endOffset, codeFeatures_1.codeFeatures.verification, propertyName);
69
+ yield* (0, wrapWith_1.wrapWith)('template', startOffset, endOffset, codeFeatures_1.codeFeatures.verification, propertyName);
70
70
  yield `: { `;
71
71
  for (const mod of modifiers) {
72
72
  yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlight);
@@ -79,7 +79,7 @@ function* generateValue(options, ctx, prop) {
79
79
  if (exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
80
80
  return;
81
81
  }
82
- yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `value`);
82
+ yield* (0, wrapWith_1.wrapWith)('template', exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `value`);
83
83
  yield `: `;
84
84
  yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
85
85
  }
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
3
3
  import type { Code, VueCodeInformation } from '../../types';
4
4
  import type { TemplateCodegenContext } from './context';
5
5
  import type { TemplateCodegenOptions } from './index';
6
- export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
6
+ export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string): Generator<Code>;
7
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>;
@@ -12,9 +12,8 @@ const utils_1 = require("../utils");
12
12
  const camelized_1 = require("../utils/camelized");
13
13
  const wrapWith_1 = require("../utils/wrapWith");
14
14
  const interpolation_1 = require("./interpolation");
15
- function* generateElementEvents(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
15
+ function* generateElementEvents(options, ctx, node, componentOriginalVar) {
16
16
  let emitsVar;
17
- let propsVar;
18
17
  for (const prop of node.props) {
19
18
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
20
19
  && (prop.name === 'on'
@@ -22,12 +21,9 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
22
21
  || options.vueCompilerOptions.strictVModel
23
22
  && prop.name === 'model'
24
23
  && (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
25
- ctx.currentComponent.used = true;
26
24
  if (!emitsVar) {
27
25
  emitsVar = ctx.getInternalVariable();
28
- propsVar = ctx.getInternalVariable();
29
- yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${componentCtxVar}.emit>${utils_1.endOfLine}`;
30
- yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
26
+ yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${ctx.currentComponent.ctxVar}.emit>${utils_1.endOfLine}`;
31
27
  }
32
28
  let source = prop.arg?.loc.source ?? 'model-value';
33
29
  let start = prop.arg?.loc.start.offset;
@@ -46,7 +42,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
46
42
  const propName = (0, shared_1.camelize)(propPrefix + source);
47
43
  const emitName = emitPrefix + source;
48
44
  const camelizedEmitName = (0, shared_1.camelize)(emitName);
49
- yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
45
+ yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${ctx.currentComponent.propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
50
46
  if (prop.name === 'on') {
51
47
  yield `{ `;
52
48
  yield* generateEventArg(options, source, start, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
@@ -83,7 +79,7 @@ function* generateEventArg(options, name, start, directive = 'on', features) {
83
79
  yield* (0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping);
84
80
  }
85
81
  else {
86
- yield* (0, wrapWith_1.wrapWith)(start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping), `'`);
82
+ yield* (0, wrapWith_1.wrapWith)('template', start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping), `'`);
87
83
  }
88
84
  }
89
85
  function* generateEventExpression(options, ctx, prop) {
@@ -7,5 +7,5 @@ export interface FailedPropExpression {
7
7
  prefix: string;
8
8
  suffix: string;
9
9
  }
10
- export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, enableCodeFeatures: boolean, failedPropExps?: FailedPropExpression[]): Generator<Code>;
11
- export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined, enableCodeFeatures?: boolean): Generator<Code>;
10
+ export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, failedPropExps?: FailedPropExpression[]): Generator<Code>;
11
+ export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined): Generator<Code>;
@@ -4,7 +4,6 @@ exports.generateElementProps = generateElementProps;
4
4
  exports.generatePropExp = generatePropExp;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const shared_1 = require("@vue/shared");
7
- const muggle_string_1 = require("muggle-string");
8
7
  const picomatch_1 = require("picomatch");
9
8
  const shared_2 = require("../../utils/shared");
10
9
  const codeFeatures_1 = require("../codeFeatures");
@@ -17,7 +16,7 @@ const elementDirectives_1 = require("./elementDirectives");
17
16
  const elementEvents_1 = require("./elementEvents");
18
17
  const interpolation_1 = require("./interpolation");
19
18
  const objectProperty_1 = require("./objectProperty");
20
- function* generateElementProps(options, ctx, node, props, strictPropsCheck, enableCodeFeatures, failedPropExps) {
19
+ function* generateElementProps(options, ctx, node, props, strictPropsCheck, failedPropExps) {
21
20
  const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
22
21
  for (const prop of props) {
23
22
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -81,15 +80,9 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
81
80
  if (shouldSpread) {
82
81
  yield `...{ `;
83
82
  }
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
- if (enableCodeFeatures) {
88
- yield* codes;
89
- }
90
- else {
91
- yield (0, muggle_string_1.toString)(codes);
92
- }
83
+ yield* (0, wrapWith_1.wrapWith)('template', prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...(prop.arg
84
+ ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize)
85
+ : (0, wrapWith_1.wrapWith)('template', prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)('template', 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)));
93
86
  if (shouldSpread) {
94
87
  yield ` }`;
95
88
  }
@@ -100,13 +93,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
100
93
  ? `[__VLS_tryAsConstant(\`\${${prop.arg.content}}Modifiers\`)]`
101
94
  : (0, shared_1.camelize)(propName) + `Modifiers`
102
95
  : `modelModifiers`;
103
- const codes = [...(0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName)];
104
- if (enableCodeFeatures) {
105
- yield* codes;
106
- }
107
- else {
108
- yield (0, muggle_string_1.toString)(codes);
109
- }
96
+ yield* (0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName);
110
97
  yield utils_1.newLine;
111
98
  }
112
99
  }
@@ -120,15 +107,9 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
120
107
  if (shouldSpread) {
121
108
  yield `...{ `;
122
109
  }
123
- 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
124
- ? generateAttrValue(prop.value, codeFeatures_1.codeFeatures.withoutNavigation)
125
- : [`true`]))];
126
- if (enableCodeFeatures) {
127
- yield* codes;
128
- }
129
- else {
130
- yield (0, muggle_string_1.toString)(codes);
131
- }
110
+ yield* (0, wrapWith_1.wrapWith)('template', 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
111
+ ? generateAttrValue(prop.value, codeFeatures_1.codeFeatures.withoutNavigation)
112
+ : [`true`]));
132
113
  if (shouldSpread) {
133
114
  yield ` }`;
134
115
  }
@@ -138,74 +119,48 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
138
119
  && !prop.arg
139
120
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
140
121
  if (prop.exp.loc.source === '$attrs') {
141
- if (enableCodeFeatures) {
142
- ctx.bindingAttrLocs.push(prop.exp.loc);
143
- }
122
+ ctx.bindingAttrLocs.push(prop.exp.loc);
144
123
  }
145
124
  else {
146
- 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))];
147
- if (enableCodeFeatures) {
148
- yield* codes;
149
- }
150
- else {
151
- yield (0, muggle_string_1.toString)(codes);
152
- }
125
+ yield* (0, wrapWith_1.wrapWith)('template', prop.exp.loc.start.offset, prop.exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp));
153
126
  yield `,${utils_1.newLine}`;
154
127
  }
155
128
  }
156
129
  }
157
130
  }
158
- function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
159
- const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
160
- const features = isShorthand
161
- ? codeFeatures_1.codeFeatures.withoutHighlightAndCompletion
162
- : codeFeatures_1.codeFeatures.all;
163
- if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
164
- if (!isShorthand) { // vue 3.4+
165
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, `(`, `)`);
166
- }
167
- else {
168
- const propVariableName = (0, shared_1.camelize)(exp.loc.source);
169
- if (utils_1.identifierRegex.test(propVariableName)) {
170
- const isDestructuredProp = options.destructuredPropNames.has(propVariableName);
171
- const isTemplateRef = options.templateRefNames.has(propVariableName);
172
- const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, features);
173
- if (ctx.hasLocalVariable(propVariableName) || isDestructuredProp) {
174
- yield* codes;
175
- }
176
- else {
177
- ctx.accessExternalVariable(propVariableName, exp.loc.start.offset);
178
- if (isTemplateRef) {
179
- yield `__VLS_unref(`;
180
- yield* codes;
181
- yield `)`;
182
- }
183
- else {
184
- yield `__VLS_ctx.`;
185
- yield* codes;
186
- }
187
- }
188
- if (enableCodeFeatures) {
189
- ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
190
- }
191
- }
192
- }
131
+ function* generatePropExp(options, ctx, prop, exp) {
132
+ if (!exp) {
133
+ yield `{}`;
134
+ }
135
+ else if (prop.arg?.loc.start.offset !== prop.exp?.loc.start.offset) {
136
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, exp.loc.source, exp.loc.start.offset, `(`, `)`);
193
137
  }
194
138
  else {
195
- yield `{}`;
139
+ const propVariableName = (0, shared_1.camelize)(exp.loc.source);
140
+ if (utils_1.identifierRegex.test(propVariableName)) {
141
+ const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
142
+ if (options.destructuredPropNames.has(propVariableName) || ctx.hasLocalVariable(propVariableName)) {
143
+ yield* codes;
144
+ }
145
+ else if (options.templateRefNames.has(propVariableName)) {
146
+ yield `__VLS_unref(`;
147
+ yield* codes;
148
+ yield `)`;
149
+ }
150
+ else {
151
+ ctx.accessExternalVariable(propVariableName, exp.loc.start.offset);
152
+ yield `__VLS_ctx.`;
153
+ yield* codes;
154
+ }
155
+ ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
156
+ }
196
157
  }
197
158
  }
198
- function* generateAttrValue(attrNode, features) {
199
- const quote = attrNode.loc.source.startsWith("'") ? "'" : '"';
159
+ function* generateAttrValue(node, features) {
160
+ const quote = node.loc.source.startsWith("'") ? "'" : '"';
161
+ const offset = (0, shared_2.getAttributeValueOffset)(node);
200
162
  yield quote;
201
- let start = attrNode.loc.start.offset;
202
- let content = attrNode.loc.source;
203
- if ((content.startsWith('"') && content.endsWith('"'))
204
- || (content.startsWith("'") && content.endsWith("'"))) {
205
- start++;
206
- content = content.slice(1, -1);
207
- }
208
- yield* (0, unicode_1.generateUnicode)(content, start, features);
163
+ yield* (0, unicode_1.generateUnicode)(node.content, offset, features);
209
164
  yield quote;
210
165
  }
211
166
  function getShouldCamelize(options, prop, propName) {