@vue/language-core 2.0.13 → 2.0.14

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 (85) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/common.d.ts +11 -0
  4. package/lib/codegen/common.js +70 -0
  5. package/lib/codegen/script/component.d.ts +9 -0
  6. package/lib/codegen/script/component.js +101 -0
  7. package/lib/codegen/script/context.d.ts +25 -0
  8. package/lib/codegen/script/context.js +124 -0
  9. package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
  10. package/lib/codegen/script/globalTypes.js +135 -0
  11. package/lib/codegen/script/index.d.ts +33 -0
  12. package/lib/codegen/script/index.js +127 -0
  13. package/lib/codegen/script/internalComponent.d.ts +5 -0
  14. package/lib/codegen/script/internalComponent.js +58 -0
  15. package/lib/codegen/script/scriptSetup.d.ts +6 -0
  16. package/lib/codegen/script/scriptSetup.js +338 -0
  17. package/lib/codegen/script/src.d.ts +2 -0
  18. package/lib/codegen/script/src.js +52 -0
  19. package/lib/codegen/script/template.d.ts +5 -0
  20. package/lib/codegen/script/template.js +193 -0
  21. package/lib/codegen/template/camelized.d.ts +2 -0
  22. package/lib/codegen/template/camelized.js +32 -0
  23. package/lib/codegen/template/context.d.ts +44 -0
  24. package/lib/codegen/template/context.js +171 -0
  25. package/lib/codegen/template/element.d.ts +7 -0
  26. package/lib/codegen/template/element.js +325 -0
  27. package/lib/codegen/template/elementChildren.d.ts +5 -0
  28. package/lib/codegen/template/elementChildren.js +21 -0
  29. package/lib/codegen/template/elementDirectives.d.ts +5 -0
  30. package/lib/codegen/template/elementDirectives.js +46 -0
  31. package/lib/codegen/template/elementEvents.d.ts +7 -0
  32. package/lib/codegen/template/elementEvents.js +141 -0
  33. package/lib/codegen/template/elementProps.d.ts +5 -0
  34. package/lib/codegen/template/elementProps.js +250 -0
  35. package/lib/codegen/template/index.d.ts +60 -0
  36. package/lib/codegen/template/index.js +217 -0
  37. package/lib/codegen/template/interpolation.d.ts +6 -0
  38. package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
  39. package/lib/codegen/template/objectProperty.d.ts +4 -0
  40. package/lib/codegen/template/objectProperty.js +31 -0
  41. package/lib/codegen/template/propertyAccess.d.ts +4 -0
  42. package/lib/codegen/template/propertyAccess.js +24 -0
  43. package/lib/codegen/template/slotOutlet.d.ts +5 -0
  44. package/lib/codegen/template/slotOutlet.js +72 -0
  45. package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
  46. package/lib/codegen/template/stringLiteralKey.js +14 -0
  47. package/lib/codegen/template/templateChild.d.ts +7 -0
  48. package/lib/codegen/template/templateChild.js +156 -0
  49. package/lib/codegen/template/vFor.d.ts +12 -0
  50. package/lib/codegen/template/vFor.js +69 -0
  51. package/lib/codegen/template/vIf.d.ts +5 -0
  52. package/lib/codegen/template/vIf.js +53 -0
  53. package/lib/languageModule.d.ts +3 -3
  54. package/lib/languageModule.js +2 -3
  55. package/lib/plugins/shared.d.ts +2 -0
  56. package/lib/plugins/shared.js +12 -0
  57. package/lib/plugins/vue-sfc-customblocks.js +2 -2
  58. package/lib/plugins/vue-sfc-scripts.js +2 -3
  59. package/lib/plugins/vue-sfc-styles.js +3 -3
  60. package/lib/plugins/vue-sfc-template.js +2 -2
  61. package/lib/plugins/vue-template-inline-css.js +34 -2
  62. package/lib/plugins/vue-template-inline-ts.js +10 -8
  63. package/lib/plugins/vue-tsx.d.ts +42 -5
  64. package/lib/plugins/vue-tsx.js +38 -28
  65. package/lib/types.d.ts +1 -3
  66. package/lib/utils/ts.js +0 -29
  67. package/lib/virtualFile/computedFiles.d.ts +1 -1
  68. package/lib/virtualFile/computedFiles.js +22 -12
  69. package/lib/virtualFile/computedMappings.js +3 -3
  70. package/lib/virtualFile/computedSfc.js +22 -1
  71. package/lib/virtualFile/embeddedFile.d.ts +2 -3
  72. package/lib/virtualFile/embeddedFile.js +1 -2
  73. package/lib/virtualFile/vueFile.d.ts +3 -5
  74. package/lib/virtualFile/vueFile.js +6 -8
  75. package/package.json +3 -3
  76. package/lib/generators/globalTypes.js +0 -135
  77. package/lib/generators/inlineCss.d.ts +0 -3
  78. package/lib/generators/inlineCss.js +0 -37
  79. package/lib/generators/script.d.ts +0 -13
  80. package/lib/generators/script.js +0 -981
  81. package/lib/generators/template.d.ts +0 -19
  82. package/lib/generators/template.js +0 -1578
  83. package/lib/generators/utils.d.ts +0 -5
  84. package/lib/generators/utils.js +0 -54
  85. package/lib/utils/transform.d.ts +0 -8
@@ -0,0 +1,5 @@
1
+ import type { Code } from '../../types';
2
+ import type { TemplateCodegenContext } from '../template/context';
3
+ import type { ScriptCodegenContext } from './context';
4
+ import type { ScriptCodegenOptions } from './index';
5
+ export declare function generateInternalComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateInternalComponent = void 0;
4
+ const common_1 = require("../common");
5
+ const component_1 = require("./component");
6
+ const template_1 = require("./template");
7
+ function* generateInternalComponent(options, ctx, templateCodegenCtx) {
8
+ if (options.sfc.scriptSetup && options.scriptSetupRanges) {
9
+ yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
10
+ yield `setup() {${common_1.newLine}`;
11
+ yield `return {${common_1.newLine}`;
12
+ if (ctx.bypassDefineComponent) {
13
+ yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
14
+ }
15
+ // bindings
16
+ const templateUsageVars = (0, template_1.getTemplateUsageVars)(options, ctx);
17
+ for (const [content, bindings] of [
18
+ [options.sfc.scriptSetup.content, options.scriptSetupRanges.bindings],
19
+ options.sfc.script && options.scriptRanges
20
+ ? [options.sfc.script.content, options.scriptRanges.bindings]
21
+ : ['', []],
22
+ ]) {
23
+ for (const expose of bindings) {
24
+ const varName = content.substring(expose.start, expose.end);
25
+ if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessGlobalVariables.has(varName)) {
26
+ continue;
27
+ }
28
+ const templateOffset = options.getGeneratedLength();
29
+ yield `${varName}: ${varName} as typeof `;
30
+ const scriptOffset = options.getGeneratedLength();
31
+ yield `${varName},${common_1.newLine}`;
32
+ options.linkedCodeMappings.push({
33
+ sourceOffsets: [scriptOffset],
34
+ generatedOffsets: [templateOffset],
35
+ lengths: [varName.length],
36
+ data: undefined,
37
+ });
38
+ }
39
+ }
40
+ yield `}${common_1.endOfLine}`; // return {
41
+ yield `},${common_1.newLine}`; // setup() {
42
+ if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
43
+ yield* (0, component_1.generateScriptSetupOptions)(ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
44
+ }
45
+ if (options.sfc.script && options.scriptRanges) {
46
+ yield* (0, component_1.generateScriptOptions)(options.sfc.script, options.scriptRanges);
47
+ }
48
+ yield `})${common_1.endOfLine}`; // defineComponent {
49
+ }
50
+ else if (options.sfc.script) {
51
+ yield `const __VLS_internalComponent = (await import('./${options.fileBaseName}')).default${common_1.endOfLine}`;
52
+ }
53
+ else {
54
+ yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
55
+ }
56
+ }
57
+ exports.generateInternalComponent = generateInternalComponent;
58
+ //# sourceMappingURL=internalComponent.js.map
@@ -0,0 +1,6 @@
1
+ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
2
+ import type { Code, Sfc } from '../../types';
3
+ import type { ScriptCodegenContext } from './context';
4
+ import { ScriptCodegenOptions } from './index';
5
+ export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Code;
6
+ export declare function generateScriptSetup(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateScriptSetup = exports.generateScriptSetupImports = void 0;
4
+ const common_1 = require("../common");
5
+ const component_1 = require("./component");
6
+ const index_1 = require("./index");
7
+ const template_1 = require("./template");
8
+ function generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
9
+ return [
10
+ scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + common_1.newLine,
11
+ 'scriptSetup',
12
+ 0,
13
+ index_1.codeFeatures.all,
14
+ ];
15
+ }
16
+ exports.generateScriptSetupImports = generateScriptSetupImports;
17
+ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
18
+ const definePropMirrors = new Map();
19
+ if (scriptSetup.generic) {
20
+ if (!options.scriptRanges?.exportDefault) {
21
+ yield `export default `;
22
+ }
23
+ yield `(<`;
24
+ yield [
25
+ scriptSetup.generic,
26
+ scriptSetup.name,
27
+ scriptSetup.genericOffset,
28
+ index_1.codeFeatures.all,
29
+ ];
30
+ if (!scriptSetup.generic.endsWith(`,`)) {
31
+ yield `,`;
32
+ }
33
+ yield `>(${common_1.newLine}`
34
+ + ` __VLS_props: Awaited<typeof __VLS_setup>['props'],${common_1.newLine}`
35
+ + ` __VLS_ctx?: ${ctx.helperTypes.Prettify.name}<Pick<Awaited<typeof __VLS_setup>, 'attrs' | 'emit' | 'slots'>>,${common_1.newLine}` // use __VLS_Prettify for less dts code
36
+ + ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${common_1.newLine}`
37
+ + ` __VLS_setup = (async () => {${common_1.newLine}`;
38
+ yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined, definePropMirrors);
39
+ yield ` return {} as {${common_1.newLine}`
40
+ + ` props: ${ctx.helperTypes.Prettify.name}<typeof __VLS_functionalComponentProps & typeof __VLS_componentProps> & typeof __VLS_publicProps,${common_1.newLine}`
41
+ + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${common_1.newLine}`
42
+ + ` attrs: any,${common_1.newLine}`
43
+ + ` slots: ReturnType<typeof __VLS_template>,${common_1.newLine}`
44
+ + ` emit: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'} & typeof __VLS_modelEmitsType,${common_1.newLine}`
45
+ + ` }${common_1.endOfLine}`;
46
+ yield ` })(),${common_1.newLine}`; // __VLS_setup = (async () => {
47
+ yield `) => ({} as import('${options.vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`;
48
+ }
49
+ else if (!options.sfc.script) {
50
+ // no script block, generate script setup code at root
51
+ yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, 'export default', definePropMirrors);
52
+ }
53
+ else {
54
+ if (!options.scriptRanges?.exportDefault) {
55
+ yield `export default `;
56
+ }
57
+ yield `await (async () => {${common_1.newLine}`;
58
+ yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, 'return', definePropMirrors);
59
+ yield `})()`;
60
+ }
61
+ if (ctx.scriptSetupGeneratedOffset !== undefined) {
62
+ for (const defineProp of scriptSetupRanges.defineProp) {
63
+ if (!defineProp.name) {
64
+ continue;
65
+ }
66
+ const propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
67
+ const propMirror = definePropMirrors.get(propName);
68
+ if (propMirror !== undefined) {
69
+ options.linkedCodeMappings.push({
70
+ sourceOffsets: [defineProp.name.start + ctx.scriptSetupGeneratedOffset],
71
+ generatedOffsets: [propMirror],
72
+ lengths: [defineProp.name.end - defineProp.name.start],
73
+ data: undefined,
74
+ });
75
+ }
76
+ }
77
+ }
78
+ }
79
+ exports.generateScriptSetup = generateScriptSetup;
80
+ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, syntax, definePropMirrors) {
81
+ const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
82
+ const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
83
+ if (options.vueCompilerOptions.target >= 3.3) {
84
+ yield `const { `;
85
+ for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
86
+ if (!ctx.bindingNames.has(macro)) {
87
+ yield macro + `, `;
88
+ }
89
+ }
90
+ yield `} = await import('${options.vueCompilerOptions.lib}')${common_1.endOfLine}`;
91
+ }
92
+ if (definePropProposalA) {
93
+ yield `declare function defineProp<T>(name: string, options: { required: true } & Record<string, unknown>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
94
+ yield `declare function defineProp<T>(name: string, options: { default: any } & Record<string, unknown>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
95
+ yield `declare function defineProp<T>(name?: string, options?: any): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${common_1.endOfLine}`;
96
+ }
97
+ if (definePropProposalB) {
98
+ yield `declare function defineProp<T>(value: T | (() => T), required?: boolean, rest?: any): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
99
+ yield `declare function defineProp<T>(value: T | (() => T) | undefined, required: true, rest?: any): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
100
+ yield `declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?: any): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${common_1.endOfLine}`;
101
+ }
102
+ ctx.scriptSetupGeneratedOffset = options.getGeneratedLength() - scriptSetupRanges.importSectionEndOffset;
103
+ let setupCodeModifies = [];
104
+ if (scriptSetupRanges.props.define && !scriptSetupRanges.props.name) {
105
+ const range = scriptSetupRanges.props.withDefaults ?? scriptSetupRanges.props.define;
106
+ const statement = scriptSetupRanges.props.define.statement;
107
+ if (statement.start === range.start && statement.end === range.end) {
108
+ setupCodeModifies.push([[`const __VLS_props = `], range.start, range.start]);
109
+ }
110
+ else {
111
+ setupCodeModifies.push([[
112
+ `const __VLS_props = `,
113
+ (0, common_1.generateSfcBlockSection)(scriptSetup, range.start, range.end, index_1.codeFeatures.all),
114
+ `${common_1.endOfLine}`,
115
+ (0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, range.start, index_1.codeFeatures.all),
116
+ `__VLS_props`,
117
+ ], statement.start, range.end]);
118
+ }
119
+ }
120
+ if (scriptSetupRanges.slots.define && !scriptSetupRanges.slots.name) {
121
+ setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
122
+ }
123
+ if (scriptSetupRanges.emits.define && !scriptSetupRanges.emits.name) {
124
+ setupCodeModifies.push([[`const __VLS_emit = `], scriptSetupRanges.emits.define.start, scriptSetupRanges.emits.define.start]);
125
+ }
126
+ if (scriptSetupRanges.expose.define) {
127
+ if (scriptSetupRanges.expose.define?.typeArg) {
128
+ setupCodeModifies.push([
129
+ [
130
+ `let __VLS_exposed!: `,
131
+ (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.expose.define.typeArg.start, scriptSetupRanges.expose.define.typeArg.end, index_1.codeFeatures.navigation),
132
+ `${common_1.endOfLine}`,
133
+ ],
134
+ scriptSetupRanges.expose.define.start,
135
+ scriptSetupRanges.expose.define.start,
136
+ ]);
137
+ }
138
+ else if (scriptSetupRanges.expose.define?.arg) {
139
+ setupCodeModifies.push([
140
+ [
141
+ `const __VLS_exposed = `,
142
+ (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.expose.define.arg.start, scriptSetupRanges.expose.define.arg.end, index_1.codeFeatures.navigation),
143
+ `${common_1.endOfLine}`,
144
+ ],
145
+ scriptSetupRanges.expose.define.start,
146
+ scriptSetupRanges.expose.define.start,
147
+ ]);
148
+ }
149
+ else {
150
+ setupCodeModifies.push([
151
+ [`const __VLS_exposed = {}${common_1.endOfLine}`],
152
+ scriptSetupRanges.expose.define.start,
153
+ scriptSetupRanges.expose.define.start,
154
+ ]);
155
+ }
156
+ }
157
+ setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
158
+ if (setupCodeModifies.length) {
159
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.importSectionEndOffset, setupCodeModifies[0][1], index_1.codeFeatures.all);
160
+ while (setupCodeModifies.length) {
161
+ const [codes, _start, end] = setupCodeModifies.shift();
162
+ for (const code of codes) {
163
+ yield code;
164
+ }
165
+ if (setupCodeModifies.length) {
166
+ const nextStart = setupCodeModifies[0][1];
167
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, end, nextStart, index_1.codeFeatures.all);
168
+ }
169
+ else {
170
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, end, scriptSetup.content.length, index_1.codeFeatures.all);
171
+ }
172
+ }
173
+ }
174
+ else {
175
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.importSectionEndOffset, scriptSetup.content.length, index_1.codeFeatures.all);
176
+ }
177
+ if (scriptSetupRanges.props.define?.typeArg && scriptSetupRanges.props.withDefaults?.arg) {
178
+ // fix https://github.com/vuejs/language-tools/issues/1187
179
+ yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
180
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.withDefaults.arg.start, scriptSetupRanges.props.withDefaults.arg.end, index_1.codeFeatures.navigation);
181
+ yield `)${common_1.endOfLine}`;
182
+ }
183
+ yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
184
+ yield* generateModelEmits(options, scriptSetup, scriptSetupRanges);
185
+ yield* (0, template_1.generateTemplate)(options, ctx);
186
+ if (syntax) {
187
+ if (!options.vueCompilerOptions.skipTemplateCodegen && (options.templateCodegen?.hasSlot || scriptSetupRanges?.slots.define)) {
188
+ yield `const __VLS_component = `;
189
+ yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
190
+ yield common_1.endOfLine;
191
+ yield `${syntax} `;
192
+ yield `{} as ${ctx.helperTypes.WithTemplateSlots.name}<typeof __VLS_component, ReturnType<typeof __VLS_template>>${common_1.endOfLine}`;
193
+ }
194
+ else {
195
+ yield `${syntax} `;
196
+ yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
197
+ yield common_1.endOfLine;
198
+ }
199
+ }
200
+ }
201
+ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors) {
202
+ if (scriptSetupRanges.props.define?.arg || scriptSetupRanges.emits.define) {
203
+ yield `const __VLS_fnComponent = `
204
+ + `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
205
+ if (scriptSetupRanges.props.define?.arg) {
206
+ yield ` props: `;
207
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, index_1.codeFeatures.navigation);
208
+ yield `,${common_1.newLine}`;
209
+ }
210
+ if (scriptSetupRanges.emits.define) {
211
+ yield ` emits: ({} as __VLS_NormalizeEmits<typeof `;
212
+ yield scriptSetupRanges.emits.name ?? '__VLS_emit';
213
+ yield `>),${common_1.newLine}`;
214
+ }
215
+ yield `})${common_1.endOfLine}`;
216
+ yield `let __VLS_functionalComponentProps!: `;
217
+ yield `${ctx.helperTypes.OmitKeepDiscriminatedUnion.name}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof typeof __VLS_publicProps>`;
218
+ yield common_1.endOfLine;
219
+ }
220
+ else {
221
+ yield `let __VLS_functionalComponentProps!: {}${common_1.endOfLine}`;
222
+ }
223
+ yield `let __VLS_publicProps!:${common_1.newLine}`
224
+ + ` import('${options.vueCompilerOptions.lib}').VNodeProps${common_1.newLine}`
225
+ + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps${common_1.newLine}`
226
+ + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps${common_1.endOfLine}`;
227
+ if (scriptSetupRanges.defineProp.length) {
228
+ yield `const __VLS_defaults = {${common_1.newLine}`;
229
+ for (const defineProp of scriptSetupRanges.defineProp) {
230
+ if (defineProp.defaultValue) {
231
+ if (defineProp.name) {
232
+ yield scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
233
+ }
234
+ else {
235
+ yield `modelValue`;
236
+ }
237
+ yield `: `;
238
+ yield scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end);
239
+ yield `,${common_1.newLine}`;
240
+ }
241
+ }
242
+ yield `}${common_1.endOfLine}`;
243
+ }
244
+ yield `let __VLS_componentProps!: `;
245
+ if (scriptSetupRanges.slots.define && options.vueCompilerOptions.jsxSlots) {
246
+ if (ctx.generatedPropsType) {
247
+ yield ` & `;
248
+ }
249
+ ctx.generatedPropsType = true;
250
+ yield `${ctx.helperTypes.PropsChildren.name}<typeof __VLS_slots>`;
251
+ }
252
+ if (scriptSetupRanges.defineProp.length) {
253
+ if (ctx.generatedPropsType) {
254
+ yield ` & `;
255
+ }
256
+ ctx.generatedPropsType = true;
257
+ yield `{${common_1.newLine}`;
258
+ for (const defineProp of scriptSetupRanges.defineProp) {
259
+ let propName = 'modelValue';
260
+ if (defineProp.name && defineProp.nameIsString) {
261
+ // renaming support
262
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, index_1.codeFeatures.navigation);
263
+ }
264
+ else if (defineProp.name) {
265
+ propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
266
+ definePropMirrors.set(propName, options.getGeneratedLength());
267
+ yield propName;
268
+ }
269
+ else {
270
+ yield propName;
271
+ }
272
+ yield defineProp.required
273
+ ? `: `
274
+ : `?: `;
275
+ if (defineProp.type) {
276
+ yield scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
277
+ }
278
+ else if (!defineProp.nameIsString) {
279
+ yield `NonNullable<typeof ${propName}['value']>`;
280
+ }
281
+ else if (defineProp.defaultValue) {
282
+ yield `typeof __VLS_defaults['${propName}']`;
283
+ }
284
+ else {
285
+ yield `any`;
286
+ }
287
+ yield `,${common_1.newLine}`;
288
+ if (defineProp.modifierType) {
289
+ let propModifierName = 'modelModifiers';
290
+ if (defineProp.name) {
291
+ propModifierName = `${scriptSetup.content.substring(defineProp.name.start + 1, defineProp.name.end - 1)}Modifiers`;
292
+ }
293
+ const modifierType = scriptSetup.content.substring(defineProp.modifierType.start, defineProp.modifierType.end);
294
+ definePropMirrors.set(propModifierName, options.getGeneratedLength());
295
+ yield `${propModifierName}?: Record<${modifierType}, true>,${common_1.endOfLine}`;
296
+ }
297
+ }
298
+ yield `}`;
299
+ }
300
+ if (scriptSetupRanges.props.define?.typeArg) {
301
+ if (ctx.generatedPropsType) {
302
+ yield ` & `;
303
+ }
304
+ ctx.generatedPropsType = true;
305
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end, index_1.codeFeatures.all);
306
+ }
307
+ if (!ctx.generatedPropsType) {
308
+ yield `{}`;
309
+ }
310
+ yield common_1.endOfLine;
311
+ }
312
+ function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
313
+ yield `let __VLS_modelEmitsType!: {}`;
314
+ if (scriptSetupRanges.defineProp.length) {
315
+ yield ` & ReturnType<typeof import('${options.vueCompilerOptions.lib}').defineEmits<{${common_1.newLine}`;
316
+ for (const defineProp of scriptSetupRanges.defineProp) {
317
+ if (!defineProp.isModel) {
318
+ continue;
319
+ }
320
+ let propName = 'modelValue';
321
+ if (defineProp.name) {
322
+ propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
323
+ propName = propName.replace(/['"]+/g, '');
324
+ }
325
+ yield `'update:${propName}': [${propName}:`;
326
+ if (defineProp.type) {
327
+ yield scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
328
+ }
329
+ else {
330
+ yield `any`;
331
+ }
332
+ yield `]${common_1.endOfLine}`;
333
+ }
334
+ yield `}>>`;
335
+ }
336
+ yield common_1.endOfLine;
337
+ }
338
+ //# sourceMappingURL=scriptSetup.js.map
@@ -0,0 +1,2 @@
1
+ import type { Code, Sfc } from '../../types';
2
+ export declare function generateSrc(script: NonNullable<Sfc['script']>, src: string): Generator<Code>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateSrc = void 0;
4
+ const common_1 = require("../common");
5
+ const index_1 = require("./index");
6
+ function* generateSrc(script, src) {
7
+ if (src.endsWith('.d.ts')) {
8
+ src = src.substring(0, src.length - '.d.ts'.length);
9
+ }
10
+ else if (src.endsWith('.ts')) {
11
+ src = src.substring(0, src.length - '.ts'.length);
12
+ }
13
+ else if (src.endsWith('.tsx')) {
14
+ src = src.substring(0, src.length - '.tsx'.length) + '.jsx';
15
+ }
16
+ if (!src.endsWith('.js') && !src.endsWith('.jsx')) {
17
+ src = src + '.js';
18
+ }
19
+ yield `export * from `;
20
+ yield [
21
+ `'${src}'`,
22
+ 'script',
23
+ script.srcOffset - 1,
24
+ {
25
+ ...index_1.codeFeatures.all,
26
+ navigation: src === script.src
27
+ ? true
28
+ : {
29
+ shouldRename: () => false,
30
+ resolveRenameEditText(newName) {
31
+ if (newName.endsWith('.jsx') || newName.endsWith('.js')) {
32
+ newName = newName.split('.').slice(0, -1).join('.');
33
+ }
34
+ if (script?.src?.endsWith('.d.ts')) {
35
+ newName = newName + '.d.ts';
36
+ }
37
+ else if (script?.src?.endsWith('.ts')) {
38
+ newName = newName + '.ts';
39
+ }
40
+ else if (script?.src?.endsWith('.tsx')) {
41
+ newName = newName + '.tsx';
42
+ }
43
+ return newName;
44
+ },
45
+ },
46
+ },
47
+ ];
48
+ yield common_1.endOfLine;
49
+ yield `export { default } from '${src}'${common_1.endOfLine}`;
50
+ }
51
+ exports.generateSrc = generateSrc;
52
+ //# sourceMappingURL=src.js.map
@@ -0,0 +1,5 @@
1
+ import type { Code } from '../../types';
2
+ import type { ScriptCodegenContext } from './context';
3
+ import { type ScriptCodegenOptions } from './index';
4
+ export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
5
+ export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTemplateUsageVars = exports.generateTemplate = void 0;
4
+ const shared_1 = require("../../utils/shared");
5
+ const common_1 = require("../common");
6
+ const context_1 = require("../template/context");
7
+ const interpolation_1 = require("../template/interpolation");
8
+ const index_1 = require("./index");
9
+ const internalComponent_1 = require("./internalComponent");
10
+ const common_2 = require("../common");
11
+ function* generateTemplate(options, ctx) {
12
+ ctx.generatedTemplate = true;
13
+ if (!options.vueCompilerOptions.skipTemplateCodegen) {
14
+ yield* generateExportOptions(options);
15
+ yield* generateConstNameOption(options);
16
+ yield `function __VLS_template() {${common_1.newLine}`;
17
+ const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)();
18
+ yield* generateTemplateContext(options, ctx, templateCodegenCtx);
19
+ yield `}${common_1.newLine}`;
20
+ yield* (0, internalComponent_1.generateInternalComponent)(options, ctx, templateCodegenCtx);
21
+ }
22
+ else {
23
+ yield `function __VLS_template() {${common_1.newLine}`;
24
+ const templateUsageVars = [...getTemplateUsageVars(options, ctx)];
25
+ yield `// @ts-ignore${common_1.newLine}`;
26
+ yield `[${templateUsageVars.join(', ')}]${common_1.newLine}`;
27
+ yield `return {}${common_1.endOfLine}`;
28
+ yield `}${common_1.newLine}`;
29
+ }
30
+ }
31
+ exports.generateTemplate = generateTemplate;
32
+ function* generateExportOptions(options) {
33
+ yield common_1.newLine;
34
+ yield `const __VLS_componentsOption = `;
35
+ if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
36
+ const componentsOption = options.scriptRanges.exportDefault.componentsOption;
37
+ yield [
38
+ options.sfc.script.content.substring(componentsOption.start, componentsOption.end),
39
+ 'script',
40
+ componentsOption.start,
41
+ index_1.codeFeatures.navigation,
42
+ ];
43
+ }
44
+ else {
45
+ yield `{}`;
46
+ }
47
+ yield common_1.endOfLine;
48
+ }
49
+ function* generateConstNameOption(options) {
50
+ yield common_1.newLine;
51
+ if (options.sfc.script && options.scriptRanges?.exportDefault?.nameOption) {
52
+ const nameOption = options.scriptRanges.exportDefault.nameOption;
53
+ yield `const __VLS_name = `;
54
+ yield `${options.sfc.script.content.substring(nameOption.start, nameOption.end)} as const`;
55
+ yield common_1.endOfLine;
56
+ }
57
+ else if (options.sfc.scriptSetup) {
58
+ yield `let __VLS_name!: '${options.fileBaseName.substring(0, options.fileBaseName.lastIndexOf('.'))}'${common_1.endOfLine}`;
59
+ }
60
+ else {
61
+ yield `const __VLS_name = undefined${common_1.endOfLine}`;
62
+ }
63
+ }
64
+ function* generateTemplateContext(options, ctx, templateCodegenCtx) {
65
+ const useGlobalThisTypeInCtx = options.fileBaseName.endsWith('.html');
66
+ yield `let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`;
67
+ yield `InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {${common_1.newLine}`;
68
+ /* CSS Module */
69
+ for (let i = 0; i < options.sfc.styles.length; i++) {
70
+ const style = options.sfc.styles[i];
71
+ if (style.module) {
72
+ yield `${style.module}: Record<string, string> & ${ctx.helperTypes.Prettify.name}<{}`;
73
+ for (const className of style.classNames) {
74
+ yield* generateCssClassProperty(i, className.text, className.offset, 'string', false, true);
75
+ }
76
+ yield `>${common_1.endOfLine}`;
77
+ }
78
+ }
79
+ yield `}${common_1.endOfLine}`;
80
+ /* Components */
81
+ yield `/* Components */${common_1.newLine}`;
82
+ yield `let __VLS_otherComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & typeof __VLS_componentsOption${common_1.endOfLine}`;
83
+ yield `let __VLS_own!: __VLS_SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & (new () => { ${(0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target)}: typeof ${options.scriptSetupRanges?.slots?.name ?? '__VLS_slots'} })>${common_1.endOfLine}`;
84
+ yield `let __VLS_localComponents!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>${common_1.endOfLine}`;
85
+ yield `let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents & typeof __VLS_ctx${common_1.endOfLine}`; // for html completion, TS references...
86
+ /* Style Scoped */
87
+ yield `/* Style Scoped */${common_1.newLine}`;
88
+ yield `type __VLS_StyleScopedClasses = {}`;
89
+ for (let i = 0; i < options.sfc.styles.length; i++) {
90
+ const style = options.sfc.styles[i];
91
+ const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses;
92
+ if (option === 'always' || (option === 'scoped' && style.scoped)) {
93
+ for (const className of style.classNames) {
94
+ yield* generateCssClassProperty(i, className.text, className.offset, 'boolean', true, !style.module);
95
+ }
96
+ }
97
+ }
98
+ yield common_1.endOfLine;
99
+ yield `let __VLS_styleScopedClasses!: __VLS_StyleScopedClasses | keyof __VLS_StyleScopedClasses | (keyof __VLS_StyleScopedClasses)[]${common_1.endOfLine}`;
100
+ yield `/* CSS variable injection */${common_1.newLine}`;
101
+ yield* generateCssVars(options, templateCodegenCtx);
102
+ yield `/* CSS variable injection end */${common_1.newLine}`;
103
+ if (options.templateCodegen) {
104
+ for (const code of options.templateCodegen.tsCodes) {
105
+ yield code;
106
+ }
107
+ }
108
+ else {
109
+ yield `// no template${common_1.newLine}`;
110
+ if (!options.scriptSetupRanges?.slots.define) {
111
+ yield `const __VLS_slots = {}${common_1.endOfLine}`;
112
+ }
113
+ }
114
+ yield `return ${options.scriptSetupRanges?.slots.name ?? '__VLS_slots'}${common_1.endOfLine}`;
115
+ }
116
+ function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propertyType, optional, referencesCodeLens) {
117
+ yield `${common_1.newLine} & { `;
118
+ yield [
119
+ '',
120
+ 'style_' + styleIndex,
121
+ offset,
122
+ referencesCodeLens
123
+ ? index_1.codeFeatures.navigation
124
+ : index_1.codeFeatures.referencesCodeLens,
125
+ ];
126
+ yield `'`;
127
+ yield [
128
+ '',
129
+ 'style_' + styleIndex,
130
+ offset,
131
+ index_1.codeFeatures.cssClassNavigation,
132
+ ];
133
+ yield [
134
+ classNameWithDot.substring(1),
135
+ 'style_' + styleIndex,
136
+ offset + 1,
137
+ common_2.combineLastMapping,
138
+ ];
139
+ yield `'`;
140
+ yield [
141
+ '',
142
+ 'style_' + styleIndex,
143
+ offset + classNameWithDot.length,
144
+ index_1.codeFeatures.none,
145
+ ];
146
+ yield `${optional ? '?' : ''}: ${propertyType}`;
147
+ yield ` }`;
148
+ }
149
+ function* generateCssVars(options, ctx) {
150
+ for (const style of options.sfc.styles) {
151
+ for (const cssBind of style.cssVars) {
152
+ for (const [segment, offset, onlyError] of (0, interpolation_1.forEachInterpolationSegment)(options.ts, options.vueCompilerOptions, ctx, cssBind.text, cssBind.offset, options.ts.createSourceFile('/a.txt', cssBind.text, 99))) {
153
+ if (offset === undefined) {
154
+ yield segment;
155
+ }
156
+ else {
157
+ yield [
158
+ segment,
159
+ style.name,
160
+ cssBind.offset + offset,
161
+ onlyError
162
+ ? index_1.codeFeatures.navigation
163
+ : index_1.codeFeatures.all,
164
+ ];
165
+ }
166
+ }
167
+ yield common_1.endOfLine;
168
+ }
169
+ }
170
+ }
171
+ function getTemplateUsageVars(options, ctx) {
172
+ const usageVars = new Set();
173
+ const components = new Set(options.sfc.template?.ast?.components);
174
+ if (options.templateCodegen) {
175
+ // fix import components unused report
176
+ for (const varName of ctx.bindingNames) {
177
+ if (components.has(varName) || components.has((0, shared_1.hyphenateTag)(varName))) {
178
+ usageVars.add(varName);
179
+ }
180
+ }
181
+ for (const component of components) {
182
+ if (component.indexOf('.') >= 0) {
183
+ usageVars.add(component.split('.')[0]);
184
+ }
185
+ }
186
+ for (const [varName] of options.templateCodegen.ctx.accessGlobalVariables) {
187
+ usageVars.add(varName);
188
+ }
189
+ }
190
+ return usageVars;
191
+ }
192
+ exports.getTemplateUsageVars = getTemplateUsageVars;
193
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1,2 @@
1
+ import type { Code, VueCodeInformation } from '../../types';
2
+ export declare function generateCamelized(code: string, offset: number, info: VueCodeInformation): Generator<Code>;