@vue/language-core 3.0.0-alpha.0 → 3.0.0-alpha.10

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 (60) hide show
  1. package/lib/codegen/codeFeatures.d.ts +5 -0
  2. package/lib/codegen/codeFeatures.js +5 -0
  3. package/lib/codegen/globalTypes.js +44 -30
  4. package/lib/codegen/localTypes.d.ts +2 -3
  5. package/lib/codegen/localTypes.js +5 -15
  6. package/lib/codegen/script/component.js +21 -9
  7. package/lib/codegen/script/context.d.ts +1 -1
  8. package/lib/codegen/script/context.js +1 -1
  9. package/lib/codegen/script/index.d.ts +1 -1
  10. package/lib/codegen/script/index.js +2 -15
  11. package/lib/codegen/script/scriptSetup.js +5 -16
  12. package/lib/codegen/script/src.js +4 -3
  13. package/lib/codegen/script/template.js +3 -5
  14. package/lib/codegen/template/context.d.ts +28 -18
  15. package/lib/codegen/template/context.js +87 -53
  16. package/lib/codegen/template/element.d.ts +2 -2
  17. package/lib/codegen/template/element.js +20 -30
  18. package/lib/codegen/template/elementChildren.d.ts +2 -2
  19. package/lib/codegen/template/elementChildren.js +4 -6
  20. package/lib/codegen/template/elementDirectives.js +3 -7
  21. package/lib/codegen/template/elementEvents.d.ts +3 -3
  22. package/lib/codegen/template/elementEvents.js +25 -18
  23. package/lib/codegen/template/elementProps.d.ts +2 -2
  24. package/lib/codegen/template/elementProps.js +8 -15
  25. package/lib/codegen/template/index.d.ts +1 -1
  26. package/lib/codegen/template/index.js +22 -11
  27. package/lib/codegen/template/interpolation.d.ts +1 -1
  28. package/lib/codegen/template/interpolation.js +52 -50
  29. package/lib/codegen/template/slotOutlet.js +2 -3
  30. package/lib/codegen/template/templateChild.d.ts +1 -1
  31. package/lib/codegen/template/templateChild.js +12 -46
  32. package/lib/codegen/template/vFor.js +5 -10
  33. package/lib/codegen/template/vIf.js +2 -10
  34. package/lib/codegen/template/vSlot.d.ts +1 -2
  35. package/lib/codegen/template/vSlot.js +111 -59
  36. package/lib/codegen/utils/index.d.ts +2 -3
  37. package/lib/codegen/utils/index.js +0 -16
  38. package/lib/languagePlugin.d.ts +1 -1
  39. package/lib/languagePlugin.js +1 -7
  40. package/lib/parsers/scriptRanges.d.ts +2 -3
  41. package/lib/parsers/scriptRanges.js +3 -10
  42. package/lib/parsers/scriptSetupRanges.js +27 -22
  43. package/lib/plugins/file-md.js +3 -0
  44. package/lib/plugins/vue-style-css.d.ts +3 -0
  45. package/lib/plugins/vue-style-css.js +18 -0
  46. package/lib/plugins/vue-template-inline-css.js +1 -1
  47. package/lib/plugins/vue-template-inline-ts.js +5 -2
  48. package/lib/plugins/vue-tsx.d.ts +27 -18
  49. package/lib/plugins/vue-tsx.js +32 -20
  50. package/lib/plugins.d.ts +1 -1
  51. package/lib/types.d.ts +2 -1
  52. package/lib/utils/shared.d.ts +0 -1
  53. package/lib/utils/shared.js +0 -4
  54. package/lib/utils/signals.d.ts +1 -0
  55. package/lib/utils/signals.js +11 -0
  56. package/lib/utils/ts.js +3 -4
  57. package/lib/virtualFile/computedSfc.js +6 -6
  58. package/package.json +6 -8
  59. package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
  60. package/lib/utils/vue2TemplateCompiler.js +0 -89
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTemplateCodegenContext = createTemplateCodegenContext;
4
+ const CompilerDOM = require("@vue/compiler-dom");
4
5
  const codeFeatures_1 = require("../codeFeatures");
5
6
  const utils_1 = require("../utils");
6
7
  const wrapWith_1 = require("../utils/wrapWith");
8
+ const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
7
9
  /**
8
10
  * Creates and returns a Context object used for generating type-checkable TS code
9
11
  * from the template section of a .vue file.
@@ -102,13 +104,11 @@ const wrapWith_1 = require("../utils/wrapWith");
102
104
  * and additionally how we use that to determine whether to propagate diagnostics back upward.
103
105
  */
104
106
  function createTemplateCodegenContext(options) {
105
- let ignoredError = false;
106
- let expectErrorToken;
107
- let lastGenericComment;
108
107
  let variableId = 0;
109
108
  function resolveCodeFeatures(features) {
110
- if (features.verification) {
111
- if (ignoredError) {
109
+ if (features.verification && stack.length) {
110
+ const data = stack[stack.length - 1];
111
+ if (data.ignoreError) {
112
112
  // We are currently in a region of code covered by a @vue-ignore directive, so don't
113
113
  // even bother performing any type-checking: set verification to false.
114
114
  return {
@@ -116,17 +116,16 @@ function createTemplateCodegenContext(options) {
116
116
  verification: false,
117
117
  };
118
118
  }
119
- if (expectErrorToken) {
119
+ if (data.expectError !== undefined) {
120
120
  // We are currently in a region of code covered by a @vue-expect-error directive. We need to
121
121
  // keep track of the number of errors encountered within this region so that we can know whether
122
122
  // we will need to propagate an "unused ts-expect-error" diagnostic back to the original
123
123
  // .vue file or not.
124
- const token = expectErrorToken;
125
124
  return {
126
125
  ...features,
127
126
  verification: {
128
127
  shouldReport: () => {
129
- token.errors++;
128
+ data.expectError.token++;
130
129
  return false;
131
130
  },
132
131
  },
@@ -148,7 +147,12 @@ function createTemplateCodegenContext(options) {
148
147
  const bindingAttrLocs = [];
149
148
  const inheritedAttrVars = new Set();
150
149
  const templateRefs = new Map();
150
+ const stack = [];
151
+ const commentBuffer = [];
151
152
  return {
153
+ get currentInfo() {
154
+ return stack[stack.length - 1];
155
+ },
152
156
  codeFeatures: new Proxy(codeFeatures_1.codeFeatures, {
153
157
  get(target, key) {
154
158
  const data = target[key];
@@ -156,11 +160,11 @@ function createTemplateCodegenContext(options) {
156
160
  },
157
161
  }),
158
162
  resolveCodeFeatures,
163
+ inVFor: false,
159
164
  slots,
160
165
  dynamicSlots,
161
166
  dollarVars,
162
167
  accessExternalVariables,
163
- lastGenericComment,
164
168
  blockConditions,
165
169
  scopedClasses,
166
170
  emptyClassOffsets,
@@ -171,6 +175,13 @@ function createTemplateCodegenContext(options) {
171
175
  currentComponent: undefined,
172
176
  singleRootElTypes: [],
173
177
  singleRootNodes: new Set(),
178
+ addTemplateRef(name, typeExp, offset) {
179
+ let refs = templateRefs.get(name);
180
+ if (!refs) {
181
+ templateRefs.set(name, refs = []);
182
+ }
183
+ refs.push({ typeExp, offset });
184
+ },
174
185
  accessExternalVariable(name, offset) {
175
186
  let arr = accessExternalVariables.get(name);
176
187
  if (!arr) {
@@ -180,26 +191,26 @@ function createTemplateCodegenContext(options) {
180
191
  arr.add(offset);
181
192
  }
182
193
  },
183
- hasLocalVariable: (name) => {
194
+ hasLocalVariable(name) {
184
195
  return !!localVars.get(name);
185
196
  },
186
- addLocalVariable: (name) => {
197
+ addLocalVariable(name) {
187
198
  localVars.set(name, (localVars.get(name) ?? 0) + 1);
188
199
  },
189
- removeLocalVariable: (name) => {
200
+ removeLocalVariable(name) {
190
201
  localVars.set(name, localVars.get(name) - 1);
191
202
  },
192
- getInternalVariable: () => {
203
+ getInternalVariable() {
193
204
  return `__VLS_${variableId++}`;
194
205
  },
195
- getHoistVariable: (originalVar) => {
206
+ getHoistVariable(originalVar) {
196
207
  let name = hoistVars.get(originalVar);
197
208
  if (name === undefined) {
198
209
  hoistVars.set(originalVar, name = `__VLS_${variableId++}`);
199
210
  }
200
211
  return name;
201
212
  },
202
- generateHoistVariables: function* () {
213
+ *generateHoistVariables() {
203
214
  // trick to avoid TS 4081 (#5186)
204
215
  if (hoistVars.size) {
205
216
  yield `// @ts-ignore${utils_1.newLine}`;
@@ -210,47 +221,12 @@ function createTemplateCodegenContext(options) {
210
221
  yield utils_1.endOfLine;
211
222
  }
212
223
  },
213
- generateConditionGuards: function* () {
224
+ *generateConditionGuards() {
214
225
  for (const condition of blockConditions) {
215
226
  yield `if (!${condition}) return${utils_1.endOfLine}`;
216
227
  }
217
228
  },
218
- ignoreError: function* () {
219
- if (!ignoredError) {
220
- ignoredError = true;
221
- yield `// @vue-ignore start${utils_1.newLine}`;
222
- }
223
- },
224
- expectError: function* (prevNode) {
225
- if (!expectErrorToken) {
226
- expectErrorToken = {
227
- errors: 0,
228
- node: prevNode,
229
- };
230
- yield `// @vue-expect-error start${utils_1.newLine}`;
231
- }
232
- },
233
- resetDirectiveComments: function* (endStr) {
234
- if (expectErrorToken) {
235
- const token = expectErrorToken;
236
- yield* (0, wrapWith_1.wrapWith)(expectErrorToken.node.loc.start.offset, expectErrorToken.node.loc.end.offset, {
237
- verification: {
238
- // If no errors/warnings/diagnostics were reported within the region of code covered
239
- // by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
240
- // diagnostics to be reported upward.
241
- shouldReport: () => token.errors === 0,
242
- },
243
- }, `// @ts-expect-error __VLS_TS_EXPECT_ERROR`);
244
- yield `${utils_1.newLine}${utils_1.endOfLine}`;
245
- expectErrorToken = undefined;
246
- yield `// @vue-expect-error ${endStr}${utils_1.newLine}`;
247
- }
248
- if (ignoredError) {
249
- ignoredError = false;
250
- yield `// @vue-ignore ${endStr}${utils_1.newLine}`;
251
- }
252
- },
253
- generateAutoImportCompletion: function* () {
229
+ *generateAutoImportCompletion() {
254
230
  const all = [...accessExternalVariables.entries()];
255
231
  if (!all.some(([_, offsets]) => offsets.size)) {
256
232
  return;
@@ -284,7 +260,65 @@ function createTemplateCodegenContext(options) {
284
260
  offsets.clear();
285
261
  }
286
262
  yield `]${utils_1.endOfLine}`;
287
- }
263
+ },
264
+ enter(node) {
265
+ if (node.type === CompilerDOM.NodeTypes.COMMENT) {
266
+ commentBuffer.push(node);
267
+ return false;
268
+ }
269
+ const data = {};
270
+ const comments = [...commentBuffer];
271
+ commentBuffer.length = 0;
272
+ for (const comment of comments) {
273
+ const match = comment.loc.source.match(commentDirectiveRegex);
274
+ if (match) {
275
+ const { name, content } = match.groups;
276
+ switch (name) {
277
+ case 'skip': {
278
+ return false;
279
+ }
280
+ case 'ignore': {
281
+ data.ignoreError = true;
282
+ break;
283
+ }
284
+ case 'expect-error': {
285
+ data.expectError = {
286
+ token: 0,
287
+ node: comment,
288
+ };
289
+ break;
290
+ }
291
+ case 'generic': {
292
+ const text = content.trim();
293
+ if (text.startsWith('{') && text.endsWith('}')) {
294
+ data.generic = {
295
+ content: text.slice(1, -1),
296
+ offset: comment.loc.start.offset + comment.loc.source.indexOf('{') + 1,
297
+ };
298
+ }
299
+ break;
300
+ }
301
+ }
302
+ }
303
+ }
304
+ stack.push(data);
305
+ return true;
306
+ },
307
+ *exit() {
308
+ const data = stack.pop();
309
+ commentBuffer.length = 0;
310
+ if (data.expectError !== undefined) {
311
+ yield* (0, wrapWith_1.wrapWith)(data.expectError.node.loc.start.offset, data.expectError.node.loc.end.offset, {
312
+ verification: {
313
+ // If no errors/warnings/diagnostics were reported within the region of code covered
314
+ // by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
315
+ // diagnostics to be reported upward.
316
+ shouldReport: () => data.expectError.token === 0,
317
+ },
318
+ }, `// @ts-expect-error`);
319
+ yield `${utils_1.newLine}${utils_1.endOfLine}`;
320
+ }
321
+ },
288
322
  };
289
323
  }
290
324
  //# sourceMappingURL=context.js.map
@@ -2,5 +2,5 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, isVForChild: boolean): Generator<Code>;
6
- export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, isVForChild: boolean): Generator<Code>;
5
+ export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
6
+ export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
@@ -19,7 +19,7 @@ const propertyAccess_1 = require("./propertyAccess");
19
19
  const styleScopedClasses_1 = require("./styleScopedClasses");
20
20
  const vSlot_1 = require("./vSlot");
21
21
  const colonReg = /:/g;
22
- function* generateComponent(options, ctx, node, isVForChild) {
22
+ function* generateComponent(options, ctx, node) {
23
23
  const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
24
24
  if (!node.isSelfClosing && options.template.lang === 'html') {
25
25
  const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
@@ -35,9 +35,11 @@ function* generateComponent(options, ctx, node, isVForChild) {
35
35
  const componentVNodeVar = ctx.getInternalVariable();
36
36
  const componentCtxVar = ctx.getInternalVariable();
37
37
  const isComponentTag = node.tag.toLowerCase() === 'component';
38
+ ctx.currentComponent?.childTypes.push(`typeof ${componentVNodeVar}`);
38
39
  ctx.currentComponent = {
39
40
  ctxVar: componentCtxVar,
40
- used: false
41
+ childTypes: [],
42
+ used: false,
41
43
  };
42
44
  let props = node.props;
43
45
  let dynamicTagInfo;
@@ -101,9 +103,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
101
103
  else if (!isComponentTag) {
102
104
  yield `const ${componentOriginalVar} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
103
105
  if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
104
- yield `typeof __VLS_self & (new () => { `
105
- + (0, shared_2.getSlotsPropertyName)(options.vueCompilerOptions.target)
106
- + `: __VLS_Slots }), `;
106
+ yield `typeof __VLS_self & (new () => { $slots: __VLS_Slots }), `;
107
107
  }
108
108
  else {
109
109
  yield `void, `;
@@ -159,7 +159,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
159
159
  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), `}`);
160
160
  yield `, ...__VLS_functionalComponentArgsRest(${componentFunctionalVar}))${utils_1.endOfLine}`;
161
161
  yield* generateFailedPropExps(options, ctx, failedPropExps);
162
- yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar);
162
+ yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar);
163
163
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
164
164
  const [refName, offset] = yield* generateElementReference(options, ctx, node);
165
165
  const tag = (0, shared_2.hyphenateTag)(node.tag);
@@ -168,15 +168,12 @@ function* generateComponent(options, ctx, node, isVForChild) {
168
168
  const componentInstanceVar = ctx.getInternalVariable();
169
169
  ctx.currentComponent.used = true;
170
170
  yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${componentCtxVar}['expose']>>[0] | null)`;
171
- if (isVForChild) {
171
+ if (ctx.inVFor) {
172
172
  yield `[]`;
173
173
  }
174
174
  yield `${utils_1.endOfLine}`;
175
175
  if (refName && offset) {
176
- ctx.templateRefs.set(refName, {
177
- typeExp: `typeof ${ctx.getHoistVariable(componentInstanceVar)}`,
178
- offset
179
- });
176
+ ctx.addTemplateRef(refName, `typeof ${ctx.getHoistVariable(componentInstanceVar)}`, offset);
180
177
  }
181
178
  if (isRootNode) {
182
179
  ctx.singleRootElTypes.push(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
@@ -189,24 +186,18 @@ function* generateComponent(options, ctx, node, isVForChild) {
189
186
  }
190
187
  (0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
191
188
  const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
192
- if (slotDir) {
193
- yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
194
- }
195
- else {
196
- // #932: reference for default slot
197
- yield* (0, vSlot_1.generateImplicitDefaultSlot)(ctx, node);
198
- yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
199
- }
189
+ yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
200
190
  if (ctx.currentComponent.used) {
201
- yield `var ${componentCtxVar}!: __VLS_PickFunctionalComponentCtx<typeof ${componentOriginalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
191
+ yield `var ${componentCtxVar}!: __VLS_FunctionalComponentCtx<typeof ${componentOriginalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
202
192
  }
203
193
  }
204
- function* generateElement(options, ctx, node, isVForChild) {
194
+ function* generateElement(options, ctx, node) {
205
195
  const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
206
196
  const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
207
197
  ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
208
198
  : undefined;
209
199
  const failedPropExps = [];
200
+ ctx.currentComponent?.childTypes.push(`__VLS_NativeElements['${node.tag}']`);
210
201
  yield `__VLS_asFunctionalElement(__VLS_elements`;
211
202
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
212
203
  if (endTagOffset !== undefined) {
@@ -221,13 +212,10 @@ function* generateElement(options, ctx, node, isVForChild) {
221
212
  const [refName, offset] = yield* generateElementReference(options, ctx, node);
222
213
  if (refName && offset) {
223
214
  let typeExp = `__VLS_NativeElements['${node.tag}']`;
224
- if (isVForChild) {
215
+ if (ctx.inVFor) {
225
216
  typeExp += `[]`;
226
217
  }
227
- ctx.templateRefs.set(refName, {
228
- typeExp,
229
- offset
230
- });
218
+ ctx.addTemplateRef(refName, typeExp, offset);
231
219
  }
232
220
  if (ctx.singleRootNodes.has(node)) {
233
221
  ctx.singleRootElTypes.push(`__VLS_NativeElements['${node.tag}']`);
@@ -236,7 +224,10 @@ function* generateElement(options, ctx, node, isVForChild) {
236
224
  ctx.inheritedAttrVars.add(`__VLS_elements.${node.tag}`);
237
225
  }
238
226
  (0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
239
- yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
227
+ const { currentComponent } = ctx;
228
+ ctx.currentComponent = undefined;
229
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
230
+ ctx.currentComponent = currentComponent;
240
231
  }
241
232
  function* generateFailedPropExps(options, ctx, failedPropExps) {
242
233
  for (const failedExp of failedPropExps) {
@@ -271,8 +262,8 @@ function* generateCanonicalComponentName(tagText, offset, features) {
271
262
  }
272
263
  }
273
264
  function* generateComponentGeneric(ctx) {
274
- if (ctx.lastGenericComment) {
275
- const { content, offset } = ctx.lastGenericComment;
265
+ if (ctx.currentInfo.generic) {
266
+ const { content, offset } = ctx.currentInfo.generic;
276
267
  yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
277
268
  content,
278
269
  'template',
@@ -280,7 +271,6 @@ function* generateComponentGeneric(ctx) {
280
271
  ctx.codeFeatures.all
281
272
  ], `>`);
282
273
  }
283
- ctx.lastGenericComment = undefined;
284
274
  }
285
275
  function* generateElementReference(options, ctx, node) {
286
276
  for (const prop of node.props) {
@@ -1,5 +1,5 @@
1
- import * as CompilerDOM from '@vue/compiler-dom';
1
+ import type * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
5
+ export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, children: (CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode)[], enterNode?: boolean): Generator<Code>;
@@ -2,12 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateElementChildren = generateElementChildren;
4
4
  const templateChild_1 = require("./templateChild");
5
- function* generateElementChildren(options, ctx, node) {
6
- yield* ctx.resetDirectiveComments('end of element children start');
7
- let prev;
8
- for (const childNode of node.children) {
9
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
10
- prev = childNode;
5
+ function* generateElementChildren(options, ctx, children, enterNode = true) {
6
+ yield* ctx.generateAutoImportCompletion();
7
+ for (const childNode of children) {
8
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, enterNode);
11
9
  }
12
10
  yield* ctx.generateAutoImportCompletion();
13
11
  }
@@ -26,9 +26,7 @@ function* generateElementDirectives(options, ctx, node) {
26
26
  || prop.name === 'slot'
27
27
  || prop.name === 'on'
28
28
  || prop.name === 'model'
29
- || prop.name === 'bind'
30
- || prop.name === 'scope'
31
- || prop.name === 'data') {
29
+ || prop.name === 'bind') {
32
30
  continue;
33
31
  }
34
32
  ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
@@ -39,9 +37,7 @@ function* generateElementDirectives(options, ctx, node) {
39
37
  function* generateIdentifier(options, ctx, prop) {
40
38
  const rawName = 'v-' + prop.name;
41
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({
42
- ...codeFeatures_1.codeFeatures.withoutHighlight,
43
- // fix https://github.com/vuejs/language-tools/issues/1905
44
- ...codeFeatures_1.codeFeatures.additionalCompletion,
40
+ ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
45
41
  verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
46
42
  })));
47
43
  }
@@ -83,6 +79,6 @@ function* generateValue(options, ctx, prop) {
83
79
  }
84
80
  yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `value`);
85
81
  yield `: `;
86
- yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp, ctx.codeFeatures.all);
82
+ yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
87
83
  }
88
84
  //# sourceMappingURL=elementDirectives.js.map
@@ -1,10 +1,10 @@
1
1
  import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type * as ts from 'typescript';
3
- import type { Code } from '../../types';
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, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
7
- export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string): Generator<Code>;
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(ctx: TemplateCodegenContext, 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;
@@ -11,9 +11,8 @@ const utils_1 = require("../utils");
11
11
  const camelized_1 = require("../utils/camelized");
12
12
  const wrapWith_1 = require("../utils/wrapWith");
13
13
  const interpolation_1 = require("./interpolation");
14
- function* generateElementEvents(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
15
- let emitVar;
16
- let eventsVar;
14
+ function* generateElementEvents(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
15
+ let emitsVar;
17
16
  let propsVar;
18
17
  for (const prop of node.props) {
19
18
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -23,12 +22,10 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
23
22
  && prop.name === 'model'
24
23
  && (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
25
24
  ctx.currentComponent.used = true;
26
- if (!emitVar) {
27
- emitVar = ctx.getInternalVariable();
28
- eventsVar = ctx.getInternalVariable();
25
+ if (!emitsVar) {
26
+ emitsVar = ctx.getInternalVariable();
29
27
  propsVar = ctx.getInternalVariable();
30
- yield `let ${emitVar}!: typeof ${componentCtxVar}.emit${utils_1.endOfLine}`;
31
- yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
28
+ yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${componentCtxVar}.emit>${utils_1.endOfLine}`;
32
29
  yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
33
30
  }
34
31
  let source = prop.arg?.loc.source ?? 'model-value';
@@ -45,32 +42,43 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
45
42
  propPrefix = 'onVnode-';
46
43
  emitPrefix = 'vnode-';
47
44
  }
48
- yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${eventsVar}, '${(0, shared_1.camelize)(propPrefix + source)}', '${emitPrefix + source}', '${(0, shared_1.camelize)(emitPrefix + source)}'> => ({${utils_1.newLine}`;
45
+ const propName = (0, shared_1.camelize)(propPrefix + source);
46
+ const emitName = emitPrefix + source;
47
+ const camelizedEmitName = (0, shared_1.camelize)(emitName);
48
+ yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> => (${utils_1.newLine}`;
49
+ if (prop.name === 'on') {
50
+ yield `{ `;
51
+ yield* generateEventArg(ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
52
+ yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
53
+ }
54
+ yield `{ `;
49
55
  if (prop.name === 'on') {
50
56
  yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
51
57
  yield `: `;
52
58
  yield* generateEventExpression(options, ctx, prop);
53
59
  }
54
60
  else {
55
- yield `'${(0, shared_1.camelize)(propPrefix + source)}': `;
61
+ yield `'${propName}': `;
56
62
  yield* generateModelEventExpression(options, ctx, prop);
57
63
  }
58
64
  yield `})${utils_1.endOfLine}`;
59
65
  }
60
66
  }
61
67
  }
62
- function* generateEventArg(ctx, name, start, directive = 'on') {
63
- const features = {
64
- ...ctx.codeFeatures.withoutHighlightAndCompletion,
65
- ...ctx.codeFeatures.navigationWithoutRename,
66
- };
68
+ function* generateEventArg(ctx, name, start, directive = 'on', features = {
69
+ ...ctx.codeFeatures.withoutHighlightAndCompletion,
70
+ ...ctx.codeFeatures.navigationWithoutRename,
71
+ }) {
72
+ if (directive.length) {
73
+ name = (0, shared_1.capitalize)(name);
74
+ }
67
75
  if (utils_1.identifierRegex.test((0, shared_1.camelize)(name))) {
68
76
  yield ['', 'template', start, features];
69
77
  yield directive;
70
- yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(name), 'template', start, utils_1.combineLastMapping);
78
+ yield* (0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping);
71
79
  }
72
80
  else {
73
- yield* (0, wrapWith_1.wrapWith)(start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)((0, shared_1.capitalize)(name), 'template', start, utils_1.combineLastMapping), `'`);
81
+ yield* (0, wrapWith_1.wrapWith)(start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping), `'`);
74
82
  }
75
83
  }
76
84
  function* generateEventExpression(options, ctx, prop) {
@@ -108,7 +116,6 @@ function* generateEventExpression(options, ctx, prop) {
108
116
  if (_isCompoundExpression) {
109
117
  ctx.removeLocalVariable('$event');
110
118
  yield utils_1.endOfLine;
111
- yield* ctx.generateAutoImportCompletion();
112
119
  yield `}`;
113
120
  }
114
121
  }
@@ -1,5 +1,5 @@
1
1
  import * as CompilerDOM from '@vue/compiler-dom';
2
- import type { Code, VueCodeInformation } from '../../types';
2
+ import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
5
  export interface FailedPropExpression {
@@ -8,4 +8,4 @@ export interface FailedPropExpression {
8
8
  suffix: string;
9
9
  }
10
10
  export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, enableCodeFeatures: boolean, failedPropExps?: FailedPropExpression[]): Generator<Code>;
11
- export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined, features: VueCodeInformation, enableCodeFeatures?: boolean): Generator<Code>;
11
+ export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined, enableCodeFeatures?: boolean): Generator<Code>;
@@ -83,7 +83,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
83
83
  }
84
84
  const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
85
85
  ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
86
- : (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures))];
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)))];
87
87
  if (enableCodeFeatures) {
88
88
  yield* codes;
89
89
  }
@@ -111,11 +111,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
111
111
  }
112
112
  }
113
113
  else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
114
- if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
115
- // Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
116
- || (options.vueCompilerOptions.target < 3
117
- && prop.name === 'persisted'
118
- && node.tag.toLowerCase() === 'transition')) {
114
+ if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))) {
119
115
  continue;
120
116
  }
121
117
  const shouldSpread = prop.name === 'style' || prop.name === 'class';
@@ -148,7 +144,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
148
144
  }
149
145
  }
150
146
  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, ctx.codeFeatures.all, enableCodeFeatures))];
147
+ 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))];
152
148
  if (enableCodeFeatures) {
153
149
  yield* codes;
154
150
  }
@@ -160,14 +156,11 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
160
156
  }
161
157
  }
162
158
  }
163
- function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures = true) {
159
+ function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
164
160
  const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
165
- if (isShorthand && features.completion) {
166
- features = {
167
- ...features,
168
- completion: undefined,
169
- };
170
- }
161
+ const features = isShorthand
162
+ ? ctx.codeFeatures.withoutHighlightAndCompletion
163
+ : ctx.codeFeatures.all;
171
164
  if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
172
165
  if (!isShorthand) { // vue 3.4+
173
166
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, `(`, `)`);
@@ -275,6 +268,6 @@ function getModelPropName(node, vueCompilerOptions) {
275
268
  }
276
269
  }
277
270
  }
278
- return vueCompilerOptions.target < 3 ? 'value' : 'modelValue';
271
+ return 'modelValue';
279
272
  }
280
273
  //# sourceMappingURL=elementProps.js.map
@@ -1,7 +1,7 @@
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 { TemplateCodegenContext } from './context';
4
+ import { type TemplateCodegenContext } from './context';
5
5
  export interface TemplateCodegenOptions {
6
6
  ts: typeof ts;
7
7
  compilerOptions: ts.CompilerOptions;