@vue/language-core 2.2.4 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/lib/codegen/globalTypes.js +1 -6
  2. package/lib/codegen/script/component.js +1 -3
  3. package/lib/codegen/script/componentSelf.js +4 -11
  4. package/lib/codegen/script/context.d.ts +0 -1
  5. package/lib/codegen/script/context.js +0 -1
  6. package/lib/codegen/script/index.d.ts +1 -4
  7. package/lib/codegen/script/index.js +4 -6
  8. package/lib/codegen/script/scriptSetup.js +46 -37
  9. package/lib/codegen/script/styleModulesType.d.ts +4 -0
  10. package/lib/codegen/script/styleModulesType.js +34 -0
  11. package/lib/codegen/script/template.js +1 -3
  12. package/lib/codegen/style/classProperty.js +4 -17
  13. package/lib/codegen/template/context.js +2 -1
  14. package/lib/codegen/template/element.js +13 -12
  15. package/lib/codegen/template/elementDirectives.js +6 -5
  16. package/lib/codegen/template/elementEvents.d.ts +1 -0
  17. package/lib/codegen/template/elementEvents.js +37 -17
  18. package/lib/codegen/template/elementProps.js +15 -14
  19. package/lib/codegen/template/index.js +2 -1
  20. package/lib/codegen/template/objectProperty.js +5 -4
  21. package/lib/codegen/template/propertyAccess.js +1 -1
  22. package/lib/codegen/template/slotOutlet.js +4 -3
  23. package/lib/codegen/template/styleScopedClasses.js +4 -50
  24. package/lib/codegen/template/vIf.js +2 -6
  25. package/lib/codegen/template/vSlot.js +3 -2
  26. package/lib/codegen/utils/camelized.d.ts +1 -1
  27. package/lib/codegen/utils/camelized.js +6 -6
  28. package/lib/codegen/utils/escaped.d.ts +2 -0
  29. package/lib/codegen/utils/escaped.js +23 -0
  30. package/lib/codegen/utils/index.d.ts +1 -2
  31. package/lib/codegen/utils/index.js +2 -14
  32. package/lib/codegen/utils/objectProperty.d.ts +3 -0
  33. package/lib/codegen/utils/objectProperty.js +41 -0
  34. package/lib/codegen/utils/stringLiteralKey.js +2 -1
  35. package/lib/codegen/utils/unicode.js +2 -2
  36. package/lib/codegen/utils/wrapWith.d.ts +3 -0
  37. package/lib/codegen/utils/wrapWith.js +24 -0
  38. package/lib/parsers/scriptSetupRanges.d.ts +2 -0
  39. package/lib/parsers/scriptSetupRanges.js +64 -78
  40. package/lib/plugins/vue-tsx.d.ts +2 -3
  41. package/lib/plugins/vue-tsx.js +0 -9
  42. package/lib/types.d.ts +1 -0
  43. package/lib/virtualFile/computedEmbeddedCodes.js +17 -0
  44. package/package.json +2 -2
@@ -10,12 +10,7 @@ function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEv
10
10
  checkUnknownProps,
11
11
  checkUnknownEvents,
12
12
  checkUnknownComponents,
13
- ].map(v => {
14
- if (typeof v === 'boolean') {
15
- return v ? 1 : 0;
16
- }
17
- return v;
18
- }).join('_') + '.d.ts';
13
+ ].map(v => (typeof v === 'boolean' ? Number(v) : v)).join('_') + '.d.ts';
19
14
  }
20
15
  function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
21
16
  const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
@@ -27,9 +27,7 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
27
27
  yield `},${utils_1.newLine}`;
28
28
  if (!ctx.bypassDefineComponent) {
29
29
  const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
30
- for (const code of emitOptionCodes) {
31
- yield code;
32
- }
30
+ yield* emitOptionCodes;
33
31
  yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length, true);
34
32
  }
35
33
  if (options.vueCompilerOptions.target >= 3.5
@@ -27,25 +27,18 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
27
27
  if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
28
28
  continue;
29
29
  }
30
- const templateOffset = options.getGeneratedLength();
30
+ const token = Symbol(varName.length);
31
+ yield ['', undefined, 0, { __linkedToken: token }];
31
32
  yield `${varName}: ${varName} as typeof `;
32
- const scriptOffset = options.getGeneratedLength();
33
+ yield ['', undefined, 0, { __linkedToken: token }];
33
34
  yield `${varName},${utils_1.newLine}`;
34
- options.linkedCodeMappings.push({
35
- sourceOffsets: [scriptOffset],
36
- generatedOffsets: [templateOffset],
37
- lengths: [varName.length],
38
- data: undefined,
39
- });
40
35
  }
41
36
  }
42
37
  yield `}${utils_1.endOfLine}`; // return {
43
38
  yield `},${utils_1.newLine}`; // setup() {
44
39
  if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
45
40
  const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
46
- for (const code of emitOptionCodes) {
47
- yield code;
48
- }
41
+ yield* emitOptionCodes;
49
42
  yield* (0, component_1.generatePropsOption)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
50
43
  }
51
44
  if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
@@ -10,7 +10,6 @@ export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>
10
10
  export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
11
11
  generatedTemplate: boolean;
12
12
  generatedPropsType: boolean;
13
- scriptSetupGeneratedOffset: number | undefined;
14
13
  bypassDefineComponent: boolean;
15
14
  bindingNames: Set<string>;
16
15
  localTypes: {
@@ -8,7 +8,6 @@ function createScriptCodegenContext(options) {
8
8
  return {
9
9
  generatedTemplate: false,
10
10
  generatedPropsType: false,
11
- scriptSetupGeneratedOffset: undefined,
12
11
  bypassDefineComponent: options.lang === 'js' || options.lang === 'jsx',
13
12
  bindingNames: new Set([
14
13
  ...options.scriptRanges?.bindings.map(({ range }) => options.sfc.script.content.slice(range.start, range.end)) ?? [],
@@ -1,4 +1,3 @@
1
- import type { Mapping } from '@volar/language-core';
2
1
  import type * as ts from 'typescript';
3
2
  import type { ScriptRanges } from '../../parsers/scriptRanges';
4
3
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
@@ -20,9 +19,7 @@ export interface ScriptCodegenOptions {
20
19
  } | undefined;
21
20
  destructuredPropNames: Set<string>;
22
21
  templateRefNames: Set<string>;
23
- getGeneratedLength: () => number;
24
- linkedCodeMappings: Mapping[];
25
22
  appendGlobalTypes: boolean;
26
23
  }
27
24
  export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
28
- export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code>;
25
+ export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
@@ -92,16 +92,14 @@ function* generateScript(options) {
92
92
  }
93
93
  else {
94
94
  yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
95
+ yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
95
96
  }
96
97
  }
97
98
  else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
98
99
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
99
100
  }
100
- if (options.sfc.script) {
101
- yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
102
- }
103
101
  if (options.sfc.scriptSetup) {
104
- yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
102
+ yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue', ';');
105
103
  }
106
104
  if (!ctx.generatedTemplate) {
107
105
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
@@ -119,8 +117,8 @@ function* generateScript(options) {
119
117
  }
120
118
  return ctx;
121
119
  }
122
- function* generateScriptSectionPartiallyEnding(source, end, mark) {
123
- yield `;`;
120
+ function* generateScriptSectionPartiallyEnding(source, end, mark, delimiter = 'debugger') {
121
+ yield delimiter;
124
122
  yield ['', source, end, codeFeatures_1.codeFeatures.verification];
125
123
  yield `/* PartiallyEnd: ${mark} */${utils_1.newLine}`;
126
124
  }
@@ -2,8 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateScriptSetupImports = generateScriptSetupImports;
4
4
  exports.generateScriptSetup = generateScriptSetup;
5
+ const shared_1 = require("@vue/shared");
5
6
  const codeFeatures_1 = require("../codeFeatures");
6
7
  const utils_1 = require("../utils");
8
+ const camelized_1 = require("../utils/camelized");
9
+ const wrapWith_1 = require("../utils/wrapWith");
7
10
  const component_1 = require("./component");
8
11
  const componentSelf_1 = require("./componentSelf");
9
12
  const index_1 = require("./index");
@@ -19,15 +22,8 @@ function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
19
22
  function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
20
23
  if (scriptSetup.generic) {
21
24
  if (!options.scriptRanges?.exportDefault) {
22
- if (options.sfc.scriptSetup) {
23
- // #4569
24
- yield [
25
- '',
26
- 'scriptSetup',
27
- options.sfc.scriptSetup.content.length,
28
- codeFeatures_1.codeFeatures.verification,
29
- ];
30
- }
25
+ // #4569
26
+ yield ['', 'scriptSetup', 0, codeFeatures_1.codeFeatures.verification];
31
27
  yield `export default `;
32
28
  }
33
29
  yield `(`;
@@ -81,8 +77,16 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
81
77
  }
82
78
  }
83
79
  function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, syntax) {
84
- ctx.scriptSetupGeneratedOffset = options.getGeneratedLength() - scriptSetupRanges.importSectionEndOffset;
85
80
  let setupCodeModifies = [];
81
+ for (const { comments } of scriptSetupRanges.defineProp) {
82
+ if (comments) {
83
+ setupCodeModifies.push([
84
+ [``],
85
+ comments.start,
86
+ comments.end,
87
+ ]);
88
+ }
89
+ }
86
90
  if (scriptSetupRanges.defineProps) {
87
91
  const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
88
92
  setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name, `__VLS_props`, `__VLS_Props`));
@@ -101,22 +105,30 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
101
105
  setupCodeModifies.push([
102
106
  [
103
107
  `let __VLS_exposed!: `,
104
- (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.navigation),
108
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
105
109
  `${utils_1.endOfLine}`,
106
110
  ],
107
111
  callExp.start,
108
112
  callExp.start,
113
+ ], [
114
+ [`typeof __VLS_exposed`],
115
+ typeArg.start,
116
+ typeArg.end,
109
117
  ]);
110
118
  }
111
119
  else if (arg) {
112
120
  setupCodeModifies.push([
113
121
  [
114
122
  `const __VLS_exposed = `,
115
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation),
123
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
116
124
  `${utils_1.endOfLine}`,
117
125
  ],
118
126
  callExp.start,
119
127
  callExp.start,
128
+ ], [
129
+ [`__VLS_exposed`],
130
+ arg.start,
131
+ arg.end,
120
132
  ]);
121
133
  }
122
134
  else {
@@ -152,9 +164,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
152
164
  `])`
153
165
  ] : [
154
166
  ` as __VLS_StyleModules[`,
155
- ['', scriptSetup.name, exp.start, codeFeatures_1.codeFeatures.verification],
156
- `'$style'`,
157
- ['', scriptSetup.name, exp.end, utils_1.combineLastMapping],
167
+ ...(0, wrapWith_1.wrapWith)(exp.start, exp.end, scriptSetup.name, codeFeatures_1.codeFeatures.verification, `'$style'`),
158
168
  `])`
159
169
  ],
160
170
  callExp.end,
@@ -228,9 +238,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
228
238
  let nextStart = Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset);
229
239
  for (const [codes, start, end] of setupCodeModifies) {
230
240
  yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, start, codeFeatures_1.codeFeatures.all);
231
- for (const code of codes) {
232
- yield code;
233
- }
241
+ yield* codes;
234
242
  nextStart = end;
235
243
  }
236
244
  yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, codeFeatures_1.codeFeatures.all);
@@ -368,7 +376,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
368
376
  continue;
369
377
  }
370
378
  yield `: `;
371
- yield getRangeName(scriptSetup, defineProp.defaultValue);
379
+ yield getRangeText(scriptSetup, defineProp.defaultValue);
372
380
  yield `,${utils_1.newLine}`;
373
381
  }
374
382
  yield `}${utils_1.endOfLine}`;
@@ -381,6 +389,13 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
381
389
  ctx.generatedPropsType = true;
382
390
  yield `${ctx.localTypes.PropsChildren}<__VLS_Slots>`;
383
391
  }
392
+ if (scriptSetupRanges.defineProps?.typeArg) {
393
+ if (ctx.generatedPropsType) {
394
+ yield ` & `;
395
+ }
396
+ ctx.generatedPropsType = true;
397
+ yield `__VLS_Props`;
398
+ }
384
399
  if (scriptSetupRanges.defineProp.length) {
385
400
  if (ctx.generatedPropsType) {
386
401
  yield ` & `;
@@ -389,11 +404,15 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
389
404
  yield `{${utils_1.newLine}`;
390
405
  for (const defineProp of scriptSetupRanges.defineProp) {
391
406
  const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
407
+ if (defineProp.comments) {
408
+ yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.comments.start, defineProp.comments.end, codeFeatures_1.codeFeatures.all);
409
+ yield utils_1.newLine;
410
+ }
392
411
  if (defineProp.isModel && !defineProp.name) {
393
412
  yield propName;
394
413
  }
395
414
  else if (defineProp.name) {
396
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, codeFeatures_1.codeFeatures.navigation);
415
+ yield* (0, camelized_1.generateCamelized)(getRangeText(scriptSetup, defineProp.name), scriptSetup.name, defineProp.name.start, codeFeatures_1.codeFeatures.navigation);
397
416
  }
398
417
  else if (defineProp.localName) {
399
418
  yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.localName.start, defineProp.localName.end, codeFeatures_1.codeFeatures.navigation);
@@ -408,19 +427,12 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
408
427
  yield `,${utils_1.newLine}`;
409
428
  if (defineProp.modifierType) {
410
429
  const modifierName = `${defineProp.name ? propName : 'model'}Modifiers`;
411
- const modifierType = getRangeName(scriptSetup, defineProp.modifierType);
430
+ const modifierType = getRangeText(scriptSetup, defineProp.modifierType);
412
431
  yield `'${modifierName}'?: Partial<Record<${modifierType}, true>>,${utils_1.newLine}`;
413
432
  }
414
433
  }
415
434
  yield `}`;
416
435
  }
417
- if (scriptSetupRanges.defineProps?.typeArg) {
418
- if (ctx.generatedPropsType) {
419
- yield ` & `;
420
- }
421
- ctx.generatedPropsType = true;
422
- yield `__VLS_Props`;
423
- }
424
436
  if (!ctx.generatedPropsType) {
425
437
  yield `{}`;
426
438
  }
@@ -434,7 +446,7 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
434
446
  const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
435
447
  yield `'update:${propName}': [value: `;
436
448
  yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
437
- if (!defineModel.required && defineModel.defaultValue === undefined) {
449
+ if (!defineModel.required && !defineModel.defaultValue) {
438
450
  yield ` | undefined`;
439
451
  }
440
452
  yield `]${utils_1.endOfLine}`;
@@ -446,7 +458,7 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
446
458
  function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
447
459
  if (defineProp.type) {
448
460
  // Infer from defineProp<T>
449
- yield getRangeName(scriptSetup, defineProp.type);
461
+ yield getRangeText(scriptSetup, defineProp.type);
450
462
  }
451
463
  else if (defineProp.runtimeType && localName) {
452
464
  // Infer from actual prop declaration code
@@ -462,19 +474,16 @@ function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
462
474
  }
463
475
  function getPropAndLocalName(scriptSetup, defineProp) {
464
476
  const localName = defineProp.localName
465
- ? getRangeName(scriptSetup, defineProp.localName)
477
+ ? getRangeText(scriptSetup, defineProp.localName)
466
478
  : undefined;
467
- let propName = defineProp.name
468
- ? getRangeName(scriptSetup, defineProp.name)
479
+ const propName = defineProp.name
480
+ ? (0, shared_1.camelize)(getRangeText(scriptSetup, defineProp.name).slice(1, -1))
469
481
  : defineProp.isModel
470
482
  ? 'modelValue'
471
483
  : localName;
472
- if (defineProp.name) {
473
- propName = propName.replace(/['"]+/g, '');
474
- }
475
484
  return [propName, localName];
476
485
  }
477
- function getRangeName(scriptSetup, range) {
486
+ function getRangeText(scriptSetup, range) {
478
487
  return scriptSetup.content.slice(range.start, range.end);
479
488
  }
480
489
  //# sourceMappingURL=scriptSetup.js.map
@@ -0,0 +1,4 @@
1
+ import type { Code } from '../../types';
2
+ import type { ScriptCodegenContext } from './context';
3
+ import { ScriptCodegenOptions } from './index';
4
+ export declare function generateStyleModulesType(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateStyleModulesType = generateStyleModulesType;
4
+ const utils_1 = require("../utils");
5
+ const index_1 = require("./index");
6
+ const template_1 = require("./template");
7
+ function* generateStyleModulesType(options, ctx) {
8
+ const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
9
+ if (!styles.length && !options.scriptSetupRanges?.useCssModule.length) {
10
+ return;
11
+ }
12
+ yield `type __VLS_StyleModules = {${utils_1.newLine}`;
13
+ for (const [style, i] of styles) {
14
+ const { name, offset } = style.module;
15
+ if (offset) {
16
+ yield [
17
+ name,
18
+ 'main',
19
+ offset + 1,
20
+ index_1.codeFeatures.all
21
+ ];
22
+ }
23
+ else {
24
+ yield name;
25
+ }
26
+ yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
27
+ for (const className of style.classNames) {
28
+ yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
29
+ }
30
+ yield `>${utils_1.endOfLine}`;
31
+ }
32
+ yield `}${utils_1.endOfLine}`;
33
+ }
34
+ //# sourceMappingURL=styleModulesType.js.map
@@ -99,9 +99,7 @@ function* generateTemplateBody(options, templateCodegenCtx) {
99
99
  yield* (0, modules_1.generateStyleModules)(options);
100
100
  yield* generateCssVars(options, templateCodegenCtx);
101
101
  if (options.templateCodegen) {
102
- for (const code of options.templateCodegen.codes) {
103
- yield code;
104
- }
102
+ yield* options.templateCodegen.codes;
105
103
  }
106
104
  else {
107
105
  yield `// no template${utils_1.newLine}`;
@@ -3,28 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateClassProperty = generateClassProperty;
4
4
  const codeFeatures_1 = require("../codeFeatures");
5
5
  const utils_1 = require("../utils");
6
+ const wrapWith_1 = require("../utils/wrapWith");
6
7
  function* generateClassProperty(styleIndex, classNameWithDot, offset, propertyType) {
7
8
  yield `${utils_1.newLine} & { `;
8
- yield [
9
- '',
10
- 'style_' + styleIndex,
11
- offset,
12
- codeFeatures_1.codeFeatures.navigation,
13
- ];
14
- yield `'`;
15
- yield [
9
+ yield* (0, wrapWith_1.wrapWith)(offset, offset + classNameWithDot.length, 'style_' + styleIndex, codeFeatures_1.codeFeatures.navigation, `'`, [
16
10
  classNameWithDot.slice(1),
17
11
  'style_' + styleIndex,
18
12
  offset + 1,
19
- codeFeatures_1.codeFeatures.navigation,
20
- ];
21
- yield `'`;
22
- yield [
23
- '',
24
- 'style_' + styleIndex,
25
- offset + classNameWithDot.length,
26
- codeFeatures_1.codeFeatures.navigation,
27
- ];
13
+ utils_1.combineLastMapping
14
+ ], `'`);
28
15
  yield `: ${propertyType}`;
29
16
  yield ` }`;
30
17
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTemplateCodegenContext = createTemplateCodegenContext;
4
4
  const codeFeatures_1 = require("../codeFeatures");
5
5
  const utils_1 = require("../utils");
6
+ const wrapWith_1 = require("../utils/wrapWith");
6
7
  /**
7
8
  * Creates and returns a Context object used for generating type-checkable TS code
8
9
  * from the template section of a .vue file.
@@ -227,7 +228,7 @@ function createTemplateCodegenContext(options) {
227
228
  resetDirectiveComments: function* (endStr) {
228
229
  if (expectErrorToken) {
229
230
  const token = expectErrorToken;
230
- yield* (0, utils_1.wrapWith)(expectErrorToken.node.loc.start.offset, expectErrorToken.node.loc.end.offset, {
231
+ yield* (0, wrapWith_1.wrapWith)(expectErrorToken.node.loc.start.offset, expectErrorToken.node.loc.end.offset, {
231
232
  verification: {
232
233
  // If no errors/warnings/diagnostics were reported within the region of code covered
233
234
  // by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
@@ -8,6 +8,7 @@ const shared_2 = require("../../utils/shared");
8
8
  const inlayHints_1 = require("../inlayHints");
9
9
  const utils_1 = require("../utils");
10
10
  const camelized_1 = require("../utils/camelized");
11
+ const wrapWith_1 = require("../utils/wrapWith");
11
12
  const elementChildren_1 = require("./elementChildren");
12
13
  const elementDirectives_1 = require("./elementDirectives");
13
14
  const elementEvents_1 = require("./elementEvents");
@@ -81,7 +82,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
81
82
  }
82
83
  else {
83
84
  const shouldCapitalize = matchImportName[0].toUpperCase() === matchImportName[0];
84
- yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, tagOffset, {
85
+ yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, {
85
86
  ...ctx.codeFeatures.withoutHighlightAndCompletion,
86
87
  navigation: {
87
88
  resolveRenameNewName: camelizeComponentName,
@@ -119,14 +120,14 @@ function* generateComponent(options, ctx, node, isVForChild) {
119
120
  yield* generateCanonicalComponentName(node.tag, tagOffsets[0], ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation);
120
121
  yield `${utils_1.endOfLine}`;
121
122
  const camelizedTag = (0, shared_1.camelize)(node.tag);
122
- if (utils_1.variableNameRegex.test(camelizedTag)) {
123
+ if (utils_1.identifierRegex.test(camelizedTag)) {
123
124
  // navigation support
124
125
  yield `/** @type {[`;
125
126
  for (const tagOffset of tagOffsets) {
126
127
  for (const shouldCapitalize of (node.tag[0] === node.tag[0].toUpperCase() ? [false] : [true, false])) {
127
128
  const expectName = shouldCapitalize ? (0, shared_1.capitalize)(camelizedTag) : camelizedTag;
128
129
  yield `typeof __VLS_components.`;
129
- yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, tagOffset, {
130
+ yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, {
130
131
  navigation: {
131
132
  resolveRenameNewName: node.tag !== expectName ? camelizeComponentName : undefined,
132
133
  resolveRenameEditText: getTagRenameApply(node.tag),
@@ -139,7 +140,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
139
140
  // auto import support
140
141
  if (options.edited) {
141
142
  yield `// @ts-ignore${utils_1.newLine}`; // #2304
142
- yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), tagOffsets[0], {
143
+ yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), 'template', tagOffsets[0], {
143
144
  completion: {
144
145
  isAdditional: true,
145
146
  onlyImport: true,
@@ -157,7 +158,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
157
158
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
158
159
  yield `}))${utils_1.endOfLine}`;
159
160
  yield `const `;
160
- yield* (0, utils_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.resolveCodeFeatures({
161
+ yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.resolveCodeFeatures({
161
162
  verification: {
162
163
  shouldReport(_source, code) {
163
164
  // https://typescript.tv/errors/#ts6133
@@ -168,7 +169,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
168
169
  yield ` = ${componentFunctionalVar}`;
169
170
  yield* generateComponentGeneric(ctx);
170
171
  yield `(`;
171
- yield* (0, utils_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), `}`);
172
+ 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), `}`);
172
173
  yield `, ...__VLS_functionalComponentArgsRest(${componentFunctionalVar}))${utils_1.endOfLine}`;
173
174
  yield* generateFailedPropExps(options, ctx, failedPropExps);
174
175
  yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar);
@@ -226,7 +227,7 @@ function* generateElement(options, ctx, node, isVForChild) {
226
227
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
227
228
  }
228
229
  yield `)(`;
229
- yield* (0, utils_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
230
+ 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), `}`);
230
231
  yield `)${utils_1.endOfLine}`;
231
232
  yield* generateFailedPropExps(options, ctx, failedPropExps);
232
233
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
@@ -257,7 +258,7 @@ function* generateFailedPropExps(options, ctx, failedPropExps) {
257
258
  }
258
259
  }
259
260
  function getCanonicalComponentName(tagText) {
260
- return utils_1.variableNameRegex.test(tagText)
261
+ return utils_1.identifierRegex.test(tagText)
261
262
  ? tagText
262
263
  : (0, shared_1.capitalize)((0, shared_1.camelize)(tagText.replace(colonReg, '-')));
263
264
  }
@@ -275,17 +276,17 @@ function getPossibleOriginalComponentNames(tagText, deduplicate) {
275
276
  return names;
276
277
  }
277
278
  function* generateCanonicalComponentName(tagText, offset, features) {
278
- if (utils_1.variableNameRegex.test(tagText)) {
279
+ if (utils_1.identifierRegex.test(tagText)) {
279
280
  yield [tagText, 'template', offset, features];
280
281
  }
281
282
  else {
282
- yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), offset, features);
283
+ yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), 'template', offset, features);
283
284
  }
284
285
  }
285
286
  function* generateComponentGeneric(ctx) {
286
287
  if (ctx.lastGenericComment) {
287
288
  const { content, offset } = ctx.lastGenericComment;
288
- yield* (0, utils_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
289
+ yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
289
290
  content,
290
291
  'template',
291
292
  offset,
@@ -304,7 +305,7 @@ function* generateElementReference(options, ctx, node) {
304
305
  yield `/** @type {typeof __VLS_ctx`;
305
306
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation, prop.value.loc);
306
307
  yield `} */${utils_1.endOfLine}`;
307
- if (utils_1.variableNameRegex.test(content) && !options.templateRefNames.has(content)) {
308
+ if (utils_1.identifierRegex.test(content) && !options.templateRefNames.has(content)) {
308
309
  ctx.accessExternalVariable(content, startOffset);
309
310
  }
310
311
  return [content, startOffset];
@@ -9,6 +9,7 @@ const codeFeatures_1 = require("../codeFeatures");
9
9
  const utils_1 = require("../utils");
10
10
  const camelized_1 = require("../utils/camelized");
11
11
  const stringLiteralKey_1 = require("../utils/stringLiteralKey");
12
+ const wrapWith_1 = require("../utils/wrapWith");
12
13
  const elementProps_1 = require("./elementProps");
13
14
  const interpolation_1 = require("./interpolation");
14
15
  const objectProperty_1 = require("./objectProperty");
@@ -32,13 +33,13 @@ function* generateElementDirectives(options, ctx, node) {
32
33
  continue;
33
34
  }
34
35
  ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
35
- yield* (0, utils_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!)`);
36
+ 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!)`);
36
37
  yield utils_1.endOfLine;
37
38
  }
38
39
  }
39
40
  function* generateIdentifier(options, ctx, prop) {
40
41
  const rawName = 'v-' + prop.name;
41
- yield* (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, ctx.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, prop.loc.start.offset, ctx.resolveCodeFeatures({
42
+ 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
43
  ...codeFeatures_1.codeFeatures.withoutHighlight,
43
44
  // fix https://github.com/vuejs/language-tools/issues/1905
44
45
  ...codeFeatures_1.codeFeatures.additionalCompletion,
@@ -55,7 +56,7 @@ function* generateArg(options, ctx, prop) {
55
56
  return;
56
57
  }
57
58
  const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
58
- yield* (0, utils_1.wrapWith)(startOffset, startOffset + arg.content.length, ctx.codeFeatures.verification, `arg`);
59
+ yield* (0, wrapWith_1.wrapWith)(startOffset, startOffset + arg.content.length, ctx.codeFeatures.verification, `arg`);
59
60
  yield `: `;
60
61
  if (arg.isStatic) {
61
62
  yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, ctx.codeFeatures.all);
@@ -72,7 +73,7 @@ function* generateModifiers(options, ctx, prop, propertyName = 'modifiers') {
72
73
  }
73
74
  const startOffset = modifiers[0].loc.start.offset - 1;
74
75
  const endOffset = modifiers.at(-1).loc.end.offset;
75
- yield* (0, utils_1.wrapWith)(startOffset, endOffset, ctx.codeFeatures.verification, propertyName);
76
+ yield* (0, wrapWith_1.wrapWith)(startOffset, endOffset, ctx.codeFeatures.verification, propertyName);
76
77
  yield `: { `;
77
78
  for (const mod of modifiers) {
78
79
  yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, ctx.codeFeatures.withoutHighlightAndNavigation);
@@ -85,7 +86,7 @@ function* generateValue(options, ctx, prop) {
85
86
  if (exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
86
87
  return;
87
88
  }
88
- yield* (0, utils_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `value`);
89
+ yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `value`);
89
90
  yield `: `;
90
91
  yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp, ctx.codeFeatures.all);
91
92
  }
@@ -6,4 +6,5 @@ import type { TemplateCodegenOptions } from './index';
6
6
  export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
7
7
  export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string): Generator<Code>;
8
8
  export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
9
+ export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
9
10
  export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;