@vue/language-core 2.2.0 → 2.2.2

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 (84) hide show
  1. package/index.d.ts +0 -1
  2. package/index.js +1 -2
  3. package/lib/codeFeatures.d.ts +1 -0
  4. package/lib/codeFeatures.js +3 -0
  5. package/lib/codegen/codeFeatures.d.ts +83 -0
  6. package/lib/codegen/codeFeatures.js +71 -0
  7. package/lib/codegen/common.d.ts +12 -0
  8. package/lib/codegen/common.js +79 -0
  9. package/lib/codegen/globalTypes.d.ts +3 -1
  10. package/lib/codegen/globalTypes.js +30 -14
  11. package/lib/codegen/localTypes.d.ts +1 -1
  12. package/lib/codegen/localTypes.js +4 -4
  13. package/lib/codegen/script/binding.d.ts +4 -0
  14. package/lib/codegen/script/binding.js +41 -0
  15. package/lib/codegen/script/component.d.ts +1 -1
  16. package/lib/codegen/script/component.js +7 -7
  17. package/lib/codegen/script/componentSelf.d.ts +1 -1
  18. package/lib/codegen/script/componentSelf.js +2 -2
  19. package/lib/codegen/script/context.d.ts +1 -1
  20. package/lib/codegen/script/index.d.ts +1 -8
  21. package/lib/codegen/script/index.js +15 -39
  22. package/lib/codegen/script/scriptSetup.d.ts +1 -1
  23. package/lib/codegen/script/scriptSetup.js +46 -58
  24. package/lib/codegen/script/src.js +2 -2
  25. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  26. package/lib/codegen/script/styleModulesType.js +2 -2
  27. package/lib/codegen/script/template.d.ts +1 -1
  28. package/lib/codegen/script/template.js +11 -32
  29. package/lib/codegen/template/camelized.d.ts +2 -0
  30. package/lib/codegen/template/camelized.js +31 -0
  31. package/lib/codegen/template/context.d.ts +17 -13
  32. package/lib/codegen/template/context.js +35 -89
  33. package/lib/codegen/template/element.js +32 -252
  34. package/lib/codegen/template/elementChildren.d.ts +1 -1
  35. package/lib/codegen/template/elementChildren.js +3 -4
  36. package/lib/codegen/template/elementDirectives.js +18 -11
  37. package/lib/codegen/template/elementProps.d.ts +2 -1
  38. package/lib/codegen/template/elementProps.js +22 -26
  39. package/lib/codegen/template/index.d.ts +1 -0
  40. package/lib/codegen/template/index.js +39 -33
  41. package/lib/codegen/template/interpolation.js +13 -9
  42. package/lib/codegen/template/slotOutlet.js +39 -17
  43. package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
  44. package/lib/codegen/template/styleScopedClasses.js +141 -0
  45. package/lib/codegen/template/templateChild.js +9 -2
  46. package/lib/codegen/template/vSlot.d.ts +5 -0
  47. package/lib/codegen/template/vSlot.js +80 -0
  48. package/lib/codegen/utils/index.d.ts +11 -1
  49. package/lib/codegen/utils/index.js +15 -4
  50. package/lib/codegen/utils/src.d.ts +2 -0
  51. package/lib/codegen/utils/src.js +19 -0
  52. package/lib/parsers/scriptSetupRanges.d.ts +5 -3
  53. package/lib/parsers/scriptSetupRanges.js +8 -11
  54. package/lib/parsers/vueCompilerOptions.d.ts +2 -2
  55. package/lib/plugins/vue-style-class-names.d.ts +5 -0
  56. package/lib/plugins/vue-style-class-names.js +32 -0
  57. package/lib/plugins/vue-style-reference-link.d.ts +1 -0
  58. package/lib/plugins/vue-style-reference-link.js +3 -0
  59. package/lib/plugins/vue-style-reference-links.d.ts +3 -0
  60. package/lib/plugins/vue-style-reference-links.js +26 -0
  61. package/lib/plugins/vue-template-inline-ts.js +53 -12
  62. package/lib/plugins/vue-tsx.d.ts +35 -28
  63. package/lib/plugins/vue-tsx.js +75 -55
  64. package/lib/plugins/vue-vine.d.ts +3 -0
  65. package/lib/plugins/vue-vine.js +35 -0
  66. package/lib/types.d.ts +6 -2
  67. package/lib/utils/findDestructuredProps.d.ts +1 -0
  68. package/lib/utils/findDestructuredProps.js +3 -0
  69. package/lib/utils/parseCssImports.d.ts +4 -0
  70. package/lib/utils/parseCssImports.js +19 -0
  71. package/lib/utils/parseSfc.js +4 -3
  72. package/lib/utils/signals.d.ts +2 -0
  73. package/lib/utils/signals.js +54 -0
  74. package/lib/utils/ts.d.ts +14 -2
  75. package/lib/utils/ts.js +117 -88
  76. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -1
  77. package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
  78. package/lib/virtualFile/computedSfc.d.ts +1 -2
  79. package/lib/virtualFile/computedSfc.js +79 -82
  80. package/lib/virtualFile/computedVueSfc.d.ts +1 -2
  81. package/lib/virtualFile/computedVueSfc.js +7 -7
  82. package/lib/virtualFile/vueFile.d.ts +5 -5
  83. package/lib/virtualFile/vueFile.js +6 -6
  84. package/package.json +4 -4
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.codeFeatures = void 0;
4
3
  exports.generateScript = generateScript;
5
4
  exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
6
5
  const path = require("path-browserify");
6
+ const codeFeatures_1 = require("../codeFeatures");
7
7
  const globalTypes_1 = require("../globalTypes");
8
8
  const utils_1 = require("../utils");
9
9
  const componentSelf_1 = require("./componentSelf");
@@ -12,28 +12,6 @@ const scriptSetup_1 = require("./scriptSetup");
12
12
  const src_1 = require("./src");
13
13
  const styleModulesType_1 = require("./styleModulesType");
14
14
  const template_1 = require("./template");
15
- exports.codeFeatures = {
16
- all: {
17
- verification: true,
18
- completion: true,
19
- semantic: true,
20
- navigation: true,
21
- },
22
- none: {},
23
- verification: {
24
- verification: true,
25
- },
26
- navigation: {
27
- navigation: true,
28
- },
29
- navigationWithoutRename: {
30
- navigation: {
31
- shouldRename() {
32
- return false;
33
- },
34
- },
35
- },
36
- };
37
15
  function* generateScript(options) {
38
16
  const ctx = (0, context_1.createScriptCodegenContext)(options);
39
17
  if (options.vueCompilerOptions.__setupedGlobalTypes) {
@@ -46,7 +24,7 @@ function* generateScript(options) {
46
24
  yield `/// <reference types="${relativePath}" />${utils_1.newLine}`;
47
25
  }
48
26
  else {
49
- yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${utils_1.newLine}`;
27
+ yield `/// <reference types=".vue-global-types/${(0, globalTypes_1.getGlobalTypesFileName)(options.vueCompilerOptions)}" />${utils_1.newLine}`;
50
28
  }
51
29
  }
52
30
  else {
@@ -62,12 +40,12 @@ function* generateScript(options) {
62
40
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
63
41
  yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
64
42
  if (exportDefault) {
65
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
43
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
66
44
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
67
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
45
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
68
46
  }
69
47
  else {
70
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
48
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
71
49
  yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
72
50
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
73
51
  }
@@ -92,27 +70,27 @@ function* generateScript(options) {
92
70
  ? options.vueCompilerOptions.optionsWrapper[1]
93
71
  : '[Missing optionsWrapper[1]]',
94
72
  });
95
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
73
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
96
74
  yield options.vueCompilerOptions.optionsWrapper[0];
97
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, exports.codeFeatures.all);
75
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, codeFeatures_1.codeFeatures.all);
98
76
  yield options.vueCompilerOptions.optionsWrapper[1];
99
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
77
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
100
78
  }
101
79
  else if (classBlockEnd !== undefined) {
102
80
  if (options.vueCompilerOptions.skipTemplateCodegen) {
103
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
81
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
104
82
  }
105
83
  else {
106
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
84
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, codeFeatures_1.codeFeatures.all);
107
85
  yield `__VLS_template = () => {${utils_1.newLine}`;
108
86
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
109
87
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
110
88
  yield `}${utils_1.endOfLine}`;
111
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
89
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
112
90
  }
113
91
  }
114
92
  else {
115
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
93
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
116
94
  }
117
95
  }
118
96
  else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
@@ -126,9 +104,7 @@ function* generateScript(options) {
126
104
  yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
127
105
  }
128
106
  if (!ctx.generatedTemplate) {
129
- yield `function __VLS_template() {${utils_1.newLine}`;
130
107
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
131
- yield `}${utils_1.endOfLine}`;
132
108
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
133
109
  }
134
110
  // #4788
@@ -138,16 +114,16 @@ function* generateScript(options) {
138
114
  }
139
115
  yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
140
116
  if (options.appendGlobalTypes) {
141
- yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions.lib, options.vueCompilerOptions.target, options.vueCompilerOptions.strictTemplates);
117
+ yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
142
118
  }
143
119
  if (options.sfc.scriptSetup) {
144
- yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, exports.codeFeatures.verification];
120
+ yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures_1.codeFeatures.verification];
145
121
  }
146
122
  return ctx;
147
123
  }
148
124
  function* generateScriptSectionPartiallyEnding(source, end, mark) {
149
125
  yield `;`;
150
- yield ['', source, end, exports.codeFeatures.verification];
126
+ yield ['', source, end, codeFeatures_1.codeFeatures.verification];
151
127
  yield `/* PartiallyEnd: ${mark} */${utils_1.newLine}`;
152
128
  }
153
129
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
2
2
  import type { Code, Sfc } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
- import { ScriptCodegenOptions } from './index';
4
+ import { type ScriptCodegenOptions } from './index';
5
5
  export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
6
  export declare function generateScriptSetup(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateScriptSetupImports = generateScriptSetupImports;
4
4
  exports.generateScriptSetup = generateScriptSetup;
5
+ const codeFeatures_1 = require("../codeFeatures");
5
6
  const utils_1 = require("../utils");
6
7
  const component_1 = require("./component");
7
8
  const componentSelf_1 = require("./componentSelf");
@@ -12,7 +13,7 @@ function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
12
13
  scriptSetup.content.slice(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
13
14
  'scriptSetup',
14
15
  0,
15
- index_1.codeFeatures.all,
16
+ codeFeatures_1.codeFeatures.all,
16
17
  ];
17
18
  }
18
19
  function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
@@ -24,7 +25,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
24
25
  '',
25
26
  'scriptSetup',
26
27
  options.sfc.scriptSetup.content.length,
27
- index_1.codeFeatures.verification,
28
+ codeFeatures_1.codeFeatures.verification,
28
29
  ];
29
30
  }
30
31
  yield `export default `;
@@ -34,7 +35,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
34
35
  scriptSetup.generic,
35
36
  scriptSetup.name,
36
37
  scriptSetup.genericOffset,
37
- index_1.codeFeatures.all,
38
+ codeFeatures_1.codeFeatures.all,
38
39
  ];
39
40
  if (!scriptSetup.generic.endsWith(`,`)) {
40
41
  yield `,`;
@@ -53,10 +54,10 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
53
54
  emitTypes.push(`typeof __VLS_modelEmit`);
54
55
  }
55
56
  yield `return {} as {${utils_1.newLine}`
56
- + ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & __VLS_TemplateResult['attrs']> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
57
+ + ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & Partial<__VLS_InheritedAttrs>> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
57
58
  + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.defineExpose ? 'typeof __VLS_exposed' : '{}'}>): void,${utils_1.newLine}`
58
59
  + ` attrs: any,${utils_1.newLine}`
59
- + ` slots: __VLS_TemplateResult['slots'],${utils_1.newLine}`
60
+ + ` slots: __VLS_Slots,${utils_1.newLine}`
60
61
  + ` emit: ${emitTypes.length ? emitTypes.join(' & ') : `{}`},${utils_1.newLine}`
61
62
  + `}${utils_1.endOfLine}`;
62
63
  yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
@@ -80,28 +81,15 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
80
81
  let setupCodeModifies = [];
81
82
  if (scriptSetupRanges.defineProps) {
82
83
  const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
83
- setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name, '__VLS_props', '__VLS_Props'));
84
+ setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name, `__VLS_props`, `__VLS_Props`));
84
85
  }
85
86
  if (scriptSetupRanges.defineEmits) {
86
87
  const { name, statement, callExp, typeArg } = scriptSetupRanges.defineEmits;
87
- setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, '__VLS_emit', '__VLS_Emit'));
88
+ setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, `__VLS_emit`, `__VLS_Emit`));
88
89
  }
89
90
  if (scriptSetupRanges.defineSlots) {
90
- const { name, callExp, isObjectBindingPattern } = scriptSetupRanges.defineSlots;
91
- if (isObjectBindingPattern) {
92
- setupCodeModifies.push([
93
- [`__VLS_slots;\nconst __VLS_slots = `],
94
- callExp.start,
95
- callExp.start,
96
- ]);
97
- }
98
- else if (!name) {
99
- setupCodeModifies.push([
100
- [`const __VLS_slots = `],
101
- callExp.start,
102
- callExp.start
103
- ]);
104
- }
91
+ const { name, statement, callExp, typeArg } = scriptSetupRanges.defineSlots;
92
+ setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, `__VLS_slots`, `__VLS_Slots`));
105
93
  }
106
94
  if (scriptSetupRanges.defineExpose) {
107
95
  const { callExp, arg, typeArg } = scriptSetupRanges.defineExpose;
@@ -109,7 +97,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
109
97
  setupCodeModifies.push([
110
98
  [
111
99
  `let __VLS_exposed!: `,
112
- (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, index_1.codeFeatures.navigation),
100
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.navigation),
113
101
  `${utils_1.endOfLine}`,
114
102
  ],
115
103
  callExp.start,
@@ -120,7 +108,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
120
108
  setupCodeModifies.push([
121
109
  [
122
110
  `const __VLS_exposed = `,
123
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation),
111
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation),
124
112
  `${utils_1.endOfLine}`,
125
113
  ],
126
114
  callExp.start,
@@ -135,18 +123,17 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
135
123
  ]);
136
124
  }
137
125
  }
138
- // TODO: circular reference
139
- // for (const { callExp } of scriptSetupRanges.useAttrs) {
140
- // setupCodeModifies.push([
141
- // [`(`],
142
- // callExp.start,
143
- // callExp.start
144
- // ], [
145
- // [` as __VLS_TemplateResult['attrs'] & Record<string, unknown>)`],
146
- // callExp.end,
147
- // callExp.end
148
- // ]);
149
- // }
126
+ for (const { callExp } of scriptSetupRanges.useAttrs) {
127
+ setupCodeModifies.push([
128
+ [`(`],
129
+ callExp.start,
130
+ callExp.start
131
+ ], [
132
+ [` as typeof __VLS_special.$attrs)`],
133
+ callExp.end,
134
+ callExp.end
135
+ ]);
136
+ }
150
137
  for (const { callExp, exp, arg } of scriptSetupRanges.useCssModule) {
151
138
  setupCodeModifies.push([
152
139
  [`(`],
@@ -155,11 +142,11 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
155
142
  ], [
156
143
  arg ? [
157
144
  ` as Omit<__VLS_StyleModules, '$style'>[`,
158
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.all),
145
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
159
146
  `])`
160
147
  ] : [
161
148
  ` as __VLS_StyleModules[`,
162
- ['', scriptSetup.name, exp.start, index_1.codeFeatures.verification],
149
+ ['', scriptSetup.name, exp.start, codeFeatures_1.codeFeatures.verification],
163
150
  `'$style'`,
164
151
  ['', scriptSetup.name, exp.end, utils_1.combineLastMapping],
165
152
  `])`
@@ -181,7 +168,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
181
168
  callExp.start,
182
169
  callExp.start
183
170
  ], [
184
- [` as __VLS_TemplateResult['slots'])`],
171
+ [` as typeof __VLS_special.$slots)`],
185
172
  callExp.end,
186
173
  callExp.end
187
174
  ]);
@@ -190,8 +177,8 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
190
177
  for (const { callExp, exp, arg } of scriptSetupRanges.useTemplateRef) {
191
178
  const templateRefType = arg
192
179
  ? [
193
- `__VLS_TemplateResult['refs'][`,
194
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.all),
180
+ `__VLS_TemplateRefs[`,
181
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
195
182
  `]`
196
183
  ]
197
184
  : [`unknown`];
@@ -232,36 +219,33 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
232
219
  setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
233
220
  let nextStart = Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset);
234
221
  for (const [codes, start, end] of setupCodeModifies) {
235
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, start, index_1.codeFeatures.all);
222
+ yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, start, codeFeatures_1.codeFeatures.all);
236
223
  for (const code of codes) {
237
224
  yield code;
238
225
  }
239
226
  nextStart = end;
240
227
  }
241
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, index_1.codeFeatures.all);
228
+ yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, codeFeatures_1.codeFeatures.all);
242
229
  yield* (0, index_1.generateScriptSectionPartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
243
230
  yield* generateMacros(options, ctx);
244
231
  yield* generateDefineProp(options);
245
232
  if (scriptSetupRanges.defineProps?.typeArg && scriptSetupRanges.withDefaults?.arg) {
246
233
  // fix https://github.com/vuejs/language-tools/issues/1187
247
234
  yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
248
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, index_1.codeFeatures.navigation);
235
+ yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, codeFeatures_1.codeFeatures.navigation);
249
236
  yield `)${utils_1.endOfLine}`;
250
237
  }
251
238
  yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges);
252
239
  yield* generateModelEmit(scriptSetup, scriptSetupRanges);
253
- yield `function __VLS_template() {${utils_1.newLine}`;
254
240
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
255
- yield `}${utils_1.endOfLine}`;
256
241
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
257
- yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${utils_1.endOfLine}`;
258
242
  if (syntax) {
259
243
  if (!options.vueCompilerOptions.skipTemplateCodegen && (options.templateCodegen?.hasSlot || scriptSetupRanges.defineSlots)) {
260
244
  yield `const __VLS_component = `;
261
245
  yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
262
246
  yield utils_1.endOfLine;
263
247
  yield `${syntax} `;
264
- yield `{} as ${ctx.localTypes.WithTemplateSlots}<typeof __VLS_component, __VLS_TemplateResult['slots']>${utils_1.endOfLine}`;
248
+ yield `{} as ${ctx.localTypes.WithSlots}<typeof __VLS_component, __VLS_Slots>${utils_1.endOfLine}`;
265
249
  }
266
250
  else {
267
251
  yield `${syntax} `;
@@ -272,6 +256,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
272
256
  }
273
257
  function* generateMacros(options, ctx) {
274
258
  if (options.vueCompilerOptions.target >= 3.3) {
259
+ yield `// @ts-ignore${utils_1.newLine}`;
275
260
  yield `declare const { `;
276
261
  for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
277
262
  if (!ctx.bindingNames.has(macro)) {
@@ -301,7 +286,7 @@ function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
301
286
  if (typeArg) {
302
287
  yield [[
303
288
  `type ${typeName} = `,
304
- (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, index_1.codeFeatures.all),
289
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
305
290
  utils_1.endOfLine,
306
291
  ], statement.start, statement.start];
307
292
  yield [[typeName], typeArg.start, typeArg.end];
@@ -313,21 +298,21 @@ function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
313
298
  else if (typeArg) {
314
299
  yield [[
315
300
  `const ${defaultName} = `,
316
- (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, index_1.codeFeatures.all)
301
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all)
317
302
  ], statement.start, typeArg.start];
318
303
  yield [[
319
- (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, index_1.codeFeatures.all),
304
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all),
320
305
  utils_1.endOfLine,
321
- (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, index_1.codeFeatures.all),
306
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
322
307
  defaultName
323
308
  ], typeArg.end, callExp.end];
324
309
  }
325
310
  else {
326
311
  yield [[
327
312
  `const ${defaultName} = `,
328
- (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, index_1.codeFeatures.all),
313
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all),
329
314
  utils_1.endOfLine,
330
- (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, index_1.codeFeatures.all),
315
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
331
316
  defaultName
332
317
  ], statement.start, callExp.end];
333
318
  }
@@ -338,7 +323,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
338
323
  yield `const __VLS_fnComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
339
324
  if (scriptSetupRanges.defineProps?.arg) {
340
325
  yield `props: `;
341
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, index_1.codeFeatures.navigation);
326
+ yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, codeFeatures_1.codeFeatures.navigation);
342
327
  yield `,${utils_1.newLine}`;
343
328
  }
344
329
  yield* (0, component_1.generateEmitsOption)(options, scriptSetupRanges);
@@ -383,7 +368,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
383
368
  yield ` & `;
384
369
  }
385
370
  ctx.generatedPropsType = true;
386
- yield `${ctx.localTypes.PropsChildren}<typeof __VLS_slots>`;
371
+ yield `${ctx.localTypes.PropsChildren}<__VLS_Slots>`;
387
372
  }
388
373
  if (scriptSetupRanges.defineProp.length) {
389
374
  if (ctx.generatedPropsType) {
@@ -397,10 +382,10 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
397
382
  yield propName;
398
383
  }
399
384
  else if (defineProp.name) {
400
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, index_1.codeFeatures.navigation);
385
+ yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, codeFeatures_1.codeFeatures.navigation);
401
386
  }
402
387
  else if (defineProp.localName) {
403
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.localName.start, defineProp.localName.end, index_1.codeFeatures.navigation);
388
+ yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.localName.start, defineProp.localName.end, codeFeatures_1.codeFeatures.navigation);
404
389
  }
405
390
  else {
406
391
  continue;
@@ -438,6 +423,9 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
438
423
  const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
439
424
  yield `'update:${propName}': [value: `;
440
425
  yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
426
+ if (!defineModel.required) {
427
+ yield ` | undefined`;
428
+ }
441
429
  yield `]${utils_1.endOfLine}`;
442
430
  }
443
431
  yield `}${utils_1.endOfLine}`;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSrc = generateSrc;
4
+ const codeFeatures_1 = require("../codeFeatures");
4
5
  const utils_1 = require("../utils");
5
- const index_1 = require("./index");
6
6
  function* generateSrc(script, src) {
7
7
  if (src.endsWith('.d.ts')) {
8
8
  src = src.slice(0, -'.d.ts'.length);
@@ -22,7 +22,7 @@ function* generateSrc(script, src) {
22
22
  'script',
23
23
  script.srcOffset - 1,
24
24
  {
25
- ...index_1.codeFeatures.all,
25
+ ...codeFeatures_1.codeFeatures.all,
26
26
  navigation: src === script.src
27
27
  ? true
28
28
  : {
@@ -1,4 +1,4 @@
1
1
  import type { Code } from '../../types';
2
2
  import type { ScriptCodegenContext } from './context';
3
- import { ScriptCodegenOptions } from './index';
3
+ import type { ScriptCodegenOptions } from './index';
4
4
  export declare function generateStyleModulesType(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStyleModulesType = generateStyleModulesType;
4
+ const codeFeatures_1 = require("../codeFeatures");
4
5
  const utils_1 = require("../utils");
5
- const index_1 = require("./index");
6
6
  const template_1 = require("./template");
7
7
  function* generateStyleModulesType(options, ctx) {
8
8
  const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
@@ -17,7 +17,7 @@ function* generateStyleModulesType(options, ctx) {
17
17
  name,
18
18
  'main',
19
19
  offset + 1,
20
- index_1.codeFeatures.all
20
+ codeFeatures_1.codeFeatures.all
21
21
  ];
22
22
  }
23
23
  else {
@@ -1,7 +1,7 @@
1
1
  import type { Code } from '../../types';
2
2
  import { TemplateCodegenContext } from '../template/context';
3
3
  import type { ScriptCodegenContext } from './context';
4
- import { type ScriptCodegenOptions } from './index';
4
+ import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code, TemplateCodegenContext>;
6
6
  export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
7
7
  export declare function generateCssClassProperty(styleIndex: number, classNameWithDot: string, offset: number, propertyType: string, optional: boolean): Generator<Code>;
@@ -4,13 +4,12 @@ exports.generateTemplate = generateTemplate;
4
4
  exports.generateTemplateDirectives = generateTemplateDirectives;
5
5
  exports.generateCssClassProperty = generateCssClassProperty;
6
6
  exports.getTemplateUsageVars = getTemplateUsageVars;
7
- const path = require("path-browserify");
8
7
  const shared_1 = require("../../utils/shared");
8
+ const codeFeatures_1 = require("../codeFeatures");
9
9
  const context_1 = require("../template/context");
10
10
  const interpolation_1 = require("../template/interpolation");
11
11
  const styleScopedClasses_1 = require("../template/styleScopedClasses");
12
12
  const utils_1 = require("../utils");
13
- const index_1 = require("./index");
14
13
  function* generateTemplate(options, ctx) {
15
14
  ctx.generatedTemplate = true;
16
15
  const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
@@ -56,25 +55,11 @@ function* generateTemplateComponents(options) {
56
55
  options.sfc.script.content.slice(componentsOption.start, componentsOption.end),
57
56
  'script',
58
57
  componentsOption.start,
59
- index_1.codeFeatures.navigation,
58
+ codeFeatures_1.codeFeatures.navigation,
60
59
  ];
61
60
  yield utils_1.endOfLine;
62
61
  types.push(`typeof __VLS_componentsOption`);
63
62
  }
64
- let nameType;
65
- if (options.sfc.script && options.scriptRanges?.exportDefault?.nameOption) {
66
- const { nameOption } = options.scriptRanges.exportDefault;
67
- nameType = options.sfc.script.content.slice(nameOption.start, nameOption.end);
68
- }
69
- else if (options.sfc.scriptSetup) {
70
- const baseName = path.basename(options.fileName);
71
- nameType = `'${options.scriptSetupRanges?.defineOptions?.name ?? baseName.slice(0, baseName.lastIndexOf('.'))}'`;
72
- }
73
- if (nameType) {
74
- types.push(`{ [K in ${nameType}]: typeof __VLS_self & (new () => { `
75
- + (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target)
76
- + `: typeof ${options.scriptSetupRanges?.defineSlots?.name ?? `__VLS_slots`} }) }`);
77
- }
78
63
  types.push(`typeof __VLS_ctx`);
79
64
  yield `type __VLS_LocalComponents =`;
80
65
  for (const type of types) {
@@ -93,7 +78,7 @@ function* generateTemplateDirectives(options) {
93
78
  options.sfc.script.content.slice(directivesOption.start, directivesOption.end),
94
79
  'script',
95
80
  directivesOption.start,
96
- index_1.codeFeatures.navigation,
81
+ codeFeatures_1.codeFeatures.navigation,
97
82
  ];
98
83
  yield utils_1.endOfLine;
99
84
  types.push(`typeof __VLS_directivesOption`);
@@ -119,18 +104,12 @@ function* generateTemplateBody(options, templateCodegenCtx) {
119
104
  else {
120
105
  yield `// no template${utils_1.newLine}`;
121
106
  if (!options.scriptSetupRanges?.defineSlots) {
122
- yield `const __VLS_slots = {}${utils_1.endOfLine}`;
107
+ yield `type __VLS_Slots = {}${utils_1.endOfLine}`;
123
108
  }
124
- yield `const __VLS_inheritedAttrs = {}${utils_1.endOfLine}`;
125
- yield `const $refs = {}${utils_1.endOfLine}`;
126
- yield `const $el = {} as any${utils_1.endOfLine}`;
109
+ yield `type __VLS_InheritedAttrs = {}${utils_1.endOfLine}`;
110
+ yield `type __VLS_TemplateRefs = {}${utils_1.endOfLine}`;
111
+ yield `type __VLS_RootEl = any${utils_1.endOfLine}`;
127
112
  }
128
- yield `return {${utils_1.newLine}`;
129
- yield ` attrs: {} as Partial<typeof __VLS_inheritedAttrs>,${utils_1.newLine}`;
130
- yield ` slots: ${options.scriptSetupRanges?.defineSlots?.name ?? '__VLS_slots'},${utils_1.newLine}`;
131
- yield ` refs: $refs,${utils_1.newLine}`;
132
- yield ` rootEl: $el,${utils_1.newLine}`;
133
- yield `}${utils_1.endOfLine}`;
134
113
  }
135
114
  function* generateStyleScopedClasses(options, ctx) {
136
115
  const firstClasses = new Set();
@@ -161,21 +140,21 @@ function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propert
161
140
  '',
162
141
  'style_' + styleIndex,
163
142
  offset,
164
- index_1.codeFeatures.navigation,
143
+ codeFeatures_1.codeFeatures.navigation,
165
144
  ];
166
145
  yield `'`;
167
146
  yield [
168
147
  classNameWithDot.slice(1),
169
148
  'style_' + styleIndex,
170
149
  offset + 1,
171
- index_1.codeFeatures.navigation,
150
+ codeFeatures_1.codeFeatures.navigation,
172
151
  ];
173
152
  yield `'`;
174
153
  yield [
175
154
  '',
176
155
  'style_' + styleIndex,
177
156
  offset + classNameWithDot.length,
178
- index_1.codeFeatures.navigationWithoutRename,
157
+ codeFeatures_1.codeFeatures.navigationWithoutRename,
179
158
  ];
180
159
  yield `${optional ? '?' : ''}: ${propertyType}`;
181
160
  yield ` }`;
@@ -187,7 +166,7 @@ function* generateCssVars(options, ctx) {
187
166
  yield `// CSS variable injection ${utils_1.newLine}`;
188
167
  for (const style of options.sfc.styles) {
189
168
  for (const cssBind of style.cssVars) {
190
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, index_1.codeFeatures.all, cssBind.text, cssBind.offset);
169
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, cssBind.text, cssBind.offset);
191
170
  yield utils_1.endOfLine;
192
171
  }
193
172
  }
@@ -0,0 +1,2 @@
1
+ import type { Code, VueCodeInformation } from '../../types';
2
+ export declare function generateCamelized(code: string, offset: number, info: VueCodeInformation): Generator<Code>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCamelized = generateCamelized;
4
+ const shared_1 = require("@vue/shared");
5
+ const common_1 = require("../common");
6
+ function* generateCamelized(code, offset, info) {
7
+ const parts = code.split('-');
8
+ for (let i = 0; i < parts.length; i++) {
9
+ const part = parts[i];
10
+ if (part !== '') {
11
+ if (i === 0) {
12
+ yield [
13
+ part,
14
+ 'template',
15
+ offset,
16
+ info,
17
+ ];
18
+ }
19
+ else {
20
+ yield [
21
+ (0, shared_1.capitalize)(part),
22
+ 'template',
23
+ offset,
24
+ common_1.combineLastMapping,
25
+ ];
26
+ }
27
+ }
28
+ offset += part.length + 1;
29
+ }
30
+ }
31
+ //# sourceMappingURL=camelized.js.map