@vue/language-core 3.1.5 → 3.1.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 (100) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +3 -2
  3. package/lib/codegen/codeFeatures.d.ts +5 -9
  4. package/lib/codegen/codeFeatures.js +5 -5
  5. package/lib/codegen/globalTypes.js +12 -18
  6. package/lib/codegen/localTypes.d.ts +1 -1
  7. package/lib/codegen/localTypes.js +6 -6
  8. package/lib/codegen/names.d.ts +30 -0
  9. package/lib/codegen/names.js +34 -0
  10. package/lib/codegen/script/component.js +45 -54
  11. package/lib/codegen/script/context.d.ts +2 -5
  12. package/lib/codegen/script/context.js +1 -7
  13. package/lib/codegen/script/index.d.ts +10 -12
  14. package/lib/codegen/script/index.js +74 -73
  15. package/lib/codegen/script/scriptSetup.d.ts +3 -2
  16. package/lib/codegen/script/scriptSetup.js +209 -283
  17. package/lib/codegen/script/src.js +9 -3
  18. package/lib/codegen/script/template.js +64 -108
  19. package/lib/codegen/style/common.d.ts +3 -0
  20. package/lib/codegen/style/common.js +43 -0
  21. package/lib/codegen/style/index.d.ts +63 -0
  22. package/lib/codegen/style/index.js +38 -0
  23. package/lib/codegen/style/modules.d.ts +3 -2
  24. package/lib/codegen/style/modules.js +12 -11
  25. package/lib/codegen/style/scopedClasses.d.ts +2 -3
  26. package/lib/codegen/style/scopedClasses.js +23 -21
  27. package/lib/codegen/template/context.d.ts +7 -16
  28. package/lib/codegen/template/context.js +81 -93
  29. package/lib/codegen/template/element.js +151 -55
  30. package/lib/codegen/template/elementDirectives.js +32 -12
  31. package/lib/codegen/template/elementEvents.js +27 -28
  32. package/lib/codegen/template/elementProps.d.ts +2 -2
  33. package/lib/codegen/template/elementProps.js +49 -23
  34. package/lib/codegen/template/index.d.ts +8 -19
  35. package/lib/codegen/template/index.js +85 -80
  36. package/lib/codegen/template/interpolation.d.ts +3 -3
  37. package/lib/codegen/template/interpolation.js +90 -136
  38. package/lib/codegen/template/objectProperty.js +8 -4
  39. package/lib/codegen/template/propertyAccess.d.ts +1 -1
  40. package/lib/codegen/template/propertyAccess.js +5 -7
  41. package/lib/codegen/template/slotOutlet.js +25 -8
  42. package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
  43. package/lib/codegen/template/styleScopedClasses.js +23 -149
  44. package/lib/codegen/template/templateChild.d.ts +0 -1
  45. package/lib/codegen/template/templateChild.js +11 -68
  46. package/lib/codegen/template/vFor.js +10 -13
  47. package/lib/codegen/template/vIf.js +5 -3
  48. package/lib/codegen/template/vSlot.js +20 -15
  49. package/lib/codegen/utils/boundary.d.ts +3 -0
  50. package/lib/codegen/utils/boundary.js +13 -0
  51. package/lib/codegen/utils/camelized.js +3 -3
  52. package/lib/codegen/utils/escaped.js +4 -2
  53. package/lib/codegen/utils/index.d.ts +3 -4
  54. package/lib/codegen/utils/index.js +42 -16
  55. package/lib/codegen/utils/merge.d.ts +2 -2
  56. package/lib/codegen/utils/merge.js +9 -9
  57. package/lib/codegen/utils/stringLiteralKey.js +6 -3
  58. package/lib/codegen/utils/transform.d.ts +8 -0
  59. package/lib/codegen/utils/transform.js +27 -0
  60. package/lib/codegen/utils/unicode.js +4 -2
  61. package/lib/compilerOptions.d.ts +5 -2
  62. package/lib/compilerOptions.js +67 -44
  63. package/lib/languagePlugin.d.ts +1 -1
  64. package/lib/languagePlugin.js +2 -2
  65. package/lib/plugins/vue-template-inline-css.js +2 -6
  66. package/lib/plugins/vue-template-inline-ts.js +12 -14
  67. package/lib/plugins/vue-tsx.d.ts +11 -20
  68. package/lib/plugins/vue-tsx.js +121 -68
  69. package/lib/plugins.js +1 -1
  70. package/lib/types.d.ts +5 -4
  71. package/lib/utils/parseSfc.js +7 -3
  72. package/lib/utils/shared.d.ts +1 -1
  73. package/lib/utils/shared.js +7 -6
  74. package/lib/utils/signals.d.ts +2 -2
  75. package/lib/utils/signals.js +8 -6
  76. package/lib/virtualCode/embeddedCodes.d.ts +12 -0
  77. package/lib/virtualCode/embeddedCodes.js +249 -0
  78. package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
  79. package/lib/virtualCode/index.js +81 -0
  80. package/lib/virtualCode/ir.d.ts +4 -0
  81. package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +59 -94
  82. package/lib/virtualCode/normalize.d.ts +2 -0
  83. package/lib/virtualCode/normalize.js +170 -0
  84. package/package.json +4 -4
  85. package/lib/codegen/style/classProperty.d.ts +0 -2
  86. package/lib/codegen/style/classProperty.js +0 -18
  87. package/lib/codegen/style/imports.d.ts +0 -2
  88. package/lib/codegen/style/imports.js +0 -27
  89. package/lib/codegen/template/elementChildren.d.ts +0 -5
  90. package/lib/codegen/template/elementChildren.js +0 -12
  91. package/lib/codegen/utils/wrapWith.d.ts +0 -2
  92. package/lib/codegen/utils/wrapWith.js +0 -15
  93. package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
  94. package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
  95. package/lib/virtualFile/computedSfc.d.ts +0 -6
  96. package/lib/virtualFile/computedVueSfc.d.ts +0 -4
  97. package/lib/virtualFile/computedVueSfc.js +0 -41
  98. package/lib/virtualFile/embeddedFile.d.ts +0 -11
  99. package/lib/virtualFile/embeddedFile.js +0 -14
  100. package/lib/virtualFile/vueFile.js +0 -49
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateScriptSetupImports = generateScriptSetupImports;
4
- exports.generateScriptSetup = generateScriptSetup;
4
+ exports.generateGeneric = generateGeneric;
5
+ exports.generateSetupFunction = generateSetupFunction;
5
6
  const shared_1 = require("@vue/shared");
6
7
  const codeFeatures_1 = require("../codeFeatures");
8
+ const names = require("../names");
7
9
  const utils_1 = require("../utils");
10
+ const boundary_1 = require("../utils/boundary");
8
11
  const camelized_1 = require("../utils/camelized");
9
- const wrapWith_1 = require("../utils/wrapWith");
12
+ const transform_1 = require("../utils/transform");
10
13
  const component_1 = require("./component");
11
- const index_1 = require("./index");
12
- const template_1 = require("./template");
13
14
  function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
14
15
  yield [
15
16
  scriptSetup.content.slice(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
@@ -18,363 +19,288 @@ function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
18
19
  codeFeatures_1.codeFeatures.all,
19
20
  ];
20
21
  }
21
- function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
22
- if (scriptSetup.generic) {
23
- yield* (0, index_1.generateConstExport)(options, scriptSetup);
24
- yield `(`;
25
- if (typeof scriptSetup.generic === 'object') {
26
- yield `<`;
27
- yield [
28
- scriptSetup.generic.text,
29
- 'main',
30
- scriptSetup.generic.offset,
31
- codeFeatures_1.codeFeatures.all,
32
- ];
33
- if (!scriptSetup.generic.text.endsWith(`,`)) {
34
- yield `,`;
35
- }
36
- yield `>`;
37
- }
38
- yield `(${utils_1.newLine}`
39
- + ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${utils_1.newLine}`
40
- + ` __VLS_ctx?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}` // use __VLS_Prettify for less dts code
41
- + ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${utils_1.newLine}`
42
- + ` __VLS_setup = (async () => {${utils_1.newLine}`;
43
- yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined);
44
- const propTypes = [];
45
- if (ctx.generatedPropsType) {
46
- propTypes.push(`__VLS_PublicProps`);
47
- }
48
- if (scriptSetupRanges.defineProps?.arg) {
49
- yield `const __VLS_propsOption = `;
50
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, codeFeatures_1.codeFeatures.navigation);
51
- yield utils_1.endOfLine;
52
- propTypes.push(`import('${options.vueCompilerOptions.lib}').${options.vueCompilerOptions.target >= 3.3 ? `ExtractPublicPropTypes` : `ExtractPropTypes`}<typeof __VLS_propsOption>`);
53
- }
54
- if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
55
- propTypes.push(`__VLS_EmitProps`);
56
- }
57
- if (options.templateCodegen?.inheritedAttrVars.size) {
58
- propTypes.push(`__VLS_InheritedAttrs`);
59
- }
60
- const emitTypes = [];
61
- if (scriptSetupRanges.defineEmits) {
62
- emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'}`);
22
+ function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic, body) {
23
+ yield `(`;
24
+ if (typeof generic === 'object') {
25
+ yield `<`;
26
+ yield [generic.text, 'main', generic.offset, codeFeatures_1.codeFeatures.all];
27
+ if (!generic.text.endsWith(`,`)) {
28
+ yield `,`;
63
29
  }
64
- if (scriptSetupRanges.defineModel.length) {
65
- emitTypes.push(`typeof __VLS_modelEmit`);
66
- }
67
- yield `return {} as {${utils_1.newLine}`
68
- + ` props: ${propTypes.length ? `${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}> & ` : ``}${options.vueCompilerOptions.target >= 3.4
69
- ? `import('${options.vueCompilerOptions.lib}').PublicProps`
70
- : options.vueCompilerOptions.target >= 3
71
- ? `import('${options.vueCompilerOptions.lib}').VNodeProps`
72
- + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
73
- + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
74
- : `globalThis.JSX.IntrinsicAttributes`} & (typeof globalThis extends { __VLS_PROPS_FALLBACK: infer P } ? P : {})${utils_1.endOfLine}`
75
- + ` expose: (exposed: ${scriptSetupRanges.defineExpose
76
- ? `import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<typeof __VLS_exposed>`
77
- : `{}`}) => void${utils_1.endOfLine}`
78
- + ` attrs: any${utils_1.endOfLine}`
79
- + ` slots: __VLS_Slots${utils_1.endOfLine}`
80
- + ` emit: ${emitTypes.length ? emitTypes.join(` & `) : `{}`}${utils_1.endOfLine}`
81
- + `}${utils_1.endOfLine}`;
82
- yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
83
- yield `) => ({} as import('${options.vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))${utils_1.endOfLine}`;
84
- }
85
- else if (!options.sfc.script) {
86
- // no script block, generate script setup code at root
87
- yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, 'export default');
30
+ yield `>`;
31
+ }
32
+ yield `(${utils_1.newLine}`
33
+ + ` ${names.props}: NonNullable<Awaited<typeof ${names.setup}>>['props'],${utils_1.newLine}`
34
+ + ` ${names.ctx}?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof ${names.setup}>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}` // use __VLS_Prettify for less dts code
35
+ + ` ${names.exposed}?: NonNullable<Awaited<typeof ${names.setup}>>['expose'],${utils_1.newLine}`
36
+ + ` ${names.setup} = (async () => {${utils_1.newLine}`;
37
+ yield* body;
38
+ const propTypes = [];
39
+ const { vueCompilerOptions } = options;
40
+ if (ctx.generatedTypes.has(names.PublicProps)) {
41
+ propTypes.push(names.PublicProps);
88
42
  }
89
- else {
90
- yield* (0, index_1.generateConstExport)(options, scriptSetup);
91
- yield `await (async () => {${utils_1.newLine}`;
92
- yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, 'return');
93
- yield `})()${utils_1.endOfLine}`;
43
+ if (scriptSetupRanges.defineProps?.arg) {
44
+ yield `const __VLS_propsOption = `;
45
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, codeFeatures_1.codeFeatures.navigation);
46
+ yield utils_1.endOfLine;
47
+ propTypes.push(`import('${vueCompilerOptions.lib}').${vueCompilerOptions.target >= 3.3 ? `ExtractPublicPropTypes` : `ExtractPropTypes`}<typeof __VLS_propsOption>`);
48
+ }
49
+ if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
50
+ propTypes.push(names.EmitProps);
51
+ }
52
+ if (options.templateCodegen?.generatedTypes.has(names.InheritedAttrs)) {
53
+ propTypes.push(names.InheritedAttrs);
54
+ }
55
+ const emitTypes = [];
56
+ if (scriptSetupRanges.defineEmits) {
57
+ emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names.emit}`);
94
58
  }
59
+ if (scriptSetupRanges.defineModel.length) {
60
+ emitTypes.push(`typeof ${names.modelEmit}`);
61
+ }
62
+ yield `return {} as {${utils_1.newLine}`;
63
+ yield ` props: ${propTypes.length ? `${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}> & ` : ``}${vueCompilerOptions.target >= 3.4
64
+ ? `import('${vueCompilerOptions.lib}').PublicProps`
65
+ : vueCompilerOptions.target >= 3
66
+ ? `import('${vueCompilerOptions.lib}').VNodeProps`
67
+ + ` & import('${vueCompilerOptions.lib}').AllowedComponentProps`
68
+ + ` & import('${vueCompilerOptions.lib}').ComponentCustomProps`
69
+ : `globalThis.JSX.IntrinsicAttributes`} & (typeof globalThis extends { ${names.PROPS_FALLBACK}: infer P } ? P : {})${utils_1.endOfLine}`;
70
+ yield ` expose: (exposed: `;
71
+ yield scriptSetupRanges.defineExpose
72
+ ? `import('${vueCompilerOptions.lib}').ShallowUnwrapRef<typeof ${names.exposed}>`
73
+ : `{}`;
74
+ if (options.vueCompilerOptions.inferComponentDollarRefs
75
+ && options.templateCodegen?.generatedTypes.has(names.TemplateRefs)) {
76
+ yield ` & { $refs: ${names.TemplateRefs}; }`;
77
+ }
78
+ if (options.vueCompilerOptions.inferComponentDollarEl
79
+ && options.templateCodegen?.generatedTypes.has(names.RootEl)) {
80
+ yield ` & { $el: ${names.RootEl}; }`;
81
+ }
82
+ yield `) => void${utils_1.endOfLine}`;
83
+ yield ` attrs: any${utils_1.endOfLine}`;
84
+ yield ` slots: ${names.Slots}${utils_1.endOfLine}`;
85
+ yield ` emit: ${emitTypes.length ? emitTypes.join(` & `) : `{}`}${utils_1.endOfLine}`;
86
+ yield `}${utils_1.endOfLine}`;
87
+ yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
88
+ yield `) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof ${names.setup}> }))${utils_1.endOfLine}`;
95
89
  }
96
- function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, syntax) {
97
- let setupCodeModifies = [];
90
+ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, body, output) {
91
+ const transforms = [];
98
92
  if (scriptSetupRanges.defineProps) {
99
93
  const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
100
- setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name, `__VLS_props`, `__VLS_Props`));
94
+ const _callExp = scriptSetupRanges.withDefaults?.callExp ?? callExp;
95
+ transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, _callExp, typeArg, name, names.props, names.Props));
101
96
  }
102
97
  if (scriptSetupRanges.defineEmits) {
103
98
  const { name, statement, callExp, typeArg } = scriptSetupRanges.defineEmits;
104
- setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, `__VLS_emit`, `__VLS_Emit`));
99
+ transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names.emit, names.Emit));
105
100
  }
106
101
  if (scriptSetupRanges.defineSlots) {
107
102
  const { name, statement, callExp, typeArg } = scriptSetupRanges.defineSlots;
108
- setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, `__VLS_slots`, `__VLS_Slots`));
103
+ transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names.slots, names.Slots));
109
104
  }
110
105
  if (scriptSetupRanges.defineExpose) {
111
106
  const { callExp, arg, typeArg } = scriptSetupRanges.defineExpose;
112
107
  if (typeArg) {
113
- setupCodeModifies.push([
114
- [
115
- `let __VLS_exposed!: `,
116
- (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
117
- utils_1.endOfLine,
118
- ],
119
- callExp.start,
120
- callExp.start,
121
- ], [
122
- [`typeof __VLS_exposed`],
123
- typeArg.start,
124
- typeArg.end,
125
- ]);
108
+ transforms.push((0, transform_1.insert)(callExp.start, function* () {
109
+ yield `let ${names.exposed}!: `;
110
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all);
111
+ yield utils_1.endOfLine;
112
+ }), (0, transform_1.replace)(typeArg.start, typeArg.end, function* () {
113
+ yield `typeof ${names.exposed}`;
114
+ }));
126
115
  }
127
116
  else if (arg) {
128
- setupCodeModifies.push([
129
- [
130
- `const __VLS_exposed = `,
131
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
132
- utils_1.endOfLine,
133
- ],
134
- callExp.start,
135
- callExp.start,
136
- ], [
137
- [`__VLS_exposed`],
138
- arg.start,
139
- arg.end,
140
- ]);
117
+ transforms.push((0, transform_1.insert)(callExp.start, function* () {
118
+ yield `const ${names.exposed} = `;
119
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all);
120
+ yield utils_1.endOfLine;
121
+ }), (0, transform_1.replace)(arg.start, arg.end, function* () {
122
+ yield `${names.exposed}`;
123
+ }));
141
124
  }
142
125
  else {
143
- setupCodeModifies.push([
144
- [`const __VLS_exposed = {}${utils_1.endOfLine}`],
145
- callExp.start,
146
- callExp.start,
147
- ]);
126
+ transforms.push((0, transform_1.insert)(callExp.start, function* () {
127
+ yield `const ${names.exposed} = {}${utils_1.endOfLine}`;
128
+ }));
148
129
  }
149
130
  }
150
131
  if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
151
132
  for (const { callExp } of scriptSetupRanges.useAttrs) {
152
- setupCodeModifies.push([
153
- [`(`],
154
- callExp.start,
155
- callExp.start,
156
- ], [
157
- [` as typeof __VLS_dollars.$attrs)`],
158
- callExp.end,
159
- callExp.end,
160
- ]);
133
+ transforms.push((0, transform_1.insert)(callExp.start, function* () {
134
+ yield `(`;
135
+ }), (0, transform_1.insert)(callExp.end, function* () {
136
+ yield ` as typeof ${names.dollars}.$attrs)`;
137
+ }));
161
138
  }
162
139
  }
163
140
  for (const { callExp, exp, arg } of scriptSetupRanges.useCssModule) {
164
- setupCodeModifies.push([
165
- [`(`],
166
- callExp.start,
167
- callExp.start,
168
- ], [
169
- arg
170
- ? [
171
- ` as Omit<__VLS_StyleModules, '$style'>[`,
172
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic),
173
- `])`,
174
- ]
175
- : [
176
- ` as __VLS_StyleModules[`,
177
- ...(0, wrapWith_1.wrapWith)(scriptSetup.name, exp.start, exp.end, codeFeatures_1.codeFeatures.verification, `'$style'`),
178
- `])`,
179
- ],
180
- callExp.end,
181
- callExp.end,
182
- ]);
141
+ transforms.push((0, transform_1.insert)(callExp.start, function* () {
142
+ yield `(`;
143
+ }));
144
+ const type = options.styleCodegen?.generatedTypes.has(names.StyleModules)
145
+ ? names.StyleModules
146
+ : `{}`;
183
147
  if (arg) {
184
- setupCodeModifies.push([
185
- [`__VLS_placeholder`],
186
- arg.start,
187
- arg.end,
188
- ]);
148
+ transforms.push((0, transform_1.insert)(callExp.end, function* () {
149
+ yield ` as Omit<${type}, '$style'>[`;
150
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic);
151
+ yield `])`;
152
+ }), (0, transform_1.replace)(arg.start, arg.end, function* () {
153
+ yield names.placeholder;
154
+ }));
155
+ }
156
+ else {
157
+ transforms.push((0, transform_1.insert)(callExp.end, function* () {
158
+ yield ` as ${type}[`;
159
+ const token = yield* (0, boundary_1.startBoundary)(scriptSetup.name, exp.start, codeFeatures_1.codeFeatures.verification);
160
+ yield `'$style'`;
161
+ yield (0, boundary_1.endBoundary)(token, exp.end);
162
+ yield `])`;
163
+ }));
189
164
  }
190
165
  }
191
166
  if (options.vueCompilerOptions.inferTemplateDollarSlots) {
192
167
  for (const { callExp } of scriptSetupRanges.useSlots) {
193
- setupCodeModifies.push([
194
- [`(`],
195
- callExp.start,
196
- callExp.start,
197
- ], [
198
- [` as typeof __VLS_dollars.$slots)`],
199
- callExp.end,
200
- callExp.end,
201
- ]);
168
+ transforms.push((0, transform_1.insert)(callExp.start, function* () {
169
+ yield `(`;
170
+ }), (0, transform_1.insert)(callExp.end, function* () {
171
+ yield ` as typeof ${names.dollars}.$slots)`;
172
+ }));
202
173
  }
203
174
  }
204
- const isTs = options.lang !== 'js' && options.lang !== 'jsx';
205
- for (const { callExp, exp, arg } of scriptSetupRanges.useTemplateRef) {
206
- const templateRefType = arg
207
- ? [
208
- `__VLS_TemplateRefs[`,
209
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic),
210
- `]`,
211
- ]
212
- : [`unknown`];
213
- if (isTs) {
214
- setupCodeModifies.push([
215
- [
216
- `<`,
217
- ...templateRefType,
218
- `>`,
219
- ],
220
- exp.end,
221
- exp.end,
222
- ]);
223
- }
224
- else {
225
- setupCodeModifies.push([
226
- [`(`],
227
- callExp.start,
228
- callExp.start,
229
- ], [
230
- [
231
- ` as __VLS_UseTemplateRef<`,
232
- ...templateRefType,
233
- `>)`,
234
- ],
235
- callExp.end,
236
- callExp.end,
237
- ]);
238
- }
175
+ for (const { callExp, arg } of scriptSetupRanges.useTemplateRef) {
176
+ transforms.push((0, transform_1.insert)(callExp.start, function* () {
177
+ yield `(`;
178
+ }), (0, transform_1.insert)(callExp.end, function* () {
179
+ yield ` as __VLS_UseTemplateRef<`;
180
+ if (arg) {
181
+ yield names.TemplateRefs;
182
+ yield `[`;
183
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic);
184
+ yield `]`;
185
+ }
186
+ else {
187
+ yield `unknown`;
188
+ }
189
+ yield `>)`;
190
+ }));
239
191
  if (arg) {
240
- setupCodeModifies.push([
241
- [`__VLS_placeholder`],
242
- arg.start,
243
- arg.end,
244
- ]);
192
+ transforms.push((0, transform_1.replace)(arg.start, arg.end, function* () {
193
+ yield names.placeholder;
194
+ }));
245
195
  }
246
196
  }
247
- setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
248
- let nextStart = Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset);
249
- for (const [codes, start, end] of setupCodeModifies) {
250
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, start, codeFeatures_1.codeFeatures.all);
251
- yield* codes;
252
- nextStart = end;
253
- }
254
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, codeFeatures_1.codeFeatures.all);
255
- yield* (0, utils_1.generatePartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
256
- yield* generateMacros(options, ctx);
257
- const hasSlots = !!(scriptSetupRanges.defineSlots
258
- || options.templateCodegen?.slots.length
259
- || options.templateCodegen?.dynamicSlots.length);
197
+ yield* (0, transform_1.generateCodeWithTransforms)(Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset), scriptSetup.content.length, transforms, (start, end) => (0, utils_1.generateSfcBlockSection)(scriptSetup, start, end, codeFeatures_1.codeFeatures.all, end === scriptSetup.content.length));
198
+ yield* generateMacros(options);
260
199
  yield* generateModels(scriptSetup, scriptSetupRanges);
261
- yield* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges, hasSlots);
262
- yield* (0, template_1.generateTemplate)(options, ctx);
263
- if (syntax) {
264
- const prefix = syntax === 'return'
265
- ? [`return `]
266
- : (0, index_1.generateConstExport)(options, scriptSetup);
267
- if (hasSlots) {
200
+ yield* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges);
201
+ yield* body;
202
+ if (output) {
203
+ if (hasSlotsType(options)) {
268
204
  yield `const __VLS_base = `;
269
205
  yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
270
206
  yield utils_1.endOfLine;
271
- yield* prefix;
272
- yield `{} as ${ctx.localTypes.WithSlots}<typeof __VLS_base, __VLS_Slots>${utils_1.endOfLine}`;
207
+ yield* output;
208
+ yield `{} as ${ctx.localTypes.WithSlots}<typeof __VLS_base, ${names.Slots}>${utils_1.endOfLine}`;
273
209
  }
274
210
  else {
275
- yield* prefix;
211
+ yield* output;
276
212
  yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
277
213
  yield utils_1.endOfLine;
278
214
  }
279
215
  }
280
216
  }
281
- function* generateMacros(options, ctx) {
217
+ function* generateMacros(options) {
282
218
  if (options.vueCompilerOptions.target >= 3.3) {
283
219
  yield `// @ts-ignore${utils_1.newLine}`;
284
220
  yield `declare const { `;
285
221
  for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
286
- if (!ctx.bindingNames.has(macro)) {
222
+ if (!options.setupExposed.has(macro)) {
287
223
  yield `${macro}, `;
288
224
  }
289
225
  }
290
226
  yield `}: typeof import('${options.vueCompilerOptions.lib}')${utils_1.endOfLine}`;
291
227
  }
292
228
  }
293
- function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, defaultName, typeName) {
229
+ function* generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, defaultName, typeName) {
294
230
  if (typeArg) {
295
- yield [
296
- [
297
- `type ${typeName} = `,
298
- (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
299
- utils_1.endOfLine,
300
- ],
301
- statement.start,
302
- statement.start,
303
- ];
304
- yield [[typeName], typeArg.start, typeArg.end];
231
+ yield (0, transform_1.insert)(statement.start, function* () {
232
+ yield `type ${typeName} = `;
233
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all);
234
+ yield utils_1.endOfLine;
235
+ });
236
+ yield (0, transform_1.replace)(typeArg.start, typeArg.end, function* () {
237
+ yield typeName;
238
+ });
305
239
  }
306
240
  if (!name) {
307
241
  if (statement.start === callExp.start && statement.end === callExp.end) {
308
- yield [[`const ${defaultName} = `], callExp.start, callExp.start];
242
+ yield (0, transform_1.insert)(callExp.start, function* () {
243
+ yield `const ${defaultName} = `;
244
+ });
309
245
  }
310
246
  else if (typeArg) {
311
- yield [
312
- [
313
- `const ${defaultName} = `,
314
- (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all),
315
- ],
316
- statement.start,
317
- typeArg.start,
318
- ];
319
- yield [
320
- [
321
- (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all),
322
- utils_1.endOfLine,
323
- (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
324
- defaultName,
325
- ],
326
- typeArg.end,
327
- callExp.end,
328
- ];
247
+ yield (0, transform_1.replace)(statement.start, typeArg.start, function* () {
248
+ yield `const ${defaultName} = `;
249
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all);
250
+ });
251
+ yield (0, transform_1.replace)(typeArg.end, callExp.end, function* () {
252
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all);
253
+ yield utils_1.endOfLine;
254
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
255
+ yield defaultName;
256
+ });
329
257
  }
330
258
  else {
331
- yield [
332
- [
333
- `const ${defaultName} = `,
334
- (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all),
335
- utils_1.endOfLine,
336
- (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
337
- defaultName,
338
- ],
339
- statement.start,
340
- callExp.end,
341
- ];
259
+ yield (0, transform_1.replace)(statement.start, callExp.end, function* () {
260
+ yield `const ${defaultName} = `;
261
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all);
262
+ yield utils_1.endOfLine;
263
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
264
+ yield defaultName;
265
+ });
342
266
  }
343
267
  }
344
268
  else if (!utils_1.identifierRegex.test(name)) {
345
- yield [[`const ${defaultName} = `], statement.start, callExp.start];
346
- yield [
347
- [
348
- utils_1.endOfLine,
349
- (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
350
- defaultName,
351
- ],
352
- statement.end,
353
- statement.end,
354
- ];
269
+ yield (0, transform_1.replace)(statement.start, callExp.start, function* () {
270
+ yield `const ${defaultName} = `;
271
+ });
272
+ yield (0, transform_1.insert)(statement.end, function* () {
273
+ yield utils_1.endOfLine;
274
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
275
+ yield defaultName;
276
+ });
355
277
  }
356
278
  }
357
- function* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges, hasSlots) {
279
+ function* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges) {
358
280
  if (scriptSetupRanges.defineProps?.typeArg && scriptSetupRanges.withDefaults?.arg) {
359
- yield `const __VLS_defaults = `;
360
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, codeFeatures_1.codeFeatures.navigation);
281
+ yield `const ${names.defaults} = `;
282
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, codeFeatures_1.codeFeatures.navigation);
361
283
  yield utils_1.endOfLine;
362
284
  }
363
285
  const propTypes = [];
364
- if (options.vueCompilerOptions.jsxSlots && hasSlots) {
365
- propTypes.push(`${ctx.localTypes.PropsChildren}<__VLS_Slots>`);
286
+ if (options.vueCompilerOptions.jsxSlots && hasSlotsType(options)) {
287
+ propTypes.push(`${ctx.localTypes.PropsChildren}<${names.Slots}>`);
366
288
  }
367
289
  if (scriptSetupRanges.defineProps?.typeArg) {
368
- propTypes.push(`__VLS_Props`);
290
+ propTypes.push(names.Props);
369
291
  }
370
292
  if (scriptSetupRanges.defineModel.length) {
371
- propTypes.push(`__VLS_ModelProps`);
293
+ propTypes.push(names.ModelProps);
372
294
  }
373
295
  if (propTypes.length) {
374
- ctx.generatedPropsType = true;
375
- yield `type __VLS_PublicProps = ${propTypes.join(` & `)}${utils_1.endOfLine}`;
296
+ yield `type ${names.PublicProps} = ${propTypes.join(` & `)}${utils_1.endOfLine}`;
297
+ ctx.generatedTypes.add(names.PublicProps);
376
298
  }
377
299
  }
300
+ function hasSlotsType(options) {
301
+ return !!(options.scriptSetupRanges?.defineSlots
302
+ || options.templateCodegen?.generatedTypes.has(names.Slots));
303
+ }
378
304
  function* generateModels(scriptSetup, scriptSetupRanges) {
379
305
  if (!scriptSetupRanges.defineModel.length) {
380
306
  return;
@@ -397,7 +323,7 @@ function* generateModels(scriptSetup, scriptSetupRanges) {
397
323
  }
398
324
  else if (defineModel.defaultValue && propName) {
399
325
  // Infer from defineModel({ default: T })
400
- modelType = `typeof __VLS_defaultModels['${propName}']`;
326
+ modelType = `typeof ${names.defaultModels}['${propName}']`;
401
327
  }
402
328
  else {
403
329
  modelType = `any`;
@@ -409,21 +335,21 @@ function* generateModels(scriptSetup, scriptSetupRanges) {
409
335
  emitCodes.push(generateModelEmit(defineModel, propName, modelType));
410
336
  }
411
337
  if (defaultCodes.length) {
412
- yield `const __VLS_defaultModels = {${utils_1.newLine}`;
338
+ yield `const ${names.defaultModels} = {${utils_1.newLine}`;
413
339
  yield* defaultCodes;
414
340
  yield `}${utils_1.endOfLine}`;
415
341
  }
416
- yield `type __VLS_ModelProps = {${utils_1.newLine}`;
342
+ yield `type ${names.ModelProps} = {${utils_1.newLine}`;
417
343
  for (const codes of propCodes) {
418
344
  yield* codes;
419
345
  }
420
346
  yield `}${utils_1.endOfLine}`;
421
- yield `type __VLS_ModelEmit = {${utils_1.newLine}`;
347
+ yield `type ${names.ModelEmit} = {${utils_1.newLine}`;
422
348
  for (const codes of emitCodes) {
423
349
  yield* codes;
424
350
  }
425
351
  yield `}${utils_1.endOfLine}`;
426
- yield `const __VLS_modelEmit = defineEmits<__VLS_ModelEmit>()${utils_1.endOfLine}`;
352
+ yield `const ${names.modelEmit} = defineEmits<${names.ModelEmit}>()${utils_1.endOfLine}`;
427
353
  }
428
354
  function* generateModelProp(scriptSetup, defineModel, propName, modelType) {
429
355
  if (defineModel.comments) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSrc = generateSrc;
4
4
  const codeFeatures_1 = require("../codeFeatures");
5
5
  const utils_1 = require("../utils");
6
- const wrapWith_1 = require("../utils/wrapWith");
6
+ const boundary_1 = require("../utils/boundary");
7
7
  function* generateSrc(src) {
8
8
  if (src === true) {
9
9
  return;
@@ -22,10 +22,16 @@ function* generateSrc(src) {
22
22
  text = text + '.js';
23
23
  }
24
24
  yield `export * from `;
25
- yield* (0, wrapWith_1.wrapWith)('main', src.offset, src.offset + src.text.length, {
25
+ const wrapCodeFeatures = {
26
26
  ...codeFeatures_1.codeFeatures.all,
27
27
  ...text !== src.text ? codeFeatures_1.codeFeatures.navigationWithoutRename : {},
28
- }, `'`, [text.slice(0, src.text.length), 'main', src.offset, utils_1.combineLastMapping], text.slice(src.text.length), `'`);
28
+ };
29
+ const token = yield* (0, boundary_1.startBoundary)('main', src.offset, wrapCodeFeatures);
30
+ yield `'`;
31
+ yield [text.slice(0, src.text.length), 'main', src.offset, { __combineToken: token }];
32
+ yield text.slice(src.text.length);
33
+ yield `'`;
34
+ yield (0, boundary_1.endBoundary)(token, src.offset + src.text.length);
29
35
  yield utils_1.endOfLine;
30
36
  yield `export { default } from '${text}'${utils_1.endOfLine}`;
31
37
  }